mirror of
https://github.com/wolfswolke/DeathGarden_API_Rebirth.git
synced 2026-04-24 06:57:15 -05:00
Added base logic for Privat Matches and removed discord msg for dev messages
This commit is contained in:
parent
660bb4207f
commit
cdda9567f9
|
|
@ -2,10 +2,9 @@ import json
|
|||
import os
|
||||
from datetime import datetime
|
||||
|
||||
from logic.match_manager import match_manager
|
||||
from logic.time_handler import get_time
|
||||
from logic.queue_handler import matchmaking_queue
|
||||
from flask_definitions import *
|
||||
import uuid
|
||||
|
||||
|
||||
@app.route("/api/v1/config/MATCH_MAKING_REGIONS/raw", methods=["GET"])
|
||||
|
|
@ -267,24 +266,22 @@ def match_register(match_id_unsanitized):
|
|||
elif match_configuration == "/Game/Configuration/MatchConfig/MatchConfig_RUI_All.MatchConfig_RUI_All":
|
||||
match_configuration = "First Strike"
|
||||
|
||||
if dev_env == "true":
|
||||
match_id = f"DEV-{match_id}"
|
||||
|
||||
webhook_data = {
|
||||
"content": "",
|
||||
"embeds": [
|
||||
{
|
||||
"title": f"Match Registered",
|
||||
"description": f"MatchID: {match_id} \n GameMode: {game_mode} \n MatchConfiguration: {match_configuration}",
|
||||
"color": 7932020
|
||||
}
|
||||
],
|
||||
"attachments": []
|
||||
}
|
||||
try:
|
||||
discord_webhook(url_list, webhook_data)
|
||||
except Exception as e:
|
||||
logger.graylog_logger(level="error", handler="discord_webhook_message", message=e)
|
||||
if dev_env == "false":
|
||||
webhook_data = {
|
||||
"content": "",
|
||||
"embeds": [
|
||||
{
|
||||
"title": f"Match Registered",
|
||||
"description": f"MatchID: {match_id} \n GameMode: {game_mode} \n MatchConfiguration: {match_configuration}",
|
||||
"color": 7932020
|
||||
}
|
||||
],
|
||||
"attachments": []
|
||||
}
|
||||
try:
|
||||
discord_webhook(url_list, webhook_data)
|
||||
except Exception as e:
|
||||
logger.graylog_logger(level="error", handler="discord_webhook_message", message=e)
|
||||
|
||||
return jsonify(response)
|
||||
|
||||
|
|
@ -368,21 +365,70 @@ def match_create():
|
|||
userid = session_manager.get_user_id(session_cookie)
|
||||
|
||||
category = sanitize_input(request.json.get("category"))
|
||||
rank = sanitize_input(request.json.get("rank"))
|
||||
region = sanitize_input(request.json.get("region"))
|
||||
players_a = request.json.get("playersA")
|
||||
players_b = request.json.get("playersB")
|
||||
props = request.json.get("props")
|
||||
props = request.json.get("props")["MatchConfiguration"]
|
||||
|
||||
matchid = matchmaking_queue.genMatchUUID()
|
||||
# match_send = matchmaking_queue.createQueueResponseMatched(userid, matchid, joinerId=players_a)
|
||||
epoch = datetime.now().timestamp()
|
||||
player_list = [players_b, players_a]
|
||||
player_list = []
|
||||
for player in players_a:
|
||||
player_list.append(player)
|
||||
for player in players_b:
|
||||
player_list.append(player)
|
||||
matchid, Match_Config = matchmaking_queue.register_private_match(players_a=players_a, players_b=players_b, match_config=props)
|
||||
# EPrivateMatchState:
|
||||
# Disabled
|
||||
# InGameSession
|
||||
# NotCreated
|
||||
# NotEnoughPlayers
|
||||
# HunterNotSelected
|
||||
# CanStart
|
||||
|
||||
data = {"MatchId": matchid, "Category": category, "Rank": rank,
|
||||
# EMatchmakingState:
|
||||
# None
|
||||
# SearchingForMatch
|
||||
# WaitingForPlayers
|
||||
data = {"MatchId": matchid, "Category": category, "Rank": 1, "Region": region,
|
||||
"CreationDateTime": epoch, "ExcludeFriends": False,
|
||||
"ExcludeClanMembers": False, "Status": "WaitingForPlayers", "Creator": userid,
|
||||
"ExcludeClanMembers": False, "Status": "OPEN", "Reason": "FString", "Creator": userid,
|
||||
"Players": player_list, "SideA": players_a, "SideB": players_b, "CustomData": {}, "Props": props,
|
||||
"Schema": 11122334455666}
|
||||
"Schema": 1}
|
||||
users = players_a.copy()
|
||||
users.append(players_b)
|
||||
current_time = get_time()[0]
|
||||
countB = len(players_b)
|
||||
data = {
|
||||
"status": "PendingWarparty",
|
||||
"QueueData": {
|
||||
"Position": 1,
|
||||
"ETA": 0,
|
||||
"Stable": False,
|
||||
"SizeA": 1,
|
||||
"SizeB": countB
|
||||
},
|
||||
"matchData": {
|
||||
"category": "Steam-te-18f25613-36778-ue4-374f864b",
|
||||
"creationDateTime": current_time,
|
||||
"creator": players_a,
|
||||
"customData": {},
|
||||
"matchId": matchid,
|
||||
"props": {
|
||||
"countA": 1,
|
||||
"countB": countB,
|
||||
"gameMode": Match_Config["gameMode"],
|
||||
"MatchConfiguration": Match_Config["MatchConfiguration"],
|
||||
"platform": "Windows",
|
||||
},
|
||||
"rank": 1,
|
||||
"schema": 3,
|
||||
"sideA": players_a,
|
||||
"sideB": players_b,
|
||||
"Players": users,
|
||||
"status": "CREATED"
|
||||
}
|
||||
}
|
||||
return jsonify(data)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,93 +0,0 @@
|
|||
from time import time
|
||||
import uuid
|
||||
|
||||
|
||||
class Match:
|
||||
def __init__(self, match_uuid, json_dict):
|
||||
self._match_uuid = match_uuid
|
||||
self.time_created = time()
|
||||
self.users = json_dict.get("Players")
|
||||
self.rank = json_dict.get("Rank")
|
||||
self.category = json_dict.get("Category")
|
||||
self.exclude_friends = json_dict.get("ExcludeFriends")
|
||||
self.exclude_clan_members = json_dict.get("ExcludeClanMembers")
|
||||
self.status = json_dict.get("Status")
|
||||
self.creator = json_dict.get("Creator")
|
||||
self.players_side_a = json_dict.get("SideA")
|
||||
self.players_side_b = json_dict.get("SideB")
|
||||
self.custom_data = json_dict.get("CustomData")
|
||||
self.props = json_dict.get("Props")
|
||||
self.schema = json_dict.get("Schema")
|
||||
|
||||
|
||||
class MatchManager:
|
||||
def __init__(self):
|
||||
self._matches = {}
|
||||
self._queue_dict = {}
|
||||
|
||||
def create_match(self, json_dict):
|
||||
self.cleanup()
|
||||
match_id = str(uuid.uuid4())
|
||||
match = Match(match_id, json_dict)
|
||||
self._matches[match_id] = match
|
||||
return match_id
|
||||
|
||||
def find_match_id_from_user(self, user_id):
|
||||
self.cleanup()
|
||||
for match_id, match in self._matches.items():
|
||||
if user_id in match.users:
|
||||
return match
|
||||
return None
|
||||
|
||||
def find_json_with_match_id(self, match_id):
|
||||
self.cleanup()
|
||||
match = self._matches.get(match_id)
|
||||
if match:
|
||||
return match
|
||||
return None
|
||||
|
||||
def cleanup(self):
|
||||
match_ids = self._matches.keys()
|
||||
for match_id, match in match_ids:
|
||||
if time() - match.time_created > 60 * 1:
|
||||
del self._matches[match_id]
|
||||
|
||||
def delete_match(self, match_id):
|
||||
del self._matches[match_id]
|
||||
|
||||
def find_eta_and_position(self, match_id):
|
||||
self.cleanup()
|
||||
match = self._matches.get(match_id)
|
||||
if match:
|
||||
queue_list = list(self._matches.values())
|
||||
rank_x_matches = [m for m in queue_list if m.rank == match.rank]
|
||||
rank_x_matches.sort(key=lambda m: m.time_created)
|
||||
eta = rank_x_matches.index(match) * 5
|
||||
position = rank_x_matches.index(match) + 1
|
||||
return eta, position
|
||||
return None, None
|
||||
|
||||
def players_searching_for_match(self, user_id, catagory, region):
|
||||
self.cleanup()
|
||||
queue = self._queue_dict
|
||||
players_a = []
|
||||
players_b = []
|
||||
for key, value in queue.items():
|
||||
if key == "B":
|
||||
players_b.append(value)
|
||||
else:
|
||||
players_a.append(value)
|
||||
|
||||
if user_id in self._queue_dict.items():
|
||||
json_dict = {{'category': catagory, 'region': region, 'playersA': [players_b],
|
||||
'playersB': [players_b],
|
||||
'props': {
|
||||
'MatchConfiguration': '/Game/Configuration/MatchConfig/MatchConfig_Demo.MatchConfig_Demo'},
|
||||
'latencies': []}}
|
||||
self.create_match(json_dict)
|
||||
|
||||
else:
|
||||
self._queue_dict[user_id] = user_id
|
||||
|
||||
|
||||
match_manager = MatchManager()
|
||||
Loading…
Reference in New Issue
Block a user