From 0b2136d51444a87edced8b30a0dd555e0ccac0cf Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 09:51:55 +0530 Subject: [PATCH 01/23] refactor(server): allow connection to all --- src/server.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/server.py b/src/server.py index 745bd3a3..9918fb27 100644 --- a/src/server.py +++ b/src/server.py @@ -1,9 +1,9 @@ import json -from websocket_server import WebsocketServer from threading import Thread -# websocket.enableTrace(True) +from websocket_server import WebsocketServer +# websocket.enableTrace(True) class Server: @@ -15,9 +15,9 @@ def __init__(self, log, Error): def start_server(self): try: # print(self.lastMessage) - with open('config.json', "r") as conf: + with open("config.json", "r") as conf: port = json.load(conf)["port"] - self.server = WebsocketServer(host='127.0.0.1', port=port) + self.server = WebsocketServer(host="0.0.0.0", port=port) # server = websocket.WebSocketApp("wss://localhost:1100", on_open=on_open, on_message=on_message, on_close=on_close) self.server.set_fn_new_client(self.handle_new_client) self.server.run_forever(threaded=True) @@ -28,10 +28,6 @@ def handle_new_client(self, client, server): if self.lastMessage != "": self.send_message(self.lastMessage) - def send_message(self, message): self.lastMessage = message self.server.send_message_to_all(message) - - - \ No newline at end of file From d48ae247081f299e2ad15ee096a837687cac332a Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 10:04:00 +0530 Subject: [PATCH 02/23] refactor(server): send different payloads --- src/Loadouts.py | 2 +- src/server.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Loadouts.py b/src/Loadouts.py index 13326fa3..9ad339b1 100644 --- a/src/Loadouts.py +++ b/src/Loadouts.py @@ -48,7 +48,7 @@ def get_match_loadouts(self, match_id, players, weaponChoose, valoApiSkins, name # weaponLists.update({player["Subject"]: color(skin["Name"], fore=rgb_color)}) final_json = self.convertLoadoutToJsonArray(PlayerInventorys, playersBackup, state, names) # self.log(f"json for website: {final_json}") - self.Server.send_message(json.dumps(final_json)) + self.Server.send_payload("matchLoadout",final_json) return weaponLists #this will convert valorant loadouts to json with player names diff --git a/src/server.py b/src/server.py index 9918fb27..ad9086d4 100644 --- a/src/server.py +++ b/src/server.py @@ -10,7 +10,7 @@ class Server: def __init__(self, log, Error): self.Error = Error self.log = log - self.lastMessage = "" + self.lastMessages = {} def start_server(self): try: @@ -25,9 +25,14 @@ def start_server(self): self.Error.PortError(port) def handle_new_client(self, client, server): - if self.lastMessage != "": - self.send_message(self.lastMessage) + for key in self.lastMessages: + self.send_message(self.lastMessages[key]) def send_message(self, message): - self.lastMessage = message self.server.send_message_to_all(message) + + def send_payload(self, type, payload): + payload["type"] = type + msg_str = json.dump(payload) + self.lastMessages[type] = msg_str + self.server.send_message_to_all(msg_str) From 571dc2135a920e2c14b86dbc80b6224d4dbcfc73 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 10:08:55 +0530 Subject: [PATCH 03/23] refactor(loadouts): return json to main --- main.py | 4 +++- src/Loadouts.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 9cf565e0..b5e9c82a 100644 --- a/main.py +++ b/main.py @@ -203,7 +203,9 @@ def program_exit(status: int): # so we don't need to import the entire sys modu server = "New server" presences.wait_for_presence(namesClass.get_players_puuid(Players)) names = namesClass.get_names_from_puuids(Players) - loadouts = loadoutsClass.get_match_loadouts(coregame.get_coregame_match_id(), Players, cfg.weapon, valoApiSkins, names, state="game") + loadouts_arr = loadoutsClass.get_match_loadouts(coregame.get_coregame_match_id(), Players, cfg.weapon, valoApiSkins, names, state="game") + loadouts = loadouts_arr[0] + loadouts_data = loadouts_arr[1] with alive_bar(total=len(Players), title='Fetching Players', bar='classic2') as bar: partyOBJ = menu.get_party_json(namesClass.get_players_puuid(Players), presence) # log(f"retrieved names dict: {names}") diff --git a/src/Loadouts.py b/src/Loadouts.py index 9ad339b1..fce91748 100644 --- a/src/Loadouts.py +++ b/src/Loadouts.py @@ -49,7 +49,7 @@ def get_match_loadouts(self, match_id, players, weaponChoose, valoApiSkins, name final_json = self.convertLoadoutToJsonArray(PlayerInventorys, playersBackup, state, names) # self.log(f"json for website: {final_json}") self.Server.send_payload("matchLoadout",final_json) - return weaponLists + return [weaponLists,final_json] #this will convert valorant loadouts to json with player names def convertLoadoutToJsonArray(self, PlayerInventorys, players, state, names): From 92296362bd6678b4ce5dbfff5ec0bb6023a87e07 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 10:28:59 +0530 Subject: [PATCH 04/23] fix(server): dumps instead of dump --- src/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.py b/src/server.py index ad9086d4..3e4ba555 100644 --- a/src/server.py +++ b/src/server.py @@ -33,6 +33,6 @@ def send_message(self, message): def send_payload(self, type, payload): payload["type"] = type - msg_str = json.dump(payload) + msg_str = json.dumps(payload) self.lastMessages[type] = msg_str self.server.send_message_to_all(msg_str) From d815a2cfeda77318f0bcbfd25a822fe0af9b7415 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 10:29:23 +0530 Subject: [PATCH 05/23] feat(main): add heartbeat --- main.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index b5e9c82a..cfa36e06 100644 --- a/main.py +++ b/main.py @@ -184,6 +184,12 @@ def program_exit(status: int): # so we don't need to import the entire sys modu is_leaderboard_needed = False + heartbeat_data = { + "time": int(time.time()), + "state": game_state, + "players": {} + } + if game_state == "INGAME": coregame_stats = coregame.get_coregame_stats() Players = coregame_stats["Players"] @@ -377,6 +383,20 @@ def program_exit(status: int): # so we don't need to import the entire sys modu } } ) + + heartbeat_data["players"][player["Subject"]] = { + "name": names[player["Subject"]], + "agent": agent_dict[player["CharacterID"].lower()], + "map": map_dict[coregame_stats["MapID"].lower()], + "rank": playerRank["rank"], + "peakRank": playerRank["peakrank"], + "rr": rr, + "agentImgLink": loadouts_data["Players"][player["Subject"]]["Agent"], + "team": loadouts_data["Players"][player["Subject"]]["Team"], + "sprays": loadouts_data["Players"][player["Subject"]]["Sprays"], + "weapons": loadouts_data["Players"][player["Subject"]]["Weapons"], + "level": loadouts_data["Players"][player["Subject"]]["Level"] + } bar() elif game_state == "PREGAME": already_played_with = [] @@ -505,6 +525,15 @@ def program_exit(status: int): # so we don't need to import the entire sys modu wr, level, ]) + + heartbeat_data["players"][player["Subject"]] = { + "name": names[player["Subject"]], + "agent": agent_dict[player["CharacterID"].lower()], + "rank": playerRank["rank"], + "peakRank": playerRank["peakrank"], + "rr": rr, + } + bar() if game_state == "MENUS": already_played_with = [] @@ -578,7 +607,14 @@ def program_exit(status: int): # so we don't need to import the entire sys modu wr, level ]) - # table.add_rows([]) + + heartbeat_data["players"][player["Subject"]] = { + "name": names[player["Subject"]], + "rank": playerRank["rank"], + "peakRank": playerRank["peakrank"], + "rr": rr, + } + bar() seen.append(player["Subject"]) if (title := game_state_dict.get(game_state)) is None: @@ -597,6 +633,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu table.set_runtime_col_flag('Agent',False) table.set_runtime_col_flag('Skin',False) + Server.send_payload("hearbeat",heartbeat_data) table.display() firstPrint = False From 656ed08d647880baa5a980fba3b6410bc4adf4be Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 10:50:26 +0530 Subject: [PATCH 06/23] fix(main): typo heartbeat --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index cfa36e06..b4948ff7 100644 --- a/main.py +++ b/main.py @@ -633,7 +633,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu table.set_runtime_col_flag('Agent',False) table.set_runtime_col_flag('Skin',False) - Server.send_payload("hearbeat",heartbeat_data) + Server.send_payload("heartbeat",heartbeat_data) table.display() firstPrint = False From e8296e9400736538092ba911fecde8efbf8a9a83 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 16:58:22 +0530 Subject: [PATCH 07/23] fix(main): add level to heartbeat in menu,pregame --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index b4948ff7..8d975070 100644 --- a/main.py +++ b/main.py @@ -531,6 +531,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu "agent": agent_dict[player["CharacterID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], + "level": player_level, "rr": rr, } @@ -612,6 +613,7 @@ def program_exit(status: int): # so we don't need to import the entire sys modu "name": names[player["Subject"]], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], + "level": player_level, "rr": rr, } From c052d3a2dc9944184a7718ecab5c17d84a774d7c Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 25 Aug 2022 17:07:22 +0530 Subject: [PATCH 08/23] style(main): QoL print server host --- main.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 8d975070..4c3dfc60 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import socket import traceback import requests import urllib3 @@ -46,7 +47,18 @@ def program_exit(status: int): # so we don't need to import the entire sys modu log(f"exited program with error code {status}") raise sys.exit(status) - +def get_ip(): + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.settimeout(0) + try: + # doesn't even have to be reachable + s.connect(('10.254.254.254', 1)) + IP = s.getsockname()[0] + except Exception: + IP = '127.0.0.1' + finally: + s.close() + return IP try: Logging = Logging() @@ -124,6 +136,8 @@ def program_exit(status: int): # so we don't need to import the entire sys modu seasonID = content.get_latest_season_id(gameContent) lastGameState = "" + print(color(f"\nWs Server - {get_ip()}:{cfg.port}", fore=(255, 127, 80))) + print(color("\nVisit https://vry.netlify.app/matchLoadouts to view full player inventories\n", fore=(255, 253, 205))) chatlog(color("\nVisit https://vry.netlify.app/matchLoadouts to view full player inventories\n", fore=(255, 253, 205))) From b389681984bcca820371cf70159f18ae7af79219 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Fri, 26 Aug 2022 12:46:06 +0530 Subject: [PATCH 09/23] refactor(main): change heartbeat level --- main.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index b9cae2fe..1c36d19a 100644 --- a/main.py +++ b/main.py @@ -403,6 +403,21 @@ def get_ip(): kd, level ]) + + heartbeat_data["players"][player["Subject"]] = { + "name": names[player["Subject"]], + "agent": agent_dict[player["CharacterID"].lower()], + "map": map_dict[coregame_stats["MapID"].lower()], + "rank": playerRank["rank"], + "peakRank": playerRank["peakrank"], + "rr": rr, + "level": player_level, + "agentImgLink": loadouts_data["Players"][player["Subject"]]["Agent"], + "team": loadouts_data["Players"][player["Subject"]]["Team"], + "sprays": loadouts_data["Players"][player["Subject"]]["Sprays"], + "weapons": loadouts_data["Players"][player["Subject"]]["Weapons"] + } + stats.save_data( { player["Subject"]: { @@ -417,19 +432,6 @@ def get_ip(): } ) - heartbeat_data["players"][player["Subject"]] = { - "name": names[player["Subject"]], - "agent": agent_dict[player["CharacterID"].lower()], - "map": map_dict[coregame_stats["MapID"].lower()], - "rank": playerRank["rank"], - "peakRank": playerRank["peakrank"], - "rr": rr, - "agentImgLink": loadouts_data["Players"][player["Subject"]]["Agent"], - "team": loadouts_data["Players"][player["Subject"]]["Team"], - "sprays": loadouts_data["Players"][player["Subject"]]["Sprays"], - "weapons": loadouts_data["Players"][player["Subject"]]["Weapons"], - "level": loadouts_data["Players"][player["Subject"]]["Level"] - } bar() elif game_state == "PREGAME": already_played_with = [] From 96d3efce2a6f02d2d0ee3e310e09d25b7a6502ee Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Fri, 26 Aug 2022 12:59:08 +0530 Subject: [PATCH 10/23] fix(main): safe get loadout keys --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 1c36d19a..7c55dea8 100644 --- a/main.py +++ b/main.py @@ -412,10 +412,10 @@ def get_ip(): "peakRank": playerRank["peakrank"], "rr": rr, "level": player_level, - "agentImgLink": loadouts_data["Players"][player["Subject"]]["Agent"], - "team": loadouts_data["Players"][player["Subject"]]["Team"], - "sprays": loadouts_data["Players"][player["Subject"]]["Sprays"], - "weapons": loadouts_data["Players"][player["Subject"]]["Weapons"] + "agentImgLink": loadouts_data["Players"][player["Subject"]].get("Agent",None), + "team": loadouts_data["Players"][player["Subject"]].get("Team",None), + "sprays": loadouts_data["Players"][player["Subject"]].get("Sprays",None), + "weapons": loadouts_data["Players"][player["Subject"]].get("Weapons",None) } stats.save_data( From 43ed29a6ea4b4d52ddac7151f067e74e0e2b40f6 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Fri, 26 Aug 2022 14:04:11 +0530 Subject: [PATCH 11/23] feat(main): send few more props in heartbeat --- main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.py b/main.py index 7c55dea8..321e751c 100644 --- a/main.py +++ b/main.py @@ -410,11 +410,14 @@ def get_ip(): "map": map_dict[coregame_stats["MapID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], + "peakRankAct": peakRankAct, "rr": rr, "level": player_level, "agentImgLink": loadouts_data["Players"][player["Subject"]].get("Agent",None), "team": loadouts_data["Players"][player["Subject"]].get("Team",None), "sprays": loadouts_data["Players"][player["Subject"]].get("Sprays",None), + "title": loadouts_data["Players"][player["Subject"]].get("Title",None), + "playerCard": loadouts_data["Players"][player["Subject"]].get("PlayerCard",None), "weapons": loadouts_data["Players"][player["Subject"]].get("Weapons",None) } From 745ffecc6abc5cca34175b9f099151dac721d875 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 15:58:24 +0530 Subject: [PATCH 12/23] feat(ws): send chat via server --- main.py | 2 +- src/websocket.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ab600c76..b1585c69 100644 --- a/main.py +++ b/main.py @@ -125,7 +125,7 @@ def get_ip(): else: rpc = None - Wss = Ws(Requests.lockfile, Requests, cfg, colors, hide_names, chatlog, rpc) + Wss = Ws(Requests.lockfile, Requests, cfg, colors, hide_names, chatlog, Server, rpc) # loop = asyncio.new_event_loop() # asyncio.set_event_loop(loop) # loop.run_forever() diff --git a/src/websocket.py b/src/websocket.py index fbbeea10..662c2d54 100644 --- a/src/websocket.py +++ b/src/websocket.py @@ -8,7 +8,7 @@ class Ws: - def __init__(self, lockfile, Requests, cfg, colors, hide_names, chatlog, rpc=None): + def __init__(self, lockfile, Requests, cfg, colors, hide_names, chatlog, server, rpc=None): self.lockfile = lockfile self.Requests = Requests @@ -26,6 +26,7 @@ def __init__(self, lockfile, Requests, cfg, colors, hide_names, chatlog, rpc=Non self.up = "\033[A" self.chat_limit = 5 self.chatlog = chatlog + self.server = server if self.cfg.get_feature_flag("discord_rpc"): self.rpc = rpc @@ -97,12 +98,14 @@ def handle(self, m, initial_game_state): name = f"{message['game_name']}#{message['game_tag']}" if self.player_data[message['puuid']]['streamer_mode'] and self.hide_names and message['puuid'] not in self.player_data["ignore"]: self.print_message(f"{color(agent, clr)}: {message['body']}") + self.server.send_payload("chat",{"agent": agent,"message": message['body']}) else: if agent == "": agent_str = "" else: agent_str = f" ({agent})" self.print_message(f"{color(name, clr)}{agent_str}: {message['body']}") + self.server.send_payload("chat",{"player": name,"agent": agent,"message": message['body']}) self.id_seen.append(message['id']) def print_message(self, message): From f92e7ef9f97c91fc6a6b5d9a5d2d5545166769ae Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 16:12:06 +0530 Subject: [PATCH 13/23] feat(main): send version to app --- src/server.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/server.py b/src/server.py index 3e4ba555..dd7db4d6 100644 --- a/src/server.py +++ b/src/server.py @@ -2,6 +2,7 @@ from threading import Thread from websocket_server import WebsocketServer +from src.constants import version # websocket.enableTrace(True) @@ -25,6 +26,9 @@ def start_server(self): self.Error.PortError(port) def handle_new_client(self, client, server): + Server.send_payload("version",{ + "version": version + }) for key in self.lastMessages: self.send_message(self.lastMessages[key]) From 995052ff1111c6cdd1fc3cc490c596625c3d2311 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 16:44:27 +0530 Subject: [PATCH 14/23] fix(server): self typo --- src/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.py b/src/server.py index dd7db4d6..a3446a7c 100644 --- a/src/server.py +++ b/src/server.py @@ -26,7 +26,7 @@ def start_server(self): self.Error.PortError(port) def handle_new_client(self, client, server): - Server.send_payload("version",{ + self.send_payload("version",{ "version": version }) for key in self.lastMessages: From e862dd274e5fca3385e7c0d347a37e70626988f1 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 19:28:44 +0530 Subject: [PATCH 15/23] fix(server): escape ansi on agent --- src/websocket.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/websocket.py b/src/websocket.py index 662c2d54..3f996a23 100644 --- a/src/websocket.py +++ b/src/websocket.py @@ -98,14 +98,14 @@ def handle(self, m, initial_game_state): name = f"{message['game_name']}#{message['game_tag']}" if self.player_data[message['puuid']]['streamer_mode'] and self.hide_names and message['puuid'] not in self.player_data["ignore"]: self.print_message(f"{color(agent, clr)}: {message['body']}") - self.server.send_payload("chat",{"agent": agent,"message": message['body']}) + self.server.send_payload("chat",{"agent": self.colors.escape_ansi(agent),"message": message['body']}) else: if agent == "": agent_str = "" else: agent_str = f" ({agent})" self.print_message(f"{color(name, clr)}{agent_str}: {message['body']}") - self.server.send_payload("chat",{"player": name,"agent": agent,"message": message['body']}) + self.server.send_payload("chat",{"player": name,"agent": self.colors.escape_ansi(agent),"message": message['body']}) self.id_seen.append(message['id']) def print_message(self, message): From 609b7d8260dc56f0a8595f6a18d30d5cb64bdd93 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 19:33:02 +0530 Subject: [PATCH 16/23] feat(main): send self puuid in heartbeat --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index b1585c69..16d7c72c 100644 --- a/main.py +++ b/main.py @@ -214,6 +214,7 @@ def get_ip(): heartbeat_data = { "time": int(time.time()), "state": game_state, + "selfPuuid": Requests.puuid, "players": {} } From 78254c8d446986eadf27a3a2d52e8ec276358fa3 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 20:02:55 +0530 Subject: [PATCH 17/23] refactor(server): version->core --- src/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.py b/src/server.py index 079d0105..0622d675 100644 --- a/src/server.py +++ b/src/server.py @@ -27,7 +27,7 @@ def start_server(self): def handle_new_client(self, client, server): self.send_payload("version",{ - "version": version + "core": version }) for key in self.lastMessages: self.send_message(self.lastMessages[key]) From 28b953002a20a88bde148624666e111179361f45 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 20:47:53 +0530 Subject: [PATCH 18/23] fix(server): dont resend certain payload --- src/server.py | 3 ++- src/websocket.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/server.py b/src/server.py index 0622d675..29954c9e 100644 --- a/src/server.py +++ b/src/server.py @@ -30,7 +30,8 @@ def handle_new_client(self, client, server): "core": version }) for key in self.lastMessages: - self.send_message(self.lastMessages[key]) + if key not in ["chat","version"]: + self.send_message(self.lastMessages[key]) def send_message(self, message): self.server.send_message_to_all(message) diff --git a/src/websocket.py b/src/websocket.py index 53fce935..be18d635 100644 --- a/src/websocket.py +++ b/src/websocket.py @@ -110,14 +110,27 @@ def handle(self, m, initial_game_state): name = f"{message['game_name']}#{message['game_tag']}" if self.player_data[message['puuid']]['streamer_mode'] and self.hide_names and message['puuid'] not in self.player_data["ignore"]: self.print_message(f"{chat_prefix} {color(self.colors.escape_ansi(agent), clr)}: {message['body']}") - self.server.send_payload("chat",{"chatType":chat_prefix,"agent": self.colors.escape_ansi(agent),"message": message['body']}) + self.server.send_payload("chat",{ + "puuid": player, + "self": message["puuid"] == self.Requests.puuid, + "chatType":self.colors.escape_ansi(chat_prefix), + "agent": self.colors.escape_ansi(agent), + "message": message['body'] + }) else: if agent == "": agent_str = "" else: agent_str = f" ({agent})" self.print_message(f"{chat_prefix} {color(name, clr)}{agent_str}: {message['body']}") - self.server.send_payload("chat",{"chatType":chat_prefix,"player": name,"agent": self.colors.escape_ansi(agent),"message": message['body']}) + self.server.send_payload("chat",{ + "puuid": player, + "self": message["puuid"] == self.Requests.puuid, + "chatType":self.colors.escape_ansi(chat_prefix), + "player": name, + "agent": self.colors.escape_ansi(agent), + "message": message['body'] + }) self.id_seen.append(message['id']) def print_message(self, message): From cfb2c23eb48fc963ac58e7a1020f5951d1f36e18 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 21:05:46 +0530 Subject: [PATCH 19/23] feat(main): send party number in heartbeat --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index e5f2c80b..0eebc79e 100644 --- a/main.py +++ b/main.py @@ -422,6 +422,7 @@ def get_ip(): heartbeat_data["players"][player["Subject"]] = { "name": names[player["Subject"]], + "partyNumber": partyCount, "agent": agent_dict[player["CharacterID"].lower()], "map": map_dict[coregame_stats["MapID"].lower()], "rank": playerRank["rank"], @@ -592,6 +593,7 @@ def get_ip(): heartbeat_data["players"][player["Subject"]] = { "name": names[player["Subject"]], + "partyNumber": partyCount, "agent": agent_dict[player["CharacterID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], From 423db268342987394c780aeb4f047d9e0eaeba23 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sat, 27 Aug 2022 21:13:05 +0530 Subject: [PATCH 20/23] fix(main): party icon fixup --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 0eebc79e..28fb01da 100644 --- a/main.py +++ b/main.py @@ -422,7 +422,7 @@ def get_ip(): heartbeat_data["players"][player["Subject"]] = { "name": names[player["Subject"]], - "partyNumber": partyCount, + "partyIcon": party_icon, "agent": agent_dict[player["CharacterID"].lower()], "map": map_dict[coregame_stats["MapID"].lower()], "rank": playerRank["rank"], @@ -593,7 +593,7 @@ def get_ip(): heartbeat_data["players"][player["Subject"]] = { "name": names[player["Subject"]], - "partyNumber": partyCount, + "partyIcon": party_icon, "agent": agent_dict[player["CharacterID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], From 54efc8de42c868a7af4ef5f4367cb1728b328f36 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Sun, 28 Aug 2022 14:14:35 +0530 Subject: [PATCH 21/23] feat(server): send party and mode in heartbeat --- main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 28fb01da..c3362669 100644 --- a/main.py +++ b/main.py @@ -215,9 +215,16 @@ def get_ip(): is_leaderboard_needed = False + priv_presence = presences.get_private_presence(presence) + if priv_presence["provisioningFlow"] == "CustomGame" or priv_presence["partyState"] == "CUSTOM_GAME_SETUP": + gamemode = "Custom Game" + else: + gamemode = gamemodes.get(priv_presence['queueId']) + heartbeat_data = { "time": int(time.time()), "state": game_state, + "mode": gamemode, "selfPuuid": Requests.puuid, "players": {} } @@ -422,7 +429,7 @@ def get_ip(): heartbeat_data["players"][player["Subject"]] = { "name": names[player["Subject"]], - "partyIcon": party_icon, + "partyNumber": partyCount if party_icon != "" else 0, "agent": agent_dict[player["CharacterID"].lower()], "map": map_dict[coregame_stats["MapID"].lower()], "rank": playerRank["rank"], @@ -593,7 +600,7 @@ def get_ip(): heartbeat_data["players"][player["Subject"]] = { "name": names[player["Subject"]], - "partyIcon": party_icon, + "partyNumber": partyCount if party_icon != "" else 0, "agent": agent_dict[player["CharacterID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], From c01530ddff9a9d55842885019230f925d976308b Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Tue, 30 Aug 2022 14:28:57 +0530 Subject: [PATCH 22/23] fix(main): correct party number --- main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index c3362669..887be0d0 100644 --- a/main.py +++ b/main.py @@ -225,7 +225,7 @@ def get_ip(): "time": int(time.time()), "state": game_state, "mode": gamemode, - "selfPuuid": Requests.puuid, + "puuid": Requests.puuid, "players": {} } @@ -260,12 +260,14 @@ def get_ip(): # with alive_bar(total=len(Players), title='Fetching Players', bar='classic2') as bar: isRange = False playersLoaded = 1 + heartbeat_data["map"] = map_dict[coregame_stats["MapID"].lower()], with richConsole.status("Loading Players...") as status: partyOBJ = menu.get_party_json(namesClass.get_players_puuid(Players), presence) # log(f"retrieved names dict: {names}") Players.sort(key=lambda Players: Players["PlayerIdentity"].get("AccountLevel"), reverse=True) Players.sort(key=lambda Players: Players["TeamID"], reverse=True) partyCount = 0 + partyNum = 0 partyIcons = {} lastTeamBoolean = False lastTeam = "Red" @@ -319,7 +321,6 @@ def get_ip(): }) party_icon = '' - # set party premade icon for party in partyOBJ: if player["Subject"] in partyOBJ[party]: @@ -327,6 +328,7 @@ def get_ip(): partyIcons.update({party: PARTYICONLIST[partyCount]}) # PARTY_ICON party_icon = PARTYICONLIST[partyCount] + partyNum = partyCount + 1 partyCount += 1 else: # PARTY_ICON @@ -428,14 +430,17 @@ def get_ip(): ]) heartbeat_data["players"][player["Subject"]] = { + "puuid": player["Subject"], "name": names[player["Subject"]], - "partyNumber": partyCount if party_icon != "" else 0, + "partyNumber": partyNum if party_icon != "" else 0, "agent": agent_dict[player["CharacterID"].lower()], - "map": map_dict[coregame_stats["MapID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], "peakRankAct": peakRankAct, "rr": rr, + "kd": ppstats["kd"], + "headshotPercentage": ppstats["hs"], + "winPercentage": f"{playerRank['wr']} ({playerRank['numberofgames']})", "level": player_level, "agentImgLink": loadouts_data["Players"][player["Subject"]].get("Agent",None), "team": loadouts_data["Players"][player["Subject"]].get("Team",None), @@ -497,6 +502,7 @@ def get_ip(): partyIcons.update({party: PARTYICONLIST[partyCount]}) # PARTY_ICON party_icon = PARTYICONLIST[partyCount] + partyNum = partyCount + 1 else: # PARTY_ICON party_icon = partyIcons[party] @@ -600,7 +606,7 @@ def get_ip(): heartbeat_data["players"][player["Subject"]] = { "name": names[player["Subject"]], - "partyNumber": partyCount if party_icon != "" else 0, + "partyNumber": partyNum if party_icon != "" else 0, "agent": agent_dict[player["CharacterID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], From 07eb003fcb4e3e41ac8973a95f11fd25b3eed5f6 Mon Sep 17 00:00:00 2001 From: tanishqmanuja Date: Thu, 1 Sep 2022 13:39:15 +0530 Subject: [PATCH 23/23] fix(server): disable not secure warnings --- main.py | 8 ++++++++ src/server.py | 5 +++-- src/websocket.py | 10 ++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 887be0d0..431bde9d 100644 --- a/main.py +++ b/main.py @@ -610,8 +610,12 @@ def get_ip(): "agent": agent_dict[player["CharacterID"].lower()], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], + "peakRankAct": peakRankAct, "level": player_level, "rr": rr, + "kd": ppstats["kd"], + "headshotPercentage": ppstats["hs"], + "winPercentage": f"{playerRank['wr']} ({playerRank['numberofgames']})", } # bar() @@ -703,8 +707,12 @@ def get_ip(): "name": names[player["Subject"]], "rank": playerRank["rank"], "peakRank": playerRank["peakrank"], + "peakRankAct": peakRankAct, "level": player_level, "rr": rr, + "kd": ppstats["kd"], + "headshotPercentage": ppstats["hs"], + "winPercentage": f"{playerRank['wr']} ({playerRank['numberofgames']})", } # bar() diff --git a/src/server.py b/src/server.py index 29954c9e..00c72e80 100644 --- a/src/server.py +++ b/src/server.py @@ -1,11 +1,12 @@ import json - +import logging from websocket_server import WebsocketServer from src.constants import version -# websocket.enableTrace(True) +logging.getLogger('websocket_server.websocket_server').disabled = True +# websocket.enableTrace(True) class Server: def __init__(self, log, Error): diff --git a/src/websocket.py b/src/websocket.py index be18d635..f325f4aa 100644 --- a/src/websocket.py +++ b/src/websocket.py @@ -111,11 +111,12 @@ def handle(self, m, initial_game_state): if self.player_data[message['puuid']]['streamer_mode'] and self.hide_names and message['puuid'] not in self.player_data["ignore"]: self.print_message(f"{chat_prefix} {color(self.colors.escape_ansi(agent), clr)}: {message['body']}") self.server.send_payload("chat",{ + "time": message["time"], "puuid": player, "self": message["puuid"] == self.Requests.puuid, - "chatType":self.colors.escape_ansi(chat_prefix), + "group":re.sub("\[|\]","",self.colors.escape_ansi(chat_prefix)), "agent": self.colors.escape_ansi(agent), - "message": message['body'] + "text": message['body'] }) else: if agent == "": @@ -124,12 +125,13 @@ def handle(self, m, initial_game_state): agent_str = f" ({agent})" self.print_message(f"{chat_prefix} {color(name, clr)}{agent_str}: {message['body']}") self.server.send_payload("chat",{ + "time": message["time"], "puuid": player, "self": message["puuid"] == self.Requests.puuid, - "chatType":self.colors.escape_ansi(chat_prefix), + "group":re.sub("\[|\]","",self.colors.escape_ansi(chat_prefix)), "player": name, "agent": self.colors.escape_ansi(agent), - "message": message['body'] + "text": message['body'] }) self.id_seen.append(message['id'])