Added Checks for broken lobby's to clear them.

This commit is contained in:
ZKWolf 2024-02-09 22:36:50 +01:00
parent 42bb748eaa
commit 946e804e51
2 changed files with 55 additions and 20 deletions

View File

@ -147,7 +147,7 @@ def match(matchid_unsanitized):
session_cookie = sanitize_input(request.cookies.get("bhvrSession"))
userid = session_manager.get_user_id(session_cookie)
try:
response_data = matchmaking_queue.createMatchResponse(matchId=matchid)
response_data = matchmaking_queue.createMatchResponse(matchId=matchid, userId=userid)
# logger.graylog_logger(level="debug", handler="match", message=response_data)
if response_data == "null":
logger.graylog_logger(level="error", handler="match", message=f"MatchResponse is null for MatchID: {matchid}")
@ -206,9 +206,13 @@ def match_register(match_id_unsanitized):
game_mode = response["props"]["gameMode"]
if game_mode == "789c81dfb11fe39b7247c7e488e5b0d4-Default":
game_mode = "Default"
elif game_mode == "08d2279d2ed3fba559918aaa08a73fa8-Default":
game_mode = "Default"
match_configuration = response["props"]["MatchConfiguration"]
if match_configuration == "/Game/Configuration/MatchConfig/MatchConfig_Demo_HarvestYourExit_1v5.MatchConfig_Demo_HarvestYourExit_1v5":
match_configuration = "Harvest Your Exit 1v5"
elif match_configuration == "/Game/Configuration/MatchConfig/MatchConfig_Demo.MatchConfig_Demo":
match_configuration = "Survival"
webhook_data = {
"content": "",
"embeds": [
@ -256,6 +260,7 @@ def match_quit(match_id_unsanitized):
matchmaking_queue.deleteMatch(match_id)
else:
matchmaking_queue.removePlayerFromQueue(userid)
matchmaking_queue.remove_player_from_match(match_id, userid)
return "", 204
@ -969,11 +974,11 @@ def remove_player_from_match(match_id_unsanitized, user_id):
match_id = sanitize_input(match_id_unsanitized)
try:
response = matchmaking_queue.remove_user_from_Match(match_id, user_id)
response = matchmaking_queue.remove_player_from_match(match_id, user_id)
if response == {"status": "success"}:
return "", 204
else:
return jsonify({"message": "Internal Server Error"}), 500
return jsonify({"message": "Something is fucked"}), 500
except Exception as e:
logger.graylog_logger(level="error", handler="remove_player_from_match", message=e)
return jsonify({"message": "Internal Server Error"}), 500

View File

@ -40,7 +40,7 @@ class QueuedPlayer:
class Lobby:
def __init__(self, isReady, host, nonHosts, id, isPrepared, hasStarted, status, MatchConfig):
def __init__(self, isReady, host, nonHosts, id, isPrepared, hasStarted, status, MatchConfig, last_host_check):
self.isReady = isReady
self.host = host
self.nonHosts = nonHosts
@ -49,6 +49,7 @@ class Lobby:
self.hasStarted = hasStarted
self.status = status
self.matchConfig = MatchConfig
self.last_host_check = last_host_check
class KilledLobby:
@ -99,6 +100,13 @@ class MatchmakingQueue:
return {}
if side == 'B':
if self.openLobbies:
for openLobby in self.openLobbies:
if openLobby.last_host_check < get_time()[0] - 15:
self.openLobbies.pop(self.openLobbies.index(openLobby))
logger.graylog_logger(level="info", handler="matchmaking_getQueueStatus", message="Lobby killed due to host not checking in")
if openLobby.host == userId:
self.openLobbies.pop(self.openLobbies.index(openLobby))
logger.graylog_logger(level="info", handler="matchmaking_getQueueStatus", message="Killed broken lobby")
for openLobby in self.openLobbies:
if not openLobby.isReady or openLobby.hasStarted or openLobby.status == "CLOSED":
continue
@ -152,10 +160,17 @@ class MatchmakingQueue:
"status": "QUEUED",
}
else:
if self.openLobbies:
for openLobby in self.openLobbies:
if openLobby.host == userId:
self.openLobbies.pop(self.openLobbies.index(openLobby))
logger.graylog_logger(level="info", handler="matchmaking_getQueueStatus",
message="Killed broken lobby")
matchId = self.genMatchUUID()
Match_Config = random_game_mode()
current_time = get_time()[0]
lobby = Lobby(isReady=False, host=queuedPlayer, nonHosts=[], id=matchId, isPrepared=False,
hasStarted=False, status="OPENED", MatchConfig=Match_Config)
hasStarted=False, status="OPENED", MatchConfig=Match_Config, last_host_check=current_time)
self.openLobbies.append(lobby)
self.queuedPlayers.pop(index)
return self.createQueueResponseMatched(userId, matchId, region=region, matchConfig=Match_Config)
@ -168,6 +183,19 @@ class MatchmakingQueue:
if index != -1:
self.queuedPlayers.pop(index)
def remove_player_from_match(self, matchId, userId):
try:
lobby, _ = self.getLobbyById(matchId)
if lobby:
for i, player in enumerate(lobby.nonHosts):
if player.userId == userId:
lobby.nonHosts.pop(i)
break
return {"status": "success"}
except Exception as e:
logger.graylog_logger(level="error", handler="remove_player_from_match", message=e)
return {"status": "error"}
def getLobbyById(self, id):
for i, lobby in enumerate(self.openLobbies):
if lobby.id == id:
@ -220,7 +248,17 @@ class MatchmakingQueue:
else:
countA = 1
countB = 5
lobby_temp, id_temp = self.getLobbyById(matchId)
if lobby_temp.host == userId:
# lobby.last_host_check = get_time()[0] + 3
self.openLobbies[id_temp].last_host_check = get_time()[0] + 3
lobby, id = self.getLobbyById(matchId)
logger.graylog_logger(level="info", handler="matchmaking_createMatchResponse", message=f"current_time: {get_time()[0]}")
logger.graylog_logger(level="info", handler="matchmaking_createMatchResponse", message=f"last_host_check: {lobby.last_host_check}")
if lobby.last_host_check < get_time()[0] - 15:
self.openLobbies.pop(self.openLobbies.index(lobby))
logger.graylog_logger(level="info", handler="matchmaking_createMatchResponse",
message="Lobby killed due to host not checking in")
if not lobby:
lobby = self.getKilledLobbyById(matchId)
host = lobby.host
@ -270,6 +308,8 @@ class MatchmakingQueue:
def createQueueResponseMatched(self, creatorId, matchId, joinerId=None, region=None, matchConfig=None):
try:
lobby, index = self.getLobbyById(matchId)
self.openLobbies[index].last_host_check = get_time()[0] + 3
if region:
countA = 1
countB = 1
@ -320,21 +360,11 @@ class MatchmakingQueue:
def genMatchUUID(self):
return str(uuid.uuid4())
def remove_user_from_Match(self, matchId, userId):
try:
lobby, _ = self.getLobbyById(matchId)
if lobby:
if lobby.host == userId:
self.deleteMatch(matchId)
else:
for i, player in enumerate(lobby.nonHosts):
if player.userId == userId:
lobby.nonHosts.pop(i)
break
return {"status": "success"}
except Exception as e:
logger.graylog_logger(level="error", handler="remove_user_from_Match", message=e)
return {"status": "error"}
def clear_queue(self):
self.queuedPlayers = []
self.openLobbies = []
self.killedLobbies = []
return {"status": "success"}
matchmaking_queue = MatchmakingQueue()