if 'T' not in metadata or\\r
'G' not in metadata or\\r
'M' not in metadata or\\r
+ 'I' not in metadata or\\r
'S' not in metadata:\r
flg_has_req_metadata = False\r
\r
\r
\r
def create_game(session=None, start_dt=None, game_type_cd=None, \r
- server_id=None, map_id=None, winner=None):\r
+ server_id=None, map_id=None, winner=None, match_id=None):\r
"""\r
Creates a game. Parameters:\r
\r
game_id = session.execute(seq)\r
game = Game(game_id=game_id, start_dt=start_dt, game_type_cd=game_type_cd,\r
server_id=server_id, map_id=map_id, winner=winner)\r
- session.add(game)\r
- log.debug("Created game id {0} on server {1}, map {2} at \\r
- {3}".format(game.game_id, \r
- server_id, map_id, start_dt))\r
+ game.match_id = match_id\r
+\r
+ try:\r
+ session.query(Game).filter(Game.server_id==server_id).\\r
+ filter(Game.match_id==match_id).one()\r
+ # if a game under the same server and match_id found, \r
+ # this is a duplicate game and can be ignored\r
+ raise pyramid.httpexceptions.HTTPOk\r
+ except NoResultFound, e:\r
+ # server_id/match_id combination not found. game is ok to insert\r
+ session.add(game)\r
+ log.debug("Created game id {0} on server {1}, map {2} at \\r
+ {3}".format(game.game_id, \r
+ server_id, map_id, start_dt))\r
\r
return game\r
\r
if key in 'S' 'n':\r
value = unicode(value, 'utf-8')\r
\r
- if key in 'V' 'T' 'G' 'M' 'S' 'C' 'R' 'W':\r
+ if key in 'V' 'T' 'G' 'M' 'S' 'C' 'R' 'W' 'I':\r
game_meta[key] = value\r
\r
if key == 'P':\r
start_dt=datetime.datetime(\r
*time.gmtime(float(game_meta['T']))[:6]), \r
server_id=server.server_id, game_type_cd=game_meta['G'], \r
- map_id=gmap.map_id)\r
+ map_id=gmap.map_id, match_id=game_meta['I'])\r
log.debug(gmap)\r
\r
# find or create a record for each player\r