mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-08-23 17:43:59 -05:00
Added Online player counter
This commit is contained in:
@@ -45,6 +45,7 @@ COPY src/logic/queue_handler.py /app/src/logic/queue_handler.py
|
||||
COPY src/logic/setup_handlers.py /app/src/logic/setup_handlers.py
|
||||
COPY src/logic/time_handler.py /app/src/logic/time_handler.py
|
||||
COPY src/logic/webhook_handler.py /app/src/logic/webhook_handler.py
|
||||
COPY src/logic/presence_handler.py /app/src/logic/presence_handler.py
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ def me_rich_presence():
|
||||
user_id = session_manager.get_user_id(session_cookie)
|
||||
|
||||
try:
|
||||
logger.graylog_logger(level="info", handler="logging_meRichPresence", message=f"User: {user_id} - {request.get_json()}")
|
||||
rich_presence_handler.update_presence(user_id, request.get_json()["userType"], request.get_json()["gameState"])
|
||||
return "", 204
|
||||
except TimeoutError:
|
||||
return jsonify({"status": "error"})
|
||||
|
||||
@@ -460,6 +460,9 @@ def debug_matchmaking():
|
||||
len_queued_runners = matchmaking_queue.get_len_of_queued_runners()
|
||||
len_queued_hunters = matchmaking_queue.get_len_of_queued_hunters()
|
||||
len_open_lobbies = matchmaking_queue.get_len_of_open_lobbies()
|
||||
len_rich_presence = rich_presence_handler.get_presence_length()
|
||||
current_players_locker_room = rich_presence_handler.get_locker_room_presence()
|
||||
current_players_arena = rich_presence_handler.get_arena_presence()
|
||||
|
||||
lobby_data = matchmaking_queue.get_lobby_data()
|
||||
if dev_env == "true":
|
||||
@@ -469,14 +472,20 @@ def debug_matchmaking():
|
||||
len_queued_runners=len_queued_runners,
|
||||
len_queued_hunters=len_queued_hunters,
|
||||
len_open_lobbies=len_open_lobbies,
|
||||
lobby_data=lobby_data)
|
||||
lobby_data=lobby_data,
|
||||
len_rich_presence=len_rich_presence,
|
||||
current_players_locker_room=current_players_locker_room,
|
||||
current_players_arena=current_players_arena)
|
||||
return render_template('debug/anon_matchmaking.html',
|
||||
len_queue=len_queue,
|
||||
len_killed_lobbies=len_killed_lobbies,
|
||||
len_queued_runners=len_queued_runners,
|
||||
len_queued_hunters=len_queued_hunters,
|
||||
len_open_lobbies=len_open_lobbies,
|
||||
lobby_data=lobby_data)
|
||||
lobby_data=lobby_data,
|
||||
len_rich_presence=len_rich_presence,
|
||||
current_players_locker_room=current_players_locker_room,
|
||||
current_players_arena=current_players_arena)
|
||||
|
||||
|
||||
@app.route("/api/debug/MatchMaking", methods=["GET"])
|
||||
@@ -487,6 +496,7 @@ def api_debug_matchmaking():
|
||||
len_queued_runners = matchmaking_queue.get_len_of_queued_runners()
|
||||
len_queued_hunters = matchmaking_queue.get_len_of_queued_hunters()
|
||||
len_open_lobbies = matchmaking_queue.get_len_of_open_lobbies()
|
||||
len_rich_presence = rich_presence_handler.get_presence_length()
|
||||
|
||||
lobby_data = matchmaking_queue.get_lobby_data()
|
||||
lobby_return_data = []
|
||||
@@ -506,7 +516,8 @@ def api_debug_matchmaking():
|
||||
"len_queued_runners": len_queued_runners,
|
||||
"len_queued_hunters": len_queued_hunters,
|
||||
"len_open_lobbies": len_open_lobbies,
|
||||
"lobby_data": lobby_return_data
|
||||
"lobby_data": lobby_return_data,
|
||||
"len_rich_presence": len_rich_presence
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from logic.hash_handler import hash_handler
|
||||
from logic.challenge_handler_new import new_challenge_handler, get_challenge_ids_from_inventory
|
||||
from logic.level_handler import update_user_xp
|
||||
from logic.webhook_handler import webhook_handler
|
||||
from logic.presence_handler import rich_presence_handler
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
48
src/logic/presence_handler.py
Normal file
48
src/logic/presence_handler.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class Presence:
|
||||
def __init__(self):
|
||||
self.user_id = None
|
||||
self.userType = None
|
||||
self.gameState = None
|
||||
self.last_updated = None
|
||||
|
||||
|
||||
class RichPresenceHandler:
|
||||
|
||||
def __init__(self):
|
||||
self.presence = {}
|
||||
|
||||
def update_presence(self, user_id, user_type, game_state):
|
||||
if user_id not in self.presence:
|
||||
self.presence[user_id] = Presence()
|
||||
self.presence[user_id].user_id = user_id
|
||||
self.presence[user_id].userType = user_type
|
||||
self.presence[user_id].gameState = game_state
|
||||
self.presence[user_id].last_updated = datetime.now()
|
||||
|
||||
def cleanup_presence(self):
|
||||
for user_id in list(self.presence.keys()):
|
||||
# if user has not checked in the last 2 min remove
|
||||
if (datetime.now() - self.presence[user_id].last_updated).seconds > 120:
|
||||
del self.presence[user_id]
|
||||
|
||||
def get_presence_length(self):
|
||||
self.cleanup_presence()
|
||||
return len(self.presence)
|
||||
|
||||
def get_presence(self):
|
||||
self.cleanup_presence()
|
||||
return self.presence
|
||||
|
||||
def get_arena_presence(self):
|
||||
self.cleanup_presence()
|
||||
return len({k: v for k, v in self.presence.items() if v.gameState == "Arena"})
|
||||
|
||||
def get_locker_room_presence(self):
|
||||
self.cleanup_presence()
|
||||
return len({k: v for k, v in self.presence.items() if v.gameState == "LockerRoom"})
|
||||
|
||||
|
||||
rich_presence_handler = RichPresenceHandler()
|
||||
@@ -57,6 +57,10 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Matchmaking Debug Information</h1>
|
||||
<p><strong>Currently online players: {{ len_rich_presence }}<br></strong></p>
|
||||
<p><strong>Current players in LockerRoom: {{ current_players_locker_room }}<br></strong></p>
|
||||
<p><strong>Current players in Arena: {{ current_players_arena }}<br></strong></p>
|
||||
<p></p>
|
||||
<p><strong>Length of Queue:</strong> {{ len_queue }}</p>
|
||||
<p><strong>Killed Lobbies:</strong> {{ len_killed_lobbies }}</p>
|
||||
<p><strong>Queued Runners:</strong> {{ len_queued_runners }}</p>
|
||||
|
||||
@@ -57,6 +57,9 @@
|
||||
</head>
|
||||
<body>
|
||||
<h1>Matchmaking Debug Information</h1>
|
||||
<p><strong>Currently online players: {{ len_rich_presence }}<br></strong></p>
|
||||
<p><strong>Current players in LockerRoom: {{ current_players_locker_room }}<br></strong></p>
|
||||
<p><strong>Current players in Arena: {{ current_players_arena }}<br></strong></p>
|
||||
<p><strong>Length of Queue:</strong> {{ len_queue }}</p>
|
||||
<p><strong>Killed Lobbies:</strong> {{ len_killed_lobbies }}</p>
|
||||
<p><strong>Queued Runners:</strong> {{ len_queued_runners }}</p>
|
||||
|
||||
Reference in New Issue
Block a user