Skip to content

Commit

Permalink
Detect geo of server.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sofar authored and sfan5 committed Jul 17, 2019
1 parent ac66259 commit 772fc29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,2 +1,2 @@
Flask>=0.10

maxminddb-geolite2>=2018.703
13 changes: 13 additions & 0 deletions server.py
@@ -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

Expand Down Expand Up @@ -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."
Expand Down

0 comments on commit 772fc29

Please sign in to comment.