Update GeoIP2 extension to new GeoLite2 .mmdb database format (#1245)

* Add support for Maxmind GeoIP2 database files (#913).

* Copy/paste error.

* Mark GeoipCode3 as deprecated.

* Fix build when compiling with AMBuild.

* Replace loose libmaxminddb files with submodule.

* Fix Linux build.

* One more hack for submodule.

* Actually fix Linux build.

* GeoIP2 extension to sourcemod

* Update basevotes

When a player leaves during a voteban, he will be banned anyway. Also added a cvar with a ban time setting.

* Update basevotes.sp

* Update AMBuilder

* ke::AString to std::string

* Update extension.cpp

* Update AMBuilder

* Added coordination natives

Added GeoipLatitude, GeoipLongitude, GeoipDistance natives.

* Create osdefs.h

* Update maxminddb_config.h

* Update extension.cpp

* Update extension.cpp

* Added automatic search for database file

* Fix automatic search for database file

* Update extension.cpp

* Update geoip.inc

* .gitmodules revert

* Update geoip.inc

* Update libmaxminddb to version 1.5.2

* Update extension.cpp

* Check language in the DB

* Removed langCount variable

* Determination of the client's language

* Update geoip.inc

* Update geoip.inc

* Update extension.cpp

* Update geoip.inc

* Update extension.cpp

* space instead of tab in .inc

* Update extension.cpp

* Update geoip.inc

* Optimizing length measurement region code

* Update package script to fetch the new GeoLite2 database

This package is the last CC-BY-SA licensed GeoLite2-City database extracted from https://src.fedoraproject.org/rpms/geolite2 from december 2019.

This doubles the download size for SM packages, but it's what we have to deal with atm :(

* Fix potentially returning uninitialized memory in GeoipRegionCode

If the lookup failed, we'd copy back whatever is on the stack in the ccode buffer.

Co-authored-by: Nick Hastings <[email protected]>
Co-authored-by: Headline <[email protected]>
Co-authored-by: Accelerator74 <[email protected]>
Co-authored-by: Peace-Maker <[email protected]>
This commit is contained in:
Accelerator
2021-06-30 13:01:12 +02:00
committed by GitHub
co-authored by Nick Hastings Headline Accelerator74 Peace-Maker
parent c38d45b9e7
commit b0563a493c
17 changed files with 3530 additions and 1212 deletions
+7 -37
View File
@@ -3,11 +3,10 @@
use strict;
use Cwd;
use File::Basename;
use File::Copy;
use File::stat;
use File::Temp qw/ tempfile :seekable/;
use Net::FTP;
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
use Time::localtime;
my ($ftp_file, $ftp_host, $ftp_user, $ftp_pass, $ftp_path, $tag);
@@ -55,48 +54,19 @@ while (my $ln = <$fh>) {
}
close($fh);
my $needNewGeoIP = 1;
if (-e '../GeoIP.dat.gz')
unless (-e '../GeoLite2-City_20191217.tar.gz')
{
my $stats = stat('../GeoIP.dat.gz');
if ($stats->size != 0)
{
my $fileModifiedTime = $stats->mtime;
my $fileModifiedMonth = localtime($fileModifiedTime)->mon;
my $currentMonth = localtime->mon;
my $thirtyOneDays = 60 * 60 * 24 * 31;
# GeoIP file only updates once per month
if ($currentMonth == $fileModifiedMonth || (time() - $fileModifiedTime) < $thirtyOneDays)
{
$needNewGeoIP = 0;
}
}
}
if ($needNewGeoIP)
{
print "Downloading GeoIP.dat...\n";
print "Downloading GeoLite2-City.mmdb...\n";
# Don't check certificate. It will fail on the slaves and we're resolving to internal addressing anyway
system('wget --no-check-certificate -q -O ../GeoIP.dat.gz https://sm.alliedmods.net/GeoIP.dat.gz');
system('wget --no-check-certificate -q -O ../GeoLite2-City_20191217.tar.gz https://sm.alliedmods.net/GeoLite2-City_20191217.tar.gz');
system('tar -C ../ -xzf GeoLite2-City_20191217.tar.gz');
copy('../GeoLite2-City_20191217/GeoLite2-City.mmdb', 'addons/sourcemod/configs/geoip/GeoLite2-City.mmdb');
}
else
{
print "Reusing existing GeoIP.dat\n";
print "Reusing existing GeoLite2-City.mmdb\n";
}
my $geoIPfile = 'addons/sourcemod/configs/geoip/GeoIP.dat';
if (-e $geoIPfile) {
unlink($geoIPfile);
}
open(my $fh, ">", $geoIPfile)
or die "cannot open $geoIPfile for writing: $!";
binmode($fh);
gunzip '../GeoIP.dat.gz' => $fh
or die "gunzip failed: $GunzipError\n";
close($fh);
my ($version);
$version = Build::ProductVersion(Build::PathFormat('../../build/product.version'));