return flg_supported\r
\r
\r
-def is_verified_request(request):\r
+def verify_request(request):\r
(idfp, status) = d0_blind_id_verify(\r
sig=request.headers['X-D0-Blind-Id-Detached-Signature'],\r
querystring='',\r
\r
log.debug('\nidfp: {0}\nstatus: {1}'.format(idfp, status))\r
\r
- if idfp != None:\r
- return True\r
- else:\r
- return False\r
+ return (idfp, status)\r
\r
\r
def has_minimum_real_players(player_events):\r
session.add(player)\r
\r
\r
-def get_or_create_server(session=None, name=None):\r
+def get_or_create_server(session=None, name=None, hashkey=None):\r
"""\r
Find a server by name or create one if not found. Parameters:\r
\r
session - SQLAlchemy database session factory\r
name - server name of the server to be found or created\r
+ hashkey - server hashkey\r
"""\r
+ # see if the server is already in the database\r
+ # if not, create one and the hashkey along with it\r
try:\r
- # find one by that name, if it exists\r
- server = session.query(Server).filter_by(name=name).one()\r
- log.debug("Found server id {0}: {1}".format(\r
- server.server_id, server.name.encode('utf-8')))\r
- except NoResultFound, e:\r
- server = Server(name=name)\r
+ hashkey = session.query(ServerHashkey).filter_by(\r
+ hashkey=hashkey).one()\r
+ server = session.query(Server).filter_by(\r
+ server_id=hashkey.server_id).one()\r
+ log.debug("Found existing server {0} with hashkey {1}".format(\r
+ server.server_id, hashkey.hashkey))\r
+ except:\r
+ server = Server()\r
+ server.name = name\r
session.add(server)\r
session.flush()\r
- log.debug("Created server id {0}: {1}".format(\r
- server.server_id, server.name.encode('utf-8')))\r
- except MultipleResultsFound, e:\r
- # multiple found, so use the first one but warn\r
- log.debug(e)\r
- servers = session.query(Server).filter_by(name=name).order_by(\r
- Server.server_id).all()\r
- server = servers[0]\r
- log.debug("Created server id {0}: {1} but found \\r
- multiple".format(\r
- server.server_id, server.name.encode('utf-8')))\r
+\r
+ hashkey = ServerHashkey(server_id=server.server_id, \r
+ hashkey=hashkey)\r
+ session.add(hashkey)\r
+ log.debug("Created server {0} with hashkey {1}".format(\r
+ server.server_id, hashkey.hashkey))\r
\r
return server\r
\r
+\r
def get_or_create_map(session=None, name=None):\r
"""\r
Find a map by name or create one if not found. Parameters:\r
Entry handler for POST stats submissions.\r
"""\r
try:\r
- if not is_verified_request(request):\r
+ (idfp, status) = verify_request(request)\r
+ if not idfp:\r
raise Exception("Request is not verified.")\r
\r
session = DBSession()\r
raise Exception("The number of real players is below the minimum. "\\r
"Stats will be ignored.")\r
\r
- server = get_or_create_server(session=session, name=game_meta['S'])\r
+ server = get_or_create_server(session=session, hashkey=idfp, \r
+ name=game_meta['S'])\r
+\r
gmap = get_or_create_map(session=session, name=game_meta['M'])\r
\r
game = create_game(session=session, \r