Country IP Blocking system for Gunz

Status
Not open for further replies.
Experienced Elementalist
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:
Or directly here:

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 will have 2 options.

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.
The program will process all the data and generate the SQL file.

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:

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.....
For option b, excecute a query like this:
Code:
UPDATE CustomIP SET IsBlock = 0
UPDATE CustomIP Set IsBlock = 1 WHERE CountryCode3 = FIRST_COUNTRY, OR CountryCode3 = SECOND_COUNTRY OR CountryCode3 = THIRD_COUNTRY.....
In FIRST_COUNTRY, SECOND_COUNTRY, etc you have to write the CountryCode3 of that country.

To get what countrycode3 has every country, look at here:


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'
6-
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:
Re: [Release] Country IP Blocking system for Gunz

Great Release
Usefull information for alot of people. Stickied.

Edit: The insert of the custom ip's need an columed named ID in the table. After making that query completed in 7:59 :D
 
Re: [Release] Country IP Blocking system for Gunz

Awesome release, but I need time to consume every instruction above, xD

EDIT - I've come across this warning.


Warning! The maximum key length is 900 bytes. The index 'IX_IPtoCountryCode_IPRange_060612' has maximum length of 24000 bytes. For some combination of large values, the insert/update operation will fail.
Warning: The maximum length of the row exceeds the permissible limit of 8060 bytes. For some combination of large values, the insert/update operation will fail.

Will it give a huge affect?
 
Last edited:
Re: [Release] Country IP Blocking system for Gunz

I have tested the ip filter, but i cant login any more.
this is the error i get:
Code:
MMatchServer::CheckIsNonBlockCountry - add new IPtoCountry(f:0, t0, c:) fail.
Any idea's?
 
Re: [Release] Country IP Blocking system for Gunz

I have tested the ip filter, but i cant login any more.
this is the error i get:
Code:
MMatchServer::CheckIsNonBlockCountry - add new IPtoCountry(f:0, t0, c:) fail.
Any idea's?

Is the server at the same computer you are trying to connect with the client?
Or even in a local area network

I think that 127.0.0.1 and 192.x.x.x are not at customip table.

Try excecuting this query for adding the 127.0.0.1 and 192.168.*.* to customip:

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())
 
Re: [Release] Country IP Blocking system for Gunz

If you know about a better IP To Country database I can create a converter for it.

I know there are better databases but they are not free.

So if you know about a better free IP To country database, or you want to share a not free database, answer at this thread or send it to me by PM

Thank you.
 
Re: [Release] Country IP Blocking system for Gunz

Nice man, But i think private servers want a lot of players in ur server and accept players of others countries.
 
Re: [Release] Country IP Blocking system for Gunz

Is the server at the same computer you are trying to connect with the client?
Or even in a local area network

I think that 127.0.0.1 and 192.x.x.x are not at customip table.

Try excecuting this query for adding the 127.0.0.1 and 192.168.*.* to customip:

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())

Works fine now, THANKS
 
Re: [Release] Country IP Blocking system for Gunz

I get the same error as 7-Eleven. Yupp. Hmm. I guess I'll do without this for a while.
 
Status
Not open for further replies.
Back