Detect geo of server.

Using geolite2, we attempt to detect the continent of the server
and store the 'continent code' in the serverlist. This is reasonably
broad enough to help players in the client find truly "nearby" server.

The client will have to be changed to select a continent to change
ordering or filtering.
This commit is contained in:
Auke Kok 2019-03-02 12:56:21 -08:00 committed by sfan5
parent ac66259801
commit 772fc29cb8
2 changed files with 14 additions and 1 deletions

View File

@ -1,2 +1,2 @@
Flask>=0.10
maxminddb-geolite2>=2018.703

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import os, re, sys, json, time, socket
from threading import Thread, RLock
from geolite2 import geolite2
from flask import Flask, request, send_from_directory
@ -277,6 +278,18 @@ def asyncFinishThread(server):
% (server["ip"], server["address"], addresses))
return
reader = geolite2.reader()
try:
geo = reader.get(server["ip"])
except geoip2.errors.GeoIP2Error:
app.logger.warning("GeoIP lookup failure for %s." % (server["address"],))
if "continent" in geo and "code" in geo["continent"]:
server["geo_continent"] = geo["continent"]["code"]
else:
app.logger.warning("Unable to get GeoIP Continent data for %s."
% (server["address"],))
server["ping"] = serverUp(info[0])
if not server["ping"]:
app.logger.warning("Server %s:%d has no ping."