return not (submission.human_nonzero_score and submission.human_fired_weapon)
-def get_remote_addr(request):
- """Get the Xonotic server's IP address"""
- if 'X-Forwarded-For' in request.headers:
- return request.headers['X-Forwarded-For']
- else:
- return request.remote_addr
+def has_required_metadata(submission):
+ """Determines if a submission has all the required metadata fields."""
+ return (submission.game_type_cd is not None
+ and submission.map_name is not None
+ and submission.match_id is not None
+ and submission.server_name is not None)
-def is_supported_gametype(gametype, version):
- """Whether a gametype is supported or not"""
- is_supported = False
+def is_supported_gametype(submission):
+ """Determines if a submission is of a valid and supported game type."""
# if the type can be supported, but with version constraints, uncomment
# here and add the restriction for a specific version below
'tdm',
)
- if gametype in supported_game_types:
- is_supported = True
- else:
- is_supported = False
+ is_supported = submission.game_type_cd in supported_game_types
# some game types were buggy before revisions, thus this additional filter
- if gametype == 'ca' and version <= 5:
+ if submission.game_type_cd == 'ca' and submission.version <= 5:
is_supported = False
return is_supported
-def do_precondition_checks(request, game_meta, raw_players):
- """Precondition checks for ALL gametypes.
- These do not require a database connection."""
- if not has_required_metadata(game_meta):
+def has_minimum_real_players(settings, submission):
+ """
+ Determines if the submission has enough human players to store in the database. The minimum
+ setting comes from the config file under the setting xonstat.minimum_real_players.
+ """
+ try:
+ minimum_required_players = int(settings.get("xonstat.minimum_required_players"))
+ except:
+ minimum_required_players = 2
+
+ return len(submission.human_players) >= minimum_required_players
+
+
+def do_precondition_checks(settings, submission):
+ """Precondition checks for ALL gametypes. These do not require a database connection."""
+ if not has_required_metadata(submission):
msg = "Missing required game metadata"
log.debug(msg)
raise pyramid.httpexceptions.HTTPUnprocessableEntity(
content_type="text/plain"
)
- try:
- version = int(game_meta['V'])
- except:
+ if submission.version is None:
msg = "Invalid or incorrect game metadata provided"
log.debug(msg)
raise pyramid.httpexceptions.HTTPUnprocessableEntity(
content_type="text/plain"
)
- if not is_supported_gametype(game_meta['G'], version):
- msg = "Unsupported game type ({})".format(game_meta['G'])
+ if not is_supported_gametype(submission):
+ msg = "Unsupported game type ({})".format(submission.game_type_cd)
log.debug(msg)
raise pyramid.httpexceptions.HTTPOk(
body=msg,
content_type="text/plain"
)
- if not has_minimum_real_players(request.registry.settings, raw_players):
+ if not has_minimum_real_players(settings, submission):
msg = "Not enough real players"
log.debug(msg)
raise pyramid.httpexceptions.HTTPOk(
content_type="text/plain"
)
- if is_blank_game(game_meta['G'], raw_players):
+ if is_blank_game(submission):
msg = "Blank game"
log.debug(msg)
raise pyramid.httpexceptions.HTTPOk(
)
+def get_remote_addr(request):
+ """Get the Xonotic server's IP address"""
+ if 'X-Forwarded-For' in request.headers:
+ return request.headers['X-Forwarded-For']
+ else:
+ return request.remote_addr
+
+
def num_real_players(player_events):
"""
Returns the number of real players (those who played
return real_players
-def has_minimum_real_players(settings, player_events):
- """
- Determines if the collection of player events has enough "real" players
- to store in the database. The minimum setting comes from the config file
- under the setting xonstat.minimum_real_players.
- """
- flg_has_min_real_players = True
-
- try:
- minimum_required_players = int(
- settings['xonstat.minimum_required_players'])
- except:
- minimum_required_players = 2
-
- real_players = num_real_players(player_events)
-
- if real_players < minimum_required_players:
- flg_has_min_real_players = False
-
- return flg_has_min_real_players
-
-
-def has_required_metadata(metadata):
- """
- Determines if a give set of metadata has enough data to create a game,
- server, and map with.
- """
- flg_has_req_metadata = True
-
- if 'G' not in metadata or\
- 'M' not in metadata or\
- 'I' not in metadata or\
- 'S' not in metadata:
- flg_has_req_metadata = False
-
- return flg_has_req_metadata
-
-
def should_do_weapon_stats(game_type_cd):
"""True of the game type should record weapon stats. False otherwise."""
- if game_type_cd in 'cts':
- return False
- else:
- return True
+ return game_type_cd not in 'CTS'
def gametype_elo_eligible(game_type_cd):