"""\r
flg_has_min_real_players = True\r
\r
- try: \r
+ try:\r
minimum_required_players = int(\r
settings['xonstat.minimum_required_players'])\r
except:\r
\r
return flg_has_req_metadata\r
\r
- \r
+\r
def is_real_player(events):\r
"""\r
Determines if a given set of player events correspond with a player who\r
- \r
+\r
1) is not a bot (P event does not look like a bot)\r
2) played in the game (matches 1)\r
3) was present at the end of the game (scoreboardvalid 1)\r
# see if that nick already exists\r
stripped_nick = strip_colors(player.nick)\r
try:\r
- player_nick = session.query(PlayerNick).filter_by(\r
- player_id=player.player_id, stripped_nick=stripped_nick).one()\r
+ player_nick = session.query(PlayerNick).filter_by(\r
+ player_id=player.player_id, stripped_nick=stripped_nick).one()\r
except NoResultFound, e:\r
- # player_id/stripped_nick not found, create one\r
+ # player_id/stripped_nick not found, create one\r
# but we don't store "Anonymous Player #N"\r
if not re.search('^Anonymous Player #\d+$', player.nick):\r
player_nick = PlayerNick()\r
# see if the player is already in the database\r
# if not, create one and the hashkey along with it\r
try:\r
- hashkey = session.query(Hashkey).filter_by(\r
+ hk = session.query(Hashkey).filter_by(\r
hashkey=hashkey).one()\r
player = session.query(Player).filter_by(\r
- player_id=hashkey.player_id).one()\r
+ player_id=hk.player_id).one()\r
log.debug("Found existing player {0} with hashkey {1}".format(\r
- player.player_id, hashkey.hashkey))\r
+ player.player_id, hashkey))\r
except:\r
player = Player()\r
session.add(player)\r
session.flush()\r
\r
- # if nick is given to us, use it. If not, use "Anonymous Player"\r
- # with a suffix added for uniqueness.\r
- if nick:\r
- player.nick = nick[:128]\r
- player.stripped_nick = strip_colors(nick[:128])\r
- else:\r
- player.nick = "Anonymous Player #{0}".format(player.player_id)\r
- player.stripped_nick = player.nick\r
+ # if nick is given to us, use it. If not, use "Anonymous Player"\r
+ # with a suffix added for uniqueness.\r
+ if nick:\r
+ player.nick = nick[:128]\r
+ player.stripped_nick = strip_colors(nick[:128])\r
+ else:\r
+ player.nick = "Anonymous Player #{0}".format(player.player_id)\r
+ player.stripped_nick = player.nick\r
\r
- hashkey = Hashkey(player_id=player.player_id, hashkey=hashkey)\r
- session.add(hashkey)\r
- log.debug("Created player {0} ({2}) with hashkey {1}".format(\r
- player.player_id, hashkey.hashkey, player.nick.encode('utf-8')))\r
+ hk = Hashkey(player_id=player.player_id, hashkey=hashkey)\r
+ session.add(hk)\r
+ log.debug("Created player {0} ({2}) with hashkey {1}".format(\r
+ player.player_id, hashkey, player.nick.encode('utf-8')))\r
\r
return player\r
\r
pwstat.frags = int(round(float(\r
player_events['acc-' + weapon_cd + '-frags'])))\r
\r
- log.debug(pwstat)\r
session.add(pwstat)\r
- log.debug(pwstat)\r
pwstats.append(pwstat)\r
\r
return pwstats\r
player_events = {}\r
current_team = None\r
players = []\r
- \r
- log.debug("----- BEGIN REQUEST BODY -----")\r
- log.debug(request.body)\r
- log.debug("----- END REQUEST BODY -----")\r
\r
for line in request.body.split('\n'):\r
try:\r
# We convert to UTF-8.\r
if key in 'S' 'n':\r
value = unicode(value, 'utf-8')\r
- \r
+\r
if key in 'V' 'T' 'G' 'M' 'S' 'C' 'R' 'W':\r
game_meta[key] = value\r
\r
if len(player_events) != 0:\r
players.append(player_events)\r
player_events = {}\r
- \r
+\r
player_events[key] = value\r
\r
if key == 'e':\r
except:\r
# no key/value pair - move on to the next line\r
pass\r
- \r
+\r
# add the last player we were working on\r
if len(player_events) > 0:\r
players.append(player_events)\r
create_player_weapon_stats(session=session, \r
player=player, game=game, pgstat=pgstat,\r
player_events=player_events)\r
- \r
+\r
\r
def stats_submit(request):\r
"""\r
try:\r
session = DBSession()\r
\r
+ log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body +\r
+ "----- END REQUEST BODY -----\n\n")\r
+\r
(idfp, status) = verify_request(request)\r
if not idfp:\r
raise pyramid.httpexceptions.HTTPUnauthorized\r
- \r
+\r
(game_meta, players) = parse_body(request) \r
- \r
+\r
if not has_required_metadata(game_meta):\r
log.debug("Required game meta fields missing. "\\r
"Can't continue.")\r
raise pyramid.exceptions.HTTPUnprocessableEntity\r
- \r
+\r
if not is_supported_gametype(game_meta['G']):\r
raise pyramid.httpexceptions.HTTPOk\r
- \r
+\r
if not has_minimum_real_players(request.registry.settings, players):\r
log.debug("The number of real players is below the minimum. " + \r
"Stats will be ignored.")\r
raise pyramid.httpexceptions.HTTPOk\r
- \r
+\r
server = get_or_create_server(session=session, hashkey=idfp, \r
name=game_meta['S'])\r
- \r
+\r
gmap = get_or_create_map(session=session, name=game_meta['M'])\r
log.debug(gmap)\r
- \r
+\r
game = create_game(session=session, \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
log.debug(gmap)\r
- \r
+\r
# find or create a record for each player\r
# and add stats for each if they were present at the end\r
# of the game\r
nick = player_events['n']\r
else:\r
nick = None\r
- \r
+\r
if 'matches' in player_events and 'scoreboardvalid' \\r
in player_events:\r
player = get_or_create_player(session=session, \r
log.debug('Creating stats for %s' % player_events['P'])\r
create_player_stats(session=session, player=player, game=game, \r
player_events=player_events)\r
- \r
+\r
session.commit()\r
log.debug('Success! Stats recorded.')\r
return Response('200 OK')\r