diff --git a/app/main/routes.py b/app/main/routes.py index ed3b332..8e55414 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -127,25 +127,29 @@ def poll_locations(game_name): requested_users = get_value_if_key_exists(payload, 'requested_users', 'none') #print(f'mode: {mode}\nlast_request: {last_update}\nrequested_users: {requested_users}') response_objects = [] - if role == Role.owner: + if role in (Role.owner, Role.hunter): for username in requested_users: - user = get_user_locations(game, username, mode, last_update) - if user: - response_objects.append(user) + locations = get_user_locations(game, username, mode, last_update, role == Role.hunter) + #print(locations) + if locations: + response_objects.append(locations) response_objects = [obj for obj_list in response_objects for obj in obj_list] return json.dumps(response_objects, cls=LocationEncoder) def get_value_if_key_exists(dictionary, key, default=None): return dictionary[key] if key in dictionary else default -def get_user_locations(game, username, mode, last_update): +def get_user_locations(game, username, mode, last_update, hunter=False): user = User.query.filter_by(name=username).first() if user is None: return None + if hunter and user.role_in_game(game) != Role.bunny: + return None if mode == 'accumulative': - if game.end_time or datetime.min < last_update: + if game.end_time or datetime.max < last_update: # Don't return locations when the game is finished return [] - locations = user.locations_during_game(game) + offset = current_app.config['HUNTER_LOCATION_DELAY'] if hunter else 0 + locations = user.locations_during_game(game, offset) if not locations: return None return [location for location in locations if location.timestamp - last_update > timedelta(milliseconds=1)] diff --git a/app/templates/game_hunter_dashboard.html b/app/templates/game_hunter_dashboard.html index 4641f31..24c53ac 100644 --- a/app/templates/game_hunter_dashboard.html +++ b/app/templates/game_hunter_dashboard.html @@ -4,7 +4,6 @@ {{ super() }} - {% endblock %} {% block player_app_content %} @@ -75,25 +74,60 @@ {% block scripts %} {{ super() }} + {% endblock %} \ No newline at end of file diff --git a/app/templates/game_owner_dashboard.html b/app/templates/game_owner_dashboard.html index 36f65ef..5e69343 100644 --- a/app/templates/game_owner_dashboard.html +++ b/app/templates/game_owner_dashboard.html @@ -134,7 +134,7 @@ } // Poll Locations - usernames = JSON.parse('{{ json.dumps(game.usernames())|safe }}') + usernames = JSON.parse('{{ json.dumps(game.usernames())|safe }}').filter(name => name != '{{ current_user.name }}') setInterval(function() { pollLocations( "{{ url_for('main.poll_locations', game_name=game.name) }}",