\r
log = logging.getLogger(__name__)\r
\r
+def get_remote_addr(request):\r
+ """Get the Xonotic server's IP address"""\r
+ if 'X-Server-IP' in request.headers:\r
+ return request.headers['X-Server-IP']\r
+ else:\r
+ return request.remote_addr\r
+\r
+\r
def is_supported_gametype(gametype):\r
"""Whether a gametype is supported or not"""\r
flg_supported = True\r
session.add(player)\r
\r
\r
-def get_or_create_server(session=None, name=None, hashkey=None):\r
+def get_or_create_server(session=None, name=None, hashkey=None, ip_addr=None,\r
+ revision=None):\r
"""\r
Find a server by name or create one if not found. Parameters:\r
\r
server.hashkey = hashkey\r
session.add(server)\r
\r
+ # store new IP address\r
+ if server.ip_addr != ip_addr:\r
+ server.ip_addr = ip_addr\r
+ session.add(server)\r
+\r
+ # store new revision\r
+ if server.revision != revision:\r
+ server.revision = revision\r
+ session.add(server)\r
+\r
log.debug("Found existing server {0}".format(server.server_id))\r
\r
except MultipleResultsFound, e:\r
if not idfp:\r
raise pyramid.httpexceptions.HTTPUnauthorized\r
\r
+ log.debug('Remote address:')\r
+ log.debug(get_remote_addr(request))\r
+\r
(game_meta, players) = parse_body(request) \r
\r
if not has_required_metadata(game_meta):\r
raise pyramid.httpexceptions.HTTPOk\r
\r
server = get_or_create_server(session=session, hashkey=idfp, \r
- name=game_meta['S'])\r
+ name=game_meta['S'], revision=game_meta['R'],\r
+ ip_addr=get_remote_addr(request))\r
\r
gmap = get_or_create_map(session=session, name=game_meta['M'])\r
log.debug(gmap)\r