From e926f809f76805270a98294987856a25d00424c9 Mon Sep 17 00:00:00 2001 From: gabriel fortier Date: Thu, 25 Nov 2021 19:28:56 -0500 Subject: [PATCH] Added clubs and fixed a lot of stuff Added some security for clubs and at login ## Clubs join request is not done (im very lazy) and only leader will have full permission because im currently facing some issue with clubs permissions --- Core.py | 34 ++- Database/ClubManager.py | 55 +++- Database/DatabaseManager.py | 15 +- Logic/Classes/LogicClientAvatar.py | 6 +- Logic/Classes/LogicClientHome.py | 15 +- Logic/Classes/LogicCommand.py | 2 +- Logic/Classes/LogicDailyData.py | 4 +- Logic/Classes/LogicPlayerMap.py | 4 +- Logic/Client/DevicesManager.py | 6 +- Logic/Client/PlayerManager.py | 29 +- Logic/Data/DataManager.py | 19 +- Logic/Data/PacketsHandler.py | 12 +- Logic/Files/Classes/Regions.py | 35 +++ Logic/Files/assets/csv_logic/regions.csv | 268 ++++++++++++++++++ Logic/Helpers/PlayerDisplayData.py | 6 +- Logic/Notifications/BandNotification.py | 2 +- Logic/Settings/Configuration.py | 7 - Logic/Stream/AllianceEventStreamEntry.py | 14 + Logic/Stream/ChatStreamEntry.py | 9 + .../Stream/JoinRequestAllianceStreamEntry.py | 14 + Logic/Stream/MessageDataStreamEntry.py | 10 + Logic/Stream/QuickChatStreamEntry.py | 13 + Logic/Stream/ReplayStreamEntry.py | 18 ++ Logic/Stream/StreamEntry.py | 13 + Logic/Stream/StreamEntryFactory.py | 31 ++ Logic/Stream/TeamCreatedStreamEntry.py | 12 + Logic/Utility/Utils.py | 31 +- .../Client/LogicClearShopTickersCommand.py | 8 +- .../LogicEnableSkinRandomizerCommand.py | 4 +- .../Commands/Client/LogicGatchaCommand.py | 3 +- .../Commands/Client/LogicHeroSeenCommand.py | 4 +- .../LogicPurchaseHeroLvlUpMaterialCommand.py | 2 +- .../Client/LogicSelectCharacterCommand.py | 3 +- .../Client/LogicSelectEmoteCommand.py | 4 +- .../Commands/Client/LogicSelectSkinCommand.py | 5 +- .../Client/LogicSelectStarPowerCommand.py | 2 +- .../LogicViewInboxNotificationCommand.py | 18 ++ .../Server/LogicChangeAvatarNameCommand.py | 2 +- Messaging/LogicMessageFactory.py | 21 ++ .../Alliance/AlliancePremadeChatMessage.py | 39 +++ .../Alliance/AskForAllianceDataMessage.py | 11 +- .../AskForJoinableAlliancesListMessage.py | 18 ++ .../ChangeAllianceMemberRoleMessage.py | 68 +++++ .../Alliance/ChangeAllianceSettingsMessage.py | 50 ++++ .../Alliance/ChatToAllianceStreamMessage.py | 38 +++ .../Client/Alliance/CreateAllianceMessage.py | 59 ++++ .../Client/Alliance/JoinAllianceMessage.py | 55 ++++ .../Client/Alliance/LeaveAllianceMessage.py | 83 ++++++ .../Client/Alliance/SearchAlliancesMessage.py | 28 ++ .../Alliance/SendAllianceMailMessage.py | 57 ++++ .../Client/Authentication/LoginMessage.py | 43 ++- .../Client/Game/EndClientTurnMessage.py | 9 +- .../Client/Home/GetPlayerProfileMessage.py | 2 +- .../Server/Alliance/AllianceDataMessage.py | 76 ++++- .../Server/Alliance/AllianceListMessage.py | 45 +++ .../Server/Alliance/AllianceMemberMessage.py | 40 +++ .../Alliance/AllianceMemberRemovedMessage.py | 15 + .../Alliance/AllianceResponseMessage.py | 14 + .../Alliance/AllianceStreamEntryMessage.py | 15 + .../Server/Alliance/AllianceStreamMessage.py | 22 ++ .../Server/Alliance/AllianceTeamsMessage.py | 13 + .../ChangeAllianceSettingsOkMessage.py | 66 +++++ .../Alliance/JoinableAllianceListMessage.py | 47 +++ .../Server/Alliance/MyAllianceMessage.py | 35 ++- .../Server/Alliance/UnknownAllianceMessage.py | 6 +- .../UnknownLeaderboardAllianceMessage.py | 4 +- .../Authentication/LoginFailedMessage.py | 7 +- .../Packets/Server/Battle/BattleEndMessage.py | 4 +- .../Home/AvailableServerCommandMessage.py | 31 ++ .../Server/Home/PlayerProfileMessage.py | 56 +++- 70 files changed, 1688 insertions(+), 128 deletions(-) create mode 100644 Logic/Files/Classes/Regions.py create mode 100644 Logic/Files/assets/csv_logic/regions.csv create mode 100644 Logic/Stream/AllianceEventStreamEntry.py create mode 100644 Logic/Stream/ChatStreamEntry.py create mode 100644 Logic/Stream/JoinRequestAllianceStreamEntry.py create mode 100644 Logic/Stream/MessageDataStreamEntry.py create mode 100644 Logic/Stream/QuickChatStreamEntry.py create mode 100644 Logic/Stream/ReplayStreamEntry.py create mode 100644 Logic/Stream/StreamEntry.py create mode 100644 Logic/Stream/StreamEntryFactory.py create mode 100644 Logic/Stream/TeamCreatedStreamEntry.py create mode 100644 Messaging/Commands/Client/LogicViewInboxNotificationCommand.py create mode 100644 Messaging/Packets/Client/Alliance/AlliancePremadeChatMessage.py create mode 100644 Messaging/Packets/Client/Alliance/AskForJoinableAlliancesListMessage.py create mode 100644 Messaging/Packets/Client/Alliance/ChangeAllianceMemberRoleMessage.py create mode 100644 Messaging/Packets/Client/Alliance/ChangeAllianceSettingsMessage.py create mode 100644 Messaging/Packets/Client/Alliance/ChatToAllianceStreamMessage.py create mode 100644 Messaging/Packets/Client/Alliance/CreateAllianceMessage.py create mode 100644 Messaging/Packets/Client/Alliance/JoinAllianceMessage.py create mode 100644 Messaging/Packets/Client/Alliance/LeaveAllianceMessage.py create mode 100644 Messaging/Packets/Client/Alliance/SearchAlliancesMessage.py create mode 100644 Messaging/Packets/Client/Alliance/SendAllianceMailMessage.py create mode 100644 Messaging/Packets/Server/Alliance/AllianceListMessage.py create mode 100644 Messaging/Packets/Server/Alliance/AllianceMemberMessage.py create mode 100644 Messaging/Packets/Server/Alliance/AllianceMemberRemovedMessage.py create mode 100644 Messaging/Packets/Server/Alliance/AllianceResponseMessage.py create mode 100644 Messaging/Packets/Server/Alliance/AllianceStreamEntryMessage.py create mode 100644 Messaging/Packets/Server/Alliance/AllianceStreamMessage.py create mode 100644 Messaging/Packets/Server/Alliance/AllianceTeamsMessage.py create mode 100644 Messaging/Packets/Server/Alliance/ChangeAllianceSettingsOkMessage.py create mode 100644 Messaging/Packets/Server/Alliance/JoinableAllianceListMessage.py create mode 100644 Messaging/Packets/Server/Home/AvailableServerCommandMessage.py diff --git a/Core.py b/Core.py index 59e7ca4..8f01b20 100644 --- a/Core.py +++ b/Core.py @@ -1,11 +1,14 @@ import socket import threading +import time import traceback from builtins import ConnectionError from Logic.Client.ClientsManager import ClientsManager from Logic.Data.PacketsHandler import PacketsHandler from Logic.Client.PlayerManager import Players +from Messaging.Packets.Server.Home.LobbyInfoMessage import LobbyInfoMessage + class Core: def __init__(self): @@ -25,7 +28,8 @@ def __init__(self, client, address): super().__init__() self.address = address self.client = client - self.player = Players + self.player = Players() + LobbyInfoMessageThread(self.client).start() def run(self): try: @@ -38,6 +42,32 @@ def run(self): ClientsManager.RemoveSocket(self.player.LowID) self.client.close() print(traceback.format_exc()) - exit(0) + # exit(0) + return + + except OSError: + print(f"Client with ip: {self.address[0]} disconnected!") + ClientsManager.RemoveSocket(self.player.LowID) + self.client.close() + print(traceback.format_exc()) + # exit(0) + return + +class LobbyInfoMessageThread(threading.Thread): + def __init__(self, client): + super().__init__() + self.client = client + self.player = Players + + def run(self): + timeout = time.time() + try: + while True: + time.sleep(0.1) + if time.time() >= timeout + 1: + LobbyInfoMessage(self.client, self.player).send(self.client) + timeout = time.time() + except: + return Core().CoreInit() \ No newline at end of file diff --git a/Database/ClubManager.py b/Database/ClubManager.py index 74690e6..c345a9d 100644 --- a/Database/ClubManager.py +++ b/Database/ClubManager.py @@ -1,5 +1,10 @@ import json import sqlite3 +import traceback +from collections import OrderedDict +from operator import getitem + +from Logic.Files.Classes.Regions import Regions class ClubManager(): @@ -27,17 +32,36 @@ def deleteClub(self, lowID): print(e) - def GetAllDb(self): - self.playersId = [] + def getAllClub(self): + clubs = [] try: self.cursor.execute("SELECT * from main") self.db = self.cursor.fetchall() for i in range(len(self.db)): - self.playersId.append(self.db[i][0]) - return self.playersId + clubs.append(json.loads(self.db[i][1])) + return clubs except Exception as e: print(e) + def getAllClubByRegion(self, regionID): + clubs = [] + try: + self.cursor.execute("SELECT * from main") + self.db = self.cursor.fetchall() + for i in range(len(self.db)): + dataLoaded = json.loads(self.db[i][1]) + if dataLoaded['RegionID'] == Regions.getIDByRegion(self, regionID): + clubs.append(dataLoaded) + return clubs + except Exception as e: + print(traceback.format_exc()) + + def getDefaultMembersData(self, player, role): + return {'HighID': player.HighID, 'LowID': player.LowID, 'Name': player.Name, 'Role': role, 'Trophies': player.trophies, 'NameColor': player.nameColor, 'Thumbnail': player.thumbnail} + + def getDefaultMessageData(self, eventType, streamType, lastID, playerID, playerName, playerRole, target={}, msgData="", premadeID=-1, messageDataID=-1): + return {'StreamType': eventType, 'EventType': streamType, 'StreamID': lastID, 'PlayerID': playerID, 'PlayerName': playerName, 'PlayerRole': playerRole, 'Message': msgData, 'Target': target, 'PremadeID': premadeID, 'MessageDataID': messageDataID} + def getClubWithLowID(self, low): try: self.cursor.execute("SELECT * from main where LowID=?", (low,)) @@ -45,6 +69,27 @@ def getClubWithLowID(self, low): except Exception as e: print(e) + def getMembersSorted(self, clubdata): + try: + return sorted(clubdata['Members'].items(), key = lambda x: x[1]['Trophies'], reverse=True) + except Exception as e: + print(e) + + def getMemberWithLowID(self, clubData, playerLowID): + try: + return clubData["Members"][str(playerLowID)] + except Exception as e: + print(e) + + def getTotalTrophies(self, clubData): + try: + totalTrophies = 0 + for i in clubData["Members"].values(): + totalTrophies += i['Trophies'] + return totalTrophies + except Exception as e: + print(e) + def LoadAccount(self, low, player): try: self.player = player @@ -54,7 +99,7 @@ def LoadAccount(self, low, player): except Exception as e: print(e) - def update_player_data(self, data, lowID): + def updateClubData(self, data, lowID): try: self.cursor.execute("UPDATE main SET Data=? WHERE LowID=?", (json.dumps(data, ensure_ascii=0), lowID)) self.conn.commit() diff --git a/Database/DatabaseManager.py b/Database/DatabaseManager.py index d90fb31..2c95f52 100644 --- a/Database/DatabaseManager.py +++ b/Database/DatabaseManager.py @@ -20,7 +20,7 @@ def createAccount(self, lowID, token, data): except Exception: print(traceback.format_exc()) - def GetAllDb(self, low_id): + def GetAllDb(self): self.playersId = [] try: self.cursor.execute("SELECT * from main") @@ -42,9 +42,10 @@ def LoadAccount(self, low, player): try: self.player = player self.cursor.execute("SELECT * from main where LowID=?", (low,)) - self.players = self.cursor.fetchall() - self.players = json.loads(self.players[0][2]) + playersdata = self.cursor.fetchall() + self.players = json.loads(playersdata[0][2]) self.player.Name = self.players['name'] + self.player.Token = playersdata[0][1] self.player.isRegistred = self.players['IsRegistred'] self.player.level = self.players['level'] self.player.doNotDisturb = self.players['DoNotDisturb'] @@ -57,21 +58,23 @@ def LoadAccount(self, low, player): self.player.brawlersTrophies = self.players['brawlersTrophies'] self.player.selectedRandomSkin = self.players['selectedRandomSkin'] self.player.starpowerID = self.players['starpowerID'] - self.player.thumbnails = self.players['playericon'] + self.player.thumbnail = self.players['playericon'] self.player.nameColor = self.players['namecolor'] + self.player.region = self.players['region'] self.player.trophies = self.players['trophies'] self.player.experience = self.players['experience'] self.player.room_id = self.players['gameroomID'] self.player.roomInfo = self.players['roomInfo'] - self.player.alliance_id = self.players['allianceID'] + self.player.allianceID = self.players['allianceID'] self.player.isBanned = self.players['isBanned'] self.player.gems = self.players['gems'] self.player.coins = self.players['coins'] + self.player.clubMailInbox = self.players['clubMailInbox'] except Exception: print(traceback.format_exc()) - def update_player_data(self, data, lowID): + def updatePlayerData(self, data, lowID): try: self.cursor.execute("UPDATE main SET Data=? WHERE LowID=?", (json.dumps(data, ensure_ascii=0), lowID)) self.conn.commit() diff --git a/Logic/Classes/LogicClientAvatar.py b/Logic/Classes/LogicClientAvatar.py index 90861c4..7a9cd1f 100644 --- a/Logic/Classes/LogicClientAvatar.py +++ b/Logic/Classes/LogicClientAvatar.py @@ -6,9 +6,9 @@ def decode(self: Reader): pass def encode(self: Writer): - self.writeVLong(self.player.HighID, self.player.LowID) # PlayerID - self.writeVLong(self.player.HighID, self.player.LowID) - self.writeVLong(self.player.HighID, self.player.LowID) + self.writeLogicLong(self.player.HighID, self.player.LowID) # PlayerID + self.writeLogicLong(self.player.HighID, self.player.LowID) + self.writeLogicLong(self.player.HighID, self.player.LowID) self.writeString(self.player.Name) # PlayerName self.writeBoolean(self.player.isRegistred) # isRegistred diff --git a/Logic/Classes/LogicClientHome.py b/Logic/Classes/LogicClientHome.py index 11cafe0..64120c3 100644 --- a/Logic/Classes/LogicClientHome.py +++ b/Logic/Classes/LogicClientHome.py @@ -15,17 +15,20 @@ def encode(self: Writer): LogicConfData.encode(self) self.writeLong(self.player.HighID, self.player.LowID) # PlayerID - self.writeVint(len(Configuration.Inbox)) # Notification Factory + self.writeVint(len(Configuration.Inbox) + len(self.player.clubMailInbox)) # Notification Factory for notifInfo in Configuration.Inbox: NotificationFactory.encode(self, (Configuration.Inbox.index(notifInfo), notifInfo)) + for notifInfo2 in self.player.clubMailInbox: + NotificationFactory.encode(self, (notifInfo2['Index'], notifInfo2)) + # TODO # self.writeVint(58) # New Club For Club League # self.writeInt(10) # self.writeBoolean(True) # self.writeInt(9999) # self.writeString("BSDS") - # self.writeVLong(0, 1) + # self.writeLogicLong(0, 1) # self.writeDataReference(0) # self.writeString("BSDS HACC") # @@ -36,8 +39,8 @@ def encode(self: Writer): # self.writeString("BSDS") # self.writeVint(1) # self.writeVint(1) - # self.writeVLong(0, 1) - # self.writeVLong(0, 1) + # self.writeLogicLong(0, 1) + # self.writeLogicLong(0, 1) # self.writeVint(1) # self.writeVint(1) # self.writeVint(1) @@ -50,8 +53,8 @@ def encode(self: Writer): # self.writeInt(9999) # self.writeString("BSDS") # self.writeVint(1) - # self.writeVLong(0, 1) - # self.writeVLong(0, 1) + # self.writeLogicLong(0, 1) + # self.writeLogicLong(0, 1) # self.writeDataReference(0, 0) # self.writeVint(1) # self.writeVint(1) diff --git a/Logic/Classes/LogicCommand.py b/Logic/Classes/LogicCommand.py index b62d825..bcda6e9 100644 --- a/Logic/Classes/LogicCommand.py +++ b/Logic/Classes/LogicCommand.py @@ -8,4 +8,4 @@ class LogicCommand: def encode(self): self.writeVint(0) self.writeVint(0) - self.writeVLong(self.player.HighID, self.player.LowID) + self.writeLogicLong(self.player.HighID, self.player.LowID) diff --git a/Logic/Classes/LogicDailyData.py b/Logic/Classes/LogicDailyData.py index dbdc96e..3083f38 100644 --- a/Logic/Classes/LogicDailyData.py +++ b/Logic/Classes/LogicDailyData.py @@ -11,7 +11,7 @@ def encode(self: Writer): self.writeVint(self.player.highestTrophies) self.writeVint(self.player.trophy_road_tier) self.writeVint(self.player.experience) - self.writeDataReference(28, self.player.thumbnails) + self.writeDataReference(28, self.player.thumbnail) self.writeDataReference(43, self.player.nameColor) # Array @@ -85,7 +85,7 @@ def encode(self: Writer): self.writeVint(0) self.writeVint(0) self.writeDataReference(16, self.player.brawlerID) - self.writeString('CA') + self.writeString(self.player.region) self.writeString("Project BSDS") self.writeVint(18) diff --git a/Logic/Classes/LogicPlayerMap.py b/Logic/Classes/LogicPlayerMap.py index 2643fab..30169f5 100644 --- a/Logic/Classes/LogicPlayerMap.py +++ b/Logic/Classes/LogicPlayerMap.py @@ -4,12 +4,12 @@ class LogicPlayerMap: def decode(self: Reader): - self.readVLong("MapID") + self.readLogicLong("MapID") self.readString("MapName") self.readVint("GameModeVariation") self.readDataReference("MapEnvironmentData") self.readCompressedString("MapData") - self.readVLong("AccountID") + self.readLogicLong("AccountID") self.readString("AvatarName") self.readVint("State") self.readLong("LastUpdateTimeSecondsSinceEpoch") diff --git a/Logic/Client/DevicesManager.py b/Logic/Client/DevicesManager.py index 2e20a1f..a32c4e0 100644 --- a/Logic/Client/DevicesManager.py +++ b/Logic/Client/DevicesManager.py @@ -1,5 +1,7 @@ class Device: + def __init__(self): + pass + major = 0 minor = 0 - build = 0 - isAndroid = True \ No newline at end of file + build = 0 \ No newline at end of file diff --git a/Logic/Client/PlayerManager.py b/Logic/Client/PlayerManager.py index 629bd48..7fe935e 100644 --- a/Logic/Client/PlayerManager.py +++ b/Logic/Client/PlayerManager.py @@ -11,6 +11,9 @@ class Players: + def __init__(self): + pass + HighID = 0 LowID = 0 Token = "" @@ -20,6 +23,8 @@ class Players: friends = [] + allianceTry = 0 + trophies = 10000 highestTrophies = 10000 experience = 999999 @@ -33,8 +38,9 @@ class Players: ClubCoins = 9999999 GearsScrap = 9999999 - thumbnails = 0 + thumbnail = 0 nameColor = 0 + region = "CA" brawlerID = 0 skinID = 0 @@ -51,7 +57,7 @@ class Players: allPins = Pins.getPinsID() allThumbnailsReward = PlayerThumbnails.getThumbnailsID() - alliance_id = 0 + allianceID = [0, 0] room_id = [0, 0] roomInfo = { @@ -60,24 +66,33 @@ class Players: "roomType": 0 } + clubMailInbox = [ + + ] + doNotDisturb = False playerState = False lastOnline = 0 device = DevicesManager.Device - def CreateAccount(self, highid, lowid, token): - if lowid == 0: + def CreateAccount(self, highid, lowid, token, overide=False): + + if overide == False: self.HighID = int(''.join([str(random.randint(0, 9)) for _ in range(1)])) self.LowID = int(''.join([str(random.randint(0, 9)) for _ in range(8)])) self.Token = ''.join(random.choice(string.ascii_letters + string.digits) for i in range(40)) + else: + self.HighID = highid + self.LowID = lowid + self.Token = token DBData = { 'HighID': self.HighID, 'LowID': self.LowID, 'Token': self.Token, 'name': self.Name, - 'allianceID': self.alliance_id, + 'allianceID': self.allianceID, 'PlayerState': self.playerState, 'LastOnline': self.lastOnline, 'DoNotDisturb': self.doNotDisturb, @@ -88,8 +103,9 @@ def CreateAccount(self, highid, lowid, token): 'brawlersTrophies': self.brawlersTrophies, 'brawlerState': self.brawlerState, 'starpowerID': self.starpowerID, - 'playericon': self.thumbnails, + 'playericon': self.thumbnail, 'namecolor': self.nameColor, + 'region': self.region, 'highestTrophies': self.highestTrophies, 'IsRegistred': self.isRegistred, 'trophies': self.trophies, @@ -99,6 +115,7 @@ def CreateAccount(self, highid, lowid, token): 'coins': self.coins, 'isBanned': self.isBanned, 'gameroomID': self.room_id, + 'clubMailInbox': self.clubMailInbox, "roomInfo": { "eventSlot": 0, "mapID": 0, diff --git a/Logic/Data/DataManager.py b/Logic/Data/DataManager.py index aeb47c1..a26c79a 100644 --- a/Logic/Data/DataManager.py +++ b/Logic/Data/DataManager.py @@ -44,7 +44,7 @@ def writeUInt8(self, integer: int): def writeLong(self, high, low): self.buffer += high.to_bytes(4, 'big') + low.to_bytes(4, 'big') - def writeVLong(self, high, low): + def writeLogicLong(self, high, low): self.writeVint(high) self.writeVint(low) @@ -104,10 +104,7 @@ def writeString(self, string = None): self.buffer += encoded def writeStringReference(self, string: str = None): - encoded = string.encode('utf-8') - self.writeInt16(0) - self.writeVint(len(encoded)) - self.buffer += encoded + self.writeString(string) def writeByte(self, data): if data > 255: @@ -142,8 +139,12 @@ def send(self, PlayerLowID, cryptoBytesEnd: int = 1): else: self.version = 0 self.writeInt16(0) - print(f"---------------------------------------------------------------------------------------------") - print(f"\033[92m[{Utils.GetTime(self)}] [CLIENT] PacketID: {self.id} Hex: {hex(self.id)} Name: {self.__class__.__name__} Length: {len(packet)} Version: {self.version}") + if self.id != 23457: + print(f"---------------------------------------------------------------------------------------------") + print(f"\033[92m[{Utils.getTime()}] [SERVER] PacketID: {self.id} Hex: {hex(self.id)} Name: {self.__class__.__name__} Length: {len(packet)} Version: {self.version} Sending to player id {PlayerLowID}") + # else: + # print(f"\033[92m[{Utils.getTime()}] [SERVER] PacketID: {self.id} Hex: {hex(self.id)} Name: {self.__class__.__name__} Length: {len(packet)} Version: {self.version}") + crypto_bytes = b'\xff\xff\x00\x00\x00\x00\x00' if cryptoInfo.changed == False: cryptoInfo.cryptobytesPosition = cryptoBytesEnd @@ -157,7 +158,7 @@ def send(self, PlayerLowID, cryptoBytesEnd: int = 1): crypto_bytes = self.buffer + packet try: - if self.id == 23457: + if self.id == 23457 or self.id == 20103: self.client.sendall(crypto_bytes) return ClientsManager.SocketsList["Sockets"][PlayerLowID].sendall(crypto_bytes) @@ -201,7 +202,7 @@ def readVint(self): n = self.readVarint(True) return (n >> 1) ^ (-(n & 1)) - def readVLong(self): + def readLogicLong(self): ID = [] ID.append(self.readVint()) ID.append(self.readVint()) diff --git a/Logic/Data/PacketsHandler.py b/Logic/Data/PacketsHandler.py index f488a10..38bf439 100644 --- a/Logic/Data/PacketsHandler.py +++ b/Logic/Data/PacketsHandler.py @@ -1,3 +1,7 @@ +import threading +import time + +from Logic.Client.PlayerManager import Players from Messaging.LogicMessageFactory import identifiers, knownList from Messaging.Packets.Server.Home.LobbyInfoMessage import LobbyInfoMessage from Logic.Utility.Utils import Utils @@ -26,18 +30,18 @@ def recv(n): packet_name = identifiers[packet_identifier].__name__ print(f"---------------------------------------------------------------------------------------------") - print(f"\033[93m[{Utils.GetTime(self)}] [SERVER] PacketID: {packet_identifier} Hex: {hex(packet_identifier)} Name: {packet_name} Length: {length} Version: {version}, Data: {data}") + print(f"\033[93m[{Utils.getTime()}] [CLIENT] PacketID: {packet_identifier} Hex: {hex(packet_identifier)} Name: {packet_name} Length: {length} Version: {version}, Data: {data}") message.decode() message.process() elif packet_identifier in knownList: print(f"---------------------------------------------------------------------------------------------") - print(f"\033[93m[{Utils.GetTime(self)}] [SERVER] PacketID: {packet_identifier} Hex: {hex(packet_identifier)} Name: {knownList[packet_identifier]} Length: {length} Version: {version}, Data: {data}") + print(f"\033[93m[{Utils.getTime()}] [CLIENT] PacketID: {packet_identifier} Hex: {hex(packet_identifier)} Name: {knownList[packet_identifier]} Length: {length} Version: {version}, Data: {data}") else: print(f"---------------------------------------------------------------------------------------------") - print(f"\033[93m[{Utils.GetTime(self)}] [SERVER] PacketID: {packet_identifier} Hex: {hex(packet_identifier)} Name: Unknown Length: {length} Version: {version}, Data: {data}") + print(f"\033[93m[{Utils.getTime()}] [CLIENT] PacketID: {packet_identifier} Hex: {hex(packet_identifier)} Name: Unknown Length: {length} Version: {version}, Data: {data}") # Yes i like to put useless line of code ¯\_(ツ)_/¯ - LobbyInfoMessage(self.client, self.player).send(self.client) \ No newline at end of file + # LobbyInfoMessage(self.client, self.player).send(self.player.LowID) \ No newline at end of file diff --git a/Logic/Files/Classes/Regions.py b/Logic/Files/Classes/Regions.py new file mode 100644 index 0000000..1d90c38 --- /dev/null +++ b/Logic/Files/Classes/Regions.py @@ -0,0 +1,35 @@ +import csv + + +class Regions: + def getRegionByID(self, regionID): + RegionID = 0 + with open('Logic/Files/assets/csv_logic/regions.csv') as csv_file: + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + for row in csv_reader: + if line_count <= 1: + line_count += 1 + elif line_count - 2 == regionID: + RegionID = row[0] + break + else: + line_count += 1 + + return RegionID + + def getIDByRegion(self, regionName): + RegionID = 0 + with open('Logic/Files/assets/csv_logic/regions.csv') as csv_file: + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + for row in csv_reader: + if line_count <= 1: + line_count += 1 + elif row[0] == regionName: + RegionID = line_count - 2 + break + else: + line_count += 1 + + return RegionID \ No newline at end of file diff --git a/Logic/Files/assets/csv_logic/regions.csv b/Logic/Files/assets/csv_logic/regions.csv new file mode 100644 index 0000000..9a1a0d4 --- /dev/null +++ b/Logic/Files/assets/csv_logic/regions.csv @@ -0,0 +1,268 @@ +Name,TID,DisplayName,IsCountry +String,String,String,boolean +_EU,,Europe,FALSE +_NA,,North America,FALSE +_SA,,South America,FALSE +_AS,,Asia,FALSE +_AU,,Australia,FALSE +_AF,,Africa,FALSE +_INT,TID_REGION_INT,International,FALSE +AF,,Afghanistan,TRUE +AX,,Åland Islands,TRUE +AL,,Albania,TRUE +DZ,,Algeria,TRUE +AS,,American Samoa,TRUE +AD,,Andorra,TRUE +AO,,Angola,TRUE +AI,,Anguilla,TRUE +AQ,,Antarctica,TRUE +AG,,Antigua and Barbuda,TRUE +AR,,Argentina,TRUE +AM,,Armenia,TRUE +AW,,Aruba,TRUE +AC,,Ascension Island,TRUE +AU,,Australia,TRUE +AT,,Austria,TRUE +AZ,,Azerbaijan,TRUE +BS,,Bahamas,TRUE +BH,,Bahrain,TRUE +BD,,Bangladesh,TRUE +BB,,Barbados,TRUE +BY,,Belarus,TRUE +BE,,Belgium,TRUE +BZ,,Belize,TRUE +BJ,,Benin,TRUE +BM,,Bermuda,TRUE +BT,,Bhutan,TRUE +BO,,Bolivia,TRUE +BA,,Bosnia and Herzegovina,TRUE +BW,,Botswana,TRUE +BV,,Bouvet Island,TRUE +BR,,Brazil,TRUE +IO,,British Indian Ocean Territory,TRUE +VG,,British Virgin Islands,TRUE +BN,,Brunei,TRUE +BG,,Bulgaria,TRUE +BF,,Burkina Faso,TRUE +BI,,Burundi,TRUE +KH,,Cambodia,TRUE +CM,,Cameroon,TRUE +CA,,Canada,TRUE +IC,,Canary Islands,TRUE +CV,,Cape Verde,TRUE +BQ,,Caribbean Netherlands,TRUE +KY,,Cayman Islands,TRUE +CF,,Central African Republic,TRUE +EA,,Ceuta and Melilla,TRUE +TD,,Chad,TRUE +CL,,Chile,TRUE +CN,,China,TRUE +CX,,Christmas Island,TRUE +CC,,Cocos (Keeling) Islands,TRUE +CO,,Colombia,TRUE +KM,,Comoros,TRUE +CG,,Congo (DRC),TRUE +CD,,Congo (Republic),TRUE +CK,,Cook Islands,TRUE +CR,,Costa Rica,TRUE +CI,,Côte d’Ivoire,TRUE +HR,,Croatia,TRUE +CU,,Cuba,TRUE +CW,,Curaçao,TRUE +CY,,Cyprus,TRUE +CZ,,Czech Republic,TRUE +DK,,Denmark,TRUE +DG,,Diego Garcia,TRUE +DJ,,Djibouti,TRUE +DM,,Dominica,TRUE +DO,,Dominican Republic,TRUE +EC,,Ecuador,TRUE +EG,,Egypt,TRUE +SV,,El Salvador,TRUE +GQ,,Equatorial Guinea,TRUE +ER,,Eritrea,TRUE +EE,,Estonia,TRUE +ET,,Ethiopia,TRUE +FK,,Falkland Islands,TRUE +FO,,Faroe Islands,TRUE +FJ,,Fiji,TRUE +FI,,Finland,TRUE +FR,,France,TRUE +GF,,French Guiana,TRUE +PF,,French Polynesia,TRUE +TF,,French Southern Territories,TRUE +GA,,Gabon,TRUE +GM,,Gambia,TRUE +GE,,Georgia,TRUE +DE,,Germany,TRUE +GH,,Ghana,TRUE +GI,,Gibraltar,TRUE +GR,,Greece,TRUE +GL,,Greenland,TRUE +GD,,Grenada,TRUE +GP,,Guadeloupe,TRUE +GU,,Guam,TRUE +GT,,Guatemala,TRUE +GG,,Guernsey,TRUE +GN,,Guinea,TRUE +GW,,Guinea-Bissau,TRUE +GY,,Guyana,TRUE +HT,,Haiti,TRUE +HM,,Heard & McDonald Islands,TRUE +HN,,Honduras,TRUE +HK,,Hong Kong,TRUE +HU,,Hungary,TRUE +IS,,Iceland,TRUE +IN,,India,TRUE +ID,,Indonesia,TRUE +IR,,Iran,TRUE +IQ,,Iraq,TRUE +IE,,Ireland,TRUE +IM,,Isle of Man,TRUE +IL,,Israel,TRUE +IT,,Italy,TRUE +JM,,Jamaica,TRUE +JP,,Japan,TRUE +JE,,Jersey,TRUE +JO,,Jordan,TRUE +KZ,,Kazakhstan,TRUE +KE,,Kenya,TRUE +KI,,Kiribati,TRUE +XK,,Kosovo,TRUE +KW,,Kuwait,TRUE +KG,,Kyrgyzstan,TRUE +LA,,Laos,TRUE +LV,,Latvia,TRUE +LB,,Lebanon,TRUE +LS,,Lesotho,TRUE +LR,,Liberia,TRUE +LY,,Libya,TRUE +LI,,Liechtenstein,TRUE +LT,,Lithuania,TRUE +LU,,Luxembourg,TRUE +MO,,Macau,TRUE +MK,,Macedonia (FYROM),TRUE +MG,,Madagascar,TRUE +MW,,Malawi,TRUE +MY,,Malaysia,TRUE +MV,,Maldives,TRUE +ML,,Mali,TRUE +MT,,Malta,TRUE +MH,,Marshall Islands,TRUE +MQ,,Martinique,TRUE +MR,,Mauritania,TRUE +MU,,Mauritius,TRUE +YT,,Mayotte,TRUE +MX,,Mexico,TRUE +FM,,Micronesia,TRUE +MD,,Moldova,TRUE +MC,,Monaco,TRUE +MN,,Mongolia,TRUE +ME,,Montenegro,TRUE +MS,,Montserrat,TRUE +MA,,Morocco,TRUE +MZ,,Mozambique,TRUE +MM,,Myanmar (Burma),TRUE +NA,,Namibia,TRUE +NR,,Nauru,TRUE +NP,,Nepal,TRUE +NL,,Netherlands,TRUE +NC,,New Caledonia,TRUE +NZ,,New Zealand,TRUE +NI,,Nicaragua,TRUE +NE,,Niger,TRUE +NG,,Nigeria,TRUE +NU,,Niue,TRUE +NF,,Norfolk Island,TRUE +KP,,North Korea,TRUE +MP,,Northern Mariana Islands,TRUE +NO,,Norway,TRUE +OM,,Oman,TRUE +PK,,Pakistan,TRUE +PW,,Palau,TRUE +PS,,Palestine,TRUE +PA,,Panama,TRUE +PG,,Papua New Guinea,TRUE +PY,,Paraguay,TRUE +PE,,Peru,TRUE +PH,,Philippines,TRUE +PN,,Pitcairn Islands,TRUE +PL,,Poland,TRUE +PT,,Portugal,TRUE +PR,,Puerto Rico,TRUE +QA,,Qatar,TRUE +RE,,Réunion,TRUE +RO,,Romania,TRUE +RU,,Russia,TRUE +RW,,Rwanda,TRUE +BL,,Saint Barthélemy,TRUE +SH,,Saint Helena,TRUE +KN,,Saint Kitts and Nevis,TRUE +LC,,Saint Lucia,TRUE +MF,,Saint Martin,TRUE +PM,,Saint Pierre and Miquelon,TRUE +WS,,Samoa,TRUE +SM,,San Marino,TRUE +ST,,São Tomé and Príncipe,TRUE +SA,,Saudi Arabia,TRUE +SN,,Senegal,TRUE +RS,,Serbia,TRUE +SC,,Seychelles,TRUE +SL,,Sierra Leone,TRUE +SG,,Singapore,TRUE +SX,,Sint Maarten,TRUE +SK,,Slovakia,TRUE +SI,,Slovenia,TRUE +SB,,Solomon Islands,TRUE +SO,,Somalia,TRUE +ZA,,South Africa,TRUE +KR,,South Korea,TRUE +SS,,South Sudan,TRUE +ES,,Spain,TRUE +LK,,Sri Lanka,TRUE +VC,,St. Vincent & Grenadines,TRUE +SD,,Sudan,TRUE +SR,,Suriname,TRUE +SJ,,Svalbard and Jan Mayen,TRUE +SZ,,Swaziland,TRUE +SE,,Sweden,TRUE +CH,,Switzerland,TRUE +SY,,Syria,TRUE +TW,,Taiwan,TRUE +TJ,,Tajikistan,TRUE +TZ,,Tanzania,TRUE +TH,,Thailand,TRUE +TL,,Timor-Leste,TRUE +TG,,Togo,TRUE +TK,,Tokelau,TRUE +TO,,Tonga,TRUE +TT,,Trinidad and Tobago,TRUE +TA,,Tristan da Cunha,TRUE +TN,,Tunisia,TRUE +TR,,Turkey,TRUE +TM,,Turkmenistan,TRUE +TC,,Turks and Caicos Islands,TRUE +TV,,Tuvalu,TRUE +UM,,U.S. Outlying Islands,TRUE +VI,,U.S. Virgin Islands,TRUE +UG,,Uganda,TRUE +UA,,Ukraine,TRUE +AE,,United Arab Emirates,TRUE +GB,,United Kingdom,TRUE +US,,United States,TRUE +UY,,Uruguay,TRUE +UZ,,Uzbekistan,TRUE +VU,,Vanuatu,TRUE +VA,,Vatican City,TRUE +VE,,Venezuela,TRUE +VN,,Vietnam,TRUE +WF,,Wallis and Futuna,TRUE +EH,,Western Sahara,TRUE +YE,,Yemen,TRUE +ZM,,Zambia,TRUE +ZW,,Zimbabwe,TRUE +CUSTOM1,TID_REGION_CUSTOM1,,FALSE +CUSTOM2,TID_REGION_CUSTOM2,,FALSE +CUSTOM3,TID_REGION_CUSTOM3,,FALSE +CUSTOM4,TID_REGION_CUSTOM4,,FALSE +CUSTOM5,TID_REGION_CUSTOM5,,FALSE diff --git a/Logic/Helpers/PlayerDisplayData.py b/Logic/Helpers/PlayerDisplayData.py index b281f52..188edfc 100644 --- a/Logic/Helpers/PlayerDisplayData.py +++ b/Logic/Helpers/PlayerDisplayData.py @@ -17,10 +17,10 @@ def decode(self: Reader): self.readVint() def encode(self: Writer, info): - self.writeString(info[1]['Sender']['Name']) + self.writeString(info['Name']) self.writeVint(100) - self.writeVint(28000000 + info[1]['Sender']['Thumbnail']) - self.writeVint(43000000 + info[1]['Sender']['NameColor']) + self.writeVint(28000000 + info['Thumbnail']) + self.writeVint(43000000 + info['NameColor']) self.writeVint(-1) def getNameColor(self, globalId): diff --git a/Logic/Notifications/BandNotification.py b/Logic/Notifications/BandNotification.py index b7da187..ca76d49 100644 --- a/Logic/Notifications/BandNotification.py +++ b/Logic/Notifications/BandNotification.py @@ -11,4 +11,4 @@ def decode(self: Reader): def encode(self: Writer, info): BaseNotification.encode(self, info) - PlayerDisplayData.encode(self, info) + PlayerDisplayData.encode(self, info[1]['Target']) diff --git a/Logic/Settings/Configuration.py b/Logic/Settings/Configuration.py index 4e89574..808a72f 100644 --- a/Logic/Settings/Configuration.py +++ b/Logic/Settings/Configuration.py @@ -21,13 +21,6 @@ class Configuration: 'ShowAtLaunch': False, 'Text': "Notification text" }, - { - 'ID': 82, - 'Timer': 9999, - 'ShowAtLaunch': False, - 'Text': "Inbox Notification", - 'Sender': {'Name': 'Crazor', 'Thumbnail': 17, 'NameColor': 9} - }, { 'ID': 79, 'Timer': 9999, diff --git a/Logic/Stream/AllianceEventStreamEntry.py b/Logic/Stream/AllianceEventStreamEntry.py new file mode 100644 index 0000000..458205f --- /dev/null +++ b/Logic/Stream/AllianceEventStreamEntry.py @@ -0,0 +1,14 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Stream.StreamEntry import StreamEntry + + +class AllianceEventStreamEntry: + def encode(self: Writer, info): + StreamEntry.encode(self, info) + self.writeVint(info['EventType']) + self.writeBoolean(info['Target'] != {}) + if info['Target'] != {}: + self.writeLogicLong(info['Target']['ID'][0], info['Target']['ID'][1]) + self.writeString(info['Target']['Name']) + diff --git a/Logic/Stream/ChatStreamEntry.py b/Logic/Stream/ChatStreamEntry.py new file mode 100644 index 0000000..98252e1 --- /dev/null +++ b/Logic/Stream/ChatStreamEntry.py @@ -0,0 +1,9 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Stream.StreamEntry import StreamEntry + + +class ChatStreamEntry: + def encode(self: Writer, info): + StreamEntry.encode(self, info) + self.writeString(info['Message']) \ No newline at end of file diff --git a/Logic/Stream/JoinRequestAllianceStreamEntry.py b/Logic/Stream/JoinRequestAllianceStreamEntry.py new file mode 100644 index 0000000..c6b1ec7 --- /dev/null +++ b/Logic/Stream/JoinRequestAllianceStreamEntry.py @@ -0,0 +1,14 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Helpers.PlayerDisplayData import PlayerDisplayData +from Logic.Stream.StreamEntry import StreamEntry + + +class JoinRequestAllianceStreamEntry: + def encode(self: Writer, info): + StreamEntry.encode(self, info) + self.writeString() + self.writeString() + self.writeVint(0) + PlayerDisplayData.encode(self, info['Target']) + diff --git a/Logic/Stream/MessageDataStreamEntry.py b/Logic/Stream/MessageDataStreamEntry.py new file mode 100644 index 0000000..85a6989 --- /dev/null +++ b/Logic/Stream/MessageDataStreamEntry.py @@ -0,0 +1,10 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Stream.StreamEntry import StreamEntry + + +class MessageDataStreamEntry: + def encode(self: Writer, info): + StreamEntry.encode(self, info) + self.writeDataReference(0, info['MessageID']) + diff --git a/Logic/Stream/QuickChatStreamEntry.py b/Logic/Stream/QuickChatStreamEntry.py new file mode 100644 index 0000000..2151d37 --- /dev/null +++ b/Logic/Stream/QuickChatStreamEntry.py @@ -0,0 +1,13 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Stream.StreamEntry import StreamEntry + + +class QuickChatStreamEntry: + def encode(self: Writer, info): + StreamEntry.encode(self, info) + self.writeDataReference(40, info['MessageDataID']) + self.writeBoolean(False) + self.writeString() + self.writeVint(0) + self.writeVint(info['PremadeID']) \ No newline at end of file diff --git a/Logic/Stream/ReplayStreamEntry.py b/Logic/Stream/ReplayStreamEntry.py new file mode 100644 index 0000000..655de35 --- /dev/null +++ b/Logic/Stream/ReplayStreamEntry.py @@ -0,0 +1,18 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Stream.StreamEntry import StreamEntry + + +class ReplayStreamEntry: + def encode(self: Writer, info): + StreamEntry.encode(self, info) + self.writeVint(0) + self.writeLong(info['ReplayID'][0], info['ReplayID'][1]) + self.writeBoolean(False) + self.writeString("String1") + self.writeString("String2") + self.writeString("String3") + self.writeVint(0) + self.writeVint(0) + self.writeVint(0) + diff --git a/Logic/Stream/StreamEntry.py b/Logic/Stream/StreamEntry.py new file mode 100644 index 0000000..c53975c --- /dev/null +++ b/Logic/Stream/StreamEntry.py @@ -0,0 +1,13 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + + +class StreamEntry: + def encode(self: Writer, info): + self.writeLogicLong(info['StreamID'][0], info['StreamID'][1]) # StreamEntryID + self.writeLogicLong(info['PlayerID'][0], info['PlayerID'][1]) # TargetID + self.writeString(info['PlayerName']) + self.writeVint(info['PlayerRole']) + self.writeVint(0) + self.writeBoolean(False) + diff --git a/Logic/Stream/StreamEntryFactory.py b/Logic/Stream/StreamEntryFactory.py new file mode 100644 index 0000000..70f60ad --- /dev/null +++ b/Logic/Stream/StreamEntryFactory.py @@ -0,0 +1,31 @@ +from Logic.Stream.AllianceEventStreamEntry import AllianceEventStreamEntry +from Logic.Stream.ChatStreamEntry import ChatStreamEntry +from Logic.Stream.JoinRequestAllianceStreamEntry import JoinRequestAllianceStreamEntry +from Logic.Stream.MessageDataStreamEntry import MessageDataStreamEntry +from Logic.Stream.QuickChatStreamEntry import QuickChatStreamEntry +from Logic.Stream.ReplayStreamEntry import ReplayStreamEntry +from Logic.Stream.StreamEntry import StreamEntry +from Logic.Stream.TeamCreatedStreamEntry import TeamCreatedStreamEntry + +StreamIDs = { + 2: ChatStreamEntry, + 3: JoinRequestAllianceStreamEntry, + 4: AllianceEventStreamEntry, + 5: ReplayStreamEntry, + 6: MessageDataStreamEntry, + 7: 'Unknown', + 8: QuickChatStreamEntry, + 77: TeamCreatedStreamEntry, +} + +class StreamEntryFactory: + def encode(self, info): + streamID = info['StreamType'] + if streamID not in StreamIDs: + StreamEntry.encode(self, info) + raise NotImplementedError(f"Stream with id {streamID} is not implemented.") + elif type(StreamIDs[streamID]) != str: + StreamIDs[streamID].encode(self, info) + else: + raise NotImplementedError(f"{StreamIDs[streamID]} is not implemented.") + diff --git a/Logic/Stream/TeamCreatedStreamEntry.py b/Logic/Stream/TeamCreatedStreamEntry.py new file mode 100644 index 0000000..d78fe73 --- /dev/null +++ b/Logic/Stream/TeamCreatedStreamEntry.py @@ -0,0 +1,12 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Stream.StreamEntry import StreamEntry + + +class TeamCreatedStreamEntry: + def encode(self: Writer, info): + StreamEntry.encode(self, info) + self.writeLong(info['TargetID'][0], info['TargetID'][1]) + self.writeVint(0) + self.writeVint(0) + self.writeVint(0) diff --git a/Logic/Utility/Utils.py b/Logic/Utility/Utils.py index 4b9d3d9..f17c487 100644 --- a/Logic/Utility/Utils.py +++ b/Logic/Utility/Utils.py @@ -2,12 +2,31 @@ import random class Utils: - def GetTime(self): + def getTime(): CurentTime = time.strftime("%H:%M:%S") return CurentTime - def GetRoomID(self): - id = [0, 0] - id[0] = int(''.join([str(random.randint(0, 9)) for _ in range(1)])) - id[1] = int(''.join([str(random.randint(0, 9)) for _ in range(8)])) - return id \ No newline at end of file + def getRandomID(): + id = [] + id.append(int(''.join([str(random.randint(0, 9)) for _ in range(2)]))) + id.append(int(''.join([str(random.randint(0, 9)) for _ in range(8)]))) + return id + + def isPromoting(currentRole, newRole): + if newRole == 2: + return True + + elif newRole == 4: + if currentRole == 2: + return False + else: + return True + + elif newRole == 3: + if currentRole == 4: + return False + else: + return True + + elif newRole == 1: + return False diff --git a/Messaging/Commands/Client/LogicClearShopTickersCommand.py b/Messaging/Commands/Client/LogicClearShopTickersCommand.py index 8240922..07c3862 100644 --- a/Messaging/Commands/Client/LogicClearShopTickersCommand.py +++ b/Messaging/Commands/Client/LogicClearShopTickersCommand.py @@ -13,10 +13,10 @@ def __init__(self, client, player, data): def decode(self): print() - print(self.readVint()) - print(self.readVint()) - print(self.readVint()) - print(self.readVint()) + self.readVint() + self.readVint() + self.readVint() + self.readVint() def process(self): pass \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicEnableSkinRandomizerCommand.py b/Messaging/Commands/Client/LogicEnableSkinRandomizerCommand.py index 94f7338..05f703b 100644 --- a/Messaging/Commands/Client/LogicEnableSkinRandomizerCommand.py +++ b/Messaging/Commands/Client/LogicEnableSkinRandomizerCommand.py @@ -15,9 +15,7 @@ def __init__(self, client, player, data): def decode(self): print() self.skinData = self.readDataReferenceDouble() - print(self.skinData) self.state = self.readBoolean() - print(self.state) def process(self): self.db = DatabaseManager() @@ -28,4 +26,4 @@ def process(self): else: self.database['brawlerState'][Skins.getBrawlerBySkin(self, self.skinData[1])] = 2 self.database['selectedSkin'][Skins.getBrawlerBySkin(self, self.skinData[1])] = self.skinData[1] - self.db.update_player_data(self.database, self.player.LowID) \ No newline at end of file + self.db.updatePlayerData(self.database, self.player.LowID) \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicGatchaCommand.py b/Messaging/Commands/Client/LogicGatchaCommand.py index 2ae6736..d6a07ff 100644 --- a/Messaging/Commands/Client/LogicGatchaCommand.py +++ b/Messaging/Commands/Client/LogicGatchaCommand.py @@ -12,8 +12,7 @@ def __init__(self, client, player, data): self.player = player def decode(self): - print() - print(self.readVint()) + self.readVint() def process(self): pass \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicHeroSeenCommand.py b/Messaging/Commands/Client/LogicHeroSeenCommand.py index 94646cf..8419cba 100644 --- a/Messaging/Commands/Client/LogicHeroSeenCommand.py +++ b/Messaging/Commands/Client/LogicHeroSeenCommand.py @@ -13,8 +13,8 @@ def __init__(self, client, player, data): def decode(self): print() - print(self.readDataReference()) - print(self.readInt()) + self.readDataReference() + self.readInt() def process(self): pass \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicPurchaseHeroLvlUpMaterialCommand.py b/Messaging/Commands/Client/LogicPurchaseHeroLvlUpMaterialCommand.py index 26f4c40..c133680 100644 --- a/Messaging/Commands/Client/LogicPurchaseHeroLvlUpMaterialCommand.py +++ b/Messaging/Commands/Client/LogicPurchaseHeroLvlUpMaterialCommand.py @@ -13,7 +13,7 @@ def __init__(self, client, player, data): def decode(self): print() - print(self.readVint()) + self.readVint() def process(self): pass \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicSelectCharacterCommand.py b/Messaging/Commands/Client/LogicSelectCharacterCommand.py index bdf2e99..dc1228d 100644 --- a/Messaging/Commands/Client/LogicSelectCharacterCommand.py +++ b/Messaging/Commands/Client/LogicSelectCharacterCommand.py @@ -14,10 +14,9 @@ def __init__(self, client, player, data): def decode(self): print() self.brawlerData = self.readDataReferenceDouble() - print(self.brawlerData) def process(self): self.db = DatabaseManager() self.database = json.loads(self.db.getPlayerWithLowID(self.player.LowID)[0][2]) self.database['brawlerID'] = self.brawlerData[1] - self.db.update_player_data(self.database, self.player.LowID) \ No newline at end of file + self.db.updatePlayerData(self.database, self.player.LowID) \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicSelectEmoteCommand.py b/Messaging/Commands/Client/LogicSelectEmoteCommand.py index 3f0ba2b..1b4dadb 100644 --- a/Messaging/Commands/Client/LogicSelectEmoteCommand.py +++ b/Messaging/Commands/Client/LogicSelectEmoteCommand.py @@ -13,8 +13,8 @@ def __init__(self, client, player, data): def decode(self): print() - print(self.readDataReferenceDouble()) - print(self.readVint()) + self.readDataReferenceDouble() + self.readVint() def process(self): pass \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicSelectSkinCommand.py b/Messaging/Commands/Client/LogicSelectSkinCommand.py index f9ed983..c7b3a34 100644 --- a/Messaging/Commands/Client/LogicSelectSkinCommand.py +++ b/Messaging/Commands/Client/LogicSelectSkinCommand.py @@ -15,8 +15,7 @@ def __init__(self, client, player, data): def decode(self): print() self.skinData = self.readDataReferenceDouble() - print(self.skinData) - print(self.readVint()) + self.readVint() def process(self): self.db = DatabaseManager() @@ -26,4 +25,4 @@ def process(self): self.database['selectedSkin'][Skins.getBrawlerBySkin(self, self.skinData[1])] = self.skinData[1] elif self.randomSkinData != 0: self.database['selectedRandomSkin'].append(self.randomSkinData[1]) - self.db.update_player_data(self.database, self.player.LowID) \ No newline at end of file + self.db.updatePlayerData(self.database, self.player.LowID) \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicSelectStarPowerCommand.py b/Messaging/Commands/Client/LogicSelectStarPowerCommand.py index 02d751b..d0b49dc 100644 --- a/Messaging/Commands/Client/LogicSelectStarPowerCommand.py +++ b/Messaging/Commands/Client/LogicSelectStarPowerCommand.py @@ -13,7 +13,7 @@ def __init__(self, client, player, data): def decode(self): print() - print(self.readDataReferenceDouble()) + self.readDataReferenceDouble() def process(self): pass \ No newline at end of file diff --git a/Messaging/Commands/Client/LogicViewInboxNotificationCommand.py b/Messaging/Commands/Client/LogicViewInboxNotificationCommand.py new file mode 100644 index 0000000..9aee938 --- /dev/null +++ b/Messaging/Commands/Client/LogicViewInboxNotificationCommand.py @@ -0,0 +1,18 @@ +import json + +from Database.DatabaseManager import DatabaseManager + +from Logic.Data.DataManager import Writer, Reader + + +class LogicViewInboxNotificationCommand(Reader): + def __init__(self, client, player, data): + super().__init__(data) + self.client = client + self.player = player + + def decode(self): + print() + + def process(self): + pass \ No newline at end of file diff --git a/Messaging/Commands/Server/LogicChangeAvatarNameCommand.py b/Messaging/Commands/Server/LogicChangeAvatarNameCommand.py index 260b66e..51162b2 100644 --- a/Messaging/Commands/Server/LogicChangeAvatarNameCommand.py +++ b/Messaging/Commands/Server/LogicChangeAvatarNameCommand.py @@ -17,7 +17,7 @@ def encode(self): self.database = json.loads(self.db.getPlayerWithLowID(self.player.LowID)[0][2]) self.database['name'] = self.player.Name self.database['IsRegistred'] = True - self.db.update_player_data(self.database, self.player.LowID) + self.db.updatePlayerData(self.database, self.player.LowID) self.writeVint(201) self.writeString(self.player.Name) diff --git a/Messaging/LogicMessageFactory.py b/Messaging/LogicMessageFactory.py index 2e9195f..0b46538 100644 --- a/Messaging/LogicMessageFactory.py +++ b/Messaging/LogicMessageFactory.py @@ -1,4 +1,14 @@ +from Messaging.Packets.Client.Alliance.SendAllianceMailMessage import SendAllianceMailMessage +from Messaging.Packets.Client.Alliance.AlliancePremadeChatMessage import AlliancePremadeChatMessage from Messaging.Packets.Client.Alliance.AskForAllianceDataMessage import AskForAllianceDataMessage +from Messaging.Packets.Client.Alliance.AskForJoinableAlliancesListMessage import AskForJoinableAlliancesListMessage +from Messaging.Packets.Client.Alliance.ChangeAllianceMemberRoleMessage import ChangeAllianceMemberRoleMessage +from Messaging.Packets.Client.Alliance.ChangeAllianceSettingsMessage import ChangeAllianceSettingsMessage +from Messaging.Packets.Client.Alliance.ChatToAllianceStreamMessage import ChatToAllianceStreamMessage +from Messaging.Packets.Client.Alliance.CreateAllianceMessage import CreateAllianceMessage +from Messaging.Packets.Client.Alliance.JoinAllianceMessage import JoinAllianceMessage +from Messaging.Packets.Client.Alliance.LeaveAllianceMessage import LeaveAllianceMessage +from Messaging.Packets.Client.Alliance.SearchAlliancesMessage import SearchAlliancesMessage from Messaging.Packets.Client.Alliance.UnknownAskMessage import UnknownAskMessage from Messaging.Packets.Client.Authentication.LoginMessage import LoginMessage from Messaging.Packets.Client.Devices.AnalyticEventMessage import AnalyticEventMessage @@ -19,7 +29,17 @@ 14109: GoHomeFromOfflinePractiseMessage, 14110: AskForBattleEndMessage, 14113: GetPlayerProfileMessage, + 14301: CreateAllianceMessage, 14302: AskForAllianceDataMessage, + 14303: AskForJoinableAlliancesListMessage, + 14305: JoinAllianceMessage, + 14306: ChangeAllianceMemberRoleMessage, + 14308: LeaveAllianceMessage, + 14315: ChatToAllianceStreamMessage, + 14316: ChangeAllianceSettingsMessage, + 14324: SearchAlliancesMessage, + 14330: SendAllianceMailMessage, + 14469: AlliancePremadeChatMessage, } knownList = { @@ -167,6 +187,7 @@ 14405: 'AskForAvatarStreamMessage', 14406: 'AskForBattleReplayStreamMessage', 14418: 'RemoveAvatarStreamEntryMessage', + 14469: 'AlliancePremadeChatMessage', 14479: 'TeamInvitationResponseMessage', 14600: 'AvatarNameCheckRequestMessage', 14700: 'ListBrawlTvChannelsMessage', diff --git a/Messaging/Packets/Client/Alliance/AlliancePremadeChatMessage.py b/Messaging/Packets/Client/Alliance/AlliancePremadeChatMessage.py new file mode 100644 index 0000000..a1b338b --- /dev/null +++ b/Messaging/Packets/Client/Alliance/AlliancePremadeChatMessage.py @@ -0,0 +1,39 @@ +import json + +from Database.ClubManager import ClubManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceStreamEntryMessage import AllianceStreamEntryMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage + + +class AlliancePremadeChatMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + + def decode(self): + self.messageID = self.readDataReferenceDouble()[1] + self.premadeID = self.readVint() + + def process(self): + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + + while len(clubData['ChatData']) >= 100: + clubData['ChatData'].pop(0) + + if len(clubData['ChatData']) == 0: + lastMessageID = 0 + else: + lastMessageID = clubData['ChatData'][len(clubData['ChatData']) - 1]['StreamID'][1] + + PremadeStreamData = clubdb.getDefaultMessageData(8, -1, [0, lastMessageID + 1], [self.player.HighID, self.player.LowID], self.player.Name, clubData['Members'][str(self.player.LowID)]['Role'], premadeID=self.premadeID, messageDataID=self.messageID) + clubData['ChatData'].append(PremadeStreamData) + clubdb.updateClubData(clubData, clubData['LowID']) + + for memberData in clubData['Members'].values(): + AllianceStreamEntryMessage(self.client, self.player, PremadeStreamData).send(memberData['LowID']) \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/AskForAllianceDataMessage.py b/Messaging/Packets/Client/Alliance/AskForAllianceDataMessage.py index 10d04d2..c8577ae 100644 --- a/Messaging/Packets/Client/Alliance/AskForAllianceDataMessage.py +++ b/Messaging/Packets/Client/Alliance/AskForAllianceDataMessage.py @@ -2,7 +2,9 @@ from Logic.Data.DataManager import Reader from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage - +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage + + class AskForAllianceDataMessage(Reader): def __init__(self, client, player, header_bytes): super().__init__(header_bytes) @@ -10,7 +12,10 @@ def __init__(self, client, player, header_bytes): self.client = client def decode(self): - self.ClubID = self.readLong() + self.clubID = self.readLong() + self.readBoolean() def process(self): - AllianceDataMessage(self.client, self.player).send(self.player.LowID) + self.player.allianceTry += 1 + AllianceDataMessage(self.client, self.player, self.clubID, self.player.allianceTry).send(self.player.LowID) + AllianceTeamsMessage(self.client, self.player).send(self.player.LowID) \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/AskForJoinableAlliancesListMessage.py b/Messaging/Packets/Client/Alliance/AskForJoinableAlliancesListMessage.py new file mode 100644 index 0000000..3e80543 --- /dev/null +++ b/Messaging/Packets/Client/Alliance/AskForJoinableAlliancesListMessage.py @@ -0,0 +1,18 @@ +from Database.ClubManager import ClubManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + +from Messaging.Packets.Server.Alliance.JoinableAllianceListMessage import JoinableAllianceListMessage + + +class AskForJoinableAlliancesListMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + + def decode(self): + pass + + def process(self): + JoinableAllianceListMessage(self.client, self.player).send(self.player.LowID) diff --git a/Messaging/Packets/Client/Alliance/ChangeAllianceMemberRoleMessage.py b/Messaging/Packets/Client/Alliance/ChangeAllianceMemberRoleMessage.py new file mode 100644 index 0000000..9bc9675 --- /dev/null +++ b/Messaging/Packets/Client/Alliance/ChangeAllianceMemberRoleMessage.py @@ -0,0 +1,68 @@ +import json + +from Database.ClubManager import ClubManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Utility.Utils import Utils + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceMemberMessage import AllianceMemberMessage +from Messaging.Packets.Server.Alliance.AllianceResponseMessage import AllianceResponseMessage +from Messaging.Packets.Server.Alliance.AllianceStreamEntryMessage import AllianceStreamEntryMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage +from Messaging.Packets.Server.Alliance.MyAllianceMessage import MyAllianceMessage + + +class ChangeAllianceMemberRoleMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + + def decode(self): + self.targetID = self.readLong() + self.targetRole = self.readVint() + + def process(self): + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + + if clubData['Members'][str(self.player.LowID)]['Role'] != 2: + if clubData['Members'][str(self.player.LowID)]['Role'] != 4: + return + + while len(clubData['ChatData']) >= 100: + clubData['ChatData'].pop(0) + + if len(clubData['ChatData']) == 0: + lastMessageID = 0 + else: + lastMessageID = clubData['ChatData'][len(clubData['ChatData']) - 1]['StreamID'][1] + + isPromotingRole = Utils.isPromoting(clubData['Members'][str(self.targetID[1])]['Role'], self.targetRole) + + if isPromotingRole: + PromoteStreamData = clubdb.getDefaultMessageData(4, 5, [0, lastMessageID + 1], [self.player.HighID, self.player.LowID], self.player.Name, clubData['Members'][str(self.player.LowID)]['Role'], target={'ID': self.targetID, 'Name': clubData['Members'][str(self.targetID[1])]['Name']}) + else: + PromoteStreamData = clubdb.getDefaultMessageData(4, 6, [0, lastMessageID + 1], [self.player.HighID, self.player.LowID], self.player.Name, clubData['Members'][str(self.player.LowID)]['Role'], target={'ID': self.targetID, 'Name': clubData['Members'][str(self.targetID[1])]['Name']}) + + clubData['ChatData'].append(PromoteStreamData) + + if self.targetRole == 2: + DemotedStreamData = clubdb.getDefaultMessageData(4, 6, [0, lastMessageID + 2], [self.player.HighID, self.player.LowID], self.player.Name, clubData['Members'][str(self.player.LowID)]['Role'], target={'ID': [self.player.HighID, self.player.LowID], 'Name': self.player.Name}) + clubData['ChatData'].append(DemotedStreamData) + clubData['Members'][str(self.player.LowID)]['Role'] = 4 + + clubData['Members'][str(self.targetID[1])]['Role'] = self.targetRole + clubdb.updateClubData(clubData, clubData['LowID']) + + for memberData in clubData['Members'].values(): + AllianceMemberMessage(self.client, self.player, self.player.allianceID, clubData['Members'][str(self.targetID[1])]).send(memberData['LowID']) + AllianceStreamEntryMessage(self.client, self.player, PromoteStreamData).send(memberData['LowID']) + if self.targetRole == 2: + AllianceStreamEntryMessage(self.client, self.player, DemotedStreamData).send(memberData['LowID']) + + if isPromotingRole: + AllianceResponseMessage(self.client, self.player, 81).send(self.player.LowID) + else: + AllianceResponseMessage(self.client, self.player, 82).send(self.player.LowID) \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/ChangeAllianceSettingsMessage.py b/Messaging/Packets/Client/Alliance/ChangeAllianceSettingsMessage.py new file mode 100644 index 0000000..8b3a3b6 --- /dev/null +++ b/Messaging/Packets/Client/Alliance/ChangeAllianceSettingsMessage.py @@ -0,0 +1,50 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceResponseMessage import AllianceResponseMessage +from Messaging.Packets.Server.Alliance.AllianceStreamEntryMessage import AllianceStreamEntryMessage +from Messaging.Packets.Server.Alliance.AllianceStreamMessage import AllianceStreamMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage +from Messaging.Packets.Server.Alliance.ChangeAllianceSettingsOkMessage import ChangeAllianceSettingsOkMessage +from Messaging.Packets.Server.Alliance.MyAllianceMessage import MyAllianceMessage + + +class ChangeAllianceSettingsMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + self.clubInfo = {} + + def decode(self): + self.clubInfo['Description'] = self.readString() + self.clubInfo['Badge'] = self.readDataReferenceDouble() + self.clubInfo['Region'] = self.readDataReferenceDouble() + self.clubInfo['Type'] = self.readVint() + self.clubInfo['RequiredTrophies'] = self.readVint() + self.clubInfo['FamilyFriendly'] = self.readBoolean() + + def process(self): + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + if clubData['Members'][str(self.player.LowID)]['Role'] == 2: + clubData['Description'] = self.clubInfo['Description'] + clubData['BadgeID'] = self.clubInfo['Badge'][1] + clubData['RegionID'] = self.clubInfo['Region'][1] + clubData['Type'] = self.clubInfo['Type'] + clubData['TrophiesRequired'] = self.clubInfo['RequiredTrophies'] + clubData['FamilyFriendly'] = self.clubInfo['FamilyFriendly'] + clubdb.updateClubData(clubData, clubData['LowID']) + + MyAllianceMessage(self.client, self.player, self.player.allianceID).send(self.player.LowID) + ChangeAllianceSettingsOkMessage(self.client, self.player, self.player.allianceID).send(self.player.LowID) + AllianceResponseMessage(self.client, self.player, 10).send(self.player.LowID) + + else: + MyAllianceMessage(self.client, self.player, self.player.allianceID).send(self.player.LowID) + AllianceResponseMessage(self.client, self.player, 95).send(self.player.LowID) \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/ChatToAllianceStreamMessage.py b/Messaging/Packets/Client/Alliance/ChatToAllianceStreamMessage.py new file mode 100644 index 0000000..d239a50 --- /dev/null +++ b/Messaging/Packets/Client/Alliance/ChatToAllianceStreamMessage.py @@ -0,0 +1,38 @@ +import json + +from Database.ClubManager import ClubManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceStreamEntryMessage import AllianceStreamEntryMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage + + +class ChatToAllianceStreamMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + + def decode(self): + self.message = self.readString() + + def process(self): + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + + while len(clubData['ChatData']) >= 100: + clubData['ChatData'].pop(0) + + if len(clubData['ChatData']) == 0: + lastMessageID = 0 + else: + lastMessageID = clubData['ChatData'][len(clubData['ChatData']) - 1]['StreamID'][1] + + ChatStreamData = clubdb.getDefaultMessageData(2, -1, [0, lastMessageID + 1], [self.player.HighID, self.player.LowID], self.player.Name, clubData['Members'][str(self.player.LowID)]['Role'], {}, self.message) + clubData['ChatData'].append(ChatStreamData) + clubdb.updateClubData(clubData, clubData['LowID']) + + for memberData in clubData['Members'].values(): + AllianceStreamEntryMessage(self.client, self.player, ChatStreamData).send(memberData['LowID']) \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/CreateAllianceMessage.py b/Messaging/Packets/Client/Alliance/CreateAllianceMessage.py new file mode 100644 index 0000000..d48ba76 --- /dev/null +++ b/Messaging/Packets/Client/Alliance/CreateAllianceMessage.py @@ -0,0 +1,59 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Utility.Utils import Utils +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceResponseMessage import AllianceResponseMessage +from Messaging.Packets.Server.Alliance.AllianceStreamMessage import AllianceStreamMessage +from Messaging.Packets.Server.Alliance.MyAllianceMessage import MyAllianceMessage + + +class CreateAllianceMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + self.clubInfo = {} + + def decode(self): + self.clubInfo['Name'] = self.readString() + self.clubInfo['Description'] = self.readString() + self.clubInfo['Badge'] = self.readDataReferenceDouble() + self.clubInfo['Region'] = self.readDataReferenceDouble() + self.clubInfo['Type'] = self.readVint() + self.clubInfo['RequiredTrophies'] = self.readVint() + self.clubInfo['FamilyFriendly'] = self.readBoolean() + + def process(self): + playerdb = DatabaseManager() + clubdb = ClubManager() + + self.clubID = Utils.getRandomID() + + clubdb.createClub(self.clubID[1], self.createClubData()) + playerData = json.loads(playerdb.getPlayerWithLowID(self.player.LowID)[0][2]) + playerData['allianceID'] = self.clubID + playerdb.updatePlayerData(playerData, self.player.LowID) + playerdb.LoadAccount(self.player.LowID, self.player) + AllianceResponseMessage(self.client, self.player, 20).send(self.player.LowID) + AllianceStreamMessage(self.client, self.player).send(self.player.LowID) + MyAllianceMessage(self.client, self.player, self.clubID).send(self.player.LowID) + + def createClubData(self): + DBData = { + 'HighID': self.clubID[0], + 'LowID': self.clubID[1], + 'Name': self.clubInfo['Name'], + 'Members': {str(self.player.LowID): {'HighID': self.player.HighID, 'LowID': self.player.LowID, 'Name': self.player.Name, 'Role': 2, 'Trophies': self.player.trophies, 'NameColor': self.player.nameColor, 'Thumbnail': self.player.thumbnail}}, + 'Description': self.clubInfo['Description'], + 'BadgeID': self.clubInfo['Badge'][1], + 'RegionID': self.clubInfo['Region'][1], + 'Type': self.clubInfo['Type'], + 'TrophiesRequired': self.clubInfo['RequiredTrophies'], + 'FamilyFriendly': self.clubInfo['FamilyFriendly'], + 'ChatData': [] + } + return DBData \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/JoinAllianceMessage.py b/Messaging/Packets/Client/Alliance/JoinAllianceMessage.py new file mode 100644 index 0000000..2305587 --- /dev/null +++ b/Messaging/Packets/Client/Alliance/JoinAllianceMessage.py @@ -0,0 +1,55 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceMemberMessage import AllianceMemberMessage +from Messaging.Packets.Server.Alliance.AllianceResponseMessage import AllianceResponseMessage +from Messaging.Packets.Server.Alliance.AllianceStreamEntryMessage import AllianceStreamEntryMessage +from Messaging.Packets.Server.Alliance.AllianceStreamMessage import AllianceStreamMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage +from Messaging.Packets.Server.Alliance.MyAllianceMessage import MyAllianceMessage + + +class JoinAllianceMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + + def decode(self): + self.clubID = self.readLong() + + def process(self): + clubdb = ClubManager() + playerdb = DatabaseManager() + clubData = json.loads(clubdb.getClubWithLowID(self.clubID[1])[0][1]) + playerData = json.loads(playerdb.getPlayerWithLowID(self.player.LowID)[0][2]) + + if len(clubData['ChatData']) == 0: + lastMessageID = 0 + else: + lastMessageID = clubData['ChatData'][len(clubData['ChatData']) - 1]['StreamID'][1] + + clubData['Members'][str(self.player.LowID)] = clubdb.getDefaultMembersData(self.player, 1) + JoinStreamData = clubdb.getDefaultMessageData(4, 3, [0, lastMessageID + 1], [self.player.HighID, self.player.LowID], self.player.Name, clubData['Members'][str(self.player.LowID)]['Role'], target={'ID': [self.player.HighID, self.player.LowID], 'Name': self.player.Name, 'Thumbnail': self.player.thumbnail, 'NameColor': self.player.nameColor}) + clubData['ChatData'].append(JoinStreamData) + clubdb.updateClubData(clubData, clubData['LowID']) + + playerData['allianceID'] = self.clubID + playerdb.updatePlayerData(playerData, self.player.LowID) + playerdb.LoadAccount(self.player.LowID, self.player) + + AllianceResponseMessage(self.client, self.player, 40).send(self.player.LowID) + AllianceTeamsMessage(self.client, self.player).send(self.player.LowID) + MyAllianceMessage(self.client, self.player, self.clubID).send(self.player.LowID) + AllianceStreamMessage(self.client, self.player).send(self.player.LowID) + + for membersData in clubData['Members'].values(): + if membersData['LowID'] != self.player.LowID: + AllianceMemberMessage(self.client, self.player, self.clubID, clubData['Members'][str(self.player.LowID)]).send(membersData['LowID']) + AllianceStreamEntryMessage(self.client, self.player, JoinStreamData).send(membersData['LowID']) + diff --git a/Messaging/Packets/Client/Alliance/LeaveAllianceMessage.py b/Messaging/Packets/Client/Alliance/LeaveAllianceMessage.py new file mode 100644 index 0000000..b44f5de --- /dev/null +++ b/Messaging/Packets/Client/Alliance/LeaveAllianceMessage.py @@ -0,0 +1,83 @@ +import json +import random + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceMemberMessage import AllianceMemberMessage +from Messaging.Packets.Server.Alliance.AllianceMemberRemovedMessage import AllianceMemberRemovedMessage +from Messaging.Packets.Server.Alliance.AllianceResponseMessage import AllianceResponseMessage +from Messaging.Packets.Server.Alliance.AllianceStreamEntryMessage import AllianceStreamEntryMessage +from Messaging.Packets.Server.Alliance.AllianceStreamMessage import AllianceStreamMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage +from Messaging.Packets.Server.Alliance.MyAllianceMessage import MyAllianceMessage + + +class LeaveAllianceMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + + def decode(self): + pass + + def process(self): + presidentLeft = False + clubdb = ClubManager() + playerdb = DatabaseManager() + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + playerData = json.loads(playerdb.getPlayerWithLowID(self.player.LowID)[0][2]) + if len(clubData['Members']) - 1 > 0: + if len(clubData['ChatData']) == 0: + lastMessageID = 0 + else: + lastMessageID = clubData['ChatData'][len(clubData['ChatData']) - 1]['StreamID'][1] + + LeaveStreamData = clubdb.getDefaultMessageData(4, 4, [0, lastMessageID + 1], [self.player.HighID, self.player.LowID], self.player.Name, clubData['Members'][str(self.player.LowID)]['Role']) + AllianceStreamEntryMessage(self.client, self.player, LeaveStreamData).send(self.player.LowID) + + if clubData['Members'][str(self.player.LowID)]['Role'] == 2: + acceptedMembers = [] + for i, v in clubData['Members'].items(): + if v['Role'] == 4: + acceptedMembers.append(v) + + if len(acceptedMembers) == 0: + for i, v in clubData['Members'].items(): + if v['Role'] == 3: + acceptedMembers.append(v) + + if len(acceptedMembers) == 0: + for i, v in clubData['Members'].items(): + if v['Role'] == 1: + acceptedMembers.append(v) + + chosenMember = random.choice(acceptedMembers) + clubData['Members'][str(chosenMember['LowID'])]['Role'] = 2 + presidentLeft = True + + clubData['Members'].pop(str(self.player.LowID)) + clubData['ChatData'].append(LeaveStreamData) + clubdb.updateClubData(clubData, clubData['LowID']) + + for memberData in clubData['Members'].values(): + if memberData['LowID'] != self.player.LowID: + AllianceStreamEntryMessage(self.client, self.player, LeaveStreamData).send(memberData['LowID']) + AllianceMemberRemovedMessage(self.client, self.player, [clubData['HighID'], clubData['LowID']], [self.player.HighID, self.player.LowID]).send(memberData['LowID']) + if presidentLeft: + AllianceMemberMessage(self.client, self.player, [clubData['HighID'], clubData['LowID']], clubData['Members'][str(chosenMember['LowID'])]).send(memberData['LowID']) + + else: + clubdb.deleteClub(clubData['LowID']) + + playerData['allianceID'] = [0, 0] + playerdb.updatePlayerData(playerData, self.player.LowID) + playerdb.LoadAccount(self.player.LowID, self.player) + + MyAllianceMessage(self.client, self.player, [0, 0]).send(self.player.LowID) + AllianceResponseMessage(self.client, self.player, 80).send(self.player.LowID) + AllianceTeamsMessage(self.client, self.player).send(self.player.LowID) \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/SearchAlliancesMessage.py b/Messaging/Packets/Client/Alliance/SearchAlliancesMessage.py new file mode 100644 index 0000000..2e20014 --- /dev/null +++ b/Messaging/Packets/Client/Alliance/SearchAlliancesMessage.py @@ -0,0 +1,28 @@ +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceListMessage import AllianceListMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage + + +class SearchAlliancesMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + self.info = {} + + def decode(self): + self.info['SearchString'] = self.readString() + self.readInt() + self.info['MinMembers'] = self.readInt() + self.info['MaxMembers'] = self.readInt() + self.info['MinTrophies'] = self.readInt() + self.info['FindOnlyJoinableClans'] = self.readBoolean() + self.info['Score'] = self.readInt() + self.readInt() # MinLevel + + + def process(self): + AllianceListMessage(self.client, self.player, self.info).send(self.player.LowID) \ No newline at end of file diff --git a/Messaging/Packets/Client/Alliance/SendAllianceMailMessage.py b/Messaging/Packets/Client/Alliance/SendAllianceMailMessage.py new file mode 100644 index 0000000..0ebc49c --- /dev/null +++ b/Messaging/Packets/Client/Alliance/SendAllianceMailMessage.py @@ -0,0 +1,57 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager +from Logic.Data.DataManager import Writer +from Logic.Data.DataManager import Reader +from Logic.Settings.Configuration import Configuration + +from Messaging.Packets.Server.Alliance.AllianceDataMessage import AllianceDataMessage +from Messaging.Packets.Server.Alliance.AllianceMemberMessage import AllianceMemberMessage +from Messaging.Packets.Server.Alliance.AllianceResponseMessage import AllianceResponseMessage +from Messaging.Packets.Server.Alliance.AllianceStreamEntryMessage import AllianceStreamEntryMessage +from Messaging.Packets.Server.Alliance.AllianceStreamMessage import AllianceStreamMessage +from Messaging.Packets.Server.Alliance.AllianceTeamsMessage import AllianceTeamsMessage +from Messaging.Packets.Server.Alliance.MyAllianceMessage import MyAllianceMessage +from Messaging.Packets.Server.Home.AvailableServerCommandMessage import AvailableServerCommandMessage + + +class SendAllianceMailMessage(Reader): + def __init__(self, client, player, header_bytes): + super().__init__(header_bytes) + self.player = player + self.client = client + + def decode(self): + self.readInt() + self.clubMessage = self.readString() + + def process(self): + if self.clubMessage == b'': + AllianceResponseMessage(self.client, self.player, 114).send(self.player.LowID) + else: + clubdb = ClubManager() + playerdb = DatabaseManager() + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + + if clubData['Members'][str(self.player.LowID)]['Role'] != 2: + if clubData['Members'][str(self.player.LowID)]['Role'] != 4: + return + + mailData = { + 'Index': (len(Configuration.Inbox) + len(self.player.clubMailInbox)) - 1, + 'ID': 82, + 'Timer': 0, + 'ShowAtLaunch': True, + 'Text': self.clubMessage, + 'Target': {'Name': self.player.Name, 'Thumbnail': self.player.thumbnail, 'NameColor': self.player.nameColor} + } + + AllianceResponseMessage(self.client, self.player, 113).send(self.player.LowID) + + for i in clubData['Members'].values(): + if i['LowID'] in playerdb.GetAllDb(): + playerData = json.loads(playerdb.getPlayerWithLowID(i['LowID'])[0][2]) + playerData['clubMailInbox'].append(mailData) + playerdb.updatePlayerData(playerData, i['LowID']) + AvailableServerCommandMessage(self.client, self.player, {'CommandID': 206, 'NotificationID': 82, 'MessageContent': self.clubMessage, 'Target': mailData['Target']}).send(i['LowID']) diff --git a/Messaging/Packets/Client/Authentication/LoginMessage.py b/Messaging/Packets/Client/Authentication/LoginMessage.py index 2be6206..a061cdd 100644 --- a/Messaging/Packets/Client/Authentication/LoginMessage.py +++ b/Messaging/Packets/Client/Authentication/LoginMessage.py @@ -1,9 +1,14 @@ +import json import time +import traceback +from Database.ClubManager import ClubManager from Logic.Client.ClientsManager import ClientsManager from Logic.Client.PlayerManager import Players from Database.DatabaseManager import DatabaseManager +from Messaging.Packets.Server.Alliance.AllianceStreamMessage import AllianceStreamMessage from Messaging.Packets.Server.Alliance.UnknownAllianceMessage import UnknownAllianceMessage +from Messaging.Packets.Server.Authentication.LoginFailedMessage import LoginFailedMessage from Messaging.Packets.Server.Authentication.LoginOkMessage import LoginOkMessage from Messaging.Packets.Server.Home.OwnHomeDataMessage import OwnHomeDataMessage @@ -24,7 +29,7 @@ def decode(self): try: self.player.HighID = self.readInt() self.player.LowID = self.readInt() - self.player.Token = self.readString() + self.Token = self.readString() self.player.device.major = self.readInt() self.player.device.minor = self.readInt() @@ -60,21 +65,47 @@ def process(self): if self.encrypted == False: self.db = DatabaseManager() try: - self.AccountCreated = self.db.GetAllDb(self.player.LowID) - if self.player.LowID in self.AccountCreated and self.player.LowID != 0: + self.AccountCreated = self.db.GetAllDb() + if self.player.LowID in self.AccountCreated: self.db.LoadAccount(self.player.LowID, self.player) + if self.player.Token != self.Token: + self.client.close() + return + + elif self.player.LowID != 0: + data = Players.CreateAccount(self.player, self.player.HighID, self.player.LowID, self.Token, True) + self.db.createAccount(self.player.LowID, self.player.Token, data) + self.db.LoadAccount(self.player.LowID, self.player) + else: - data = Players.CreateAccount(Players, self.player.HighID, self.player.LowID, self.player.Token) + data = Players.CreateAccount(self.player, self.player.HighID, self.player.LowID, self.Token) self.db.createAccount(self.player.LowID, self.player.Token, data) + self.db.LoadAccount(self.player.LowID, self.player) + except Exception: - data = Players.CreateAccount(Players, self.player.HighID, self.player.LowID, self.player.Token) + print(traceback.print_exc()) + data = Players.CreateAccount(self.player, self.player.HighID, self.player.LowID, self.Token) self.db.createAccount(self.player.LowID, self.player.Token, data) + self.db.LoadAccount(self.player.LowID, self.player) + ClientsManager.AddSocket(self.player.LowID, self.client) if self.player.device.major == 40: LoginOkMessage(self.client, self.player).send(self.player.LowID, 2) OwnHomeDataMessage(self.client, self.player).send(self.player.LowID) - MyAllianceMessage(self.client, self.player).send(self.player.LowID) + try: + clubdb = ClubManager() + json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + MyAllianceMessage(self.client, self.player, self.player.allianceID).send(self.player.LowID) + if self.player.allianceID[1] != 0: + AllianceStreamMessage(self.client, self.player).send(self.player.LowID) + except IndexError: + playerData = json.loads(self.db.getPlayerWithLowID(self.player.LowID)[0][2]) + playerData['allianceID'] = [0, 0] + self.db.updatePlayerData(playerData, self.player.LowID) + self.db.LoadAccount(self.player.LowID, self.player) + MyAllianceMessage(self.client, self.player, self.player.allianceID).send(self.player.LowID) + UnknownAllianceMessage(self.client, self.player).send(self.player.LowID) else: diff --git a/Messaging/Packets/Client/Game/EndClientTurnMessage.py b/Messaging/Packets/Client/Game/EndClientTurnMessage.py index e132119..136ef61 100644 --- a/Messaging/Packets/Client/Game/EndClientTurnMessage.py +++ b/Messaging/Packets/Client/Game/EndClientTurnMessage.py @@ -12,16 +12,15 @@ def __init__(self, client, player, header_bytes): self.commmandID = [] def decode(self): - print(self.readBoolean()) - print(self.readVint()) - print(self.readVint()) + self.readBoolean() + self.readVint() + self.readVint() count = self.readVint() - print(count) for command in range(count): self.commmandID.append(self.readVint()) self.tick1 = self.readVint() self.tick2 = self.readVint() - self.readVLong() + self.readLogicLong() if self.commmandID[command] in commandIdentifiers: if type(commandIdentifiers[self.commmandID[command]]) != str: command = commandIdentifiers[self.commmandID[command]] diff --git a/Messaging/Packets/Client/Home/GetPlayerProfileMessage.py b/Messaging/Packets/Client/Home/GetPlayerProfileMessage.py index 68dd359..6d470f7 100644 --- a/Messaging/Packets/Client/Home/GetPlayerProfileMessage.py +++ b/Messaging/Packets/Client/Home/GetPlayerProfileMessage.py @@ -14,4 +14,4 @@ def decode(self): self.playerID = self.readLong() def process(self): - PlayerProfileMessage(self.client, self.player, self).send(self.player.LowID) \ No newline at end of file + PlayerProfileMessage(self.client, self.player, self.playerID).send(self.player.LowID) \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceDataMessage.py b/Messaging/Packets/Server/Alliance/AllianceDataMessage.py index 464bbe7..e400032 100644 --- a/Messaging/Packets/Server/Alliance/AllianceDataMessage.py +++ b/Messaging/Packets/Server/Alliance/AllianceDataMessage.py @@ -1,12 +1,84 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager from Logic.Data.DataManager import Writer +from Logic.Files.Classes.Regions import Regions class AllianceDataMessage(Writer): - def __init__(self, client, player): + def __init__(self, client, player, clubID, sentTry=0): super().__init__(client) self.id = 24301 self.client = client self.player = player + self.clubID = clubID + self.sentTry = sentTry def encode(self): - self.writeBoolean(False) \ No newline at end of file + playerdb = DatabaseManager() + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(self.clubID[1])[0][1]) + playerdb.LoadAccount(self.player.LowID, self.player) + + '''if self.sentTry == 1: + if clubData['Members'][str(self.player.LowID)]['Role'] == 2: + self.writeBoolean(True) + elif clubData['Members'][str(self.player.LowID)]['Role'] == 4: + self.writeBoolean(True) + else: + self.writeBoolean(False) + elif self.sentTry == 2 and clubData['LowID'] == self.player.allianceID[1]: + self.writeBoolean(False) + self.sentTry = 0 + else: + self.writeBoolean(False) + self.sentTry = 0 + ''' + + self.writeBoolean(False) + + self.writeLong(clubData['HighID'], clubData['LowID']) + self.writeString(clubData['Name']) + self.writeDataReference(8, clubData['BadgeID']) + self.writeVint(clubData['Type']) # Type + self.writeVint(len(clubData['Members'])) # Total Members + self.writeVint(clubdb.getTotalTrophies(clubData)) # Total Trophies + self.writeVint(clubData['TrophiesRequired']) # Trophies Required + self.writeDataReference(0) + self.writeString(Regions.getRegionByID(self, clubData['RegionID'])) # Region + self.writeVint(0) + self.writeBoolean(clubData['FamilyFriendly']) # Family Friendly + self.writeVint(0) + + self.writeString(clubData['Description']) # Description + + self.writeVint(len(clubData['Members'])) # Members Count + + for i in clubdb.getMembersSorted(clubData): + playerData = i[1] + self.writeLong(playerData['HighID'], playerData['LowID']) + self.writeVint(playerData['Role']) # Role + self.writeVint(playerData['Trophies']) # Trophies + self.writeVint(0) # Player State TODO: Members state + self.writeVint(0) # State Timer + + # whatIsThat = 5 + whatIsThat = 0 + self.writeVint(whatIsThat) + # if whatIsThat >= 1: + # self.writeVint(1) # idk + # self.writeVint(3) # Power League Rank + + self.writeBoolean(False) # DoNotDisturb TODO: Do not disturb sync + + self.writeString(playerData['Name']) # Player Name + self.writeVint(100) + self.writeVint(28000000 + playerData['Thumbnail']) # Player Thumbnail + self.writeVint(43000000 + playerData['NameColor']) # Player Name Color + self.writeVint(-1) # Player Brawlpass Name + + self.writeVint(-1) + self.writeBoolean(False) + + self.writeVint(0) # Club Leauge? \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceListMessage.py b/Messaging/Packets/Server/Alliance/AllianceListMessage.py new file mode 100644 index 0000000..ae63bfb --- /dev/null +++ b/Messaging/Packets/Server/Alliance/AllianceListMessage.py @@ -0,0 +1,45 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager +from Logic.Data.DataManager import Writer +from Logic.Files.Classes.Regions import Regions + + +class AllianceListMessage(Writer): + def __init__(self, client, player, searchInfo): + super().__init__(client) + self.id = 24310 + self.client = client + self.player = player + self.searchInfo = searchInfo + + def encode(self): + clubdb = ClubManager() + allClubs = clubdb.getAllClub() + finalList = [] + + found = 0 + for i in allClubs: + if found == 100: return + elif i['Name'].lower().startswith(self.searchInfo['SearchString']): + finalList.append(i) + found += 1 + + self.writeString(self.searchInfo['SearchString']) + + self.writeVint(len(finalList)) + + for clubData in finalList: + self.writeLong(clubData['HighID'], clubData['LowID']) + self.writeString(clubData['Name']) + self.writeDataReference(8, clubData['BadgeID']) + self.writeVint(clubData['Type']) # Type + self.writeVint(len(clubData['Members'])) # Total Members + self.writeVint(clubdb.getTotalTrophies(clubData)) # Total Trophies + self.writeVint(clubData['TrophiesRequired']) # Trophies Required + self.writeDataReference(0) + self.writeString(Regions.getRegionByID(self, clubData['RegionID'])) # Region + self.writeVint(0) + self.writeBoolean(clubData['FamilyFriendly']) # Family Friendly + self.writeVint(0) \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceMemberMessage.py b/Messaging/Packets/Server/Alliance/AllianceMemberMessage.py new file mode 100644 index 0000000..b7cc326 --- /dev/null +++ b/Messaging/Packets/Server/Alliance/AllianceMemberMessage.py @@ -0,0 +1,40 @@ +from Logic.Data.DataManager import Writer + + +class AllianceMemberMessage(Writer): + def __init__(self, client, player, clubID, memberData): + super().__init__(client) + self.id = 24308 + self.client = client + self.player = player + self.clubID = clubID + self.memberData = memberData + + def encode(self): + self.writeLong(self.clubID[0], self.clubID[1]) + + self.writeLong(self.memberData['HighID'], self.memberData['LowID']) + self.writeVint(self.memberData['Role']) # Role + self.writeVint(self.memberData['Trophies']) # Trophies + self.writeVint(0) # Player State TODO: Members state + self.writeVint(0) # State Timer + + # whatIsThat = 5 + whatIsThat = 0 + self.writeVint(whatIsThat) + # if whatIsThat >= 1: + # self.writeVint(1) # idk + # self.writeVint(3) # Power League Rank + + self.writeBoolean(False) # DoNotDisturb TODO: Do not disturb sync + + self.writeString(self.memberData['Name']) # Player Name + self.writeVint(100) + self.writeVint(28000000 + self.memberData['Thumbnail']) # Player Thumbnail + self.writeVint(43000000 + self.memberData['NameColor']) # Player Name Color + self.writeVint(-1) # Player Brawlpass Name + + self.writeVint(-1) + self.writeBoolean(False) + + self.writeVint(0) # Club League? \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceMemberRemovedMessage.py b/Messaging/Packets/Server/Alliance/AllianceMemberRemovedMessage.py new file mode 100644 index 0000000..10915d1 --- /dev/null +++ b/Messaging/Packets/Server/Alliance/AllianceMemberRemovedMessage.py @@ -0,0 +1,15 @@ +from Logic.Data.DataManager import Writer + + +class AllianceMemberRemovedMessage(Writer): + def __init__(self, client, player, clubID, playerID): + super().__init__(client) + self.id = 24309 + self.client = client + self.player = player + self.clubID = clubID + self.playerID = playerID + + def encode(self): + self.writeLong(self.clubID[0], self.clubID[1]) + self.writeLong(self.playerID[0], self.playerID[1]) \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceResponseMessage.py b/Messaging/Packets/Server/Alliance/AllianceResponseMessage.py new file mode 100644 index 0000000..286ab4b --- /dev/null +++ b/Messaging/Packets/Server/Alliance/AllianceResponseMessage.py @@ -0,0 +1,14 @@ +from Logic.Data.DataManager import Writer + + +class AllianceResponseMessage(Writer): + def __init__(self, client, player, response): + super().__init__(client) + self.id = 24333 + self.client = client + self.player = player + self.response = response + + def encode(self): + self.writeVint(self.response) + self.writeVint(0) \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceStreamEntryMessage.py b/Messaging/Packets/Server/Alliance/AllianceStreamEntryMessage.py new file mode 100644 index 0000000..6c54dfc --- /dev/null +++ b/Messaging/Packets/Server/Alliance/AllianceStreamEntryMessage.py @@ -0,0 +1,15 @@ +from Logic.Data.DataManager import Writer +from Logic.Stream.StreamEntryFactory import StreamEntryFactory + + +class AllianceStreamEntryMessage(Writer): + def __init__(self, client, player, stream): + super().__init__(client) + self.id = 24312 + self.client = client + self.player = player + self.streamData = stream + + def encode(self): + self.writeVint(self.streamData['StreamType']) + StreamEntryFactory.encode(self, self.streamData) \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceStreamMessage.py b/Messaging/Packets/Server/Alliance/AllianceStreamMessage.py new file mode 100644 index 0000000..83e0660 --- /dev/null +++ b/Messaging/Packets/Server/Alliance/AllianceStreamMessage.py @@ -0,0 +1,22 @@ +import json + +from Database.ClubManager import ClubManager +from Logic.Data.DataManager import Writer +from Logic.Stream.StreamEntryFactory import StreamEntryFactory + + +class AllianceStreamMessage(Writer): + def __init__(self, client, player): + super().__init__(client) + self.id = 24311 + self.client = client + self.player = player + + def encode(self): + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + self.writeVint(len(clubData['ChatData'])) + + for i in clubData['ChatData']: + self.writeVint(i['StreamType']) + StreamEntryFactory.encode(self, i) \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/AllianceTeamsMessage.py b/Messaging/Packets/Server/Alliance/AllianceTeamsMessage.py new file mode 100644 index 0000000..7d40bfe --- /dev/null +++ b/Messaging/Packets/Server/Alliance/AllianceTeamsMessage.py @@ -0,0 +1,13 @@ +from Logic.Data.DataManager import Writer + + +class AllianceTeamsMessage(Writer): + def __init__(self, client, player): + super().__init__(client) + self.id = 24364 + self.client = client + self.player = player + + def encode(self): + self.writeBoolean(True) + self.writeVint(0) # AllianceTeamEntry \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/ChangeAllianceSettingsOkMessage.py b/Messaging/Packets/Server/Alliance/ChangeAllianceSettingsOkMessage.py new file mode 100644 index 0000000..4cfb1b4 --- /dev/null +++ b/Messaging/Packets/Server/Alliance/ChangeAllianceSettingsOkMessage.py @@ -0,0 +1,66 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager +from Logic.Data.DataManager import Writer +from Logic.Files.Classes.Regions import Regions + + +class ChangeAllianceSettingsOkMessage(Writer): + def __init__(self, client, player, clubid): + super().__init__(client) + self.id = 24313 + self.client = client + self.player = player + self.clubID = clubid + + def encode(self): + playerdb = DatabaseManager() + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(self.clubID[1])[0][1]) + playerdb.LoadAccount(self.player.LowID, self.player) + + self.writeLong(clubData['HighID'], clubData['LowID']) + self.writeString(clubData['Name']) + self.writeDataReference(8, clubData['BadgeID']) + self.writeVint(clubData['Type']) # Type + self.writeVint(len(clubData['Members'])) # Total Members + self.writeVint(clubdb.getTotalTrophies(clubData)) # Total Trophies + self.writeVint(clubData['TrophiesRequired']) # Trophies Required + self.writeDataReference(0) + self.writeString(Regions.getRegionByID(self, clubData['RegionID'])) # Region + self.writeVint(0) + self.writeBoolean(clubData['FamilyFriendly']) # Family Friendly + self.writeVint(0) + + self.writeString(clubData['Description']) # Description + + self.writeVint(len(clubData['Members'])) # Members Count + + for i in clubdb.getMembersSorted(clubData): + playerData = i[1] + self.writeLong(playerData['HighID'], playerData['LowID']) + self.writeVint(playerData['Role']) # Role + self.writeVint(playerData['Trophies']) # Trophies + self.writeVint(0) # Player State TODO: Members state + self.writeVint(0) # State Timer + + # whatIsThat = 5 + whatIsThat = 0 + self.writeVint(whatIsThat) + # if whatIsThat >= 1: + # self.writeVint(1) # idk + # self.writeVint(3) # Power League Rank + + self.writeBoolean(False) # DoNotDisturb TODO: Do not disturb sync + + self.writeString(playerData['Name']) # Player Name + self.writeVint(100) + self.writeVint(28000000 + playerData['Thumbnail']) # Player Thumbnail + self.writeVint(43000000 + playerData['NameColor']) # Player Name Color + self.writeVint(-1) # Player Brawlpass Name + + self.writeVint(-1) + self.writeBoolean(False) + + self.writeVint(0) # Club Leauge? \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/JoinableAllianceListMessage.py b/Messaging/Packets/Server/Alliance/JoinableAllianceListMessage.py new file mode 100644 index 0000000..44840e3 --- /dev/null +++ b/Messaging/Packets/Server/Alliance/JoinableAllianceListMessage.py @@ -0,0 +1,47 @@ +import json +import random + +from Database.ClubManager import ClubManager +from Logic.Data.DataManager import Writer +from Logic.Files.Classes.Regions import Regions + + +class JoinableAllianceListMessage(Writer): + def __init__(self, client, player): + super().__init__(client) + self.id = 24304 + self.client = client + self.player = player + + def encode(self): + clubdb = ClubManager() + allClubs = clubdb.getAllClubByRegion(self.player.region) + if len(allClubs) >= 50: + maxClub = 50 + self.writeVint(50) + else: + maxClub = len(allClubs) + self.writeVint(len(allClubs)) + + if maxClub != 1: + found = 0 + randomClubList = [] + while found != maxClub: + randomEntry = random.choice(allClubs) + if randomEntry not in randomClubList: + randomClubList.append(randomEntry) + found += 1 + + for clubData in allClubs: + self.writeLong(clubData['HighID'], clubData['LowID']) + self.writeString(clubData['Name']) + self.writeDataReference(8, clubData['BadgeID']) + self.writeVint(clubData['Type']) # Type + self.writeVint(len(clubData['Members'])) # Total Members + self.writeVint(clubdb.getTotalTrophies(clubData)) # Total Trophies + self.writeVint(clubData['TrophiesRequired']) # Trophies Required + self.writeDataReference(0) + self.writeString(Regions.getRegionByID(self, clubData['RegionID'])) # Region + self.writeVint(0) + self.writeBoolean(clubData['FamilyFriendly']) # Family Friendly + self.writeVint(0) diff --git a/Messaging/Packets/Server/Alliance/MyAllianceMessage.py b/Messaging/Packets/Server/Alliance/MyAllianceMessage.py index dc6e641..df0d645 100644 --- a/Messaging/Packets/Server/Alliance/MyAllianceMessage.py +++ b/Messaging/Packets/Server/Alliance/MyAllianceMessage.py @@ -1,13 +1,42 @@ +import json + +from Database.ClubManager import ClubManager from Logic.Data.DataManager import Writer +from Logic.Files.Classes.Regions import Regions class MyAllianceMessage(Writer): - def __init__(self, client, player): + def __init__(self, client, player, clubID): super().__init__(client) self.id = 24399 self.client = client self.player = player + self.ClubID = clubID def encode(self): - self.writeVint(0) - self.writeVint(0) \ No newline at end of file + clubdb = ClubManager() + if self.ClubID[1] != 0: + clubData = json.loads(clubdb.getClubWithLowID(self.player.allianceID[1])[0][1]) + localMemberData = clubdb.getMemberWithLowID(clubData, self.player.LowID) + self.writeVint(1) # Onlines Members TODO: members state + self.writeBoolean(True) + self.writeDataReference(25, localMemberData['Role']) # Role + + self.writeLong(clubData['HighID'], clubData['LowID']) + self.writeString(clubData['Name']) + self.writeDataReference(8, clubData['BadgeID']) + self.writeVint(clubData['Type']) # Type + self.writeVint(len(clubData['Members'])) # Total Members + self.writeVint(clubdb.getTotalTrophies(clubData)) # Total Trophies + self.writeVint(clubData['TrophiesRequired']) # Trophies Required + self.writeDataReference(0) + self.writeString(Regions.getRegionByID(self, clubData['RegionID'])) # Region + self.writeVint(0) + self.writeBoolean(clubData['FamilyFriendly']) # Family Friendly + self.writeVint(0) + + self.writeBoolean(False) + + else: + self.writeVint(0) + self.writeVint(0) \ No newline at end of file diff --git a/Messaging/Packets/Server/Alliance/UnknownAllianceMessage.py b/Messaging/Packets/Server/Alliance/UnknownAllianceMessage.py index 45a81b0..9937967 100644 --- a/Messaging/Packets/Server/Alliance/UnknownAllianceMessage.py +++ b/Messaging/Packets/Server/Alliance/UnknownAllianceMessage.py @@ -34,12 +34,12 @@ def encode(self): self.writeBoolean(True) - self.writeVLong(0, 1) # LeagueID + self.writeLogicLong(0, 1) # LeagueID self.writeVint(0) self.writeVint(0) self.writeVint(0) self.writeVint(0) - self.writeVLong(0, 1) + self.writeLogicLong(0, 1) self.writeVint(1) # Day number self.writeVint(0) self.writeVint(0) @@ -50,7 +50,7 @@ def encode(self): self.writeBoolean(True) - self.writeVLong(0, 1) + self.writeLogicLong(0, 1) self.writeVint(0) self.writeVint(0) self.writeVint(0) # Used normal tickets diff --git a/Messaging/Packets/Server/Alliance/UnknownLeaderboardAllianceMessage.py b/Messaging/Packets/Server/Alliance/UnknownLeaderboardAllianceMessage.py index 3ea5088..520cbd8 100644 --- a/Messaging/Packets/Server/Alliance/UnknownLeaderboardAllianceMessage.py +++ b/Messaging/Packets/Server/Alliance/UnknownLeaderboardAllianceMessage.py @@ -10,13 +10,13 @@ def __init__(self, client, player): def encode(self): self.writeVint(1) - self.writeVLong(0, 1) + self.writeLogicLong(0, 1) self.writeVint(1) self.writeVint(1) self.writeVint(1) - self.writeVLong(0, 1) + self.writeLogicLong(0, 1) self.writeLong(0, 1) self.writeDataReference(8, 16) self.writeVint(0) diff --git a/Messaging/Packets/Server/Authentication/LoginFailedMessage.py b/Messaging/Packets/Server/Authentication/LoginFailedMessage.py index f3aed3c..5cf649e 100644 --- a/Messaging/Packets/Server/Authentication/LoginFailedMessage.py +++ b/Messaging/Packets/Server/Authentication/LoginFailedMessage.py @@ -1,19 +1,20 @@ from Logic.Data.DataManager import Writer class LoginFailedMessage(Writer): - def __init__(self, client, player): + def __init__(self, client, player, errorInfo): super().__init__(client) self.id = 20103 self.client = client self.player = player + self.errorInfo = errorInfo def encode(self): - self.writeInt(1) - self.writeString() + self.writeInt(self.errorInfo['ErrorID']) self.writeString() self.writeString() self.writeString() self.writeString() + self.writeString(self.errorInfo['Message']) self.writeInt(0) self.writeBoolean(False) self.writeBytes(b'') diff --git a/Messaging/Packets/Server/Battle/BattleEndMessage.py b/Messaging/Packets/Server/Battle/BattleEndMessage.py index 3a6321c..3463158 100644 --- a/Messaging/Packets/Server/Battle/BattleEndMessage.py +++ b/Messaging/Packets/Server/Battle/BattleEndMessage.py @@ -56,7 +56,7 @@ def encode(self): self.writeLong(self.player.HighID, self.player.LowID) self.writeString(playerEntry["Name"]) # PlayerName self.writeVint(100) - self.writeVint(28000000 + self.player.thumbnails) # PlayerThumbnail + self.writeVint(28000000 + self.player.thumbnail) # PlayerThumbnail self.writeVint(43000000 + self.player.nameColor) # NameColor self.writeVint(-1) @@ -74,7 +74,7 @@ def encode(self): self.writeVint(9999999) self.writeVint(9999999) - self.writeDataReference(28, self.player.thumbnails) + self.writeDataReference(28, self.player.thumbnail) self.writeBoolean(False) # PlayAgainStatus diff --git a/Messaging/Packets/Server/Home/AvailableServerCommandMessage.py b/Messaging/Packets/Server/Home/AvailableServerCommandMessage.py new file mode 100644 index 0000000..b601150 --- /dev/null +++ b/Messaging/Packets/Server/Home/AvailableServerCommandMessage.py @@ -0,0 +1,31 @@ +from Logic.Data.DataManager import Writer +from Logic.Client.ClientsManager import ClientsManager +from Logic.Helpers.PlayerDisplayData import PlayerDisplayData +from Logic.Settings.Configuration import Configuration + + +class AvailableServerCommandMessage(Writer): + def __init__(self, client, player, info): + super().__init__(client) + self.id = 24111 + self.client = client + self.player = player + self.info = info + + def encode(self): + self.writeVint(self.info['CommandID']) + self.writeVint(1) + if self.info['CommandID'] == 206: + self.writeVint(self.info['NotificationID']) + self.writeInt((len(Configuration.Inbox) + len(self.player.clubMailInbox)) - 1) + self.writeBoolean(False) + self.writeInt(0) + self.writeString(self.info["MessageContent"]) + + PlayerDisplayData.encode(self, self.info['Target']) + + self.writeVint(3) + self.writeVint(-1) + self.writeVint(-1) + self.writeVint(0) + self.writeVint(0) \ No newline at end of file diff --git a/Messaging/Packets/Server/Home/PlayerProfileMessage.py b/Messaging/Packets/Server/Home/PlayerProfileMessage.py index 9b512c2..5bbeb1b 100644 --- a/Messaging/Packets/Server/Home/PlayerProfileMessage.py +++ b/Messaging/Packets/Server/Home/PlayerProfileMessage.py @@ -1,20 +1,31 @@ +import json + +from Database.ClubManager import ClubManager +from Database.DatabaseManager import DatabaseManager from Logic.Data.DataManager import Writer +from Logic.Files.Classes.Regions import Regions class PlayerProfileMessage(Writer): - def __init__(self, client, player, entry): + def __init__(self, client, player, playerID): super().__init__(client) self.id = 24113 self.client = client self.player = player - self.info = entry + self.playerID = playerID def encode(self): - self.writeVLong(self.info.playerID[0], self.info.playerID[1]) + playerdb = DatabaseManager() + try: + playerData = json.loads(playerdb.getPlayerWithLowID(self.playerID[1])[0][2]) + except IndexError: + return + + self.writeLogicLong(self.playerID[0], self.playerID[1]) self.writeVint(0) # Brawlers - self.writeVint(len(self.player.allBrawlers)) + self.writeVint(len(self.player.allBrawlers)) # TODO: Sync player brawlers for i in self.player.allBrawlers: self.writeDataReference(16, i) self.writeDataReference(0, 0) @@ -28,13 +39,13 @@ def encode(self): self.writeVint(0) # 3v3 Victories self.writeVint(2) - self.writeVint(self.player.experience) # Experince + self.writeVint(playerData['experience']) # Experince self.writeVint(3) - self.writeVint(self.player.trophies) # Current Trophies + self.writeVint(playerData['trophies']) # Current Trophies self.writeVint(4) - self.writeVint(self.player.highestTrophies) # Highest Trophies + self.writeVint(playerData['highestTrophies']) # Highest Trophies self.writeVint(5) self.writeVint(len(self.player.allBrawlers)) @@ -72,11 +83,32 @@ def encode(self): self.writeVint(19) self.writeVint(0) # Highest club league - self.writeString(self.player.Name) + self.writeString(playerData['name']) self.writeVint(100) - self.writeVint(28000000 + self.player.thumbnails) - self.writeVint(43000000 + self.player.nameColor) + self.writeVint(28000000 + playerData['playericon']) + self.writeVint(43000000 + playerData['namecolor']) self.writeVint(-1) - self.writeVint(0) - self.writeVint(0) \ No newline at end of file + self.writeBoolean(playerData['allianceID'] != [0, 0]) + + if playerData['allianceID'] != [0, 0]: + clubdb = ClubManager() + clubData = json.loads(clubdb.getClubWithLowID(playerData['allianceID'][1])[0][1]) + localMemberData = clubdb.getMemberWithLowID(clubData, self.playerID[1]) + self.writeLong(clubData['HighID'], clubData['LowID']) + self.writeString(clubData['Name']) + self.writeDataReference(8, clubData['BadgeID']) + self.writeVint(clubData['Type']) # Type + self.writeVint(len(clubData['Members'])) # Total Members + self.writeVint(clubdb.getTotalTrophies(clubData)) # Total Trophies + self.writeVint(clubData['TrophiesRequired']) # Trophies Required + self.writeDataReference(0) + self.writeString(Regions.getRegionByID(self, clubData['RegionID'])) # Region + self.writeVint(0) + self.writeBoolean(clubData['FamilyFriendly']) # Family Friendly + self.writeVint(0) + + self.writeDataReference(25, localMemberData['Role']) + + else: + self.writeDataReference(0, 0) \ No newline at end of file