示例#1
0
    def process(self):
        if self.major != 26:
            LoginFailedMessage(
                self.client, self.player,
                "The server does not support your version").send()

        elif self.player.LowID != 0:

            if self.player.maintenance:
                LoginFailedMessage(self.client, self.player, "").send()

            if self.player.patch:
                if self.fingerprint_sha != self.player.patch_sha:
                    LoginFailedMessage(self.client, self.player, "").send()

            LoginOkMessage(self.client, self.player).send()
            DataBase.loadAccount(self)  # load account
            OwnHomeDataMessage(self.client, self.player).send()
            MyAllianceMessage(self.client, self.player).send()
            if self.player.DoNotDistrub == 1:
                DoNotDistrubOkMessage(self.client, self.player).send()
            if self.player.roomID > 0:
                TeamGameroomDataMessage(self.client, self.player).send()

        else:
            self.player.LowID = Helpers.randomID(self)
            self.player.HighID = 0
            self.player.Token = Helpers.randomStringDigits(self)
            LoginOkMessage(self.client, self.player).send()
            OwnHomeDataMessage(self.client, self.player).send()
            MyAllianceMessage(self.client, self.player).send()
示例#2
0
    def process(self):
        if self.major != 26:
            self.player.err_code = 8
            LoginFailedMessage(
                self.client, self.player,
                "Your client is outdated, click below to download the new version!"
            ).send()

        elif self.player.low_id != 0:

            if self.player.maintenance:
                LoginFailedMessage(self.client, self.player, "").send()

            if self.player.patch:
                if self.fingerprint_sha != self.player.patch_sha:
                    LoginFailedMessage(self.client, self.player, "").send()

            LoginOkMessage(self.client, self.player).send()
            DataBase.loadAccount(self)  # load account
            OwnHomeDataMessage(self.client, self.player).send()
            MyAllianceMessage(self.client, self.player).send()
            if self.player.do_not_distrub == 1:
                DoNotDistrubOkMessage(self.client, self.player).send()
            if self.player.room_id > 0:
                TeamGameroomDataMessage(self.client, self.player).send()

        else:
            self.player.low_id = Helpers.randomID(self)
            self.player.high_id = 0
            self.player.token = Helpers.randomStringDigits(self)

            LoginOkMessage(self.client, self.player).send()
            OwnHomeDataMessage(self.client, self.player).send()
            MyAllianceMessage(self.client, self.player).send()
 def test_handle_image(self):
     self.handler = InputHandler(db="test")
     header = {'Authorization':"michau:pass2"}
     with open("wizytowka/1.jpg", "rb") as file:
         self.handler.handle_image(file.read(), header)
         db = DataBase()
         print(db.view_database("michau"))
    def encode(self):
        self.writeVint(1)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)

        if (self.player.roomID == 0):
            self.player.roomID = random.randint(0, 2147483647)
            self.writeInt(self.player.roomID)
            DataBase.replaceValue(self, 'roomID', self.player.roomID)

        else:
           self.writeInt(self.player.roomID)

        self.writeVint(1557129593)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(15)
        self.writeVint(self.player.mapID) # map ID
        self.writeVint(1)
        self.writeVint(1)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)  # high id
        self.writeInt(self.player.LowID)  # low id
        self.writeVint(16)
        self.writeVint(self.player.brawlerID)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(99999)
        self.writeVint(1)
        self.writeVint(3)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeString(self.player.name) # player name
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(23)
        self.writeVint(self.player.starpower)
        if self.player.useGadget == 1:
            self.writeVint(23)
            self.writeVint(self.player.gadget)
        else:
           self.writeVint(0)
           self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(6)
        self.writeHexa('''FF-FF-00-00-00-00-00''')
示例#5
0
 def encode(self):
     self.writeVint(201)
     self.writeString(self.player.name)
     self.writeVint(0)
     self.writeVint(1)
     self.writeVint(-1)
     self.writeVint(-1)
     self.writeVint(0)
     self.writeVint(0)
     DataBase.replaceValue(self, 'name', self.player.name)
示例#6
0
    def setUp(self):
        try:
            os.remove("Database/Data/database.db")
        except FileNotFoundError:
            print("file already removed!")
        self.db = DataBase()
        self.user1 = {
            "name": "Rick Sanchez",
            "password": "******",
            "email": "*****@*****.**"
        }
        self.user2 = {
            "name": "Talos Valcoran",
            "password": "******",
            "email": "*****@*****.**"
        }
        self.user3 = {
            "name": "Uzas",
            "password": "******",
            "email": "*****@*****.**"
        }

        self.add_user = lambda user: self.db.add_user(user["name"], user[
            "password"], user["email"])

        self.recname1 = "Indrick Boreale"
        self.recname2 = "Vandred Anrathi"
        self.recname3 = "Cyrion"
        self.rec1 = {
            self.recname1: {
                "email": "*****@*****.**",
                "telefon": "13432425253",
                "website": "www.cptBoreale.dr"
            }
        }
        self.rec2 = {
            self.recname2: {
                "alias": "The Exalted",
                "email": "*****@*****.**",
                "adres": "The Covenant"
            }
        }
        self.rec3 = {
            self.recname3: {
                "fax": "123221",
                "affiliation": "slaanesh",
                "email": "*****@*****.**"
            }
        }
示例#7
0
 def __init__(self, db="user"):
     self.DE = DataExtractor()
     self.db = DataBase()
     self.handlers = {
         #  "/register": lambda data, headers: self.add_user(data),
         # "/download": lambda headers: self.send_databse(headers),
         "/add_user":
         lambda data, headers: self.add_user(data),
         "/remove_user":
         lambda data, headers: self.remove_user(data, headers),
         "/login":
         lambda headers: self.login(headers),
         "/get_data":
         lambda headers: self.get_data(
             headers),  #todo maybe separate get and post callbacks
         "/handle_image":
         lambda data, headers: self.handle_image(data, headers),
         "/change_password":
         lambda data, headers: self.change_password(data, headers),
         "/change_data":
         lambda data, headers: self.change_data(data, headers),
         "/remove_record":
         lambda data, headers: self.remove_record(data, headers),
     }
    def process(self):
        if self.type == 1:

            def by_trophy(plr):
                return plr['trophies']

            players = DataBase.getAllPlayers(self)
            players.sort(key=by_trophy, reverse=True)

            if self.is_local == 1 or self.type == 0:
                GetLeaderboardLocalOkMessage(self.client, self.player,
                                             players).send()
            else:
                GetLeaderboardGlobalOkMessage(self.client, self.player,
                                              players).send()

        elif self.type == 2:
            if self.is_local == 1:
                GetLeaderboardClubLocalOkMessage(self.client, self.player,
                                                 self.type).send()
            else:
                GetLeaderboardClubGlobalOkMessage(self.client, self.player,
                                                  self.type).send()
示例#9
0
 def process(self):
     DataBase.replaceValue(self, 'profileIcon', self.player.profile_icon)
示例#10
0
    def process(self):
        DataBase.replaceValue(self, 'skinID', self.player.skin_id)
        self.player.brawlers_skins[str(self.player.brawler_id)] = self.player.skin_id
        DataBase.replaceValue(self, 'brawlersSkins', self.player.brawlers_skins)

        if self.player.brawler_id == 0:  # Shelly
            self.player.starpower = 76
            self.player.gadget = 255

        elif self.player.brawler_id == 1:  # Colt
            self.player.starpower = 77
            self.player.gadget = 273

        elif self.player.brawler_id == 2:  # Bull
            self.player.starpower = 78
            self.player.gadget = 272

        elif self.player.brawler_id == 3:  # Brock
            self.player.starpower = 79
            self.player.gadget = 245

        elif self.player.brawler_id == 4:  # Rico
            self.player.starpower = 80
            self.player.gadget = 246

        elif self.player.brawler_id == 5:  # Spike
            self.player.starpower = 81
            self.player.gadget = 247

        elif self.player.brawler_id == 6:  # Barley
            self.player.starpower = 82
            self.player.gadget = 273

        elif self.player.brawler_id == 7:  # Jessie
            self.player.starpower = 83
            self.player.gadget = 251

        elif self.player.brawler_id == 8:  # Nita
            self.player.starpower = 84
            self.player.gadget = 249

        elif self.player.brawler_id == 9:  # Dynamike
            self.player.starpower = 85
            self.player.gadget = 258

        elif self.player.brawler_id == 10:  # El Primo
            self.player.starpower = 86
            self.player.gadget = 264

        elif self.player.brawler_id == 11:  # Mortis
            self.player.starpower = 87
            self.player.gadget = 265

        elif self.player.brawler_id == 12:  # Crow
            self.player.starpower = 88
            self.player.gadget = 243

        elif self.player.brawler_id == 13:  # Poco
            self.player.starpower = 89
            self.player.gadget = 267

        elif self.player.brawler_id == 14:  # Bo
            self.player.starpower = 90
            self.player.gadget = 263

        elif self.player.brawler_id == 15:  # Piper
            self.player.starpower = 91
            self.player.gadget = 268

        elif self.player.brawler_id == 16:  # PAM
            self.player.starpower = 92
            self.player.gadget = 257

        elif self.player.brawler_id == 17:  # Tara
            self.player.starpower = 93
            self.player.gadget = 266

        elif self.player.brawler_id == 18:  # Darryl
            self.player.starpower = 94
            self.player.gadget = 260

        elif self.player.brawler_id == 19:  # Penny
            self.player.starpower = 99
            self.player.gadget = 248

        elif self.player.brawler_id == 20:  # Frank
            self.player.starpower = 104
            self.player.gadget = 261

        elif self.player.brawler_id == 21:  # Gene
            self.player.starpower = 109
            self.player.gadget = 252

        elif self.player.brawler_id == 22:  # Tick
            self.player.starpower = 114
            self.player.gadget = 253

        elif self.player.brawler_id == 23:  # Leon
            self.player.starpower = 119
            self.player.gadget = 276

        elif self.player.brawler_id == 24:  # Rosa
            self.player.starpower = 124
            self.player.gadget = 242

        elif self.player.brawler_id == 25:  # Carl
            self.player.starpower = 129
            self.player.gadget = 262

        elif self.player.brawler_id == 26:  # Bibi
            self.player.starpower = 134
            self.player.gadget = 275

        elif self.player.brawler_id == 27:  # 8-Bit
            self.player.starpower = 168
            self.player.gadget = 259

        elif self.player.brawler_id == 28:  # Sandy
            self.player.starpower = 186
            self.player.gadget = 270

        elif self.player.brawler_id == 29:  # Bea
            self.player.starpower = 192
            self.player.gadget = 271

        elif self.player.brawler_id == 30:  # EMZ
            self.player.starpower = 198
            self.player.gadget = 274

        elif self.player.brawler_id == 31:  # Mr. P
            self.player.starpower = 204
            self.player.gadget = 269

        elif self.player.brawler_id == 32:  # Max
            self.player.starpower = 210
            self.player.gadget = 254

        elif self.player.brawler_id == 34:  # Jacky
            self.player.starpower = 222
            self.player.gadget = 256

        elif self.player.brawler_id == 35:  # Gale
            self.player.starpower = 228
            self.player.gadget = 277

        elif self.player.brawler_id == 36:  # Nani
            self.player.starpower = 234
            self.player.gadget = 278

        elif self.player.brawler_id == 37:  # Sprout
            self.player.starpower = 240
            self.player.gadget = 244

        DataBase.replaceValue(self, 'starpower', self.player.starpower)
        DataBase.replaceValue(self, 'gadget', self.player.gadget)

        DataBase.replaceValue(self, 'brawlerID', self.player.brawler_id)
示例#11
0
    def encode(self):
        DataBase.loadAccount(self)

        self.writeVint(2020007)
        self.writeVint(75158)  # Timestamp

        self.writeVint(self.player.trophies)  # Player Trophies
        self.writeVint(self.player.trophies)  # Player Max Reached Trophies

        self.writeVint(122)
        self.writeVint(99)  # Trophy Road Reward

        self.writeVint(1262469)  # Starting Level (exp points)

        self.writeScId(28, self.player.profileIcon)  # Player Icon ID
        self.writeScId(43, self.player.namecolor)  # Player Name Color ID

        self.writeVint(9)  # count

        for i in range(9):
            self.writeVint(i)

        self.writeVint(3)
        self.writeVint(29)

        self.writeVint(14)
        self.writeVint(29)

        self.writeVint(self.player.skinID)  # skinID
        self.writeVint(29)

        self.writeVint(0)

        # Unlocked Skins array
        self.writeVint(len(self.player.SkinsCount))

        for skin_id in self.player.SkinsCount:
            self.writeScId(29, skin_id)

        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)

        self.writeBoolean(False)  # "token limit reached message" if true

        self.writeVint(1)
        self.writeVint(1)
        self.writeVint(0)

        self.writeVint(248791)  # Season End Timer

        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(200)
        self.writeVint(200)

        self.writeVint(5)

        for i in [93, 206, 456, 1001, 2264]:
            self.writeVint(i)

        self.writeVint(8)

        self.writeVint(2)
        self.writeVint(2)
        self.writeVint(2)
        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(0)  # array

        self.writeVint(0)  # array

        self.writeVint(100)  # Available Tokens
        self.writeVint(99999)  # Time till Bonus Tokens (seconds)

        self.writeBoolean(True)  # Tickets enabled
        self.writeVint(0)
        self.writeVint(self.player.tickets)  # Tickets value
        self.writeVint(-21)

        self.writeScId(16, self.player.brawlerID)  # Selected Brawler

        self.writeString("RO")  # Location
        self.writeString("26.165")  # Supported Content Creator

        self.writeVint(-133169153)

        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(2019053)

        self.writeVint(100)
        self.writeVint(10)

        self.writeVint(30)  # Shop Big Box price
        self.writeVint(3)

        self.writeVint(80)  # Shop Mega Box price
        self.writeVint(10)

        self.writeVint(50)  # Shop Token Doubler price
        self.writeVint(1000)  # Shop Token Doubler amount

        self.writeVint(550)
        self.writeVint(0)
        self.writeVint(999900)

        self.writeVint(6)  # count

        for i in range(6):
            self.writeVint(i)

        self.writeVint(15)  # count

        for i in range(15):
            self.writeVint(i)

        totalSlots = 10
        mapsList = [7, 32, 17, 0, 24, 202, 97, 167, 174]
        self.writeVint(totalSlots - 1)  # map slots count

        for i in range(1, totalSlots):

            self.writeVint(-133000102)
            self.writeVint(i)
            self.writeVint(0)
            self.writeVint(75992)  # Timer
            self.writeVint(10)

            self.writeScId(15, int(mapsList[i - 1]))  # Game Mode Slot Map ID

            self.writeVint(2)  # [3 = Nothing, 2 = Star Token, 1 = New Event]

            self.writeString()
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)

        # Shop
        self.writeVint(0)

        self.writeVint(8)
        for i in [20, 35, 75, 140, 290, 480, 800, 1250]:
            self.writeVint(i)

        self.writeVint(8)
        for i in [1, 2, 3, 4, 5, 10, 15, 20]:
            self.writeVint(i)

        self.writeVint(3)
        for i in [10, 30, 80]:  # Tickets price
            self.writeVint(i)

        self.writeVint(3)
        for i in [6, 20, 60]:  # Tickets amount
            self.writeVint(i)

        self.writeVint(4)
        for i in [20, 50, 140, 280]:  # Gold price
            self.writeVint(i)

        self.writeVint(4)
        for i in [150, 400, 1200, 2600]:  # Gold amount
            self.writeVint(i)

        self.writeVint(2)

        self.writeVint(999)  # Max tokens
        self.writeVint(20)  # Plus tokens

        self.writeVint(8640)
        self.writeVint(10)
        self.writeVint(5)

        self.writeVint(6)

        self.writeVint(50)
        self.writeVint(604800)

        self.writeBoolean(True)

        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)

        self.writeInt(0)
        self.writeInt(1)

        self.writeVint(0)
        self.writeVint(-1)

        self.writeBoolean(False)

        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(0)  # High Id
        self.writeVint(1)  # Low Id

        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(0)
        self.writeVint(0)

        if self.player.name is None:

            self.writeString("Guest")  # player name
            self.writeVint(0)
            DataBase.createAccount(self)  # create new account

        else:
            self.writeString(self.player.name)  # player name
            self.writeVint(1)

        self.writeVint(1207959551)

        # Unlocked Brawlers & Resources array
        self.writeVint(len(self.player.CardUnlockID) + 4)  # count

        for unlock_id in self.player.CardUnlockID:
            self.writeVint(23)
            self.writeVint(unlock_id)
            self.writeVint(1)

        for resource in self.player.Resources:
            self.writeVint(5)  # csv id
            self.writeVint(
                self.player.Resources[resource]['id'])  # resource id
            self.writeVint(
                self.player.Resources[resource]['amount'])  # resource amount

        # Brawlers Trophies array
        self.writeVint(len(self.player.BrawlersCount))  # brawlers count

        for brawler_id in self.player.BrawlersCount:
            self.writeScId(16, brawler_id)
            self.writeVint(self.player.BrawlersTrophies[str(brawler_id)])

        # Brawlers Trophies for Rank array
        self.writeVint(len(self.player.BrawlersCount))  # brawlers count

        for brawler_id in self.player.BrawlersCount:
            self.writeScId(16, brawler_id)
            self.writeVint(self.player.BrawlersTrophies[str(brawler_id)])

        self.writeVint(0)

        # Brawlers Upgrade Poitns array
        self.writeVint(len(self.player.BrawlersCount))  # brawlers count

        for brawler_id in self.player.BrawlersCount:
            self.writeScId(16, brawler_id)
            self.writeVint(self.player.brawler_upgrade_points)

        # Brawlers Power Level array
        self.writeVint(len(self.player.BrawlersCount))  # brawlers count

        for brawler_id in self.player.BrawlersCount:
            self.writeScId(16, brawler_id)
            self.writeVint(self.player.brawler_power_level)

        # Gadgets and Star Powers array
        self.writeVint(len(self.player.CardSkillsID))  # count

        for skill_id in self.player.CardSkillsID:
            self.writeVint(23)
            self.writeVint(skill_id)
            self.writeVint(1)

        # "new" Brawler Tag array
        self.writeVint(len(self.player.BrawlersCount))  # brawlers count

        for brawler_id in self.player.BrawlersCount:
            self.writeScId(16, brawler_id)
            self.writeVint(2)

        self.writeVint(self.player.gems)  # Player Gems
        self.writeVint(0)
        self.writeVint(99)
        self.writeVint(100)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(2)
        self.writeVint(1589967120)
示例#12
0
    def encode(self):
        DataBase.loadAccount(self)

        self.writeVint(0)
        self.writeVint(int(datetime.timestamp(datetime.now())))  # Timestamp

        self.writeVint(self.player.trophies)  # Player Trophies
        self.writeVint(self.player.trophies)  # Player Max Reached Trophies

        self.writeVint(0)
        self.writeVint(95)  # Trophy Road Reward

        self.writeVint(500)  # Starting Level (exp points)

        self.writeScId(28, self.player.profile_icon)  # Player Icon ID
        self.writeScId(43, self.player.name_color)  # Player Name Color ID

        self.writeVint(0)  # array

        # Selected Skins array
        self.writeVint(len(self.player.brawlers_skins))
        for brawler_id in self.player.brawlers_skins:
            self.writeVint(29)
            self.writeVint(self.player.brawlers_skins[brawler_id])  # skinID

        # Unlocked Skins array
        self.writeVint(len(self.player.skins_id))

        for skin_id in self.player.skins_id:
            self.writeScId(29, skin_id)

        self.writeVint(0)  # array

        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)

        self.writeBoolean(False)
        self.writeVint(1)
        self.writeBoolean(True)

        self.writeVint(0)  # Remaining Tokens
        self.writeVint(0)  # Season End Timer
        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)  # array

        self.writeByte(8)  # related to shop token doubler

        self.writeBoolean(True)
        self.writeBoolean(True)
        self.writeBoolean(True)

        self.writeVint(0)
        self.writeVint(0)

        # Shop Offers array

        count = len(Shop.offers)

        self.writeVint(count)
        for i in range(count):
            item = Shop.offers[i]

            self.writeVint(1)

            self.writeVint(item['ID'])
            self.writeVint(item['Multiplier'])
            self.writeVint(0)
            self.writeVint(item['SkinID'])
            self.writeVint(
                item['ShopType'])  # [0 = Offer, 2 = Skins 3 = Star Shop]

            self.writeVint(item['Cost'])  # Cost
            self.writeVint(item['Timer'])

            self.writeVint(1)
            self.writeVint(100)
            self.writeBoolean(False)  # is Offer Purchased

            self.writeBoolean(False)
            self.writeVint(
                item['ShopDisplay'])  # [0 = Normal, 1 = Daily Deals]
            self.writeBoolean(False)
            self.writeVint(0)

            self.writeInt(0)

            self.write_string_reference(item['OfferTitle'])

            self.writeBoolean(False)
            self.writeString()
            self.writeVint(0)
            self.writeBoolean(False)

        self.writeVint(0)  # array

        self.writeVint(200)  # Available Tokens
        self.writeVint(0)  # Time till Bonus Tokens (seconds)

        self.writeVint(0)  # array

        self.writeVint(self.player.tickets)  # Tickets
        self.writeVint(0)

        self.writeScId(16, self.player.brawler_id)  # Selected Brawler

        self.writeString("RO")  # Location
        self.writeString("26.165")  # Supported Content Creator

        self.writeVint(0)  # array
        self.writeVint(0)  # array
        self.writeVint(0)  # array
        self.writeVint(0)  # array

        self.writeBoolean(False)

        self.writeVint(2019049)

        self.writeVint(100)
        self.writeVint(10)

        for item in Shop.boxes:
            self.writeVint(item['Cost'])
            self.writeVint(item['Multiplier'])

        self.writeVint(Shop.token_doubler['Cost'])
        self.writeVint(Shop.token_doubler['Amount'])

        self.writeVint(500)
        self.writeVint(50)
        self.writeVint(999900)

        self.writeVint(0)  # array

        self.writeVint(8)  # array
        for i in range(1, 8 + 1):
            self.writeVint(i)

        # Logic Events
        count = len(EventSlots.maps)
        self.writeVint(count)

        for map in EventSlots.maps:

            self.writeVint(8)
            self.writeVint(EventSlots.maps.index(map) + 1)
            self.writeVint(0)
            self.writeVint(2802)
            self.writeVint(0)

            self.writeScId(15, map['ID'])

            self.writeVint(map['Status'])

            self.writeString()
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)

        self.writeVint(0)  # array

        # Logic Shop

        self.writeVint(8)
        for i in [20, 35, 75, 140, 290, 480, 800, 1250]:
            self.writeVint(i)

        self.writeVint(8)
        for i in [1, 2, 3, 4, 5, 10, 15, 20]:
            self.writeVint(i)

        self.writeVint(3)
        for i in [10, 30, 80]:  # Tickets price
            self.writeVint(i)

        self.writeVint(3)
        for i in [6, 20, 60]:  # Tickets amount
            self.writeVint(i)

        self.writeVint(len(Shop.gold))
        for item in Shop.gold:
            self.writeVint(item['Cost'])

        self.writeVint(len(Shop.gold))
        for item in Shop.gold:
            self.writeVint(item['Amount'])

        self.writeVint(2)

        self.writeVint(200)  # Max Tokens
        self.writeVint(20)  # Plus Tokens

        self.writeVint(8640)
        self.writeVint(10)
        self.writeVint(5)

        self.writeByte(6)

        self.writeVint(50)
        self.writeVint(604800)

        self.writeBoolean(True)

        self.writeVint(0)  # array

        self.writeVint(2)  # Menu Theme
        self.writeInt(1)
        self.writeInt(41000011)  # Theme ID
        self.writeInt(30)
        self.writeInt(1)

        self.writeVint(0)  # array

        self.writeInt(0)
        self.writeInt(1)

        self.writeVint(0)  # array

        self.writeVint(1)

        self.writeBoolean(True)

        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(0)  # High Id
        self.writeVint(1)  # Low Id

        self.writeVint(0)
        self.writeVint(0)

        self.writeVint(0)
        self.writeVint(0)

        if self.player.name == "Guest":
            self.writeString("Guest")  # Player Name
            self.writeVint(0)
            DataBase.createAccount(self)
        else:
            self.writeString(self.player.name)  # Player Name
            self.writeVint(1)

        self.writeInt(0)

        self.writeVint(8)

        # Unlocked Brawlers & Resources array
        self.writeVint(len(self.player.card_unlock_id) + 4)  # count

        for unlock_id in self.player.card_unlock_id:
            self.writeVint(23)
            self.writeVint(unlock_id)
            self.writeVint(1)

        self.writeVint(5)  # csv id
        self.writeVint(1)  # resource id
        self.writeVint(self.player.brawl_boxes)  # resource amount

        self.writeVint(5)  # csv id
        self.writeVint(8)  # resource id
        self.writeVint(self.player.gold)  # resource amount

        self.writeVint(5)  # csv id
        self.writeVint(9)  # resource id
        self.writeVint(self.player.big_boxes)  # resource amount

        self.writeVint(5)  # csv id
        self.writeVint(10)  # resource id
        self.writeVint(self.player.star_points)  # resource amount

        # Brawlers Trophies array
        self.writeVint(len(self.player.brawlers_id))  # brawlers count

        for brawler_id in self.player.brawlers_id:
            self.writeScId(16, brawler_id)
            try:
                self.writeVint(self.player.brawlers_trophies[str(brawler_id)])
            except KeyError:
                self.player.brawlers_trophies.update(
                    {f'{brawler_id}': self.player.brawler_trophies_for_rank})
                DataBase.replaceValue(self, 'brawlersTrophies',
                                      self.player.brawlers_trophies)
                self.writeVint(self.player.brawlers_trophies[str(brawler_id)])

        # Brawlers Trophies for Rank array
        self.writeVint(len(self.player.brawlers_id))  # brawlers count

        for brawler_id in self.player.brawlers_id:
            self.writeScId(16, brawler_id)
            try:
                self.writeVint(self.player.brawlers_trophies[str(brawler_id)])
            except KeyError:
                self.player.brawlers_trophies.update(
                    {f'{brawler_id}': self.player.brawler_trophies_for_rank})
                DataBase.replaceValue(self, 'brawlersTrophies',
                                      self.player.brawlers_trophies)
                self.writeVint(self.player.brawlers_trophies[str(brawler_id)])

        self.writeVint(0)

        # Brawlers Upgrade Poitns array
        self.writeVint(len(self.player.brawlers_id))  # brawlers count

        for brawler_id in self.player.brawlers_id:
            self.writeScId(16, brawler_id)
            self.writeVint(self.player.brawler_upgrade_points)

        # Brawlers Power Level array
        self.writeVint(len(self.player.brawlers_id))  # brawlers count

        for brawler_id in self.player.brawlers_id:
            self.writeScId(16, brawler_id)
            self.writeVint(self.player.brawler_power_level)

        # Gadgets and Star Powers array
        self.writeVint(len(self.player.card_skills_id))  # count

        for skill_id in self.player.card_skills_id:
            self.writeVint(23)
            self.writeVint(skill_id)
            self.writeVint(1)

        # "New" Brawlers array
        self.writeVint(len(self.player.brawlers_id))  # brawlers count

        for brawler_id in self.player.brawlers_id:
            self.writeScId(16, brawler_id)
            self.writeVint(2)

        self.writeVint(self.player.gems)  # Player Gems
        self.writeVint(self.player.gems)
        self.writeVint(1)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(2)
        self.writeVint(1585502369)
示例#13
0
 def process(self):
     DataBase.replaceValue(self, 'DoNotDistrub',
                           self.player.DoNotDistrubMessage)
     DoNotDistrubOkMessage(self.client, self.player).send()
示例#14
0
    def encode(self):
        self.writeVint(2)

        self.writeVint(self.player.rank)  # player rank

        brawler_trophies = self.player.brawlers_trophies[str(
            self.player.brawler_id)]

        if 0 <= brawler_trophies <= 49:
            rank_1_val = 10
            rank_2_val = 8
            rank_3_val = 7
            rank_4_val = 6
            rank_5_val = 4
            rank_6_val = 2
            rank_7_val = 2
            rank_8_val = 1
            rank_9_val = 0
            rank_10_val = 0
        else:
            if 50 <= brawler_trophies <= 99:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 7
                rank_4_val = 6
                rank_5_val = 3
                rank_6_val = 2
                rank_7_val = 2
                rank_8_val = 0
                rank_9_val = -1
                rank_10_val = -2

            if 100 <= brawler_trophies <= 199:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 7
                rank_4_val = 6
                rank_5_val = 3
                rank_6_val = 1
                rank_7_val = 0
                rank_8_val = -1
                rank_9_val = -2
                rank_10_val = -2

            if 200 <= brawler_trophies <= 299:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 6
                rank_4_val = 5
                rank_5_val = 3
                rank_6_val = 1
                rank_7_val = 0
                rank_8_val = -2
                rank_9_val = -3
                rank_10_val = -3

            if 300 <= brawler_trophies <= 399:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 6
                rank_4_val = 5
                rank_5_val = 2
                rank_6_val = 0
                rank_7_val = 0
                rank_8_val = -3
                rank_9_val = -4
                rank_10_val = -4

            if 400 <= brawler_trophies <= 499:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 6
                rank_4_val = 5
                rank_5_val = 2
                rank_6_val = -1
                rank_7_val = -2
                rank_8_val = -3
                rank_9_val = -5
                rank_10_val = -5

            if 500 <= brawler_trophies <= 599:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 6
                rank_4_val = 4
                rank_5_val = 2
                rank_6_val = -1
                rank_7_val = -2
                rank_8_val = -5
                rank_9_val = -6
                rank_10_val = -6

            if 600 <= brawler_trophies <= 699:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 6
                rank_4_val = 4
                rank_5_val = 1
                rank_6_val = -2
                rank_7_val = -2
                rank_8_val = -5
                rank_9_val = -7
                rank_10_val = -8

            if 700 <= brawler_trophies <= 799:
                rank_1_val = 10
                rank_2_val = 8
                rank_3_val = 6
                rank_4_val = 4
                rank_5_val = 1
                rank_6_val = -3
                rank_7_val = -4
                rank_8_val = -5
                rank_9_val = -8
                rank_10_val = -9

            if 800 <= brawler_trophies <= 899:
                rank_1_val = 9
                rank_2_val = 7
                rank_3_val = 5
                rank_4_val = 2
                rank_5_val = 0
                rank_6_val = -3
                rank_7_val = -4
                rank_8_val = -7
                rank_9_val = -9
                rank_10_val = -10

            if 900 <= brawler_trophies <= 999:
                rank_1_val = 8
                rank_2_val = 6
                rank_3_val = 4
                rank_4_val = 1
                rank_5_val = -1
                rank_6_val = -3
                rank_7_val = -6
                rank_8_val = -8
                rank_9_val = -10
                rank_10_val = -11

            if 1000 <= brawler_trophies <= 1099:
                rank_1_val = 6
                rank_2_val = 5
                rank_3_val = 3
                rank_4_val = 1
                rank_5_val = -2
                rank_6_val = -5
                rank_7_val = -6
                rank_8_val = -9
                rank_9_val = -11
                rank_10_val = -12

            if 1100 <= brawler_trophies <= 1199:
                rank_1_val = 5
                rank_2_val = 4
                rank_3_val = 1
                rank_4_val = 0
                rank_5_val = -2
                rank_6_val = -6
                rank_7_val = -7
                rank_8_val = -10
                rank_9_val = -12
                rank_10_val = -13

            if brawler_trophies >= 1200:
                rank_1_val = 5
                rank_2_val = 3
                rank_3_val = 0
                rank_4_val = -1
                rank_5_val = -2
                rank_6_val = -6
                rank_7_val = -8
                rank_8_val = -11
                rank_9_val = -12
                rank_10_val = -13

        if self.player.rank == 1:
            new_trophies = self.player.trophies + rank_1_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_1_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 2:
            new_trophies = self.player.trophies + rank_2_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_2_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 3:
            new_trophies = self.player.trophies + rank_3_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_3_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 4:
            new_trophies = self.player.trophies + rank_4_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_4_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 5:
            new_trophies = self.player.trophies + rank_5_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_5_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 6:
            new_trophies = self.player.trophies + rank_6_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_6_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 7:
            new_trophies = self.player.trophies + rank_7_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_7_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 8:
            new_trophies = self.player.trophies + rank_8_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_8_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 9:
            new_trophies = self.player.trophies + rank_9_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_9_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        elif self.player.rank == 10:
            new_trophies = self.player.trophies + rank_10_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + rank_10_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(32)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(1)
        self.writeVint(16)
        self.writeVint(self.player.brawler_id)
        self.writeVint(29)
        self.writeVint(self.player.skin_id)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeString(self.player.name)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(11)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(49)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(35)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(50)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(31)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(51)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(3)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(52)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(26)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(53)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(34)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(54)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(25)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(55)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(8)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(56)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(30)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(1)
        self.writeVint(57)
        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(28)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(-1040385)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
示例#15
0
 def __init__(self):
     self.db = DataBase()
示例#16
0
class sqlite_test:

    def __init__(self):
        self.db = DataBase()

    def connect(self):
        self.connection = sqlite3.connect(DB_FILENAME)

    def do_stuff(self):
        self.connection.execute("""
        CREATE TABLE IF NOT EXISTS user (
            username TEXT,
            password TEXT,
            email    TEXT,
            data     JSON
        )
        """)
        self.connection.commit()

        some_data = {"sample": "raz",
                     "cos": "cosjescze"}
        jobject = json.dumps(some_data)

        self.connection.executemany("""
        INSERT INTO user (username, password, email, data)
        VALUES (?, ?, ?, ?)
        """, (('wonsz_rzeczny', 'jest_niebezpieczny', "*****@*****.**", jobject),
              ('Radovid', '20pointsShani', "*****@*****.**", jobject)))
        self.connection.commit()

        for row in self.connection.execute("SELECT * FROM user"):
            print(row)

    def test(self):
        self.test_add_user()
        self.test_remove_user()
        self.test_ver()
        self.test_remove_record()
        self.test_add_record()
        self.test_update_record()


    #   name = "Radovid"
     #   data = {"smth":"2",
     #           "moar":"yas"}
     #   db.add_record(name, data)
      #  res = db.view_database("Bob Girlyman")
       # print(res.fetchone())

    def test_ver(self):
        name = "Indrick Boreale"
        password = "******"
        self.db.add_user(name, password)
        res = self.db.verify_user("Indrick Boreale", "SpessMehrens")
        if res is True:
            print("!!! 1ver test passed")
        else:
            print("!!! 1ver test failed")

        self.db.remove_user("Indrick Boreale")
        res = self.db.verify_user("Indrick Boreale", "SpessMehrens")
        if res is False:
            print("!!! 2ver test passed")
        else:
            print("!!! 2ver test failed")

    def test_add_user(self):
        self.db.remove_user("Indrick Boreale")
        name = "Indrick Boreale"
        password = "******"
        self.db.add_user(name, password)
        res = self.db.verify_user("Indrick Boreale", "SpessMehrens")
        print("res val is " + str(res))
        if res is True:
            print("!!!add  user test passed")
        else:
            print("!!!add  user test failed")

    def test_update(self):
        self.db.update_user("test", "silver")

    def test_remove_user(self):
        self.db.remove_user("Indrick Boreale")
        self.db.remove_user("Indrick Boreale")
        res = self.db.verify_user("Indrick Boreale", "SpessMehrens")
        if res is False:
            print("!!!remove test passed")
        else:
            print("!!!remove test failes=d")

    def test_add_record(self):
        name = "Bob Gyrlyman"
        dataname = "Marneus"
        rec = {dataname: {"password": "******", "email": "*****@*****.**"}}
        js = json.dumps(rec)
        self.db.add_record(data=js, name=name)
        self.db.add_record(data=js, name=name)
        db = self.db.view_database(name)
        if db[dataname] == rec[dataname]:
            print("!!!1 add record test passed")
        else:
            print("!!!1 add record test failed")

        self.db.remove_record(name, dataname)
        self.db.add_record(data=js, name=name)
        db = self.db.view_database(name)
        if db[dataname] == rec[dataname]:
            print("!!!2 add record test passed")
        else:
            print("!!!2 add record test failed")

    def test_update_record(self):
        name = "Bob Gyrlyman"
        dataname = "Marneus"
        rec = {dataname: {"password": "******", "email": "*****@*****.**"}}
        js = json.dumps(rec)
        self.db.add_record(data=js, name=name)
        up = {dataname: {"password": "******", "email": "*****@*****.**"}}
        self.db.update_record(name, up)
        res = self.db.view_database(name)
        if res[dataname] == up[dataname]:
            print("!!! update record test passed")
        else:
            print("!!! update record test failed")

    def test_remove_record(self):
        name = "Bob Gyrlyman"
        dataname = "Marneus"
        rec = {dataname: {"password": "******", "email": "*****@*****.**"}}
        js = json.dumps(rec)
        self.db.add_record(data=js, name=name)
        print("remove")
        self.db.remove_record(name, dataname)
        self.db.remove_record(name, dataname)
        db = self.db.view_database("Bob Gyrlyman")
        try:
            db[dataname]
        except KeyError:
            print("!!! remove record test pass")
            return
        print("!!! remove record test failed")
示例#17
0
 def process(self):
     if self.gold == 0:
         newGold = self.player.gold + 150
         newGems = self.player.gems - 20
         DataBase.replaceValue(self, 'gold', newGold)
         DataBase.replaceValue(self, 'gems', newGems)
     elif self.gold == 1:
         newGold = self.player.gold + 400
         newGems = self.player.gems - 50
         DataBase.replaceValue(self, 'gold', newGold)
         DataBase.replaceValue(self, 'gems', newGems)
     elif self.gold == 2:
         newGold = self.player.gold + 1200
         newGems = self.player.gems - 140
         DataBase.replaceValue(self, 'gold', newGold)
         DataBase.replaceValue(self, 'gems', newGems)
示例#18
0
class DatabaseTest(unittest.TestCase):
    def setUp(self):
        try:
            os.remove("Database/Data/database.db")
        except FileNotFoundError:
            print("file already removed!")
        self.db = DataBase()
        self.user1 = {
            "name": "Rick Sanchez",
            "password": "******",
            "email": "*****@*****.**"
        }
        self.user2 = {
            "name": "Talos Valcoran",
            "password": "******",
            "email": "*****@*****.**"
        }
        self.user3 = {
            "name": "Uzas",
            "password": "******",
            "email": "*****@*****.**"
        }

        self.add_user = lambda user: self.db.add_user(user["name"], user[
            "password"], user["email"])

        self.recname1 = "Indrick Boreale"
        self.recname2 = "Vandred Anrathi"
        self.recname3 = "Cyrion"
        self.rec1 = {
            self.recname1: {
                "email": "*****@*****.**",
                "telefon": "13432425253",
                "website": "www.cptBoreale.dr"
            }
        }
        self.rec2 = {
            self.recname2: {
                "alias": "The Exalted",
                "email": "*****@*****.**",
                "adres": "The Covenant"
            }
        }
        self.rec3 = {
            self.recname3: {
                "fax": "123221",
                "affiliation": "slaanesh",
                "email": "*****@*****.**"
            }
        }

    def test_verify(self):
        self.add_user(self.user1)
        self.assertEqual(
            True,
            self.db.verify_user(self.user1["name"], self.user1["password"]),
            "1 Verify true test failed!")
        self.add_user(self.user1)
        self.assertEqual(
            False,
            self.db.verify_user(self.user1["name"], self.user2["password"]),
            "2 Verify false test failed!")
        self.add_user(user=self.user1)
        self.assertEqual(
            False,
            self.db.verify_user(self.user2["name"], self.user1["password"]),
            "3 Verify false test failed!")

    def test_add_user(self):
        self.db.remove_user(self.user1["name"])
        self.add_user(self.user2)
        self.assertEqual(
            True,
            self.db.verify_user(self.user2["name"], self.user2["password"]),
            "1 Add to empty db test failed!")
        self.add_user(self.user1)
        self.db.add_user(self.user2["name"], self.user1["password"],
                         self.user1["email"])
        self.db.add_user(self.user1["name"], self.user1["password"],
                         self.user1["email"])
        self.assertEqual(
            True,
            self.db.verify_user(self.user1["name"], self.user1["password"]),
            "2 Add to non empty db test failed!")
        self.assertEqual(
            True,
            self.db.verify_user(self.user2["name"], self.user2["password"]),
            "3 Add override db test failed!")
        self.db.remove_user(self.user2["name"])
        ret = self.add_user(self.user2)
        self.assertEqual(True, ret, "4 Add incorect return value!")
        ret = self.add_user(self.user2)
        self.assertEqual(False, ret, "5 Add incorect return value!")

    def test_remove_user(self):
        self.db.remove_user(self.user1["name"])
        self.db.remove_user(self.user2["name"])
        self.assertEqual(
            False,
            self.db.verify_user(self.user1["name"], self.user1["password"]),
            "1 Remove not existing record test failed!")
        self.add_user(self.user2)
        self.db.remove_user(self.user2["name"])
        self.assertEqual(
            False,
            self.db.verify_user(self.user1["name"], self.user1["password"]),
            "2 Remove only record test failed!")
        self.add_user(self.user1)
        self.add_user(self.user2)
        self.db.remove_user(self.user1["name"])
        self.assertEqual(
            False,
            self.db.verify_user(self.user1["name"], self.user1["password"]),
            "3.1 Remove one record test failed! - record not removed")
        self.assertEqual(
            True,
            self.db.verify_user(self.user2["name"], self.user2["password"]),
            "3.2 Remove one record test failed! - other record corrupted!")
        self.db.remove_user(self.user1["name"])
        self.db.remove_user(self.user1["name"])
        self.db.remove_user(self.user1["name"])
        self.assertEqual(
            False,
            self.db.verify_user(self.user1["name"], self.user1["password"]),
            "4.1 Remove not existing record test failed! - record not removed")
        self.assertEqual(
            True,
            self.db.verify_user(self.user2["name"], self.user2["password"]),
            "4.2 Remove not existing record test failed! - other record corrupted!"
        )

    def test_update_user(self):
        # assusre that user1 is self.user1
        self.db.remove_user(self.user1["name"])
        self.add_user(self.user1)

        new_pass = "******"
        self.db.update_user(self.user1["name"], new_pass)

        self.assertEqual(
            False,
            self.db.verify_user(self.user1["name"], self.user1["password"]),
            "1 Update user updated failed! - record not changed")
        self.assertEqual(True, self.db.verify_user(self.user1["name"],
                                                   new_pass),
                         "2 Updated user test failed!")

    def test_add_record(self):
        # assusre that user1 is self.user1
        self.db.remove_user(self.user1["name"])
        self.add_user(self.user1)

        self.db.add_record(self.user1["name"], self.rec1)
        res = self.db.view_database(self.user1["name"])
        self.assertEqual(res, self.rec1,
                         "1 Add record Failed - first record, first user ")

        self.db.remove_user(self.user2["name"])
        self.add_user(self.user2)

        self.db.add_record(self.user2["name"], self.rec1)
        res = self.db.view_database(self.user2["name"])
        self.assertEqual(res, self.rec1,
                         "2 Add record Failed - first record, second user ")

        self.db.add_record(self.user1["name"], self.rec2)
        res = self.db.view_database(self.user1["name"])
        rec = copy.deepcopy(self.rec1)
        rec.update(self.rec2)
        self.assertEqual(res, rec,
                         "3 Add record Failed - second record, first user ")

        self.db.add_record(self.user1["name"], self.rec3)
        res = self.db.view_database(self.user1["name"])
        rec.update(self.rec3)
        self.assertEqual(res, rec,
                         "4 Add record Failed - third record, first user ")

        # TODO duplicate names

    def test_remove_record(self):
        self.db.remove_user(self.user1["name"])
        self.db.remove_user(self.user2["name"])
        self.add_user(self.user1)

        self.db.add_record(self.user1["name"], self.rec1)
        self.db.remove_record(self.user1["name"], self.recname1)
        self.assertEqual({}, self.db.view_database(self.user1["name"]),
                         "1 Remove record - only one record ")

        self.db.add_record(self.user1["name"], self.rec1)
        self.db.add_record(self.user1["name"], self.rec2)
        self.db.remove_record()

    def test_thread_safety(self):
        thread = Thread(target=self.async_fun)
        thread2 = Thread(target=self.async_fun)
        thread3 = Thread(target=self.async_fun)
        thread.start()
        thread2.start()
        thread3.start()

        thread.join()
        thread2.join()
        thread3.join()
        self.remove_user("Wonsz")
        self.add_user(self.new_user)
        self.assertEqual(True, self.verify_user("Wonsz", "rzeczny"),
                         "Thread test failed!")

    def async_fun(self):
        i = 0
        while i < 15:
            i += 1
            self.add_user(user=self.new_user)
            self.update_user(user=self.updated)
            self.remove_user("Wonsz")
            self.add_user(user=self.new_user2)
            self.verify_user("Wonsz", "rzeczny")
            self.remove_user("Wonsz2")

    def run_all(self):
        self.setUp()
        self.test_verify()
        self.test_add_user()
        self.test_remove_user()
        self.test_update_user()
        self.test_add_record()
        self.test_remove_record()
示例#19
0
class InputHandler:
    cookies = {}

    def __init__(self, db="user"):
        self.DE = DataExtractor()
        self.db = DataBase()
        self.handlers = {
            #  "/register": lambda data, headers: self.add_user(data),
            # "/download": lambda headers: self.send_databse(headers),
            "/add_user":
            lambda data, headers: self.add_user(data),
            "/remove_user":
            lambda data, headers: self.remove_user(data, headers),
            "/login":
            lambda headers: self.login(headers),
            "/get_data":
            lambda headers: self.get_data(
                headers),  #todo maybe separate get and post callbacks
            "/handle_image":
            lambda data, headers: self.handle_image(data, headers),
            "/change_password":
            lambda data, headers: self.change_password(data, headers),
            "/change_data":
            lambda data, headers: self.change_data(data, headers),
            "/remove_record":
            lambda data, headers: self.remove_record(data, headers),
        }

    def add_user(self, inp):
        data = self.decode_json(inp)
        print(data)
        return 200 if self.db.add_user(data['name'], data['password'],
                                       data["email"]) else 234

    def change_password(self, data, headers):
        if not self.verify_user(headers):
            return 234
        data = self.decode_json(data)
        name = self.parse_header(headers)[0]
        return 200 if self.db.update_user(name, data['password']) else 234

    def remove_user(self, data, headers):
        data = self.decode_json(data)
        print(data)
        if not self.verify_user(headers):
            return 234
        self.db.remove_user(data['name'])
        return 200

    def login(self, headers):
        if self.verify_user(headers):
            name = self.parse_header(headers)[0]
            InputHandler.cookies[name] = ''.join(
                random.choice(string.digits + string.ascii_letters)
                for _ in range(20))  #todo remove cookies
            return InputHandler.cookies[name]
        else:
            return None

    def get_data(
            self,  #GET
            headers):
        if not self.verify_user(headers):
            return 234
        name = self.parse_header(headers)[0]
        return self.db.view_database(name)

    def remove_record(self, data, headers):
        if not self.verify_user(headers):
            return 234
        record = data.decode('utf-8')
        name = self.parse_header(headers)[0]
        self.db.remove_record(name, record)
        return 200

    def change_data(self, data, headers):
        if not self.verify_user(headers):
            return 234
        data = self.decode_json(data)
        name = self.parse_header(headers)[0]
        return 200 if self.db.update_record(name, data) else 234

    def add_image(self, headers):
        if not self.verify_user(headers):
            return 234
        name = self.parse_header(headers)[0]
        return self.db.view_database(name)

    def verify_user(self, headers):
        name, password = self.parse_header(headers)
        print(name, password)
        if InputHandler.cookies.get(name) == password:
            return True
        return True if self.db.verify_user(name, password) else False

    def handle_image(self, data, headers):
        if not self.verify_user(headers):
            return 234
        user = self.parse_header(headers)[0]

        OCR = self.DE.extract(data)
        self.db.add_record(user, OCR)
        return 200

    def decode_json(self, data):
        ret = data.decode('utf-8')
        return ast.literal_eval(ret)

    def get_handlers(self):
        return self.handlers

    def parse_header(self, header):
        authorization = header.get("Authorization")
        creds = authorization.split(':')
        password = creds[1]
        name = creds[0]
        return name, password

    #todo remove prints


#{
#    "name":"michau",
#    "email":"*****@*****.**",
#    "password":"******"
#}
    def encode(self):
        reward_list = [
            0, 0, 3, 2, 8, 2, 8, 8, 0, 3, 3, 0, 0, 2, 3, 0, 0, 0, 0, 3
        ]

        if self.player.box_id == 5:
            reward = random.choice(reward_list)
            value = random.randrange(5, 20)
            GoldValue = random.randrange(10, 50)
            totalreward = 2

            if reward == 8:
                newGems = self.player.gems + value
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 3:
                newTickets = self.player.tickets + value
                DataBase.replaceValue(self, 'tickets', newTickets)
            elif reward == 2:
                newTokensDoubler = 200
                value = newTokensDoubler
            elif reward == 0:
                totalreward = 1
                value = 0

            self.writeVint(203)
            self.writeVint(0)
            self.writeVint(1)
            self.writeVint(10)  # brawl box
            self.writeVint(totalreward)

            self.writeVint(GoldValue)
            newGold = self.player.gold + GoldValue
            DataBase.replaceValue(self, 'gold', newGold)

            self.writeVint(0)
            self.writeVint(7)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(value)
            self.writeVint(1)
            self.writeVint(0)
            self.writeVint(reward)

            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(-1040385)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)

        if self.player.box_id == 4 or self.player.box_id == 1:
            tokendoublerlist = [
                200, 400, 200, 600, 200, 200, 400, 200, 200, 400, 200, 200,
                400, 600, 200, 200, 600, 400, 200, 600
            ]
            reward = random.choice(reward_list)
            value = random.randrange(5, 20)
            GoldValue = random.randrange(43, 500)
            totalreward = 2

            if reward == 8:
                newGems = self.player.gems + value
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 3:
                newTickets = self.player.tickets + value
                DataBase.replaceValue(self, 'tickets', newTickets)
            elif reward == 2:
                value = random.choice(tokendoublerlist)
            elif reward == 0:
                totalreward = 1
                value = 0

            self.writeVint(203)
            self.writeVint(0)
            self.writeVint(1)
            self.writeVint(12)
            self.writeVint(totalreward)

            self.writeVint(GoldValue)
            newGold = self.player.gold + GoldValue
            DataBase.replaceValue(self, 'gold', newGold)

            self.writeVint(0)
            self.writeVint(7)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(value)
            self.writeVint(1)
            self.writeVint(0)
            self.writeVint(reward)

            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(-1040385)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)

        if self.player.box_id == 3:
            tokendoublerlist = [
                200, 400, 200, 600, 200, 200, 400, 200, 200, 400, 200, 200,
                400, 600, 200, 200, 600, 400, 200, 600
            ]
            reward = random.choice(reward_list)
            value = random.randrange(1, 20)
            GoldValue = random.randrange(100, 1200)
            totalreward = 2

            if reward == 8:
                newGems = self.player.gems + value
                newGems = self.player.gems - 80
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 3:
                newGems = self.player.gems - 80
                newTickets = self.player.tickets + value
                DataBase.replaceValue(self, 'tickets', newTickets)
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 2:
                newGems = self.player.gems - 80
                value = random.choice(tokendoublerlist)
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 0:
                totalreward = 1
                value = 0
                newGems = self.player.gems - 80
                DataBase.replaceValue(self, 'gems', newGems)

            self.writeVint(203)
            self.writeVint(0)
            self.writeVint(1)
            self.writeVint(11)
            self.writeVint(totalreward)

            self.writeVint(GoldValue)
            newGold = self.player.gold + GoldValue
            DataBase.replaceValue(self, 'gold', newGold)

            self.writeVint(0)
            self.writeVint(7)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(value)
            self.writeVint(1)
            self.writeVint(0)
            self.writeVint(reward)

            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(-1040385)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)

        if self.player.box_id == 2:
            tokendoublerlist = [
                200, 400, 200, 600, 200, 200, 400, 200, 200, 400, 200, 200,
                400, 600, 200, 200, 600, 400, 200, 600
            ]
            reward = random.choice(reward_list)
            value = random.randrange(1, 20)
            GoldValue = random.randrange(100, 1200)
            totalreward = 2

            if reward == 8:
                newGems = self.player.gems + value
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 3:
                newTickets = self.player.tickets + value
                DataBase.replaceValue(self, 'tickets', newTickets)
            elif reward == 2:
                value = random.choice(tokendoublerlist)
            elif reward == 0:
                totalreward = 1
                value = 0

            self.writeVint(203)
            self.writeVint(0)
            self.writeVint(1)
            self.writeVint(11)
            self.writeVint(totalreward)

            self.writeVint(GoldValue)
            newGold = self.player.gold + GoldValue
            DataBase.replaceValue(self, 'gold', newGold)

            self.writeVint(0)
            self.writeVint(7)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(value)
            self.writeVint(1)
            self.writeVint(0)
            self.writeVint(reward)

            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(-1040385)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)

        if self.player.box_id == 1 or self.player.box_id == 10:
            tokendoublerlist = [
                200, 400, 200, 600, 200, 200, 400, 200, 200, 400, 200, 200,
                400, 600, 200, 200, 600, 400, 200, 600
            ]
            reward = random.choice(reward_list)
            value = random.randrange(5, 20)
            GoldValue = random.randrange(43, 500)
            totalreward = 2

            if reward == 8:
                newGems = self.player.gems + value
                newGems = self.player.gems - 30
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 3:
                newTickets = self.player.tickets + value
                newGems = self.player.gems - 30
                DataBase.replaceValue(self, 'gems', newGems)
                DataBase.replaceValue(self, 'tickets', newTickets)
            elif reward == 2:
                value = random.choice(tokendoublerlist)
                newGems = self.player.gems - 30
                DataBase.replaceValue(self, 'gems', newGems)
            elif reward == 0:
                totalreward = 1
                value = 0
                newGems = self.player.gems - 30
                DataBase.replaceValue(self, 'gems', newGems)

            self.writeVint(203)
            self.writeVint(0)
            self.writeVint(1)
            self.writeVint(12)
            self.writeVint(totalreward)

            self.writeVint(GoldValue)
            newGold = self.player.gold + GoldValue
            DataBase.replaceValue(self, 'gold', newGold)

            self.writeVint(0)
            self.writeVint(7)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(value)
            self.writeVint(1)
            self.writeVint(0)
            self.writeVint(reward)

            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(-1040385)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
            self.writeVint(0)
示例#21
0
    def decode(self):
        self.string = self.read_string()

        if self.string.lower() == 'reset':
            self.send_ofs = True
            DataBase.replaceValue(self, 'gold', 99999)
            DataBase.replaceValue(self, 'gems', 99999)
            DataBase.replaceValue(self, 'tickets', 99999)

        elif self.string.lower().startswith('gems'):
            newGems = self.string.split(" ", 4)[1:]
            try:
                DataBase.replaceValue(self, 'gems', int(newGems[0]))
                self.send_ofs = True
            except ValueError:
                pass

        elif self.string.lower().startswith('gold'):
            newGold = self.string.split(" ", 4)[1:]
            try:
                DataBase.replaceValue(self, 'gold', int(newGold[0]))
                self.send_ofs = True
            except ValueError:
                pass

        elif self.string.lower().startswith('tickets'):
            newTickets = self.string.split(" ", 7)[1:]
            try:
                DataBase.replaceValue(self, 'tickets', int(newTickets[0]))
                self.send_ofs = True
            except ValueError:
                pass

        elif self.string.lower().startswith('starpoints'):
            newStarpoints = self.string.split(" ", 10)[1:]
            try:
                DataBase.replaceValue(self, 'starpoints', int(newStarpoints[0]))
                self.send_ofs = True
            except ValueError:
                pass
    def encode(self):
        self.writeVint(1)
        self.writeVint(self.player.battle_result)

        brawler_trophies = self.player.brawlers_trophies[str(
            self.player.brawler_id)]

        if 0 <= brawler_trophies <= 49:
            win_val = 8
            lose_val = 0

        else:
            if 50 <= brawler_trophies <= 99:
                win_val = 8
                lose_val = -1

            if 100 <= brawler_trophies <= 199:
                win_val = 8
                lose_val = -2

            if 200 <= brawler_trophies <= 299:
                win_val = 8
                lose_val = -3

            if 300 <= brawler_trophies <= 399:
                win_val = 8
                lose_val = -4

            if 400 <= brawler_trophies <= 499:
                win_val = 8
                lose_val = -5

            if 500 <= brawler_trophies <= 599:
                win_val = 8
                lose_val = -6

            if 600 <= brawler_trophies <= 699:
                win_val = 8
                lose_val = -7

            if 700 <= brawler_trophies <= 799:
                win_val = 8
                lose_val = -8

            if 800 <= brawler_trophies <= 899:
                win_val = 7
                lose_val = -9

            if 900 <= brawler_trophies <= 999:
                win_val = 6
                lose_val = -10

            if 1000 <= brawler_trophies <= 1099:
                win_val = 5
                lose_val = -11

            if 1100 <= brawler_trophies <= 1199:
                win_val = 4
                lose_val = -12

            if brawler_trophies >= 1200:
                win_val = 3
                lose_val = -12

        if self.player.battle_result == 0:
            new_trophies = self.player.trophies + win_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + win_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)
        else:
            new_trophies = self.player.trophies + lose_val
            self.player.brawlers_trophies[str(
                self.player.brawler_id)] = brawler_trophies + lose_val
            DataBase.replaceValue(self, 'brawlersTrophies',
                                  self.player.brawlers_trophies)
            DataBase.replaceValue(self, 'trophies', new_trophies)

        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(32)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(6)
        self.writeVint(1)
        self.writeVint(16)
        self.writeVint(self.player.brawler_id)
        self.writeVint(29)
        self.writeVint(self.player.skin_id)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)

        self.writeString(self.player.name)

        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(0)
        self.writeVint(16)
        self.writeVint(self.player.bot1)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)

        self.writeString(self.player.bot1_n)

        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(0)
        self.writeVint(16)
        self.writeVint(self.player.bot2)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)

        self.writeString(self.player.bot2_n)

        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(self.player.bot3)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)

        self.writeString(self.player.bot3_n)

        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(self.player.bot4)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)

        self.writeString(self.player.bot4_n)

        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(2)
        self.writeVint(16)
        self.writeVint(self.player.bot5)
        self.writeVint(0)
        self.writeVint(99999)
        self.writeVint(0)
        self.writeVint(10)
        self.writeVint(0)

        self.writeString(self.player.bot5_n)

        self.writeVint(100)
        self.writeVint(28000000)
        self.writeVint(43000000)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(28)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(-1040385)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
        self.writeVint(0)
示例#23
0
    def process(self):
        if self.Unk != 23:
            if self.BrawlerSkinId == 0:
                self.player.brawler_id = 0

            elif self.BrawlerSkinId == 29:
                self.player.brawler_id = 0

            elif self.BrawlerSkinId == 52:
                self.player.brawler_id = 0

            elif self.BrawlerSkinId == 122:
                self.player.brawler_id = 0

            elif self.BrawlerSkinId == 159:
                self.player.brawler_id = 0

            elif self.BrawlerSkinId == 14:
                self.player.brawler_id = 8

            elif self.BrawlerSkinId == 15:
                self.player.brawler_id = 8

            elif self.BrawlerSkinId == 60:
                self.player.brawler_id = 8

            elif self.BrawlerSkinId == 79:
                self.player.brawler_id = 8

            elif self.BrawlerSkinId == 148:
                self.player.brawler_id = 8

            elif self.BrawlerSkinId == 1:
                self.player.brawler_id = 1

            elif self.BrawlerSkinId == 2:
                self.player.brawler_id = 1

            elif self.BrawlerSkinId == 69:
                self.player.brawler_id = 1

            elif self.BrawlerSkinId == 103:
                self.player.brawler_id = 1

            elif self.BrawlerSkinId == 135:
                self.player.brawler_id = 1

            elif self.BrawlerSkinId == 3:
                self.player.brawler_id = 2

            elif self.BrawlerSkinId == 25:
                self.player.brawler_id = 2

            elif self.BrawlerSkinId == 64:
                self.player.brawler_id = 2

            elif self.BrawlerSkinId == 102:
                self.player.brawler_id = 2

            elif self.BrawlerSkinId == 178:
                self.player.brawler_id = 2

            elif self.BrawlerSkinId == 13:
                self.player.brawler_id = 7

            elif self.BrawlerSkinId == 44:
                self.player.brawler_id = 7

            elif self.BrawlerSkinId == 47:
                self.player.brawler_id = 7

            elif self.BrawlerSkinId == 123:
                self.player.brawler_id = 7

            elif self.BrawlerSkinId == 162:
                self.player.brawler_id = 7

            elif self.BrawlerSkinId == 174:
                self.player.brawler_id = 7

            elif self.BrawlerSkinId == 4:
                self.player.brawler_id = 3

            elif self.BrawlerSkinId == 5:
                self.player.brawler_id = 3

            elif self.BrawlerSkinId == 58:
                self.player.brawler_id = 3

            elif self.BrawlerSkinId == 72:
                self.player.brawler_id = 3

            elif self.BrawlerSkinId == 91:
                self.player.brawler_id = 3

            elif self.BrawlerSkinId == 6:
                self.player.brawler_id = 9

            elif self.BrawlerSkinId == 56:
                self.player.brawler_id = 9

            elif self.BrawlerSkinId == 57:
                self.player.brawler_id = 9

            elif self.BrawlerSkinId == 97:
                self.player.brawler_id = 9

            elif self.BrawlerSkinId == 160:
                self.player.brawler_id = 9

            elif self.BrawlerSkinId == 22:
                self.player.brawler_id = 14

            elif self.BrawlerSkinId == 94:
                self.player.brawler_id = 14

            elif self.BrawlerSkinId == 98:
                self.player.brawler_id = 14

            elif self.BrawlerSkinId == 99:
                self.player.brawler_id = 14

            elif self.BrawlerSkinId == 163:
                self.player.brawler_id = 14

            elif self.BrawlerSkinId == 86:
                self.player.brawler_id = 22

            elif self.BrawlerSkinId == 106:
                self.player.brawler_id = 27

            elif self.BrawlerSkinId == 109:
                self.player.brawler_id = 27

            elif self.BrawlerSkinId == 143:
                self.player.brawler_id = 27

            elif self.BrawlerSkinId == 119:
                self.player.brawler_id = 30

            elif self.BrawlerSkinId == 167:
                self.player.brawler_id = 30

            elif self.BrawlerSkinId == 7:
                self.player.brawler_id = 10

            elif self.BrawlerSkinId == 28:
                self.player.brawler_id = 10

            elif self.BrawlerSkinId == 30:
                self.player.brawler_id = 10

            elif self.BrawlerSkinId == 128:
                self.player.brawler_id = 10

            elif self.BrawlerSkinId == 12:
                self.player.brawler_id = 6

            elif self.BrawlerSkinId == 27:
                self.player.brawler_id = 6

            elif self.BrawlerSkinId == 59:
                self.player.brawler_id = 6

            elif self.BrawlerSkinId == 90:
                self.player.brawler_id = 6

            elif self.BrawlerSkinId == 92:
                self.player.brawler_id = 6

            elif self.BrawlerSkinId == 116:
                self.player.brawler_id = 6

            elif self.BrawlerSkinId == 21:
                self.player.brawler_id = 13

            elif self.BrawlerSkinId == 71:
                self.player.brawler_id = 13

            elif self.BrawlerSkinId == 140:
                self.player.brawler_id = 13

            elif self.BrawlerSkinId == 77:
                self.player.brawler_id = 24

            elif self.BrawlerSkinId == 9:
                self.player.brawler_id = 4

            elif self.BrawlerSkinId == 26:
                self.player.brawler_id = 4

            elif self.BrawlerSkinId == 68:
                self.player.brawler_id = 4

            elif self.BrawlerSkinId == 130:
                self.player.brawler_id = 4

            elif self.BrawlerSkinId == 171:
                self.player.brawler_id = 4

            elif self.BrawlerSkinId == 34:
                self.player.brawler_id = 18

            elif self.BrawlerSkinId == 70:
                self.player.brawler_id = 18

            elif self.BrawlerSkinId == 158:
                self.player.brawler_id = 18

            elif self.BrawlerSkinId == 41:
                self.player.brawler_id = 19

            elif self.BrawlerSkinId == 61:
                self.player.brawler_id = 19

            elif self.BrawlerSkinId == 88:
                self.player.brawler_id = 19

            elif self.BrawlerSkinId == 165:
                self.player.brawler_id = 19

            elif self.BrawlerSkinId == 73:
                self.player.brawler_id = 25

            elif self.BrawlerSkinId == 93:
                self.player.brawler_id = 25

            elif self.BrawlerSkinId == 104:
                self.player.brawler_id = 25

            elif self.BrawlerSkinId == 132:
                self.player.brawler_id = 25

            elif self.BrawlerSkinId == 134:
                self.player.brawler_id = 25

            elif self.BrawlerSkinId == 142:
                self.player.brawler_id = 34

            elif self.BrawlerSkinId == 176:
                self.player.brawler_id = 34

            elif self.BrawlerSkinId == 23:
                self.player.brawler_id = 15

            elif self.BrawlerSkinId == 108:
                self.player.brawler_id = 15

            elif self.BrawlerSkinId == 120:
                self.player.brawler_id = 15

            elif self.BrawlerSkinId == 147:
                self.player.brawler_id = 15

            elif self.BrawlerSkinId == 24:
                self.player.brawler_id = 16

            elif self.BrawlerSkinId == 179:
                self.player.brawler_id = 16

            elif self.BrawlerSkinId == 42:
                self.player.brawler_id = 20

            elif self.BrawlerSkinId == 45:
                self.player.brawler_id = 20

            elif self.BrawlerSkinId == 125:
                self.player.brawler_id = 20

            elif self.BrawlerSkinId == 81:
                self.player.brawler_id = 26

            elif self.BrawlerSkinId == 146:
                self.player.brawler_id = 26

            elif self.BrawlerSkinId == 114:
                self.player.brawler_id = 29

            elif self.BrawlerSkinId == 139:
                self.player.brawler_id = 29

            elif self.BrawlerSkinId == 156:
                self.player.brawler_id = 36

            elif self.BrawlerSkinId == 18:
                self.player.brawler_id = 11

            elif self.BrawlerSkinId == 50:
                self.player.brawler_id = 11

            elif self.BrawlerSkinId == 63:
                self.player.brawler_id = 11

            elif self.BrawlerSkinId == 75:
                self.player.brawler_id = 11

            elif self.BrawlerSkinId == 173:
                self.player.brawler_id = 11

            elif self.BrawlerSkinId == 32:
                self.player.brawler_id = 17

            elif self.BrawlerSkinId == 111:
                self.player.brawler_id = 17

            elif self.BrawlerSkinId == 145:
                self.player.brawler_id = 17

            elif self.BrawlerSkinId == 67:
                self.player.brawler_id = 21

            elif self.BrawlerSkinId == 117:
                self.player.brawler_id = 21

            elif self.BrawlerSkinId == 172:
                self.player.brawler_id = 21

            elif self.BrawlerSkinId == 127:
                self.player.brawler_id = 32

            elif self.BrawlerSkinId == 137:
                self.player.brawler_id = 32

            elif self.BrawlerSkinId == 121:
                self.player.brawler_id = 31

            elif self.BrawlerSkinId == 152:
                self.player.brawler_id = 31

            elif self.BrawlerSkinId == 157:
                self.player.brawler_id = 37

            elif self.BrawlerSkinId == 177:
                self.player.brawler_id = 37

            elif self.BrawlerSkinId == 10:
                self.player.brawler_id = 5

            elif self.BrawlerSkinId == 11:
                self.player.brawler_id = 5

            elif self.BrawlerSkinId == 96:
                self.player.brawler_id = 5

            elif self.BrawlerSkinId == 19:
                self.player.brawler_id = 12

            elif self.BrawlerSkinId == 20:
                self.player.brawler_id = 12

            elif self.BrawlerSkinId == 49:
                self.player.brawler_id = 12

            elif self.BrawlerSkinId == 95:
                self.player.brawler_id = 12

            elif self.BrawlerSkinId == 100:
                self.player.brawler_id = 12

            elif self.BrawlerSkinId == 101:
                self.player.brawler_id = 12

            elif self.BrawlerSkinId == 62:
                self.player.brawler_id = 23

            elif self.BrawlerSkinId == 110:
                self.player.brawler_id = 23

            elif self.BrawlerSkinId == 126:
                self.player.brawler_id = 23

            elif self.BrawlerSkinId == 131:
                self.player.brawler_id = 23

            elif self.BrawlerSkinId == 113:
                self.player.brawler_id = 28

            elif self.BrawlerSkinId == 118:
                self.player.brawler_id = 28

            elif self.BrawlerSkinId == 155:
                self.player.brawler_id = 35

            elif self.BrawlerSkinId == 180:
                self.player.brawler_id = 35

            if self.player.brawler_id == 0:  #Shelly
                self.player.starpower = 76
                self.player.gadget = 255

            elif self.player.brawler_id == 1:  #Colt
                self.player.starpower = 77
                self.player.gadget = 273

            elif self.player.brawler_id == 2:  #Bull
                self.player.starpower = 78
                self.player.gadget = 272

            elif self.player.brawler_id == 3:  #Brock
                self.player.starpower = 79
                self.player.gadget = 245

            elif self.player.brawler_id == 4:  #Rico
                self.player.starpower = 80
                self.player.gadget = 246

            elif self.player.brawler_id == 5:  #Spike
                self.player.starpower = 81
                self.player.gadget = 247

            elif self.player.brawler_id == 6:  #Barley
                self.player.starpower = 82
                self.player.gadget = 273

            elif self.player.brawler_id == 7:  #Jessie
                self.player.starpower = 83
                self.player.gadget = 251

            elif self.player.brawler_id == 8:  #Nita
                self.player.starpower = 84
                self.player.gadget = 249

            elif self.player.brawler_id == 9:  #Dynamike
                self.player.starpower = 85
                self.player.gadget = 258

            elif self.player.brawler_id == 10:  #El Primo
                self.player.starpower = 86
                self.player.gadget = 264

            elif self.player.brawler_id == 11:  #Mortis
                self.player.starpower = 87
                self.player.gadget = 265

            elif self.player.brawler_id == 12:  #Crow
                self.player.starpower = 88
                self.player.gadget = 243

            elif self.player.brawler_id == 13:  #Poco
                self.player.starpower = 89
                self.player.gadget = 267

            elif self.player.brawler_id == 14:  #Bo
                self.player.starpower = 90
                self.player.gadget = 263

            elif self.player.brawler_id == 15:  #Piper
                self.player.starpower = 91
                self.player.gadget = 268

            elif self.player.brawler_id == 16:  #PAM
                self.player.starpower = 92
                self.player.gadget = 257

            elif self.player.brawler_id == 17:  #Tara
                self.player.starpower = 93
                self.player.gadget = 266

            elif self.player.brawler_id == 18:  #Darryl
                self.player.starpower = 94
                self.player.gadget = 260

            elif self.player.brawler_id == 19:  #Penny
                self.player.starpower = 99
                self.player.gadget = 248

            elif self.player.brawler_id == 20:  #Frank
                self.player.starpower = 104
                self.player.gadget = 261

            elif self.player.brawler_id == 21:  #Gene
                self.player.starpower = 109
                self.player.gadget = 252

            elif self.player.brawler_id == 22:  #Tick
                self.player.starpower = 114
                self.player.gadget = 253

            elif self.player.brawler_id == 23:  #Leon
                self.player.starpower = 119
                self.player.gadget = 276

            elif self.player.brawler_id == 24:  #Rosa
                self.player.starpower = 124
                self.player.gadget = 242

            elif self.player.brawler_id == 25:  #Carl
                self.player.starpower = 129
                self.player.gadget = 262

            elif self.player.brawler_id == 26:  #Bibi
                self.player.starpower = 134
                self.player.gadget = 275

            elif self.player.brawler_id == 27:  #8-Bit
                self.player.starpower = 168
                self.player.gadget = 259

            elif self.player.brawler_id == 28:  #Sandy
                self.player.starpower = 186
                self.player.gadget = 270

            elif self.player.brawler_id == 29:  #Bea
                self.player.starpower = 192
                self.player.gadget = 271

            elif self.player.brawler_id == 30:  #EMZ
                self.player.starpower = 198
                self.player.gadget = 274

            elif self.player.brawler_id == 31:  #Mr. P
                self.player.starpower = 204
                self.player.gadget = 269

            elif self.player.brawler_id == 32:  #Max
                self.player.starpower = 210
                self.player.gadget = 254

            elif self.player.brawler_id == 34:  #Jacky
                self.player.starpower = 222
                self.player.gadget = 256

            elif self.player.brawler_id == 35:  #Gale
                self.player.starpower = 228
                self.player.gadget = 277

            elif self.player.brawler_id == 36:  #Nani
                self.player.starpower = 234
                self.player.gadget = 278

            elif self.player.brawler_id == 37:  #Sprout
                self.player.starpower = 240
                self.player.gadget = 244

            DataBase.replaceValue(self, 'starpower', self.player.starpower)
            DataBase.replaceValue(self, 'gadget', self.player.gadget)

            TeamGameroomDataMessage(self.client, self.player).send()
示例#24
0
 def process(self):
     DataBase.replaceValue(self, 'starpower', self.player.starpower)
     if self.player.room_id > 0:
         TeamGameroomDataMessage(self.client, self.player).send()
示例#25
0
 def process(self):
     self.player.room_id = 0
     DataBase.replaceValue(self, 'roomID', self.player.room_id)
     TeamLeftMessage(self.client, self.player).send()
示例#26
0
 def process(self):
     DataBase.replaceValue(self, 'namecolor', self.namecolor)
示例#27
0
    def decode(self):
        self.msg = self.read_string()

        if self.msg.lower() == '/stats':
            self.bot_msg = f'Server status:\nBuild version: 1.1 (for v26.165)\nFingerprint SHA: {self.player.patch_sha}'

        elif self.msg.lower() == '/reset':
            self.send_ofs = True
            DataBase.replaceValue(self, 'gold', 99999)
            DataBase.replaceValue(self, 'gems', 99999)
            DataBase.replaceValue(self, 'tickets', 99999)

        elif self.msg.lower().startswith('/gems'):
            newGems = self.msg.split(" ", 4)[1:]
            try:
                DataBase.replaceValue(self, 'gems', int(newGems[0]))
                self.send_ofs = True
            except ValueError:
                pass

        elif self.msg.lower().startswith('/gold'):
            newGold = self.msg.split(" ", 4)[1:]
            try:
                DataBase.replaceValue(self, 'gold', int(newGold[0]))
                self.send_ofs = True
            except ValueError:
                pass

        elif self.msg.lower().startswith('/tickets'):
            newTickets = self.msg.split(" ", 7)[1:]
            try:
                DataBase.replaceValue(self, 'tickets', int(newTickets[0]))
                self.send_ofs = True
            except ValueError:
                pass

        elif self.msg.lower().startswith('/starpoints'):
            newStarpoints = self.msg.split(" ", 10)[1:]
            try:
                DataBase.replaceValue(self, 'starpoints',
                                      int(newStarpoints[0]))
                self.send_ofs = True
            except ValueError:
                pass

        elif self.msg.lower() == '/help':
            self.bot_msg = 'Club Commands\n/stats - show server status\n/reset - reset all resources\n/gems [int] - add gems to your account, where int is the number of gems\n/gold [int] - add gold to your account, where int is the number of gold\n/tickets [int] - add tickets to your account, where int is the number of tickets\n/starpoints [int] - add starpoints to your account, where int is the number of starpoints'
 def populate_db(self):
     db = DataBase(name=self.name)
     db.add_record(json.loads(open("Database/Data/BC1.json").read()))
     db.add_record(json.loads(open("Database/Data/BC2.json").read()))
示例#29
0
 def process(self):
     newGems = self.player.gems - 50
     DataBase.replaceValue(self, 'gems', newGems)
示例#30
0
 def __init__(self, name="users"):
     DataBase.__init__(self, name)
     self._lock = Lock()