- Joined
- Mar 16, 2006
- Messages
- 238
- Reaction score
- 112
Country IP Blocking System
Introduction:
I have researched and designed a system for Gunz that denies the access to your server for people from selected countries.
It works like in some official servers, when you open gunz, you will get a messagebox telling you that people from your country can't access to the server. And then if they try to connect, connection will be rejected.
Purpose of this development:
If you make a server destinated only for people from your country or region, you can prevent from getting people from other countries that you don't want.
Overview of the System:
This works with the original functions that locator and matchserver have to block countries.
It uses 4 sql tables that come with the official DB, some procedures and 2 functions.
I have created a program in C++ that takes a IP_To_Country CSV database (you can get it for free), and formats it into MSSQL queries that will work with your Gunz Database.
Then you only have to excecute that SQL file, configure some things, and all will be working.
Installation:
1-
First, you need to download the ip_to_country CSV database.
You can get it from here:
To view the content, you need to sign in or register
Or directly here:
To view the content, you need to sign in or register
This database is free and it's updated once a month.
You must use only this database, any other ip to country database will not work with my program.
2-
Download GunzCountryDB.rar from the attachment (It's the program that converts the CSV database to the MSSQL queries).
3-
- Decompress both files IN THE SAME FOLDER
- Open GunzCountryDB.exe
You must select option 1 if it's the first time you are using this or something went wrong and you want to reinstall the requiered tables, procedures and functions.
You can select option 2 ONLY if you want to update the Ip To Country database because you downloaded a new one.
To select an option, just type the number and press enter.
- Then you will prompted to write the IP_To_Country CSV file name, you should write for example ip_to_country.csv (the file must be at the same folder where you are excecuting the program).
- After that you have to write the destination file name, it may have a .sql extension, if the file doesn't exists, it will be created automatically, if it exists, it will be deleted and re-created.
NOTE: If you had any problem with the program, you can download the SQL files generated with the latest ip-to-country.csv Database
There you have ipcountry_mode1.sql and ipcountry_mode2.sql, so mode1 and two mean the mode used in the program to generate them.
Generated with the CSV File created at October 2008
Download:
To view the content, you need to sign in or register
4-
Now you have to excecute the SQL file in your Gunz Database.
So open your SQL Manager, I recommend EMS SQL Manager, but you can also use Microsoft SQL Server Management Studio.
Then load the sql file and excecute it to your Gunz DB.
NOTE: It will take LONG to excecute, it will take like 10 minutes to excecute. (Taked 9 minutes in my Core 2 Duo E6550, 2 GB Ram Computer)
NOTE 2: If you want to be able to connect from 127.0.0.1 (Gunz Client and Server in the same computer) or from 192.168.*.* (Gunz Server in LAN) you must execute this query after excecuting the other script:
Code:
INSERT INTO CustomIP (ID, IPFrom, IPTo, IsBlock, CountryCode3, comment, RegDate)
(SELECT 90000, 2130706433, 2130706433, 0, '', 'IP Blocked', GETDATE())
UNION ALL
(SELECT 90001, 3232235521, 3232301055, 0, '', 'IP Blocked', GETDATE())
5-
Now you have to configure what countries you want to allow in your server and what countries you don't want.
To block a country you have to set the column IsBlock to 1 to the countries you don't want at the table CustomIP.
You have 2 ways to do this.
a- Blocking all countries and then allowing the countries you want to access to your server.
b- Allowing all countries and blocking the countries you don't want to access your server.
This depends in the number of countries that you will block.
If you only want 1 or little countries to access your server use option a
If you want almost all the countries to access and to block a few, use option b.
So you should use the CountryCode3 of the countries to set IsBlock in CustomIP.
For option a, excecute a query like this:
Code:
UPDATE CustomIP SET IsBlock = 1
UPDATE CustomIP Set IsBlock = 0 WHERE CountryCode3 = FIRST_COUNTRY, OR CountryCode3 = SECOND_COUNTRY OR CountryCode3 = THIRD_COUNTRY.....
Code:
UPDATE CustomIP SET IsBlock = 0
UPDATE CustomIP Set IsBlock = 1 WHERE CountryCode3 = FIRST_COUNTRY, OR CountryCode3 = SECOND_COUNTRY OR CountryCode3 = THIRD_COUNTRY.....
To get what countrycode3 has every country, look at here:
To view the content, you need to sign in or register
Or you can also see what country code has every country at the table CountryCode.
In that table you have 2 columns, the first one has the country code 3, and the second the country name.
After Setting IsBlock in CustomIP, do the same but in the table BlockCountryCode, use the same queries you used before, but with BlockCountryCode as table name.
NOTE:
In BlockCountryCode you should leave the first row (That one with empty CountryCode3) with 0 in IsBlock, because if the country of someone is not detected, the system will return that empty countrycode3 and you should allow that people to access.
NOTE 2:
If you look at the table CustomIP the column comment has set this for all the rows: You are not allowed access from your country
That message will be displayed when someone from a blocked country tries to connect to your server.
You can change it by excecuting:
Code:
UPDATE CustomIP SET comment = 'NEW_MESSAGE'
It's almost done.
The last thing you have to do, is to activate the system at your locator and matchserver.
So open the Locator.ini from your locator,
search for the line:
USE_COUNTRY_CODE_FILTER="no"
Change it to:
USE_COUNTRY_CODE_FILTER="yes"
Then open Server.ini from you matchserver,
search for:
[FILTER]
USE="0"
ACCEPT_INVALID_IP="0"
Change it to:
[FILTER]
USE="1"
ACCEPT_INVALID_IP="0"
Now you only have to restart your locator and matchserver.
If you want to deactivate the country restriction, you only have to set Locator.ini and Matchserver.ini with the configurations you had before.
After doing all that, it's all done!
I hope you like this system.
If you have any problem with this or to make any comment, post at this thread.
Thank You
Attachments
Last edited: