Advertisement
Guest User

Untitled

a guest
Oct 14th, 2017
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 238.04 KB | None | 0 0
  1. # -*- coding: cp1254 -*-
  2. # 2017.06.19 20:28:46 Hora oficial do Brasil
  3. # Embedded file name: MainServer.py
  4. # coding: utf-8
  5. import os, sys, json, time, random, sqlite3, traceback, ConfigParser, urllib2, time as _time
  6. sys.dont_write_bytecode = True
  7. sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))))
  8. from utils import *
  9. from modules import *
  10. from datetime import datetime
  11. from twisted.internet import reactor, protocol
  12. from datetime import timedelta
  13.  
  14. class Client():
  15.  
  16.     def __init__(this):
  17.         this.games = this
  18.         this.langue = 'BR'
  19.         this.packages = ''
  20.         this.roomName = ''
  21.         this.marriage = ''
  22.         this.shopItems = ''
  23.         this.tribeName = ''
  24.         this.mDirection = ''
  25.         this.emailAddress = ''
  26.         this.tradeName = ''
  27.         this.playerName = ''
  28.         this.shamanItems = ''
  29.         this.lastMessage = ''
  30.         this.tribeMessage = ''
  31.         this.tempMouseColor = ''
  32.         this.silenceMessage = ''
  33.         this.currentCaptcha = ''
  34.         this.mouseColor = '78583a'
  35.         this.nameColor = ''
  36.         this.shamanColor = '95d9d6'
  37.     this.modoPwetLangue = 'ALL'
  38.         this.playerLook = '1;0,0,0,0,0,0,0,0,0,0'
  39.         this.shamanLook = '0,0,0,0,0,0,0,0,0,0,0'
  40.         this.botVillage = ''
  41.         this.mouseName = ''
  42.         this.limitPacket = 40
  43.         this.packetSent = 0
  44.         this.gameError = 0
  45.         this.useAnime = 0
  46.         this.TimeGiro = 0
  47.         this.gameEmail = 0
  48.         this.gameAvatar = 0
  49.         this.gameUsername = 0
  50.         this.gamePassword = 0
  51.         this.changepw = 0
  52.         this.changeuser = 0
  53.         this.validLangue = 0
  54.         this.regalos = 0
  55.         this.explosion = 0
  56.         this.ballons = 0
  57.         this.flypoints = 0
  58.         this.invocationpoints = 0
  59.         this.racingADD = 0
  60.         this.bootcampADD = 0
  61.         this.wrongLoginAttempts = 0
  62.         this.ClientGotHole = 1
  63.         this.pet = 0
  64.         this.posX = 0
  65.         this.posY = 0
  66.         this.velX = 0
  67.         this.velY = 0
  68.         this.gender = 0
  69.         this.petEnd = 0
  70.         this.viewMessage = 0
  71.         this.priceDoneVisu = 0
  72.         this.cannonX = 2
  73.         this.cannonY = 8
  74.         this.cXpos = 189
  75.         this.activeArtefact = 0
  76.         this.cYpos = 133
  77.         this.cnCustom = 0
  78.         this.playerAvatar = 1
  79.         this.page = 1
  80.         this.countP = 0
  81.         this.survivorDeath = 0
  82.         this.lastOn = 0
  83.         this.regDate = 0
  84.         this.langueID = 0
  85.         this.playerID = 0
  86.         this.banHours = 0
  87.         this.iceCount = 2
  88.         this.privLevel = 0
  89.         this.shamanExp = 0
  90.         this.tribeCode = 0
  91.         this.tribeRank = 0
  92.         this.tribeChat = 0
  93.         this.titleStars = 0
  94.         this.firstCount = 0
  95.         this.XDCoins = 0
  96.         this.XDFichas = 0
  97.         this.deathCount = 0
  98.         this.deathRounds = 0
  99.         this.playerCode = 0
  100.         this.shamanType = 0
  101.         this.tribeHouse = 0
  102.         this.tribeJoined = 0
  103.         this.tribePoints = 0
  104.         this.silenceType = 0
  105.         this.playerScore = 0
  106.         this.titleNumber = 0
  107.         this.cheeseCount = 0
  108.         this.shopFraises = 0
  109.         this.shamanSaves = 0
  110.         this.shamanLevel = 1
  111.         this.lastGameMode = 0
  112.         this.bubblesCount = 0
  113.         this.currentPlace = 0
  114.         this.shamanCheeses = 0
  115.         this.hardModeSaves = 0
  116.         this.bootcampCount = 0
  117.         this.shopCheeses = 100
  118.         this.shamanExpNext = 32
  119.         this.ambulanceCount = 0
  120.         this.defilantePoints = 0
  121.         this.divineModeSaves = 0
  122.         this.lastDivorceTimer = 0
  123.         this.equipedShamanBadge = 0
  124.         this.playerStartTimeMillis = 0
  125.         this.dac = 0
  126.         this.artefactID = 0
  127.         this.PInfo = [0, 0, 125]
  128.         this.lastPacketID = random.randint(0, 99)
  129.         this.authKey = random.randint(1, 2147483347)
  130.         this.authKeyLogin = random.randint(1, 39238)
  131.         this.blockedPost = True
  132.         this.protectTimer = True
  133.         this.protectTimerRanking = True
  134.         this.protectTimerCafe = True
  135.         this.AbrirMenu = True
  136.         this.canUseConsumable = True
  137.         this.canUseTribulle = True
  138.         this.canUseSpawnAll = True
  139.         this.PlayerDeathVivo = False
  140.         this.hasArtefact = False
  141.         this.libCn = False
  142.         this.isAfk = False
  143.         this.isDead = False
  144.         this.isMute = False
  145.         this.isCafe = False
  146.         this.isGuest = False
  147.         this.isVoted = False
  148.         this.isTrade = False
  149.         this.useTotem = False
  150.         this.openStaffChat = False
  151.         this.isHidden = False
  152.         this.isClosed = False
  153.         this.isShaman = False
  154.         this.isTeleport = False
  155.         this.isFly = False
  156.         this.isSpeed = False
  157.         this.hasEnter = False
  158.         this.isSuspect = False
  159.         this.isVampire = False
  160.         this.hasCheese = False
  161.         this.isJumping = False
  162.         this.resetTotem = False
  163.     this.isModoPwet = False
  164.         this.canRespawn = False
  165.         this.enabledLua = False
  166.         this.isNewclient = False
  167.         this.isEnterRoom = False
  168.         this.tradeConfirm = False
  169.         this.isFFA = False
  170.         this.canSpawnCN = True
  171.         this.isReloadCafe = False
  172.         this.isMovingLeft = False
  173.         this.isMovingRight = False
  174.         this.isOpportunist = False
  175.         this.qualifiedVoted = False
  176.         this.desintegration = False
  177.         this.canShamanRespawn = False
  178.         this.validatingVersion = False
  179.         this.canRedistributeSkills = False
  180.         this.canCN = False
  181.         this.modMute = False
  182.         this.Cursor = Cursor
  183.         this.CMDTime = time.time()
  184.         this.CAPTime = time.time()
  185.         this.CTBTime = time.time()
  186.         this.room = None
  187.         this.awakeTimer = None
  188.         this.resSkillsTimer = None
  189.         this.consumablesTimer = None
  190.         this.spawnTimer = None
  191.         this.tribulleTimer = None
  192.         this.games.TimeHole = None
  193.         this.games.RebootTimer1 = None
  194.         this.games.RebootTimer2 = None
  195.         this.games.RebootTimer3 = None
  196.         this.games.RebootTimer4 = None
  197.         this.games.RebootTimer5 = None
  198.         this.games.RebootTimer6 = None
  199.         this.allUsersTribe = []
  200.         this.allUsersFriends = []
  201.         this.totem = [0, '']
  202.         this.PInfo = [0, 0, 100]
  203.         this.tempTotem = [0, '']
  204.         this.racingStats = [0] * 4
  205.         this.survivorStats = [0] * 4
  206.         this.chats = []
  207.         this.voteBan = []
  208.         this.clothes = []
  209.         this.titleList = []
  210.         this.shopBadges = []
  211.         this.friendsList = []
  212.         this.tribeInvite = []
  213.         this.shamanBadges = []
  214.         this.ignoredsList = []
  215.         this.shopTitleList = []
  216.         this.marriageInvite = []
  217.         this.firstTitleList = []
  218.         this.cheeseTitleList = []
  219.         this.shamanTitleList = []
  220.         this.bootcampTitleList = []
  221.         this.hardModeTitleList = []
  222.         this.equipedConsumables = []
  223.         this.ignoredTribeInvites = []
  224.         this.divineModeTitleList = []
  225.         this.ignoredMarriageInvites = []
  226.         this.specialTitleList = []
  227.         this.visusRemove = []
  228.         this.custom = []
  229.         this.visuDone = []
  230.         this.loginTime = time.time()
  231.         this.createTime = time.time()
  232.         this.tribeRanks = {}
  233.         this.playerSkills = {}
  234.         this.tradeConsumables = {}
  235.         this.playerConsumables = {}
  236.         this.itensBots = {'Papaille': [(4,
  237.                        800,
  238.                        50,
  239.                        4,
  240.                        2253,
  241.                        50),
  242.                       (4,
  243.                        800,
  244.                        50,
  245.                        4,
  246.                        2254,
  247.                        50),
  248.                       (4,
  249.                        800,
  250.                        50,
  251.                        4,
  252.                        2257,
  253.                        50),
  254.                       (4,
  255.                        800,
  256.                        50,
  257.                        4,
  258.                        2260,
  259.                        50),
  260.                       (4,
  261.                        800,
  262.                        50,
  263.                        4,
  264.                        2261,
  265.                        50)],
  266.          'Buffy': [(1,
  267.                     147,
  268.                     1,
  269.                     4,
  270.                     2254,
  271.                     200),
  272.                    (2,
  273.                     17,
  274.                     1,
  275.                     4,
  276.                     2254,
  277.                     150),
  278.                    (2,
  279.                     18,
  280.                     1,
  281.                     4,
  282.                     2254,
  283.                     150),
  284.                    (2,
  285.                     19,
  286.                     1,
  287.                     4,
  288.                     2254,
  289.                     150),
  290.                    (3,
  291.                     398,
  292.                     1,
  293.                     4,
  294.                     2254,
  295.                     150),
  296.                    (3,
  297.                     392,
  298.                     1,
  299.                     4,
  300.                     2254,
  301.                     50)],
  302.          'Indiana Mouse': [(3,
  303.                             255,
  304.                             1,
  305.                             4,
  306.                             2257,
  307.                             50),
  308.                            (3,
  309.                             394,
  310.                             1,
  311.                             4,
  312.                             2257,
  313.                             50),
  314.                            (3,
  315.                             395,
  316.                             1,
  317.                             4,
  318.                             2257,
  319.                             50),
  320.                            (3,
  321.                             320,
  322.                             1,
  323.                             4,
  324.                             2257,
  325.                             50),
  326.                            (3,
  327.                             393,
  328.                             1,
  329.                             4,
  330.                             2257,
  331.                             50),
  332.                            (3,
  333.                             402,
  334.                             1,
  335.                             4,
  336.                             2257,
  337.                             50),
  338.                            (3,
  339.                             397,
  340.                             1,
  341.                             4,
  342.                             2257,
  343.                             50),
  344.                            (3,
  345.                             341,
  346.                             1,
  347.                             4,
  348.                             2257,
  349.                             50),
  350.                            (3,
  351.                             335,
  352.                             1,
  353.                             4,
  354.                             2257,
  355.                             25),
  356.                            (3,
  357.                             403,
  358.                             1,
  359.                             4,
  360.                             2257,
  361.                             50),
  362.                            (1,
  363.                             6,
  364.                             1,
  365.                             4,
  366.                             2257,
  367.                             50),
  368.                            (1,
  369.                             17,
  370.                             1,
  371.                             4,
  372.                             2257,
  373.                             50)],
  374.          'Elise': [(4,
  375.                     31,
  376.                     2,
  377.                     4,
  378.                     2261,
  379.                     5),
  380.                    (4,
  381.                     2256,
  382.                     2,
  383.                     4,
  384.                     2261,
  385.                     5),
  386.                    (4,
  387.                     2232,
  388.                     2,
  389.                     4,
  390.                     2253,
  391.                     1),
  392.                    (4,
  393.                     21,
  394.                     5,
  395.                     4,
  396.                     2253,
  397.                     1),
  398.                    (4,
  399.                     33,
  400.                     2,
  401.                     4,
  402.                     2260,
  403.                     1),
  404.                    (4,
  405.                     33,
  406.                     2,
  407.                     4,
  408.                     2254,
  409.                     1)],
  410.          'Oracle': [(1,
  411.                      145,
  412.                      1,
  413.                      4,
  414.                      2253,
  415.                      200),
  416.                     (2,
  417.                      16,
  418.                      1,
  419.                      4,
  420.                      2253,
  421.                      150),
  422.                     (2,
  423.                      21,
  424.                      1,
  425.                      4,
  426.                      2253,
  427.                      150),
  428.                     (2,
  429.                      24,
  430.                      1,
  431.                      4,
  432.                      2253,
  433.                      150),
  434.                     (2,
  435.                      20,
  436.                      1,
  437.                      4,
  438.                      2253,
  439.                      150),
  440.                     (3,
  441.                      390,
  442.                      1,
  443.                      4,
  444.                      2253,
  445.                      50),
  446.                     (3,
  447.                      391,
  448.                      1,
  449.                      4,
  450.                      2253,
  451.                      200),
  452.                     (3,
  453.                      399,
  454.                      1,
  455.                      4,
  456.                      2253,
  457.                      150)],
  458.          'Prof': [(4,
  459.                    800,
  460.                    20,
  461.                    4,
  462.                    2257,
  463.                    10),
  464.                   (4,
  465.                    19,
  466.                    2,
  467.                    4,
  468.                    2257,
  469.                    5),
  470.                   (4,
  471.                    2258,
  472.                    2,
  473.                    4,
  474.                    2257,
  475.                    4),
  476.                   (4,
  477.                    2262,
  478.                    5,
  479.                    4,
  480.                    2257,
  481.                    2),
  482.                   (4,
  483.                    2259,
  484.                    10,
  485.                    4,
  486.                    2257,
  487.                    1),
  488.                   (4,
  489.                    20,
  490.                    1,
  491.                    4,
  492.                    2257,
  493.                    2)],
  494.          'Cassidy': [(1,
  495.                       154,
  496.                       1,
  497.                       4,
  498.                       2261,
  499.                       200), (2,
  500.                       23,
  501.                       1,
  502.                       4,
  503.                       2261,
  504.                       150), (3,
  505.                       400,
  506.                       1,
  507.                       4,
  508.                       2261,
  509.                       100)],
  510.          'Von Drekkemouse': [(2,
  511.                               22,
  512.                               1,
  513.                               4,
  514.                               2260,
  515.                               150), (1,
  516.                               153,
  517.                               1,
  518.                               4,
  519.                               2260,
  520.                               200), (3,
  521.                               401,
  522.                               1,
  523.                               4,
  524.                               2260,
  525.                               100)],
  526.          'Tod': [(4,
  527.                   2259,
  528.                   10,
  529.                   4,
  530.                   2257,
  531.                   1), (4,
  532.                   2258,
  533.                   10,
  534.                   4,
  535.                   2254,
  536.                   230), (3,
  537.                   401,
  538.                   1,
  539.                   4,
  540.                   2260,
  541.                   100)]}
  542.         this.aventureCounts = {}
  543.         this.aventurePoints = {}
  544.         this.can = this
  545.         this.can.Loop_Decoded = False
  546.         return None
  547.  
  548.     def dataReceived(this, packet):
  549.         if packet.startswith('<policy-file-request/>'):
  550.             this.transport.write('<cross-domain-policy><allow-access-from domain="*" to-ports="*"/></cross-domain-policy>')
  551.             this.transport.loseConnection()
  552.             return
  553.         elif packet in ('', ' ', '\x00', '\x01'):
  554.             this.server.tempIPBanList.append(this.ipAddress)
  555.             this.server.disconnectIPAddress(this.ipAddress)
  556.             this.transport.loseConnection()
  557.             this.can.Loop_Decoded = True
  558.             return
  559.         elif packet == None or len(packet) < 2:
  560.             return
  561.         else:
  562.             this.packages += packet
  563.             while this.packages.strip(chr(0)):
  564.                 if len(this.packages) >= 5:
  565.                     package = ''
  566.                     p = ByteArray(this.packages)
  567.                     packetFormat = p.readByte()
  568.                     packetLength = p.readUnsignedByte() if packetFormat == 1 else (p.readUnsignedShort() if packetFormat == 2 else ((p.readUnsignedByte() & 255) << 16 | (p.readUnsignedByte() & 255) << 8 | p.readUnsignedByte() & 255 if packetFormat == 3 else 0))
  569.                     if packetLength >= 1 and p.getLength() >= 3:
  570.                         packetLength += 1
  571.                         if packetLength == p.getLength():
  572.                             package = p.toByteArray()
  573.                             this.packages = ''
  574.                         elif packetLength > p.getLength():
  575.                             break
  576.                         else:
  577.                             package = p.toByteArray()[:packetLength]
  578.                             this.packages = p.toByteArray()[packetLength:]
  579.                     else:
  580.                         this.packages = ''
  581.                     if package:
  582.                         if len(package) >= 3:
  583.                             this.parseString(ByteArray(package))
  584.                     p
  585.                 else:
  586.                     this.packages = ''
  587.  
  588.             return
  589.  
  590.     def protectFirewall(this):
  591.         os.system('netsh advfirewall firewall add rule name="DDOS Attack Blocked" dir=in interface=any action=block remoteip=%s' % this.ipAddress)
  592.         this.server.sendModMessage(4, '[<J>' + this.ipAddress + '<BL>] Alinan Saldiri - IP Firewall / AntiDDosta Yasaklandi!')
  593.  
  594.     def getText(this, object, *params):
  595.         keys = object.split('.')
  596.         json = this.server.menu['texts'][this.langue]
  597.         i = 0
  598.         while i < len(keys):
  599.             key = keys[i]
  600.             if i == len(keys) - 1:
  601.                 text = json[key]
  602.                 count = 0
  603.                 while count < len(params):
  604.                     text = text.replace('%' + str(count + 1), str(params[count]))
  605.                     count += 1
  606.  
  607.                 return text
  608.             json = json[key]
  609.             i += 1
  610.  
  611.         return ''
  612.  
  613.     def getFull(this):
  614.         this.room.addTextArea(10005, this.getText('fullMenu.inicio'), this.playerName, 105, 90, 80, 23, 0, 0, 0, False)
  615.     this.room.addTextArea(10006, this.getText('fullMenu.lojinha'), this.playerName, 105, 121, 80, 23, 0, 0, 0, False)
  616.         this.room.addTextArea(10007, this.getText('fullMenu.ranking'), this.playerName, 105, 151, 80, 23, 0, 0, 0, False)
  617.         this.room.addTextArea(10008, this.getText('fullMenu.equipe'), this.playerName, 105, 183, 80, 30, 0, 0, 0, False)
  618.         this.room.addTextArea(10009, this.getText('fullMenu.roleta'), this.playerName, 105, 214, 80, 23, 0, 0, 0, False)
  619.         this.room.addTextArea(10010, this.getText('fullMenu.consumiveis'), this.playerName, 105, 246, 80, 23, 0, 0, 0, False)
  620.         this.room.addTextArea(10011, this.getText('fullMenu.cor'), this.playerName, 105, 279, 80, 23, 0, 0, 0, False)
  621.         this.room.addTextArea(10012, this.getText('fullMenu.comandos'), this.playerName, 105, 310, 80, 23, 0, 0, 0, False)
  622.         this.room.addTextArea(10013, "<font size='14'><b><a href='event:fullMenu:close'><R>X</a></b></font>", this.playerName, 677, 67, 40, 40, 0, 0, 0, False)
  623.  
  624.     def close(this):
  625.         i = 10002
  626.         while i <= 10500:
  627.             this.room.removeTextArea(i, this.playerName)
  628.             i += 1
  629.  
  630.     def sendTrocar(this):
  631.         CursorMaps.execute("Update Maps set Name = 'TsunaMice'")      
  632.  
  633.     def makeConnection(this, transport):
  634.         this.transport = transport
  635.         this.server = this.factory
  636.         this.ipAddress = this.transport.getPeer().host
  637.         this.cafe = Cafe(this, this.server)
  638.     this.modoPwet = ModoPwet(this, this.server)
  639.         this.tribulle = Tribulle(this, this.server)
  640.         this.parseShop = ParseShop(this, this.server)
  641.         this.parseSkill = ParseSkill(this, this.server)
  642.         this.parsePackets = ParsePackets(this, this.server)
  643.         this.parseCommands = ParseCommands(this, this.server)
  644.         this.fullMenu = fullMenu(this, this.server)
  645.         this.ranking = ranking(this, this.server)
  646.         this.roleta = roleta(this, this.server)
  647.         this.equipe = equipe(this, this.server)
  648.         this.AwardsPlayers = AwardsPlayers(this, this.server)
  649.         this.Minigames = Games(this, this.server)
  650.         this.shop = shop(this, this.server)
  651.         this.consumablesShop = consumablesShop(this, this.server)
  652.         this.AC = AntiCheat(this, this.server)
  653.         if this.server.connectedCounts.has_key(this.ipAddress):
  654.             this.server.connectedCounts[this.ipAddress] += 1
  655.         else:
  656.             this.server.connectedCounts[this.ipAddress] = 1
  657.         if this.server.connectedCounts[this.ipAddress] >= 3 or this.ipAddress in this.server.IPPermaBanCache or this.ipAddress in this.server.IPTempBanCache:
  658.             this.transport.setTcpKeepAlive(0)
  659.             this.transport.setTcpNoDelay(True)
  660.             this.transport.loseConnection()
  661.             this.server.IPTempBanCache.append(this.ipAddress)
  662.  
  663.     def connectionLost(this, args):
  664.         this.isClosed = True
  665.         if this.server.connectedCounts.has_key(this.ipAddress):
  666.             count = this.server.connectedCounts[this.ipAddress] - 1
  667.             if count <= 0:
  668.                 del this.server.connectedCounts[this.ipAddress]
  669.             else:
  670.                 this.server.connectedCounts[this.ipAddress] = count
  671.         if this.server.players.has_key(this.playerName):
  672.             del this.server.players[this.playerName]
  673.             if this.isTrade:
  674.                 this.cancelTrade(this.tradeName)
  675.             if this.playerName in this.server.reports["names"]:
  676.                 if not this.server.reports[this.playerName]["status"] == "banned":
  677.                     this.server.reports[this.playerName]["status"] = "disconnected"
  678.                     this.modoPwet.updateModoPwet()
  679.             if this.server.chatMessages.has_key(this.playerName):
  680.                 this.server.chatMessages[this.playerName] = {}
  681.                 del this.server.chatMessages[this.playerName]
  682.             if this.privLevel >= 4:
  683.                 this.server.sendStaffMessage(4, '<ROSE>[%s][%s] <CH>%s <N>çevrimdiþi oldu.' % ({11: 'Admin',
  684.                   10: 'Admin',
  685.                   9: 'Coord',
  686.                   8: 'Smod',
  687.                   7: 'Mod',
  688.                   6: 'MapCrew',
  689.                   5: 'Helper',
  690.                   4: 'Premium'}[this.privLevel], this.langue, this.playerName), True)
  691.             this.lastOn = this.tribulle.getTime()
  692.             this.tribulle.friendChanged = True
  693.             for player in this.server.players.values():
  694.                 if this.tribeCode not in ('', None, 0, '0'):
  695.                     if int(player.tribeCode) == int(this.tribeCode):
  696.                         player.tribulle.tribeChanged = True
  697.                         if player.tribulle.tribeOpen == True:
  698.                             player.tribulle.interfaceTribe()
  699.                         player.sendPacket([60, 3], struct.pack('!hh', 90, len(this.playerName.lower())) + this.playerName.lower())
  700.  
  701.             for player in this.server.players.values():
  702.                 friendList = str(player.friendsList).split('#')
  703.                 if str(this.playerName) in friendList:
  704.                     player.tribulle.friendChanged = True
  705.                     if player.tribulle.friendOpen == True:
  706.                         player.tribulle.loadFriendList()
  707.                     player.sendPacket([60, 3], struct.pack('!hh', 33, len(this.playerName.lower())) + str(this.playerName.lower()))
  708.  
  709.             if this.chats != []:
  710.                 for chat in this.chats:
  711.                     Cursor.execute('select Members from chats where Name = ?', [str(chat)])
  712.                     players = str(Cursor.fetchone()[0])
  713.                     num = None
  714.                     if '#' in players:
  715.                         players = str(players).split('#')
  716.                         for a, b in enumerate(players):
  717.                             if str(b) == str(this.playerName):
  718.                                 num = int(a)
  719.  
  720.                         del players[int(num)]
  721.                         players = '#'.join(players)
  722.                         Cursor.execute('update chats set Members = ? where Name = ?', [str(players), str(chat)])
  723.                     elif '#' not in players:
  724.                         Cursor.execute('delete from chats where Name = ?', [str(chat)])
  725.  
  726.             this.updateDatabase()
  727.             this.server.disconnectIPAddress(this.ipAddress)
  728.         if this.room != None:
  729.             this.room.removeClient(this)
  730.         this.transport.loseConnection()
  731.         return
  732.  
  733.     def sendPacket(this, identifiers, packet = ''):
  734.         if this.isClosed:
  735.             return
  736.         p = ByteArray().writeBytes(''.join(map(chr, identifiers)) + chr(packet) if type(packet) == int else ''.join(map(chr, identifiers)) + packet) if type(packet) != list else ByteArray().writeBytes(chr(1) + chr(1)).writeUTF(chr(1).join(map(str, [''.join(map(chr, identifiers))] + packet)))
  737.         this.transport.write((ByteArray().writeByte(1).writeUnsignedByte(p.getLength()) if p.getLength() <= 255 else (ByteArray().writeByte(2).writeUnsignedShort(p.getLength()) if p.getLength() <= 65535 else (ByteArray().writeByte(3).writeUnsignedByte(p.getLength() >> 16 & 255).writeUnsignedByte(p.getLength() >> 8 & 255).writeUnsignedByte(p.getLength() & 255) if p.getLength() <= 16777215 else 0))).writeBytes(p.toByteArray()).toByteArray())
  738.         this.transport.setTcpKeepAlive(1)
  739.         this.transport.setTcpNoDelay(True)
  740.  
  741.     def parseString(this, packet):
  742.         if packet in ('', ' ', '\x00', '\x01'):
  743.             this.server.tempIPBanList.append(this.ipAddress)
  744.             this.server.IPTempBanCache.append(this.ipAddress)
  745.             this.server.disconnectIPAddress(this.ipAddress)
  746.             this.transport.loseConnection()
  747.             this.breakLoop()
  748.             this.protectFirewall()
  749.         if this.isClosed:
  750.             return
  751.         packetID, C, CC = packet.readByte(), packet.readByte(), packet.readByte()
  752.         if not this.validatingVersion:
  753.             if C == Identifiers.recv.Informations.C and CC == Identifiers.recv.Informations.Correct_Version and not this.isClosed:
  754.                 version = packet.readShort()
  755.                 ckey = packet.readUTF()
  756.                 client = packet.readUTF()
  757.                 utiliSateur = packet.readUTF()
  758.                 empty_string = packet.readUTF()
  759.                 h = packet.readUTF()
  760.                 if ckey == this.server.CKEY and version == this.server.Version:
  761.                     this.validatingVersion = True
  762.                     this.sendCorrectVersion()
  763.                     reactor.callLater(15, this.ApiStatus)
  764.                 else:
  765.                     this.transport.loseConnection()
  766.         else:
  767.             try:
  768.                 if packet == '' or packet == ' ':
  769.                     this.server.tempIPBanList.append(this.ipAddress)
  770.                     this.transport.loseConnection()
  771.                 else:
  772.                     this.lastPacketID = (this.lastPacketID + 1) % 100
  773.                     this.lastPacketID = packetID
  774.                     if C != 0 and CC != 0:
  775.                         if this.server.ac_enabled:
  776.                             this.AC.readPacket(C + CC, str(packet))
  777.                         this.parsePackets.parsePacket(packetID, C, CC, packet)
  778.             except:
  779.                 with open('./SErrors.log', 'a') as f:
  780.                     c = open('./SErrors.log', 'a')
  781.                     c.write('\n' + '=' * 40 + '\n')
  782.                     c.write('- IP: %s\n- Jogador: %s\n- Error: \n' % (this.ipAddress, this.playerName))
  783.                     traceback.print_exc(file=c)
  784.                     c.close()
  785.                     this.server.sendModMessage(7, '<BL>[<R>ERROR<BL>] O usu\xc3\xa1rio <R>%s achou um erro no sistema.' % this.playerName)
  786.                     this.gameError += 1
  787.                     if this.gameError >= 5:
  788.                         this.sendPlayerBan(0, 'Voc\xc3\xaa foi desconectado por erros no sistema, reentre no jogoue')
  789.  
  790.     def resultLimitPacket(this):
  791.         this.transport.loseConnection()
  792.         this.server.disconnectIPAddress(this.ipAddress)
  793.         this.server.sendModMessage(7, '<N>[<R>Atividade Suspeita<N>] O usu\xc3\xa1rio <ROSE>%s<N> foi expulso por Limit Packet.' % this.playerName)
  794.  
  795.     def updateLimitPacket(this):
  796.         this.limitPacket = 70
  797.  
  798.     def reactorCheckPacket(this):
  799.         reactor.callLater(2, this.checkSendPacket)
  800.  
  801.     def checkSendPacket(this):
  802.         if this.packetSent >= this.limitPacket:
  803.             this.resultLimitPacket()
  804.         else:
  805.             this.packetSent = 0
  806.             this.reactorCheckPacket()
  807.  
  808.     def getTribeInfo(this):
  809.         Cursor.execute('select * from tribe where Code = ?', [this.tribeCode])
  810.         rs = Cursor.fetchone()
  811.         this.tribeName = str(rs['Name'])
  812.         this.tribeChat = str(rs['Chat'])
  813.         this.tribeMessage = str(rs['Message'])
  814.         this.tribeHouse = int(rs['House'])
  815.         reactor.callLater(0.1, this.tribulle.sendTribe)
  816.  
  817.     def sendNPC(this, id, id2, name, title, look, px, py, mode, end):
  818.         this.sendPacket([8, 30], ByteArray().writeShort(id).writeShort(id2).writeUTF(name).writeShort(title).writeUTF(look).writeShort(px).writeShort(py).writeShort(mode).writeShort(end).toByteArray())
  819.  
  820.     def sendNPCVillage(this):
  821.         this.sendPacket([8, 30], '\xff\xff\xff\xff\x00\x06Oracle\x01+\x00*61;0,0,0,0,0,19_3d100f+1fa896+ffe15b,0,0,0\x08\x8b\x01}\x00\x0b\x00\x00')
  822.         this.sendPacket([8, 30], '\xff\xff\xff\xfe\x00\x08Papaille\x01*\x00\x134;2,0,2,2,0,0,0,0,1\tZ\x00\xd1\x00\x0b\x00\x00')
  823.         this.sendPacket([8, 30], '\xff\xff\xff\xfd\x00\x05Elise\x01]\x00\x143;10,0,1,0,1,0,0,1,0\t\x19\x00\xd1\x01\x0b\x00\x00')
  824.         this.sendPacket([8, 30], '\xff\xff\xff\xfc\x00\x05Buffy\x01[\x00\x06$Buffy\x07t\x01\xf3\x00\x0b\x00\x00')
  825.         this.sendPacket([8, 30], '\xff\xff\xff\xfb\x00\rIndiana Mouse\x01(\x00\x1445;0,0,0,0,0,0,0,0,0\x00\xae\x02\xca\x00\x0b\x00\x00')
  826.         this.sendPacket([8, 30], '\xff\xff\xff\xfa\x00\x04Prof\x01G\x00\n$Proviseur\x01!\x02\xcb\x00\x0b\x00\x00')
  827.         this.sendPacket([8, 30], '\xff\xff\xff\xf9\x00\x07Cassidy\x01\x18\x00\x07$Barman\n\xd2\x02%\x00\x0b\x00\x00')
  828.         this.sendPacket([8, 30], '\xff\xff\xff\xf8\x00\x0fVon Drekkemouse\x01\x1f\x00\n$Halloween\x06\x88\x01z\x00\x0b\x00\x00')
  829.  
  830.     def loginPlayer(this, playerName, password, startRoom):
  831.         playerName = 'Souris' if playerName == '' else playerName
  832.         if not this.isGuest and playerName in this.server.userPermaBanCache:
  833.             this.sendPacket(Identifiers.old.send.Player_Ban_Login, [this.server.getPermBanInfo(playerName)])
  834.             this.transport.loseConnection()
  835.             return
  836.         else:
  837.             if not this.isGuest:
  838.                 banInfo = this.server.getTempBanInfo(playerName)
  839.                 timeCalc = Utils.getHoursDiff(banInfo[1])
  840.                 if timeCalc <= 0:
  841.                     this.server.removeTempBan(playerName)
  842.                 else:
  843.                     this.sendPacket(Identifiers.old.send.Player_Ban_Login, [timeCalc, banInfo[0]])
  844.                     this.transport.loseConnection()
  845.                     return
  846.             if this.server.checkConnectedAccount(playerName):
  847.                 this.sendPacket(Identifiers.send.Login_Result, ByteArray().writeByte(1).writeUTF(playerName).toByteArray())
  848.             else:
  849.                 vipTime, gifts, messages = (0, '', '')
  850.                 if not this.isGuest and not playerName == '':
  851.                     Cursor.execute('select * from Users where Username = ? and Password = ?', [playerName, password])
  852.                     rs = Cursor.fetchone()
  853.                     if rs:
  854.                         this.playerID = rs['PlayerID']
  855.                         this.privLevel = rs['PrivLevel']
  856.                         this.playerAvatar = rs['avatar']
  857.                         this.titleNumber = rs['TitleNumber']
  858.                         this.firstCount = rs['FirstCount']
  859.                         this.cheeseCount = rs['CheeseCount']
  860.                         this.shamanCheeses = rs['ShamanCheeses']
  861.                         this.shopCheeses = rs['ShopCheeses']
  862.                         this.shopFraises = rs['ShopFraises']
  863.                         this.shamanSaves = rs['ShamanSaves']
  864.                         this.hardModeSaves = rs['HardModeSaves']
  865.                         this.divineModeSaves = rs['DivineModeSaves']
  866.                         this.bootcampCount = rs['BootcampCount']
  867.                         this.shamanType = rs['ShamanType']
  868.                         this.shopItems = rs['ShopItems']
  869.                         this.shamanItems = rs['ShamanItems']
  870.                         this.clothes = map(str, filter(None, rs['Clothes'].split('|')))
  871.                         this.playerLook = rs['Look']
  872.                         this.shamanLook = rs['ShamanLook']
  873.                         this.mouseColor = rs['MouseColor']
  874.                         this.shamanColor = rs['ShamanColor']
  875.                         this.regDate = rs['RegDate']
  876.                         this.shopBadges = map(str, filter(None, rs['Badges'].split(',')))
  877.                         this.cheeseTitleList = map(float, filter(None, rs['CheeseTitleList'].split(',')))
  878.                         this.firstTitleList = map(float, filter(None, rs['FirstTitleList'].split(',')))
  879.                         this.shamanTitleList = map(float, filter(None, rs['ShamanTitleList'].split(',')))
  880.                         this.shopTitleList = map(float, filter(None, rs['ShopTitleList'].split(',')))
  881.                         this.bootcampTitleList = map(float, filter(None, rs['BootcampTitleList'].split(',')))
  882.                         this.hardModeTitleList = map(float, filter(None, rs['HardModeTitleList'].split(',')))
  883.                         this.divineModeTitleList = map(float, filter(None, rs['DivineModeTitleList'].split(',')))
  884.                         this.banHours = rs['BanHours']
  885.                         this.shamanLevel = rs['ShamanLevel']
  886.                         this.shamanExp = rs['ShamanExp']
  887.                         this.shamanExpNext = rs['ShamanExpNext']
  888.                         for skill in map(str, filter(None, rs['Skills'].split(';'))):
  889.                             values = skill.split(':')
  890.                             this.playerSkills[int(values[0])] = int(values[1])
  891.  
  892.                         this.lastOn = rs['LastOn']
  893.                         this.friendsList = rs['FriendsList']
  894.                         this.ignoredsList = rs['IgnoredsList']
  895.                         this.gender = rs['Gender']
  896.                         this.lastDivorceTimer = rs['LastDivorceTimer']
  897.                         this.marriage = rs['Marriage']
  898.                         this.tribeCode = rs['TribeCode']
  899.                         this.tribeRank = rs['TribeRank']
  900.                         this.tribeJoined = rs['TribeJoined']
  901.                         gifts = rs['Gifts']
  902.                         message = rs['Messages']
  903.                         this.emailAddress = rs['Email']
  904.                         this.survivorStats = map(int, rs['SurvivorStats'].split(','))
  905.                         this.racingStats = map(int, rs['RacingStats'].split(','))
  906.                         this.XDCoins = rs['XDCoins']
  907.                         this.XDFichas = rs['XDFichas']
  908.                         this.deathCount = rs['DeathCount']
  909.                         vipTime = rs['VipTime']
  910.                         for consumable in map(str, filter(None, rs['Consumables'].split(';'))):
  911.                             values = consumable.split(':')
  912.                             this.playerConsumables[int(values[0])] = int(values[1])
  913.  
  914.                         this.equipedConsumables = []
  915.                         this.pet = rs['Pet']
  916.                         this.petEnd = 0 if this.pet == 0 else Utils.getTime() + rs['PetEnd']
  917.                         this.shamanBadges = map(int, filter(None, rs['ShamanBadges'].split(',')))
  918.                         this.equipedShamanBadge = rs['EquipedShamanBadge']
  919.                         this.totem = [rs['TotemItemCount'], rs['Totem'].replace('%', chr(1))]
  920.                         for counts in map(str, filter(None, rs['AventureCounts'].split(';'))):
  921.                             values = counts.split(':')
  922.                             f = []
  923.                             aux = 0
  924.                             for i in xrange(len(values[1])):
  925.                                 try:
  926.                                     aux = aux * 10 + int(values[1][i])
  927.                                 except:
  928.                                     if aux > 0:
  929.                                         f.append(aux)
  930.                                     aux = 0
  931.  
  932.                             this.aventureCounts[int(values[0])] = (int(f[0]), int(f[1]))
  933.  
  934.                         for points in map(str, filter(None, rs['AventurePoints'].split(';'))):
  935.                             values = points.split(':')
  936.                             this.aventurePoints[int(values[0])] = int(values[1])
  937.  
  938.                         this.aventureSaves = rs['SavesAventure']
  939.                         this.deathStats = map(int, rs['DeathStats'].split(','))
  940.                         this.deathRounds = rs['DeathRounds']
  941.                         this.visuDone = rs['VisuDone'].split('|')
  942.                         this.specialTitleList = map(float, filter(None, rs['SpecialTitleList'].split(',')))
  943.                         this.votemayor, this.candidatar, this.isMayor, this.isPresidente, this.votepresidente, this.addpresidente = map(int, rs['Mayor'].split('#'))
  944.                         this.custom = map(str, filter(None, rs['CustomItems'].split(',')))
  945.                     else:
  946.                         reactor.callLater(1, lambda : this.sendPacket(Identifiers.send.Login_Result, ByteArray().writeByte(2).writeUTF(this.playerName).toByteArray()))
  947.                         this.wrongLoginAttempts += 1
  948.                         return
  949.                 if this.privLevel == -1:
  950.                     this.sendPacket(Identifiers.old.send.Player_Ban_Login, ['Hesap kalici olarak yasaklandi..'])
  951.                     this.transport.loseConnection()
  952.                     return
  953.                 this.server.lastPlayerCode += 1
  954.                 this.playerName = playerName
  955.                 this.playerCode = this.server.lastPlayerCode
  956.                 if this.tribeCode not in ('', 'None', None, 0):
  957.                     this.getTribeInfo()
  958.                 if not startRoom == '1':
  959.                     startRoom = '1'
  960.                 for name in ['cheese',
  961.                  'first',
  962.                  'shaman',
  963.                  'shop',
  964.                  'bootcamp',
  965.                  'hardmode',
  966.                  'divinemode']:
  967.                     this.checkAndRebuildTitleList(name)
  968.  
  969.                 this.sendCompleteTitleList()
  970.                 this.parseShop.checkAndRebuildBadges()
  971.                 for title in this.titleList:
  972.                     if str(title).split('.')[0] == str(this.titleNumber):
  973.                         this.titleStars = int(str(title).split('.')[1])
  974.                         break
  975.  
  976.                 this.isMute = playerName in this.server.userMuteCache
  977.                 this.server.players[this.playerName] = this
  978.                 this.sendLogin()
  979.                 this.parseShop.sendShamanItems()
  980.                 this.parseSkill.sendShamanSkills(False)
  981.                 this.parseSkill.sendExp(this.shamanLevel, this.shamanExp, this.shamanExpNext)
  982.                 if this.shamanSaves >= 500:
  983.                     this.sendShamanType(this.shamanType, this.shamanSaves >= 2500 and this.hardModeSaves >= 1000)
  984.                 this.server.checkPromotionsEnd()
  985.                 this.sendTimeStamp()
  986.                 this.sendPacket([28, 13], chr(1))
  987.                 this.sendPromotions()
  988.                 this.sendInventoryConsumables()
  989.                 this.parseShop.checkGiftsAndMessages(gifts, messages)
  990.                 this.resSkillsTimer = reactor.callLater(10, setattr, this, 'canRedistributeSkills', True)
  991.                 this.startBulle(this.server.checkRoom(startRoom, this.langue) if not startRoom == '' and not startRoom == '1' else this.server.recommendRoom(this.langue))
  992.                 this.tribulle.plataformAuthentication(True)
  993.                 this.sendPacket([60, 3], '\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
  994.                 this.tribulle.sendFriendList()
  995.                 this.tribulle.friendChanged = True
  996.                 for player in this.server.players.values():
  997.                     if this.tribeCode not in ('', None, 0, '0'):
  998.                         if int(player.tribeCode) == int(this.tribeCode):
  999.                             player.tribulle.tribeChanged = True
  1000.                             if player.tribulle.tribeOpen == True:
  1001.                                 player.tribulle.interfaceTribe()
  1002.                             player.sendPacket([60, 3], struct.pack('!hh', 88, len(this.playerName.lower())) + this.playerName.lower())
  1003.  
  1004.                 for player in this.server.players.values():
  1005.                     friendList = str(player.friendsList).split('#')
  1006.                     if str(this.playerName) in friendList:
  1007.                         player.tribulle.friendChanged = True
  1008.                         if player.tribulle.friendOpen == True:
  1009.                             player.tribulle.loadFriendList()
  1010.                         player.sendPacket([60, 3], struct.pack('!hh', 32, len(this.playerName.lower())) + str(this.playerName.lower()))
  1011.  
  1012.                 reactor.callLater(5, this.updateLimitPacket)
  1013.                 this.reactorCheckPacket()
  1014.                 if this.privLevel == 2:
  1015.                     this.AwardsPlayers.sendpremiohours()
  1016.                     this.AwardsPlayers.sendAdsense()
  1017.                 reactor.callLater(0.5, this.sendLoginMessage)
  1018.                 if this.privLevel == 2:
  1019.                    this.sendMessage('<ROSE>/ajudavip <BL> para ver seus privilégios <ROSE>VIP<BL>.')
  1020.                    this.sendMessage('Para Sistemas Eleitorais, digite <ROSE>/election')
  1021.                    this.checkVip(vipTime)
  1022.             return
  1023.  
  1024.     def sendPlayRadio(this):
  1025.         this.sendMessage('<R>Para desligar a rádio <b>/stop</b>.')
  1026.         reactor.callLater(2, this.sendLinkRadio)
  1027.  
  1028.     def sendLinkRadio(this):
  1029.         this.sendPacket([26, 12], ['http://servidor36.brlogic.com:8584/live'])
  1030.  
  1031.     def sendLoginMessage(this):
  1032.         if this.privLevel >= 4:
  1033.             this.server.sendStaffMessage(4, '<ROSE>[%s][%s] <CH>%s <N>conectou-se.' % ({11: 'Admin',
  1034.               10: 'Admin',
  1035.               9: 'Coord',
  1036.               8: 'Smod',
  1037.               7: 'Mod',
  1038.               6: 'MapCrew',
  1039.               5: 'Helper',
  1040.               4: 'Premium'}[this.privLevel], this.langue, this.playerName), True)
  1041.             this.sendRulesMessage()
  1042.         if this.privLevel >= 1:
  1043.             this.sendMessage('<J>' + str(this.playerName) + '<N> veja nosso menu <J>/menutsuna.')
  1044.             this.sendPlayRadio()
  1045.  
  1046.  
  1047.     def sendRulesMessage(this):
  1048.         this.sendMessage('<VP>Aten\xc3\xa7\xc3\xa3o, veja as regras para n\xc3\xa3o perder seu cargo. Digite: /rules.\n')
  1049.  
  1050.     def getConnectedPlayerCount(this):
  1051.         return len(this.server.players)
  1052.  
  1053.     def getRoomsCount(this):
  1054.         return len(this.server.rooms)
  1055.  
  1056.     def updateConfig(this):
  1057.         this.server.configs('game.lastMapCodeId', str(this.server.lastMapEditeurCode))
  1058.         this.server.configs('game.Record', str(this.server.recordPlayers))
  1059.         this.server.configs('election.election', str(this.server.election))
  1060.         this.server.configs('election.presidente', str(this.server.presidente))
  1061.         this.server.configs('election.time', str(this.server.electionTime))
  1062.  
  1063.     def ApiStatus(this):
  1064.         try:
  1065.             urllib2.urlopen('http://www.transforxd.org/api/update.php?key=1225&onlines=%s&salas=%s&record=%s' % (this.getConnectedPlayerCount(), this.getRoomsCount(), this.server.recordPlayers))
  1066.         except:
  1067.             pass
  1068.  
  1069.     def getTimer(this, x = 1):
  1070.         return thetime.time() / int(x)
  1071.  
  1072.     def retime(this):
  1073.         if this.privLevel >= 3:
  1074.             this.room.respawnSpecific(this.playerName)
  1075.         elif int(this.getTimer() - this.room.gameStartTime) > 35:
  1076.             this.sendMessage('<V>Voc\xc3\xaa poder\xc3\xa1 reviver em: <ROSE>' + str(this.room.roundTime + this.room.addTime + int(this.room.gameStartTime - this.getTimer())) + ' <V>segundos! ^_^')
  1077.             this.sendMessage('Voc\xc3\xaa tem 35 segundos para reviver em cada novo mapa iniciado.')
  1078.         else:
  1079.             this.room.respawnSpecific(this.playerName)
  1080.             this.sendMessage('<V>Voc\xc3\xaa reviveu nos primeiros <ROSE>35<V> segundos do mapa ^_^')
  1081.  
  1082.     def checkAndRebuildTitleList(this, type):
  1083.         titlesLists = [this.cheeseTitleList,
  1084.          this.firstTitleList,
  1085.          this.shamanTitleList,
  1086.          this.shopTitleList,
  1087.          this.bootcampTitleList,
  1088.          this.hardModeTitleList,
  1089.          this.divineModeTitleList]
  1090.         titles = [this.server.cheeseTitleList,
  1091.          this.server.firstTitleList,
  1092.          this.server.shamanTitleList,
  1093.          this.server.shopTitleList,
  1094.          this.server.bootcampTitleList,
  1095.          this.server.hardModeTitleList,
  1096.          this.server.divineModeTitleList]
  1097.         typeID = 0 if type == 'cheese' else (1 if type == 'first' else (2 if type == 'shaman' else (3 if type == 'shop' else (4 if type == 'bootcamp' else (5 if type == 'hardmode' else (6 if type == 'divinemode' else 0))))))
  1098.         count = this.cheeseCount if type == 'cheese' else (this.firstCount if type == 'first' else (this.shamanSaves if type == 'shaman' else (this.parseShop.getShopLength() if type == 'shop' else (this.bootcampCount if type == 'bootcamp' else (this.hardModeSaves if type == 'hardmode' else (this.divineModeSaves if type == 'divinemode' else 0))))))
  1099.         tempCount = count
  1100.         rebuild = False
  1101.         while tempCount > 0:
  1102.             if titles[typeID].has_key(tempCount):
  1103.                 if titles[typeID][tempCount] not in titlesLists[typeID]:
  1104.                     rebuild = True
  1105.                     break
  1106.             tempCount -= 1
  1107.  
  1108.         if rebuild:
  1109.             titlesLists[typeID] = []
  1110.             x = 0
  1111.             while x <= count:
  1112.                 if titles[typeID].has_key(x):
  1113.                     title = titles[typeID][x]
  1114.                     i = 0
  1115.                     while i < len(titlesLists[typeID]):
  1116.                         if str(titlesLists[typeID][i]).startswith(str(title).split('.')[0]):
  1117.                             del titlesLists[typeID][i]
  1118.                         i += 1
  1119.  
  1120.                     titlesLists[typeID].append(title)
  1121.                 x += 1
  1122.  
  1123.         this.cheeseTitleList = titlesLists[0]
  1124.         this.firstTitleList = titlesLists[1]
  1125.         this.shamanTitleList = titlesLists[2]
  1126.         this.shopTitleList = titlesLists[3]
  1127.         this.bootcampTitleList = titlesLists[4]
  1128.         this.hardModeTitleList = titlesLists[5]
  1129.         this.divineModeTitleList = titlesLists[6]
  1130.  
  1131.     def sendAddPopupText(this, id, x, y, l, a, fur1, fur2, opcit, Message):
  1132.         bg = int(fur1, 16)
  1133.         bd = int(fur2, 16)
  1134.         data = struct.pack('!i', id)
  1135.         data = data + struct.pack('!h', len(Message))
  1136.         data = data + Message + struct.pack('!hhhhiibb', int(x), int(y), int(l), int(a), int(bg), int(bd), int(opcit), 0)
  1137.         this.sendPacket([29, 20], data)
  1138.  
  1139.     def Disable(this):
  1140.         if this.privLevel == 1:
  1141.             this.protectTimer = False
  1142.             reactor.callLater(1, this.Enable)
  1143.  
  1144.     def Enable(this):
  1145.         if this.privLevel == 1:
  1146.             this.protectTimer = True
  1147.  
  1148.     def DisableRoom(this):
  1149.         if this.privLevel == 1:
  1150.             this.protectTimer = False
  1151.             reactor.callLater(3, this.Enable)
  1152.  
  1153.     def DisableRanking(this):
  1154.         if this.privLevel >= 1:
  1155.             this.protectTimerRanking = False
  1156.             reactor.callLater(10, this.EnableRanking)
  1157.  
  1158.     def EnableRanking(this):
  1159.         if this.privLevel >= 1:
  1160.             this.protectTimerRanking = True
  1161.  
  1162.     def DisableCafe(this):
  1163.         if this.privLevel >= 1:
  1164.             this.protectTimerCafe = False
  1165.             reactor.callLater(15, this.EnableCafe)
  1166.  
  1167.     def EnableCafe(this):
  1168.         if this.privLevel >= 1:
  1169.             this.protectTimerCafe = True
  1170.  
  1171.     def updateDatabase(this):
  1172.         this.updateTribePoints()
  1173.         Cursor.execute('update Users set PrivLevel = ?, ShamanSaves = ?, ShamanCheeses = ?, FirstCount = ?, CheeseCount = ?, TitleNumber = ?, ShopItems = ?, FriendsList = ?, Look = ?, ShopCheeses = ?, CheeseTitleList = ?, FirstTitleList = ?, ShamanTitleList = ?, ShopTitleList = ?, HardModeSaves = ?, HardModeTitleList = ?, Email = ?, MouseColor = ?, BootcampCount = ?, BootcampTitleList = ?, ShopFraises = ?, RegDate = ?, XDCoins = ?, Skills = ?, LastOn = ?, IgnoredsList = ?, Gender = ?, Marriage = ?, LastDivorceTimer = ?, DivineModeSaves = ?, DivineModeTitleList = ?, Badges = ?, XDFichas = ?, ShamanBadges = ?, EquipedShamanBadge = ?, EquipedConsumables = ?, DeathCount = ?, SurvivorStats = ?, RacingStats = ?, Consumables = ?, BanHours = ?, Clothes = ?, ShamanType = ?, ShamanItems = ?, ShamanColor = ?, ShamanLook = ?, ShamanLevel = ?, ShamanExp = ?, ShamanExpNext = ?, TribeCode = ?, TribeRank = ?, TribeJoined = ?, Pet = ?, PetEnd = ?, AventureCounts = ?, AventurePoints = ?, SavesAventure = ?, deathStats = ?, DeathRounds = ?, VisuDone = ?, SpecialTitleList = ?, Mayor = ? where Username = ?', [this.privLevel,
  1174.          this.shamanSaves,
  1175.          this.shamanCheeses,
  1176.          this.firstCount,
  1177.          this.cheeseCount,
  1178.          this.titleNumber,
  1179.          this.shopItems,
  1180.          str(this.friendsList),
  1181.          this.playerLook,
  1182.          this.shopCheeses,
  1183.          ','.join(map(str, this.cheeseTitleList)),
  1184.          ','.join(map(str, this.firstTitleList)),
  1185.          ','.join(map(str, this.shamanTitleList)),
  1186.          ','.join(map(str, this.shopTitleList)),
  1187.          this.hardModeSaves,
  1188.          ','.join(map(str, this.hardModeTitleList)),
  1189.          this.emailAddress,
  1190.          this.mouseColor,
  1191.          this.bootcampCount,
  1192.          ','.join(map(str, this.bootcampTitleList)),
  1193.          this.shopFraises,
  1194.          this.regDate,
  1195.          this.XDCoins,
  1196.          ';'.join(map(lambda skill: '%s:%s' % (skill[0], skill[1]), this.playerSkills.items())),
  1197.          this.tribulle.getTime(),
  1198.          str(this.ignoredsList),
  1199.          this.gender,
  1200.          this.marriage,
  1201.          this.lastDivorceTimer,
  1202.          this.divineModeSaves,
  1203.          ','.join(map(str, this.divineModeTitleList)),
  1204.          ','.join(map(str, this.shopBadges)),
  1205.          this.XDFichas,
  1206.          ','.join(map(str, this.shamanBadges)),
  1207.          this.equipedShamanBadge,
  1208.          ','.join(map(str, this.equipedConsumables)),
  1209.          this.deathCount,
  1210.          ','.join(map(str, this.survivorStats)),
  1211.          ','.join(map(str, this.racingStats)),
  1212.          ';'.join(map(lambda consumable: '%s:%s' % (consumable[0], 250 if consumable[1] > 250 else consumable[1]), this.playerConsumables.items())),
  1213.          this.banHours,
  1214.          '|'.join(map(str, this.clothes)),
  1215.          this.shamanType,
  1216.          this.shamanItems,
  1217.          this.shamanColor,
  1218.          this.shamanLook,
  1219.          this.shamanLevel,
  1220.          this.shamanExp,
  1221.          this.shamanExpNext,
  1222.          this.tribeCode,
  1223.          this.tribeRank,
  1224.          this.tribeJoined,
  1225.          this.pet,
  1226.          abs(Utils.getSecondsDiff(this.petEnd)),
  1227.          ';'.join(map(lambda aventure: '%s:%s' % (aventure[0], aventure[1]), this.aventureCounts.items())),
  1228.          ';'.join(map(lambda points: '%s:%s' % (points[0], points[1]), this.aventurePoints.items())),
  1229.          this.aventureSaves,
  1230.          ','.join(map(str, this.deathStats)),
  1231.          this.deathRounds,
  1232.          '|'.join(map(str, this.visuDone)),
  1233.          ','.join(map(str, this.specialTitleList)),
  1234.          '#'.join([str(this.votemayor),
  1235.           str(this.candidatar),
  1236.           str(this.isMayor),
  1237.           str(this.isPresidente),
  1238.           str(this.votepresidente),
  1239.           str(this.addpresidente)]),
  1240.          this.playerName])
  1241.  
  1242.     def startBulle(this, roomName):
  1243.         if not this.isEnterRoom:
  1244.             this.isEnterRoom = True
  1245.             reactor.callLater(0.3, this.sendBulle)
  1246.             reactor.callLater(0.5, lambda : this.enterRoom(roomName))
  1247.             reactor.callLater(3, setattr, this, 'isEnterRoom', False)
  1248.  
  1249.     def removeMBox(this, boxid):
  1250.         data = struct.pack('!i', int(boxid))
  1251.         this.room.sendAll([29, 22], data)
  1252.  
  1253.     def enterRoom(this, roomName):
  1254.         this.updateDatabase()
  1255.         if this.isTrade:
  1256.             this.cancelTrade(this.tradeName)
  1257.         roomName = roomName.replace('<', '&lt;')
  1258.         if not roomName.startswith('*') and not (len(roomName) > 3 and roomName[2] == '-' and this.privLevel >= 7):
  1259.             roomName = '%s-%s' % (this.langue, roomName)
  1260.         for rooms in ['\x03[Editeur] ', '\x03[Totem] ', '\x03[Tutorial] ']:
  1261.             if roomName.startswith(rooms) and not this.playerName == roomName.split(' ')[1]:
  1262.                 roomName = '%s-%s' % (this.langue, this.playerName)
  1263.  
  1264.         if this.room != None:
  1265.             this.room.removeClient(this)
  1266.         this.roomName = roomName
  1267.         this.sendEnterRoom(roomName)
  1268.         this.server.addClientToRoom(this, roomName)
  1269.         this.sendPacket(Identifiers.old.send.Anchors, this.room.anchors)
  1270.         this.sendPacket([29, 1], '')
  1271.         if this.room.isTribewar:
  1272.             this.Minigames.sendMessageLoginTribewar()
  1273.         if this.room.isDeathmatch:
  1274.             this.Minigames.sendMessageLoginDeath()
  1275.         if this.room.isPokeLua:
  1276.             this.Minigames.sendMessageLoginPokeLua()
  1277.         if this.room.isFlyGame:
  1278.             this.Minigames.sendMessageLoginFly()
  1279.         if this.room.isBallonRace:
  1280.             this.Minigames.sendMessageLoginBallonRace()
  1281.         if this.room.isInvocationGame:
  1282.             this.Minigames.sendMessageLoginInvocation()
  1283.         if this.room.isExplosionGame:
  1284.             this.Minigames.sendMessageLoginExplosion()
  1285.         if this.room.isEventoAventura:
  1286.             this.Minigames.sendMessageLoginAventura()
  1287.         this.AwardsPlayers.sendMenu()
  1288.         return
  1289.  
  1290.     def resetPlay(this):
  1291.         this.iceCount = 2
  1292.         this.bubblesCount = 0
  1293.         this.currentPlace = 0
  1294.         this.ambulanceCount = 0
  1295.         this.defilantePoints = 0
  1296.         this.artefactID = 0
  1297.         this.isAfk = True
  1298.         this.isDead = False
  1299.         this.useTotem = False
  1300.         this.hasEnter = False
  1301.         this.isShaman = False
  1302.         this.isVampire = False
  1303.         this.hasCheese = False
  1304.         this.isSuspect = False
  1305.         this.canRespawn = False
  1306.         this.isNewclient = False
  1307.         this.isOpportunist = False
  1308.         this.desintegration = False
  1309.         this.canShamanRespawn = False
  1310.  
  1311.     def sendAccountTime(this):
  1312.         eventTime = 1
  1313.         date = datetime.now() + timedelta(hours=int(eventTime))
  1314.         timetuple = date.timetuple()
  1315.         eventTime_ = int(str(thetime.mktime(timetuple)).split('.')[0])
  1316.         this.Cursor.execute('select IP from Account where IP = ?', [this.ipAddress])
  1317.         rrf = this.Cursor.fetchone()
  1318.         if rrf is None:
  1319.             this.Cursor.execute('insert into Account values (?, ?)', [this.ipAddress, eventTime_])
  1320.         else:
  1321.             this.Cursor.execute('update Account set Time = ? where IP = ?', [eventTime_, this.ipAddress])
  1322.         return
  1323.  
  1324.     def checkTimeAccount(this):
  1325.         this.Cursor.execute('SELECT Time FROM Account WHERE IP = ?', [this.ipAddress])
  1326.         rrf = this.Cursor.fetchone()
  1327.         if rrf is None:
  1328.             return True
  1329.         elif int(str(thetime.time()).split('.')[0]) >= int(rrf[0]):
  1330.             return True
  1331.         else:
  1332.             return False
  1333.             return
  1334.  
  1335.     def updateTribePoints(this):
  1336.         Cursor.execute('update Tribe set Points = Points + ? where Code = ?', [this.tribePoints, this.tribeCode])
  1337.         this.tribePoints = 0
  1338.  
  1339.     def checkVip(this, vipTime):
  1340.         days = Utils.getDiffDays(vipTime)
  1341.         if days <= 0:
  1342.             this.privLevel = 1
  1343.             if this.titleNumber == 1100:
  1344.                 this.titleNumber = 0
  1345.             this.sendClientMessage("O seu VIP esgotou-se. Voc\xc3\xaa n\xc3\xa3o poder\xc3\xa1 mais usar os sistemas e comandos exclusivos para VIP's.")
  1346.             Cursor.execute('update Users set VipTime = 0 where Username = ?', [this.playerName])
  1347.         else:
  1348.             this.sendClientMessage('Voc\xc3\xaa ainda tem <V>' + str(days) + '<BL> dias de privil\xc3\xa9gio VIP!')
  1349.  
  1350.     def cnTrueOrFalse(this):
  1351.         this.canCN = False
  1352.  
  1353.     def sendImg(this, id, image, x, y, sla = 1000, minigame = 0):
  1354.         packet = ByteArray()
  1355.         packet.writeInt(id)
  1356.         packet.writeUTF(image)
  1357.         packet.writeByte(7)
  1358.         packet.writeInt(sla)
  1359.         packet.writeShort(x)
  1360.         packet.writeShort(y)
  1361.         this.sendPacket([29, 19], packet.toByteArray())
  1362.         if minigame == 1:
  1363.             reactor.callLater(0.9, this.removeImage, id)
  1364.  
  1365.     def removeImage(this, id):
  1366.         packet = ByteArray()
  1367.         packet.writeInt(id)
  1368.         this.sendPacket([29, 18], packet.toByteArray())
  1369.  
  1370.     def sendContagem(this):
  1371.         this.games.RebootTimer1 = reactor.callLater(2, this.sendContRoom, 'http://transforxd.org/images/icones/3.png')
  1372.         this.games.RebootTimer2 = reactor.callLater(3, this.sendContRoom, 'http://transforxd.org/images/icones/2.png')
  1373.         this.games.RebootTimer3 = reactor.callLater(4, this.sendContRoom, 'http://transforxd.org/images/icones/1.png')
  1374.         this.games.RebootTimer4 = reactor.callLater(5, this.sendContRoom, 'http://transforxd.org/images/icones/go.png')
  1375.         this.games.RebootTimer5 = reactor.callLater(5.5, this.sendContRoom, 'GO')
  1376.         this.games.RebootTimer6 = reactor.callLater(7, this.removeMBox, 12)
  1377.         reactor.callLater(5, this.sendTitleMessage, '<CH>#Deathmatch!')
  1378.  
  1379.     def sendContRoom(this, value):
  1380.         if value == 'GO':
  1381.             if this.room.isDeathmatch and not this.isDead:
  1382.                 this.sendMessage('<ROSE>[DEATH]<N> GO! Mate seus advers\xc3\xa1rios e seja o \xc3\xbanico sobrevivente!')
  1383.                 this.countP = 0
  1384.                 this.ClientGotHole = 1
  1385.                 this.isDead = False
  1386.                 this.room.canCannon = True
  1387.                 this.PlayerDeathVivo = True
  1388.         this.sendMBox('<p align="center"><font size="35"><N><img src="' + str(value) + '"></p>', 290, 80, 500, 500, '0%', '#000000', '#FFFFFF', 12)
  1389.  
  1390.     def sendDeathInventory(this, page = 1):
  1391.         ids = (504, 505, 506, 507)
  1392.         for id in ids:
  1393.             this.sendPacket([29, 18], ByteArray().writeInt(id).toByteArray())
  1394.  
  1395.         message1 = ''
  1396.         message2 = '<font color="#9ab7c6"><a href="event:prev">Voltar</a></font>'
  1397.         message3 = ''
  1398.         message4 = ''
  1399.         message5 = '<font color="#9ab7c6"><a href="event:next">Avan\xc3\xa7ar</a></font>'
  1400.         message6 = ''
  1401.         message7 = ''
  1402.         message8 = '<p align="center"><font size="28" face="Soopafresh,Verdana,Arial,sans-serif" color="#9ab7c6">Invent\xc3\xa1rio</font></p>'
  1403.         message9 = '<p align="center"><font color="#9ab7c6" size="16"><a href="event:close">X</a></font></p>'
  1404.         if page == 1:
  1405.             message10 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Happy Halloween</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">Use !f to choose your cannon. This is only temporary and will be removed in the future.</font>\n\n<font color="#c2c2da">'
  1406.             message11 = ''
  1407.             message12 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 15 else '<a href="event:inventory#use#15"><p align="center">Equipar</p>'
  1408.             message13 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Golden Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">This cannon was forged with the purest gold found in land. It is meant only for the best of all the mice.</font>\n\n<font color="#c2c2da">'
  1409.             message14 = ''
  1410.             message15 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 16 else '<a href="event:inventory#use#16"><p align="center">Equipar</p>'
  1411.             message16 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Silver Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">These cannons might work really well on weremice!</font>\n\n<font color="#c2c2da">'
  1412.             message17 = ''
  1413.             message18 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 17 else '<a href="event:inventory#use#17"><p align="center">Equipar</p>'
  1414.             this.sendImg(504, '149aeaa271c.png', 233, 145, 300)
  1415.             this.sendImg(505, '149af112d8f.png', 391, 145, 301)
  1416.             this.sendImg(506, '149af12c2d6.png', 549, 145, 302)
  1417.         if page == 2:
  1418.             message10 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Bronze Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">Never before was a cannon so hard and durable.</font>\n\n<font color="#c2c2da">'
  1419.             message11 = ''
  1420.             message12 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 18 else '<a href="event:inventory#use#18"><p align="center">Equipar</p>'
  1421.             message13 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Balanced Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">It might be time for a diet, you should eat more cheese.</font>\n\n<font color="#c2c2da">'
  1422.             message14 = ''
  1423.             message15 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 19 else '<a href="event:inventory#use#19"><p align="center">Equipar</p>'
  1424.             message16 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Plate-Spike Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">This cannon was re-inforced with metal plating and spikes. It must not have been deadly enough yet.</font>\n\n<font color="#c2c2da">'
  1425.             message17 = ''
  1426.             message18 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 20 else '<a href="event:inventory#use#20"><p align="center">Equipar</p>'
  1427.             this.sendImg(504, '149af130a30.png', 233, 145, 300)
  1428.             this.sendImg(505, '149af0fdbf7.png', 391, 145, 301)
  1429.             this.sendImg(506, '149af0ef041.png', 549, 145, 302)
  1430.         if page == 3:
  1431.             message10 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Death Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">This cannon was forged by death himself.</font>\n\n<font color="#c2c2da">'
  1432.             message11 = ''
  1433.             message12 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 21 else '<a href="event:inventory#use#21"><p align="center">Equipar</p>'
  1434.             message13 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Diamond Ore Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">Why is there diamond in my cannon?</font>\n\n<font color="#c2c2da">'
  1435.             message14 = ''
  1436.             message15 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 22 else '<a href="event:inventory#use#22"><p align="center">Equipar</p>'
  1437.             message16 = '<p align="center"><p align="center"><font size="15" face="Soopafresh,Verdana,Arial,sans-serif" color="#C2C2DA">Lightning Cannon</font></p></p>\n\n\n\n\n<p align="justify"><font size="10"><font color="#93ADBA">This cannon is lightning fast and hits as thunder.</font>\n\n<font color="#c2c2da">'
  1438.             message17 = ''
  1439.             message18 = '<a href="event:inventory#remove"><p align="center">Desequipar</p></a>' if this.deathStats[4] == 23 else '<a href="event:inventory#use#23"><p align="center">Equipar</p>'
  1440.             this.sendImg(504, '149af13e210.png', 233, 145, 300)
  1441.             this.sendImg(505, '149af129a4c.png', 391, 145, 301)
  1442.             this.sendImg(506, '149aeaa06d1.png', 549, 145, 302)
  1443.         this.sendMBox(message1, 95, 99, 70, 16, '100%', '698358', '698358', 131458)
  1444.         this.sendMBox(message2, 95, 100, 70, 16, '100%', '324650', '324650', 123479)
  1445.         this.sendMBox(message3, 95, 131, 70, 16, '100%', '000001', '000001', 130449)
  1446.         this.sendMBox(message4, 95, 129, 70, 16, '100%', '698358', '698358', 131459)
  1447.         this.sendMBox(message5, 95, 130, 70, 16, '100%', '324650', '324650', 123480)
  1448.         this.sendMBox(message6, 165, 61, 485, 300, '100%', '000001', '000001', 6992)
  1449.         this.sendMBox(message7, 165, 59, 485, 300, '100%', '698358', '698358', 8002)
  1450.         this.sendMBox(message8, 165, 60, 485, 300, '100%', '324650', '324650', 23)
  1451.         this.sendMBox(message9, 623, 60, 30, 30, '0%', '000000', '000000', 9012)
  1452.         this.sendMBox(message10, 179, 110, 140, 245, '100%', '204318', '988183', 9013)
  1453.         this.sendMBox(message11, 229, 141, 40, 40, '100%', '697666', '988183', 9893)
  1454.         this.sendMBox(message12, 179, 325, 140, 30, '30%', '791275', '000000', 8983)
  1455.         this.sendMBox(message13, 337, 110, 140, 245, '100%', '204318', '988183', 9014)
  1456.         this.sendMBox(message14, 387, 141, 40, 40, '100%', '697666', '988183', 9894)
  1457.         this.sendMBox(message15, 337, 325, 140, 30, '30%', '791275', '000000', 8984)
  1458.         this.sendMBox(message16, 495, 110, 140, 245, '100%', '204318', '988183', 9015)
  1459.         this.sendMBox(message17, 545, 141, 40, 40, '100%', '697666', '988183', 9895)
  1460.         this.sendMBox(message18, 495, 325, 140, 30, '30%', '791275', '000000', 8985)
  1461.         this.sendImg(507, '149af1e58d7.png', 601, 124, 300)
  1462.  
  1463.     def sendDeathProfile(this):
  1464.         ids = (39, 40, 41)
  1465.         for id in ids:
  1466.             this.sendPacket([29, 18], ByteArray().writeInt(id).toByteArray())
  1467.  
  1468.         yn = 'Ativado' if this.deathStats[3] == 0 else 'Desativado'
  1469.         message1 = ''
  1470.         message2 = '<p align="center"><font size="28" face="Soopafresh,Verdana,Arial,sans-serif" color="#9ab7c6">' + this.playerName + '</font></p>\n<p><font color="#c0c0d8"> Configura\xc3\xa7\xc3\xb5es</font>\n<font color="#6b76bf">    \xe2\x80\xa2 Offset X : </font><font color="#009b9b">' + str(this.deathStats[0]) + '</font><J> <a href="event:offset#offsetX#1">[+]</a> <a href="event:offset#offsetX#-1">[\xe2\x88\x92]</a>\n<font color="#6b76bf">    \xe2\x80\xa2 Offset Y : </font><font color="#009b9b">' + str(this.deathStats[1]) + '</font><J> <a href="event:offset#offsetY#1">[+]</a> <a href="event:offset#offsetY#-1">[\xe2\x88\x92]</a>\n<font color="#6b76bf">    \xe2\x80\xa2 CN Personalizado : </font><font color="#009b9b"><J><a href="event:show">' + yn + '</a></font></p><p>\n<font color="#c0c0d8"> Seu Perfil</font>\n<font color="#6b76bf">    \xe2\x80\xa2 Venceu : </font><font color="#009b9b">' + str(this.deathCount) + '</font>\n<font color="#6b76bf">    \xe2\x80\xa2 Rodadas : </font><font color="#009b9b">' + str(this.deathRounds) + '</font></p>\n\n<N><p><font color="#c0c0d8"> Dica</font>\n<p align="center"> Para usar CN padr\xc3\xa3o, deixe <CH>Offset <b>X</b>: 2<N> / <CH>Offset <b>Y</b>: 8<N> e desative o CN Personalizado.</p>'
  1471.         message3 = '<p align="center"><font color="#9ab7c6" size="16"><a href="event:close">X</a></font></p>'
  1472.         message4 = ''
  1473.         message5 = ''
  1474.         message6 = ''
  1475.         this.sendImg(39, '149af12df23.png', 445, 80, 201)
  1476.         this.sendImg(40, '149af10434e.png', this.deathStats[5], this.deathStats[6], 202)
  1477.         this.sendImg(41, '149af10637b.png', 152, 90, 203)
  1478.         this.sendMBox(message1, 267, 59, 278, 290, '100%', '111111', '111111', 7999, False)
  1479.         this.sendMBox(message2, 267, 60, 278, 280, '100%', '282828', '282828', 20)
  1480.         this.sendMBox(message3, 518, 59, 30, 30, '0%', '000000', '000000', 9009)
  1481.         this.sendMBox(message4, 152, 91, 101, 101, '100%', '000001', '000001', 7239)
  1482.         this.sendMBox(message5, 152, 89, 101, 101, '100%', '111111', '111111', 8249)
  1483.         this.sendMBox(message6, 152, 90, 101, 101, '100%', '324650', '324650', 270, False)
  1484.  
  1485.     def sendMBox(this, text, x, y, width, height, alpha, bgcolor, bordercolor, boxid, fixed = True):
  1486.         p = ByteArray()
  1487.         text = str(text)
  1488.         x, y, width, height = (int(x),
  1489.          int(y),
  1490.          int(width),
  1491.          int(height))
  1492.         alpha = str(alpha).split('%')[0]
  1493.         alpha = int(alpha)
  1494.         if '#' in str(bgcolor):
  1495.             bgcolor = str(bgcolor[1:])
  1496.         if '#' in str(bordercolor):
  1497.             bordercolor = str(bordercolor[1:])
  1498.         bgcolor, bordercolor = int(bgcolor, 16), int(bordercolor, 16)
  1499.         p.writeInt(int(boxid))
  1500.         p.writeUTF(text)
  1501.         p.writeShort(x)
  1502.         p.writeShort(y)
  1503.         p.writeShort(width)
  1504.         p.writeShort(height)
  1505.         p.writeInt(bgcolor)
  1506.         p.writeInt(bordercolor)
  1507.         p.writeByte(alpha)
  1508.         p.writeShort(fixed)
  1509.         this.sendPacket([29, 20], p.toByteArray())
  1510.  
  1511.     def startPlay(this):
  1512.         this.playerStartTimeMillis = this.room.gameStartTimeMillis
  1513.         this.isNewclient = this.isDead
  1514.         this.sendMap(newMapCustom=True) if this.room.mapCode != -1 else (this.sendMap() if this.room.isEditor and this.room.EMapCode != 0 else this.sendMap(True))
  1515.         shamanCode, shamanCode2 = (0, 0)
  1516.         if this.room.isDoubleMap:
  1517.             shamans = this.room.getDoubleShamanCode()
  1518.             shamanCode = shamans[0]
  1519.             shamanCode2 = shamans[1]
  1520.         else:
  1521.             shamanCode = this.room.getShamanCode()
  1522.         if this.room.isDeathmatch and this.room.getPlayerCountUnique() >= this.server.needToFirst:
  1523.             this.deathRounds += 1
  1524.         if this.playerCode == shamanCode or this.playerCode == shamanCode2:
  1525.             this.isShaman = True
  1526.         if this.isShaman and not this.room.noShamanSkills:
  1527.             this.parseSkill.getkills()
  1528.         if this.room.currentShamanName != '' and not this.room.noShamanSkills:
  1529.             this.parseSkill.getPlayerSkills(this.room.currentShamanSkills)
  1530.         if this.room.currentSecondShamanName != '' and not this.room.noShamanSkills:
  1531.             this.parseSkill.getPlayerSkills(this.room.currentSecondShamanSkills)
  1532.         this.sendPlayerList()
  1533.         if this.room.catchTheCheeseMap and not this.room.noShamanSkills:
  1534.             this.sendPacket(Identifiers.old.send.Catch_The_Cheese_Map, [shamanCode])
  1535.             this.sendPacket(Identifiers.old.send.Player_Get_Cheese, [shamanCode])
  1536.             if this.room.currentMap not in (108, 109):
  1537.                 this.sendShamanCode(shamanCode, shamanCode2)
  1538.         else:
  1539.             this.sendShamanCode(shamanCode, shamanCode2)
  1540.         this.sendSync(this.room.getSyncCode())
  1541.         this.sendRoundTime(this.room.roundTime + (this.room.gameStartTime - Utils.getTime()) + this.room.addTime)
  1542.         this.sendMapStartTimer(False) if this.isDead or this.room.isDeathmatch or this.room.isTutorial or this.room.isTotemEditor or this.room.isBootcamp or this.room.isDefilante or this.room.getPlayerCountUnique() < 2 else this.sendMapStartTimer(True)
  1543.         if this.room.isTotemEditor:
  1544.             this.initTotemEditor()
  1545.         if this.useAnime >= 1:
  1546.             this.useAnime = 0
  1547.         if this.room.isExplosionGame:
  1548.             this.sendPacket([29, 25], struct.pack('!h', len('<N>#Explosion')) + '<N>#Explosion')
  1549.             this.enableKey(32)
  1550.             if this.explosion == 0:
  1551.                 this.explosion += 5
  1552.         if this.room.isBallonRace:
  1553.             this.sendPacket([29, 25], struct.pack('!h', len('<ROSE>#BallonRace')) + '<ROSE>#BallonRace')
  1554.             this.enableKey(32)
  1555.             if this.ballons == 0:
  1556.                 this.ballons += 5
  1557.         if this.room.isPokeLua:
  1558.             this.sendPacket([29, 25], struct.pack('!h', len('<VP>#PokeLua')) + '<VP>#PokeLua')
  1559.         if this.room.isFlyGame:
  1560.             this.sendPacket([29, 25], struct.pack('!h', len('<R>#Fly')) + '<R>#Fly')
  1561.             this.enableKey(32)
  1562.             if this.flypoints == 0:
  1563.                 this.flypoints += 6
  1564.         if this.room.isInvocationGame:
  1565.             this.sendPacket([29, 25], struct.pack('!h', len('<J>#Invocation')) + '<J>#Invocation')
  1566.             this.enableKey(32)
  1567.             if this.invocationpoints == 0:
  1568.                 this.invocationpoints += 7
  1569.         if this.room.isSurvivor and this.isShaman:
  1570.             this.sendPacket(Identifiers.send.Can_Meep, 1)
  1571.         if this.room.currentMap in range(200, 211) and not this.isShaman:
  1572.             this.sendPacket(Identifiers.send.Can_Transformation, 1)
  1573.         if this.room.isDeathmatch:
  1574.             this.enableKey(ord('L'))
  1575.         if this.room.isVillage:
  1576.             reactor.callLater(0.2, this.sendNPCVillage)
  1577.  
  1578.     def enableKey(this, key, onKeyPress = True, onKeyLeave = True):
  1579.         if not this.isDead:
  1580.             this.sendPacket([29, 2], struct.pack('!hbb', int(key), onKeyPress, onKeyLeave))
  1581.  
  1582.     def disableKey(this, key, onKeyPress = False, onKeyLeave = False):
  1583.         this.sendPacket([29, 2], struct.pack('!hbb', int(key), onKeyPress, onKeyLeave))
  1584.  
  1585.     def getPlayerData(this):
  1586.         return '#'.join(map(str, [this.playerName if this.mouseName == '' else this.mouseName,
  1587.          this.playerCode,
  1588.          1,
  1589.          1 if this.isDead else 0,
  1590.          this.playerScore,
  1591.          1 if this.hasCheese else 0,
  1592.          '%s,%s,%s' % (this.titleNumber, this.titleStars, this.gender),
  1593.          0,
  1594.          this.playerLook if not this.room.isBootcamp else '1;0,0,0,0,0,0,0,0,0',
  1595.          0,
  1596.          this.tempMouseColor if not this.tempMouseColor == '' else this.mouseColor,
  1597.          this.shamanColor,
  1598.          0]))
  1599.  
  1600.     def sendShamanCode(this, shamanCode, shamanCode2):
  1601.         this.sendShaman(shamanCode, shamanCode2, this.server.getShamanType(shamanCode), this.server.getShamanType(shamanCode2), this.server.getShamanLevel(shamanCode), this.server.getShamanLevel(shamanCode2), this.server.getShamanBadge(shamanCode), this.server.getShamanBadge(shamanCode2))
  1602.  
  1603.     def sendCorrectVersion(this):
  1604.         this.sendPacket(Identifiers.send.Correct_Version, ByteArray().writeInt(0).writeByte(this.lastPacketID).writeUTF('br').writeUTF('br').writeInt(this.authKey).writeInt(this.authKeyLogin).toByteArray())
  1605.         this.sendPacket(Identifiers.send.Banner_Login, ByteArray().writeByte(1).writeByte(this.server.adventureID).writeByte(1).writeBoolean(False).toByteArray())
  1606.         this.sendPacket(Identifiers.send.Image_Login, ByteArray().writeUTF(this.server.adventureIMG).toByteArray())
  1607.         this.awakeTimer = reactor.callLater(120, this.transport.loseConnection)
  1608.  
  1609.     def sendLogin(this):
  1610.     if this.privLevel in [7, 8, 9, 10]:
  1611.             this.sendPacket([26, 2], ByteArray().writeInt(this.playerID).writeUTF(this.playerName).writeInt(6000000).writeByte(this.langueID).writeInt(this.playerCode).writeBoolean(True).writeByte(5).writeByte(5).writeBoolean(False).writeByte(10).writeByte(-1).writeByte(-1).writeByte(-1).toByteArray())
  1612.  
  1613.         if this.privLevel in [5, 6]:
  1614.             this.sendPacket([26, 2], ByteArray().writeInt(this.playerID).writeUTF(this.playerName).writeInt(6000000).writeByte(this.langueID).writeInt(this.playerCode).writeBoolean(True).writeByte(1).writeByte(3).writeBoolean(False).toByteArray())
  1615.  
  1616.         if this.privLevel in [1, 2, 3, 4]:
  1617.             this.sendPacket([26, 2], ByteArray().writeInt(this.playerID).writeUTF(this.playerName).writeInt(6000000).writeByte(this.langueID).writeInt(this.playerCode).writeBoolean(True).writeByte(1).writeByte(0).writeBoolean(False).toByteArray())
  1618.     if this.isGuest:
  1619.         this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(1).writeByte(10).toByteArray())
  1620.         this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(2).writeByte(5).toByteArray())
  1621.         this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(3).writeByte(15).toByteArray())
  1622.         this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(4).writeUnsignedByte(200).toByteArray())
  1623.  
  1624.     def sendTimeStamp(this):
  1625.         this.sendPacket(Identifiers.send.Time_Stamp, ByteArray().writeInt(Utils.getTime()).toByteArray())
  1626.  
  1627.     def sendPromotions(this):
  1628.         for promotion in this.server.shopPromotions:
  1629.             this.sendPacket(Identifiers.send.Promotion, ByteArray().writeInt(promotion[0] * (10000 if promotion[1] > 99 else 100) + promotion[1] + (10000 if promotion[1] > 99 else 0)).writeInt(promotion[3]).writeByte(promotion[2]).toByteArray())
  1630.  
  1631.         if len(this.server.shopPromotions) > 0:
  1632.             promotion = this.server.shopPromotions[0]
  1633.             item = promotion[0] * (10000 if promotion[1] > 99 else 100) + promotion[1] + (10000 if promotion[1] > 99 else 0)
  1634.             this.sendPacket(Identifiers.send.Promotion_Popup, ByteArray().writeByte(promotion[0]).writeByte(promotion[1]).writeByte(promotion[2]).writeShort(this.server.shopBadges.get(item, 0)).toByteArray())
  1635.  
  1636.     def sendGameType(this, gameType, serverType):
  1637.         this.sendPacket(Identifiers.send.Room_Type, gameType)
  1638.         this.sendPacket(Identifiers.send.Room_Server, serverType)
  1639.  
  1640.     def sendEnterRoom(this, roomName):
  1641.         found = False
  1642.         rooms = roomName[3:]
  1643.         count = ''.join((i for i in rooms if i.isdigit()))
  1644.         for room in ['vanilla',
  1645.          'survivor',
  1646.          'racing',
  1647.          'music',
  1648.          'bootcamp',
  1649.          'defilante']:
  1650.             if rooms.startswith(room) and not count == '' or rooms.isdigit():
  1651.                 found = not (int(count) < 1 or int(count) > 1000000000 or rooms == room)
  1652.  
  1653.         this.sendPacket(Identifiers.send.Enter_Room, ByteArray().writeBoolean(found).writeUTF(roomName).toByteArray())
  1654.  
  1655.     def sendMap(this, newMap = False, newMapCustom = False):
  1656.         this.sendPacket(Identifiers.send.New_Map, ByteArray().writeInt(this.room.currentMap if newMap else (this.room.mapCode if newMapCustom else -1)).writeShort(this.room.getPlayerCount()).writeByte(this.room.lastRoundCode).writeShort(0).writeUTF('' if newMap else (this.room.mapXML.encode('zlib') if newMapCustom else this.room.EMapXML.encode('zlib'))).writeUTF('' if newMap else (this.room.mapName if newMapCustom else '-')).writeByte(0 if newMap else (this.room.mapPerma if newMapCustom else 100)).writeBoolean(this.room.mapInverted if newMapCustom else False).toByteArray())
  1657.  
  1658.     def sendPlayerList(this):
  1659.         this.sendPacket(Identifiers.old.send.Player_List, this.room.getPlayerList())
  1660.  
  1661.     def sendSync(this, playerCode):
  1662.         this.sendPacket(Identifiers.old.send.Sync, [playerCode, ''] if this.room.mapCode != 1 or this.room.EMapCode != 0 else [playerCode])
  1663.  
  1664.     def sendRoundTime(this, time):
  1665.         this.sendPacket(Identifiers.send.Round_Time, ByteArray().writeShort(0 if time < 0 or time > 32767 else time).toByteArray())
  1666.  
  1667.     def sendMapStartTimer(this, startMap):
  1668.         this.sendPacket(Identifiers.send.Map_Start_Timer, ByteArray().writeBoolean(startMap).toByteArray())
  1669.  
  1670.     def sendPlayerDisconnect(this):
  1671.         this.room.sendAll(Identifiers.old.send.Player_Disconnect, [this.playerCode])
  1672.  
  1673.     def sendChangeMap(this, time):
  1674.         this.room.sendAll([5, 22], ByteArray().writeShort(time).toByteArray())
  1675.         if this.room.changeMapTimer:
  1676.             try:
  1677.                 this.room.changeMapTimer.cancel()
  1678.             except:
  1679.                 this.room.changeMapTimer = None
  1680.  
  1681.         this.room.changeMapTimer = reactor.callLater(time, this.room.mapChange)
  1682.         return
  1683.  
  1684.     def sendPlayerDied(this):
  1685.         this.room.sendAll(Identifiers.old.send.Player_Died, [this.playerCode, this.playerScore])
  1686.         this.hasCheese = False
  1687.         if this.room.isDeathmatch:
  1688.             this.PlayerDeathVivo = False
  1689.         if this.room.getAliveCount() < 1 or this.room.catchTheCheeseMap or this.isAfk:
  1690.             this.canShamanRespawn = False
  1691.         if this.room.checkIfTooFewRemaining() and not this.canShamanRespawn or this.room.checkIfShamanIsDead() and not this.canShamanRespawn or this.room.checkIfDoubleShamansAreDead():
  1692.             this.room.send20SecRemainingTimer()
  1693.         if this.canShamanRespawn:
  1694.             this.isDead = False
  1695.             this.isAfk = False
  1696.             this.hasCheese = False
  1697.             this.hasEnter = False
  1698.             this.canShamanRespawn = False
  1699.             this.playerStartTimeMillis = time.time()
  1700.             this.room.sendAll(Identifiers.old.send.Player_Respawn, [this.getPlayerData(), 1])
  1701.             for client in this.room.clients.values():
  1702.                 client.sendShamanCode(this.playerCode, 0)
  1703.  
  1704.     def closedDeathWin(this):
  1705.         this.sendMBox('', 585, 30, 200, 20, '100%', '000000', '000000', 65)
  1706.  
  1707.     def spawnObject(this, code, x, y, ghost):
  1708.         this.room.objectID += 2
  1709.         this.room.sendAll([5, 20], ByteArray().writeInt(this.room.objectID).writeShort(code).writeShort(x).writeShort(y).writeShort(0).writeByte(0).writeByte(0).writeByte(ghost).writeByte(0).toByteArray())
  1710.  
  1711.     def addShamanObject(this, code, x, y, ghost, angle = 0):
  1712.         if this.PlayerDeathVivo:
  1713.             this.room.objectID += 1
  1714.             p = ByteArray().writeInt(this.room.objectID).writeShort(code).writeShort(x).writeShort(y).writeShort(angle).writeByte('0').writeShort(ghost).writeShort(0)
  1715.             this.room.sendAll([5, 20], p.toByteArray())
  1716.         else:
  1717.             this.room.objectID = 1
  1718.             this.room.removeObject(1704)
  1719.  
  1720.     def deathRoundWinner(this, playername):
  1721.         for client in this.room.clients.values():
  1722.             if client.playerName == playername:
  1723.                 this.ClientGotHole = 0
  1724.                 this.room.numCompleted += 1
  1725.                 holeTime = int(Utils.getTime() - this.room.gameStartTime)
  1726.                 holeTime *= 100
  1727.                 this.room.sendAll([5, 13], [str(client.playerCode)])
  1728.             this.room.canCannon = False
  1729.             this.PlayerDeathVivo = False
  1730.             client.sendMBox("<p align='center'><CH>" + str(this.playerName) + '<N> \xc3\xa9 o vencedor!</p>', 585, 30, 200, 20, '45%', '000000', '222222', 65)
  1731.             client.sendMessage('<ROSE>[DEATH] <CH>' + str(this.playerName) + '<J> foi o \xc3\xbanico sobrevivente e ganhou a partida recebendo <ROSE>+1 <J>ponto e <ROSE>7<J> firsts e moedas.')
  1732.             client.sendTitleMessage('<VP>Pr\xc3\xb3xima rodada come\xc3\xa7ar\xc3\xa1 em 5 segundos.')
  1733.             reactor.callLater(1, client.sendTitleMessage, '<VP>Pr\xc3\xb3xima rodada come\xc3\xa7ar\xc3\xa1 em 4 segundos.')
  1734.             reactor.callLater(2, client.sendTitleMessage, '<VP>Pr\xc3\xb3xima rodada come\xc3\xa7ar\xc3\xa1 em 3 segundos.')
  1735.             reactor.callLater(3, client.sendTitleMessage, '<VP>Pr\xc3\xb3xima rodada come\xc3\xa7ar\xc3\xa1 em 2 segundos.')
  1736.             reactor.callLater(4, client.sendTitleMessage, '<VP>Pr\xc3\xb3xima rodada come\xc3\xa7ar\xc3\xa1 em 1 segundos.')
  1737.  
  1738.         reactor.callLater(5, this.room.checkChangeMap)
  1739.  
  1740.     def sendSettime(this, time):
  1741.         for client in this.room.clients.values():
  1742.             client.sendRoundTime(time)
  1743.  
  1744.         this.room.changeMapTimers(time)
  1745.  
  1746.     def sendTitleMessage(this, message):
  1747.         for client in this.room.clients.values():
  1748.             info = struct.pack('!h', len(message)) + message + '\n'
  1749.             client.sendPacket([29, 25], info)
  1750.  
  1751.     def sendShaman(this, shamanCode, shamanCode2, shamanType, shamanType2, shamanLevel, shamanLevel2, shamanBadge, shamanBadge2):
  1752.         this.sendPacket(Identifiers.send.Shaman_Info, ByteArray().writeInt(shamanCode).writeInt(shamanCode2).writeByte(shamanType).writeByte(shamanType2).writeShort(shamanLevel).writeShort(shamanLevel2).writeShort(shamanBadge).writeShort(shamanBadge2).toByteArray())
  1753.  
  1754.     def sendConjurationDestroy(this, x, y):
  1755.         this.room.sendAll(Identifiers.old.send.Conjuration_Destroy, [x, y])
  1756.  
  1757.     def sendGiveCheese(this, distance = -1):
  1758.         if distance != -1 and distance != 1000 and not this.room.catchTheCheeseMap and this.room.countStats:
  1759.             if distance >= 30:
  1760.                 this.isSuspect = True
  1761.         this.room.canChangeMap = False
  1762.         if not this.hasCheese:
  1763.             this.room.sendAll(Identifiers.old.send.Player_Get_Cheese, [this.playerCode])
  1764.             this.hasCheese = True
  1765.             this.room.numGetCheese += 1
  1766.             if this.room.currentMap in range(108, 114):
  1767.                 if this.room.numGetCheese >= 10:
  1768.                     this.room.killShaman()
  1769.             if this.room.isTutorial:
  1770.                 this.sendPacket(Identifiers.send.Tutorial, 1)
  1771.             if int(this.room.getPlayerCount()) >= int(this.server.needToFirst) and this.room.countStats and not this.isShaman:
  1772.                 if this.room.isNormRoom or this.room.isRacing:
  1773.                     if this.room.numGetCheese == 1:
  1774.                         this.XDCoins += 2
  1775.         this.room.canChangeMap = True
  1776.  
  1777.     def playerWin(this, holeType, distance = -1):
  1778.         if this.activeArtefact == 0 and this.room.isEventoAventura:
  1779.             this.sendMessage('<CH>Voc\xc3\xaa precisa coletar o item do evento para poder firstar. Voc\xc3\xaa morreu!')
  1780.         else:
  1781.             if distance != -1 and distance != 1000 and this.isSuspect and this.room.countStats:
  1782.                 if distance >= 30:
  1783.                     this.server.sendModMessage(7, '[<V>ANTI-HACK</V>][<J>%s</J>][<V>%s</V>] Instant win detected.' % (this.ipAddress, this.playerName))
  1784.                     this.sendPacket(Identifiers.old.send.Player_Ban_Login, [0, 'Instant win detected.'])
  1785.                     this.transport.loseConnection()
  1786.                     return
  1787.             timeTaken = int((time.time() - (this.playerStartTimeMillis if this.room.autoRespawn else this.room.gameStartTimeMillis)) * 100)
  1788.             if timeTaken > 5:
  1789.                 this.room.canChangeMap = False
  1790.                 canGo = this.room.checkIfShamanCanGoIn() if this.isShaman else True
  1791.                 if not canGo:
  1792.                     this.sendSaveRemainingMiceMessage()
  1793.                 if this.isDead or not this.hasCheese and not this.isOpportunist:
  1794.                     canGo = False
  1795.                 if this.room.isTutorial:
  1796.                     this.sendPacket(Identifiers.send.Tutorial, 2)
  1797.                     this.hasCheese = False
  1798.                     reactor.callLater(10, lambda : this.startBulle(this.server.recommendRoom(this.langue)))
  1799.                     this.sendRoundTime(10)
  1800.                     return
  1801.                 if this.room.isEditor:
  1802.                     if not this.room.EMapValidated and this.room.EMapCode != 0:
  1803.                         this.room.EMapValidated = True
  1804.                         this.sendPacket(Identifiers.old.send.Map_Validated, [''])
  1805.                 if canGo:
  1806.                     this.isDead = True
  1807.                     this.hasCheese = False
  1808.                     this.hasEnter = True
  1809.                     this.room.numCompleted += 1
  1810.                     place = this.room.numCompleted
  1811.                     if this.room.isDoubleMap:
  1812.                         if holeType == 1:
  1813.                             this.room.FSnumCompleted += 1
  1814.                         elif holeType == 2:
  1815.                             this.room.SSnumCompleted += 1
  1816.                         else:
  1817.                             this.room.FSnumCompleted += 1
  1818.                             this.room.SSnumCompleted += 1
  1819.                     place = this.room.numCompleted
  1820.                     this.currentPlace = place
  1821.                     if place == 1:
  1822.                         this.playerScore += (4 if this.room.isRacing else 16) if not this.room.noAutoScore else 0
  1823.                         if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn:
  1824.                             if not this.room.isEventoAventura:
  1825.                                 this.firstCount += 2
  1826.                                 this.cheeseCount += 2
  1827.                                 this.XDCoins += 3
  1828.                 this.aventurePoints[24] += 1
  1829.                 this.sendMessage('[x] Parabéns, você firstou e recebeu <V>3</V> first.')
  1830.                             if this.room.isEventoAventura:
  1831.                                 if this.activeArtefact == 1:
  1832.                                     this.firstCount += 6
  1833.                                     this.cheeseCount += 6
  1834.                                     this.XDCoins += 6
  1835.                                     this.sendMessage('[x] Parabéns, você firstou e recebeu <V>6</V> first no evento.')
  1836.                             if this.room.isRacing:
  1837.                                 if not this.isGuest:
  1838.                                     for client in this.room.clients.values():
  1839.                                         this.sendSettime(15)
  1840.  
  1841.                             if this.room.isTribewar:
  1842.                                 tribes = {}
  1843.                                 for client in this.room.clients.values():
  1844.                                     if client.tribeName != '':
  1845.                                         try:
  1846.                                             tribes[client.tribeName] += 1
  1847.                                         except:
  1848.                                             tribes[client.tribeName] = 1
  1849.  
  1850.                                 if len(tribes) >= 2:
  1851.                                     if this.tribeName != '':
  1852.                                         tribepoints = str(random.randrange(6, 10))
  1853.                                         for client in this.room.clients.values():
  1854.                                             client.sendMessage('<V>[TribeBOT] <ROSE>' + this.playerName + ' <V>ganhou <ROSE>' + tribepoints + ' <V>pontos para tribo: <ROSE>' + this.tribeName)
  1855.  
  1856.                                         Cursor.execute('UPDATE tribe SET Points = Points+? WHERE Name = ?', [tribepoints, this.tribeName])
  1857.                                 else:
  1858.                                     this.sendMessage('<V>[TribeBOT] Precisa ter mais de uma Tribo participante para valer pontos!')
  1859.                             timeTaken = int((time.time() - (this.playerStartTimeMillis if this.room.autoRespawn else this.room.gameStartTimeMillis)) * 100)
  1860.                             if timeTaken > 100:
  1861.                                 t = timeTaken / 100.0
  1862.                             else:
  1863.                                 t = timeTaken / 10.0
  1864.                             if not this.isShaman and not this.room.isDeathmatch and not this.room.isTribeHouse:
  1865.                                 if int(this.room.getPlayerCount()) >= int(this.server.needToFirst):
  1866.                                     if this.room.mapCode not in (-1, 31, 41, 42, 54, 55, 59, 60, 62, 89, 92, 99, 114, 801):
  1867.                                         try:
  1868.                                             CursorMaps.execute('select TopTime from maps where code = ?', [this.room.mapCode])
  1869.                                             timeDB = CursorMaps.fetchone()
  1870.                                             if timeDB[0] == 0 or timeTaken < timeDB[0]:
  1871.                                                 CursorMaps.execute('update maps set TopTime = ?, TopTimeNick = ? where code = ?', [timeTaken, this.playerName, this.room.mapCode])
  1872.                                                 this.sendMessage('<R>Parabéns! Seu novo record é: <J>' + str(t) + 's você ganhou +<J>5<R> moedas.')
  1873.                             this.XDCoins += 5
  1874.                                                 for client in this.room.clients.values():
  1875.                                                     client.sendMessage('<N>Vuashh! O usuário <J>' + this.playerName + ' <N>bateu um novo record. Tempo: <J>' + str(t) + 's')
  1876.  
  1877.                                         except:
  1878.                                             pass
  1879.  
  1880.                     elif place == 2:
  1881.                         if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn:
  1882.                             if not this.room.isEventoAventura:
  1883.                                 this.firstCount += 2
  1884.                                 this.cheeseCount += 2
  1885.                                 this.XDCoins += 2
  1886.                                 this.aventurePoints[24] += 1
  1887.                 this.sendMessage('[x] Parabéns, você recebeu <V>2</V> first.')
  1888.                             if this.room.isEventoAventura:
  1889.                                 if this.activeArtefact == 1:
  1890.                                     this.firstCount += 3
  1891.                                     this.cheeseCount += 3
  1892.                                     this.XDCoins += 3
  1893.                     this.sendMessage('[x] Parabéns, você recebeu <V>3</V> first do evento.')
  1894.                         this.playerScore += (3 if this.room.isRacing else 14) if not this.room.noAutoScore else 0
  1895.                         this.playerScore += (2 if this.room.isRacing else 12) if not this.room.noAutoScore else 0
  1896.                     else:
  1897.                         this.playerScore += (1 if this.room.isRacing else 10) if not this.room.noAutoScore else 0
  1898.                     if this.room.isDefilante:
  1899.                         if not this.room.noAutoScore:
  1900.                             this.playerScore += this.defilantePoints
  1901.                     if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.room.isBootcamp:
  1902.                         if this.playerCode == this.room.currentShamanCode or this.playerCode == this.room.currentSecondShamanCode:
  1903.                             this.shamanCheeses += 1
  1904.                         else:
  1905.                             this.firstCount += 1
  1906.                             this.cheeseCount += 1
  1907.                             place = this.room.numCompleted
  1908.                             count = 4 if place == 1 else (3 if place == 2 else (2 if place == 2 else 1))
  1909.                             this.shopCheeses += count
  1910.                             this.shopFraises += count
  1911.                             this.sendGiveCurrency(0, count)
  1912.                             this.parseSkill.earnExp(False, 20)
  1913.                             if not this.isGuest:
  1914.                                 if place == 1 and this.server.firstTitleList.has_key(this.firstCount):
  1915.                                     title = this.server.firstTitleList[this.firstCount]
  1916.                                     this.checkAndRebuildTitleList('first')
  1917.                                     this.sendUnlockedTitle(int(title - title % 1), int(round(title % 1 * 10)))
  1918.                                     this.sendCompleteTitleList()
  1919.                                     this.sendTitleList()
  1920.                                 if this.server.cheeseTitleList.has_key(this.cheeseCount):
  1921.                                     title = this.server.cheeseTitleList[this.cheeseCount]
  1922.                                     this.checkAndRebuildTitleList('cheese')
  1923.                                     this.sendUnlockedTitle(int(title - title % 1), int(round(title % 1 * 10)))
  1924.                                     this.sendCompleteTitleList()
  1925.                                     this.sendTitleList()
  1926.                     elif this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.isBootcamp:
  1927.                         this.bootcampCount += 1
  1928.                         if this.server.bootcampTitleList.has_key(this.bootcampCount):
  1929.                             title = this.server.bootcampTitleList[this.bootcampCount]
  1930.                             this.checkAndRebuildTitleList('bootcamp')
  1931.                             this.sendUnlockedTitle(int(title - title % 1), int(round(title % 1 * 10)))
  1932.                             this.sendCompleteTitleList()
  1933.                             this.sendTitleList()
  1934.                     this.room.giveShamanSave(this.room.currentSecondShamanName if holeType == 2 and this.room.isDoubleMap else this.room.currentShamanName, 0)
  1935.                     if this.room.currentShamanType != 0:
  1936.                         this.room.giveShamanSave(this.room.currentShamanName, this.room.currentShamanType)
  1937.                     if this.room.currentSecondShamanType != 0:
  1938.                         this.room.giveShamanSave(this.room.currentSecondShamanName, this.room.currentSecondShamanType)
  1939.                     player = this.server.players.get(this.room.currentSecondShamanName if holeType == 2 and this.room.isDoubleMap else this.room.currentShamanName)
  1940.                     if player != None:
  1941.                         if this.hasArtefact:
  1942.                             player.aventureSaves += 1
  1943.                     if this.hasArtefact:
  1944.                         if not this.artefactID == 0:
  1945.                             imageID = this.artefactID
  1946.                             if imageID not in this.aventureCounts:
  1947.                                 this.aventureCounts[imageID] = (3, 1)
  1948.                             else:
  1949.                                 count = this.aventureCounts[imageID][1] + 1
  1950.                                 this.aventureCounts[imageID] = (3, count)
  1951.                             if this.aventurePoints[24] == 30:
  1952.                                 titles = ['420.1']
  1953.                                 title = random.choice(titles)
  1954.                                 while title in this.titleList:
  1955.                                     try:
  1956.                                         titles.remove(title)
  1957.                                         title = random.choice(titles)
  1958.                                     except:
  1959.                                         break
  1960.  
  1961.                                 if title not in this.titleList:
  1962.                                     stitle = title.split('.')
  1963.                                     this.specialTitleList = this.specialTitleList + [float(title)]
  1964.                                     this.sendUnlockedTitle(stitle[0], stitle[1])
  1965.                                     this.sendCompleteTitleList()
  1966.                                     this.sendTitleList()
  1967.                             if this.aventurePoints[24] == 60:
  1968.                                 medal = 181
  1969.                                 if int(medal) not in this.shopBadges:
  1970.                                     this.parseShop.sendUnlockedBadge(medal)
  1971.                                     this.shopBadges.append(str(medal))
  1972.                             if this.aventurePoints[24] == 90:
  1973.                                 titles = ['421.1']
  1974.                                 title = random.choice(titles)
  1975.                                 while title in this.titleList:
  1976.                                     try:
  1977.                                         titles.remove(title)
  1978.                                         title = random.choice(titles)
  1979.                                     except:
  1980.                                         break
  1981.  
  1982.                                 if title not in this.titleList:
  1983.                                     stitle = title.split('.')
  1984.                                     this.specialTitleList = this.specialTitleList + [float(title)]
  1985.                                     this.sendUnlockedTitle(stitle[0], stitle[1])
  1986.                                     this.sendCompleteTitleList()
  1987.                                     this.sendTitleList()
  1988.                     place = this.room.numCompleted
  1989.                     this.sendPlayerWin(place, timeTaken)
  1990.                     if this.room.getPlayerCount() >= 2 and this.room.checkIfTooFewRemaining() and not this.room.isDoubleMap:
  1991.                         enterHole = False
  1992.                         for client in this.room.clients.values():
  1993.                             if client.isShaman and client.isOpportunist:
  1994.                                 client.isOpportunist = True
  1995.                                 client.playerWin(0)
  1996.                                 enterHole = True
  1997.                                 break
  1998.  
  1999.                         this.room.checkChangeMap()
  2000.                     else:
  2001.                         this.room.checkChangeMap()
  2002.                 this.room.canChangeMap = True
  2003.             else:
  2004.                 this.isDead = True
  2005.                 this.sendPlayerDied()
  2006.         return
  2007.  
  2008.     def sendSaveRemainingMiceMessage(this):
  2009.         this.sendPacket(Identifiers.old.send.Save_Remaining, [])
  2010.  
  2011.     def sendGiveCurrency(this, type, count):
  2012.         this.sendPacket(Identifiers.send.Give_Currency, ByteArray().writeByte(type).writeByte(count).toByteArray())
  2013.  
  2014.     def sendPlayerWin(this, place, timeTaken):
  2015.         this.room.sendAll(Identifiers.send.Player_Win, ByteArray().writeByte(1 if this.room.isDefilante else (2 if this.playerName in this.room.blueTeam else (3 if this.playerName in this.room.blueTeam else 0))).writeInt(this.playerCode).writeShort(this.playerScore).writeUnsignedByte(255 if place >= 255 else place).writeUnsignedShort(65535 if timeTaken >= 65535 else timeTaken).toByteArray())
  2016.         this.hasCheese = False
  2017.         if not this.cheeseCount >= 60000 and not this.room.isEditor and not this.room.EMapValidated and not this.room.EMapCode:
  2018.             if timeTaken < 500:
  2019.                 if this.privLevel <= 3:
  2020.                     this.sendPlayerBan(0, 'Autowin Detectado - Se persistir, voc\xc3\xaa ser\xc3\xa1 banido.', True)
  2021.                     this.transport.loseConnection()
  2022.                     this.server.disconnectIPAddress(this.ipAddress)
  2023.                     this.server.sendModMessage(7, '[<J>' + this.ipAddress + '<BL>] O jogador <V>' + this.playerName + '<BL> foi expulso do servidor por suspeita de Autowin.')
  2024.  
  2025.     def sendCompleteTitleList(this):
  2026.         this.titleList = []
  2027.         this.titleList.append(0.1)
  2028.         this.titleList.extend(this.shopTitleList)
  2029.         this.titleList.extend(this.firstTitleList)
  2030.         this.titleList.extend(this.cheeseTitleList)
  2031.         this.titleList.extend(this.shamanTitleList)
  2032.         this.titleList.extend(this.bootcampTitleList)
  2033.         this.titleList.extend(this.hardModeTitleList)
  2034.         this.titleList.extend(this.divineModeTitleList)
  2035.         this.titleList.extend(this.specialTitleList)
  2036.         if this.privLevel == 4:
  2037.             this.titleList.extend([447.9])
  2038.         if this.privLevel == 5:
  2039.             this.titleList.extend([445.9])
  2040.         if this.privLevel == 6:
  2041.             this.titleList.extend([444.9])
  2042.         if this.privLevel == 7:
  2043.             this.titleList.extend([442.9])
  2044.         if this.privLevel == 8:
  2045.             this.titleList.extend([440.9,
  2046.              442.9,
  2047.              444.9,
  2048.              445.9,
  2049.              446.9,
  2050.              447.9,
  2051.              448.9,
  2052.              449.9,
  2053.              450.9,
  2054.              451.9,
  2055.              452.9,
  2056.              453.9])
  2057.         if this.privLevel == 9:
  2058.             this.titleList.extend([440.9,
  2059.              442.9,
  2060.              444.9,
  2061.              445.9,
  2062.              446.9,
  2063.              447.9,
  2064.              448.9,
  2065.              449.9,
  2066.              450.9,
  2067.              451.9,
  2068.              452.9,
  2069.              453.9])
  2070.         if this.privLevel >= 10:
  2071.             this.titleList.extend([440.9,
  2072.              442.9,
  2073.              444.9,
  2074.              445.9,
  2075.              446.9,
  2076.              447.9,
  2077.              448.9,
  2078.              449.9,
  2079.              450.9,
  2080.              451.9,
  2081.              452.9,
  2082.              453.9])
  2083.  
  2084.     def sendTitleList(this):
  2085.         this.sendPacket(Identifiers.old.send.Titles_List, [this.titleList])
  2086.  
  2087.     def sendUnlockedTitle(this, title, stars):
  2088.         this.room.sendAll(Identifiers.old.send.Unlocked_Title, [this.playerCode, title, stars])
  2089.  
  2090.     def sendMessage(this, message, all = False):
  2091.         p = ByteArray().writeUTF(message)
  2092.         this.sendPacket([6, 9], p.toByteArray())
  2093.  
  2094.     def sendClientMessage(this, message):
  2095.         this.sendPacket([6, 20], ByteArray().writeByte(0).writeUTF(message).writeByte(0).toByteArray())
  2096.  
  2097.     def sendProfile(this, playerName):
  2098.         player = this.server.players.get(playerName)
  2099.         if player != None and not player.isGuest:
  2100.             packet = ByteArray().writeUTF(player.playerName).writeInt(this.server.getplayerAvatar(playerName)).writeInt(str(player.regDate)[:10]).writeByte({1: 1,
  2101.              2: 1,
  2102.              3: 13,
  2103.              4: 13,
  2104.              5: 11,
  2105.              6: 11,
  2106.              7: 5,
  2107.              8: 5,
  2108.              9: 10,
  2109.              10: 10}[player.privLevel]).writeByte(player.gender).writeUTF(player.tribeName).writeUTF(player.marriage)
  2110.             for stat in [player.shamanSaves,
  2111.              player.shamanCheeses,
  2112.              player.firstCount,
  2113.              player.cheeseCount,
  2114.              player.hardModeSaves,
  2115.              player.bootcampCount,
  2116.              player.divineModeSaves]:
  2117.                 packet.writeInt(stat)
  2118.  
  2119.             packet.writeShort(player.titleNumber).writeShort(len(player.titleList))
  2120.             for title in player.titleList:
  2121.                 packet.writeShort(int(title - title % 1))
  2122.                 packet.writeByte(int(round(title % 1 * 10)))
  2123.  
  2124.             packet.writeUTF(player.playerLook + ';' + player.mouseColor)
  2125.             packet.writeShort(player.shamanLevel)
  2126.             packet.writeShort(len(player.shopBadges) * 2)
  2127.             badges = map(int, player.shopBadges)
  2128.             for badge in [120,
  2129.              121,
  2130.              122,
  2131.              123,
  2132.              124,
  2133.              125,
  2134.              126,
  2135.              127,
  2136.              145,
  2137.              42,
  2138.              54,
  2139.              55,
  2140.              0,
  2141.              1,
  2142.              6,
  2143.              7,
  2144.              9,
  2145.              16,
  2146.              17,
  2147.              18,
  2148.              28,
  2149.              29,
  2150.              30,
  2151.              33,
  2152.              34,
  2153.              35,
  2154.              46,
  2155.              47,
  2156.              50,
  2157.              51,
  2158.              57,
  2159.              58,
  2160.              59,
  2161.              64,
  2162.              65,
  2163.              69,
  2164.              71,
  2165.              73,
  2166.              129,
  2167.              130,
  2168.              131,
  2169.              132,
  2170.              133,
  2171.              134,
  2172.              139,
  2173.              142,
  2174.              144,
  2175.              147,
  2176.              153,
  2177.              154,
  2178.              158,
  2179.              161,
  2180.              162,
  2181.              169,
  2182.              170]:
  2183.                 if badge in badges:
  2184.                     packet.writeUnsignedByte(badge).writeByte(player.racingStats[0] / 1500 if badge == 124 else (player.racingStats[1] / 10000 if badge == 125 else (player.racingStats[2] / 10000 if badge == 127 else (player.racingStats[3] / 10000 if badge == 126 else (player.survivorStats[0] / 1000 if badge == 120 else (player.survivorStats[1] / 800 if badge == 121 else (player.survivorStats[2] / 20000 if badge == 122 else (player.survivorStats[3] / 10000 if badge == 123 else 0))))))))
  2185.                     badges.remove(int(badge))
  2186.  
  2187.             for badge in badges:
  2188.                 packet.writeUnsignedByte(badge).writeByte(player.racingStats[0] / 1500 if badge == 124 else (player.racingStats[1] / 10000 if badge == 125 else (player.racingStats[2] / 10000 if badge == 127 else (player.racingStats[3] / 10000 if badge == 126 else (player.survivorStats[0] / 1000 if badge == 120 else (player.survivorStats[1] / 800 if badge == 121 else (player.survivorStats[2] / 20000 if badge == 122 else (player.survivorStats[3] / 10000 if badge == 123 else 0))))))))
  2189.  
  2190.             stats = [[30,
  2191.               player.racingStats[0],
  2192.               1500,
  2193.               124],
  2194.              [31,
  2195.               player.racingStats[1],
  2196.               10000,
  2197.               125],
  2198.              [33,
  2199.               player.racingStats[2],
  2200.               10000,
  2201.               127],
  2202.              [32,
  2203.               player.racingStats[3],
  2204.               10000,
  2205.               126],
  2206.              [26,
  2207.               player.survivorStats[0],
  2208.               1000,
  2209.               120],
  2210.              [27,
  2211.               player.survivorStats[1],
  2212.               800,
  2213.               121],
  2214.              [28,
  2215.               player.survivorStats[2],
  2216.               20000,
  2217.               122],
  2218.              [29,
  2219.               player.survivorStats[3],
  2220.               10000,
  2221.               123]]
  2222.             packet.writeByte(len(stats))
  2223.             for stat in stats:
  2224.                 packet.writeByte(stat[0]).writeInt(stat[1]).writeInt(stat[2]).writeByte(stat[3])
  2225.  
  2226.             shamanBadges = range(1, 31)
  2227.             packet.writeUnsignedByte(player.equipedShamanBadge).writeUnsignedByte(len(shamanBadges))
  2228.             for shamanBadge in shamanBadges:
  2229.                 packet.writeUnsignedByte(shamanBadge)
  2230.  
  2231.             count = 0
  2232.             for c in player.aventurePoints.values():
  2233.                 count += c
  2234.  
  2235.             packet.writeByte(1).writeInt(count)
  2236.             this.sendPacket(Identifiers.send.Profile, packet.toByteArray())
  2237.         return None
  2238.  
  2239.     def sendPlayerBan(this, hours, reason, silent):
  2240.         this.sendPacket(Identifiers.old.send.Player_Ban, [hours * 3600000, reason])
  2241.         if not silent and this.room != None:
  2242.             for client in this.room.clients.values():
  2243.                 client.sendLangueMessage('', '<ROSE>\xe2\x80\xa2 [Modera\xc3\xa7\xc3\xa3o] $Message_Ban', this.playerName, str(hours), reason)
  2244.  
  2245.         this.server.disconnectIPAddress(this.ipAddress)
  2246.         return
  2247.  
  2248.     def sendPlayerEmote(this, emoteID, flag, others, lua):
  2249.         packet = ByteArray().writeInt(this.playerCode).writeByte(emoteID)
  2250.         if not flag == '':
  2251.             packet.writeUTF(flag)
  2252.         this.room.sendAllOthers(this, Identifiers.send.Player_Emote, packet.writeBoolean(lua).toByteArray()) if others else this.room.sendAll(Identifiers.send.Player_Emote, packet.writeBoolean(lua).toByteArray())
  2253.  
  2254.     def sendEmotion(this, emotion):
  2255.         this.room.sendAllOthers(this, Identifiers.send.Emotion, ByteArray().writeInt(this.playerCode).writeByte(emotion).toByteArray())
  2256.  
  2257.     def sendPlaceObject(this, objectID, code, px, py, angle, vx, vy, dur, sendAll):
  2258.         packet = ByteArray().writeInt(objectID).writeShort(code).writeShort(px).writeShort(py).writeShort(angle).writeByte(vx).writeByte(vy).writeBoolean(dur)
  2259.         if this.isGuest or sendAll:
  2260.             packet.writeByte(0)
  2261.         else:
  2262.             packet.writeBytes(this.parseShop.getShamanItemCustom(code))
  2263.         if not sendAll:
  2264.             this.room.sendAllOthers(this, Identifiers.send.Spawn_Object, packet.toByteArray())
  2265.             this.room.objectID = objectID
  2266.         else:
  2267.             this.room.sendAll(Identifiers.send.Spawn_Object, packet.toByteArray())
  2268.  
  2269.     def sendPlaceObjectDeath(this, objectID, code, px, py, angle, vx, vy, dur, sendAll):
  2270.         if this.PlayerDeathVivo:
  2271.             packet = ByteArray().writeInt(objectID).writeShort(code).writeShort(px).writeShort(py).writeShort(angle).writeByte(vx).writeByte(vy).writeBoolean(dur)
  2272.             if this.isGuest or sendAll:
  2273.                 packet.writeByte(0)
  2274.             else:
  2275.                 packet.writeBytes(this.parseShop.getShamanItemCustom(code))
  2276.             if not sendAll:
  2277.                 this.room.sendAllOthers(this, Identifiers.send.Spawn_Object, packet.toByteArray())
  2278.                 this.room.objectID = objectID
  2279.             else:
  2280.                 this.room.sendAll(Identifiers.send.Spawn_Object, packet.toByteArray())
  2281.         else:
  2282.             this.room.objectID = 1
  2283.             this.room.removeObject(objectID)
  2284.  
  2285.     def sendTotem(this, totem, x, y, playerCode):
  2286.         this.sendPacket(Identifiers.old.send.Totem, ['%s#%s#%s%s' % (playerCode,
  2287.           x,
  2288.           y,
  2289.           totem)])
  2290.  
  2291.     def sendTotemItemCount(this, number):
  2292.         if this.room.isTotemEditor:
  2293.             this.sendPacket(Identifiers.send.Totem_Item_Count, ByteArray().writeShort(number * 2).toByteArray())
  2294.  
  2295.     def initTotemEditor(this):
  2296.         if this.resetTotem:
  2297.             this.sendTotemItemCount(0)
  2298.             this.resetTotem = False
  2299.         elif not this.totem[1] == '':
  2300.             this.tempTotem[0] = this.totem[0]
  2301.             this.tempTotem[1] = this.totem[1]
  2302.             this.sendTotemItemCount(this.tempTotem[0])
  2303.             this.sendTotem(this.tempTotem[1], 400, 204, this.playerCode)
  2304.         else:
  2305.             this.sendTotemItemCount(0)
  2306.  
  2307.     def sendShamanType(this, mode, canDivine):
  2308.         this.sendPacket(Identifiers.send.Shaman_Type, ByteArray().writeByte(mode).writeBoolean(canDivine).writeInt(int(this.shamanColor, 16)).toByteArray())
  2309.  
  2310.     def sendBanConsideration(this):
  2311.         this.sendPacket(Identifiers.old.send.Ban_Consideration, ['0'])
  2312.  
  2313.     def sendShamanPosition(this, direction):
  2314.         this.room.sendAll(Identifiers.send.Shaman_Position, ByteArray().writeInt(this.playerCode).writeBoolean(direction).toByteArray())
  2315.  
  2316.     def sendLangueMessage(this, community, message, *args):
  2317.         packet = ByteArray().writeUTF(community).writeUTF(message).writeByte(len(args))
  2318.         for arg in args:
  2319.             packet.writeUTF(arg)
  2320.  
  2321.         this.sendPacket(Identifiers.send.Message_Langue, packet.toByteArray())
  2322.  
  2323.     def sendMessageLangueError(this):
  2324.         this.sendPacket([28, 28], ByteArray().writeShort(1).toByteArray())
  2325.  
  2326.     def sendMessageLangue(this, message1, message2, *args):
  2327.         p = ByteArray().writeUTF(message1).writeUTF(message2).writeByte(len(args))
  2328.         for arg in args:
  2329.             p.writeUTF(arg)
  2330.  
  2331.         this.sendPacket([28, 5], p.toByteArray())
  2332.  
  2333.     def sendModMute(this, playerName, hours, reason, only):
  2334.         if not only:
  2335.             this.room.sendMessage('', '<ROSE>\xe2\x80\xa2 [Modera\xc3\xa7\xc3\xa3o] $MuteInfo2', playerName, playerName, hours, reason)
  2336.         else:
  2337.             client = this.server.players.get(playerName)
  2338.             if client:
  2339.                 client.sendLangueMessage('', '<ROSE>\xe2\x80\xa2 [Modera\xc3\xa7\xc3\xa3o] $MuteInfo1', hours, reason)
  2340.  
  2341.     def sendVampireMode(this, others):
  2342.         this.isVampire = True
  2343.         if others:
  2344.             this.room.sendAllOthers(this, Identifiers.send.Vampire_Mode, ByteArray().writeInt(this.playerCode).toByteArray())
  2345.         else:
  2346.             this.room.sendAll(Identifiers.send.Vampire_Mode, ByteArray().writeInt(this.playerCode).toByteArray())
  2347.  
  2348.     def sendRemoveCheese(this):
  2349.         this.room.sendAll(Identifiers.send.Remove_Cheese, ByteArray().writeInt(this.playerCode).toByteArray())
  2350.  
  2351.     def sendLuaMessage(this, message):
  2352.         this.sendPacket(Identifiers.send.Lua_Message, ByteArray().writeUTF(message).toByteArray())
  2353.  
  2354.     def sendGameMode(this, mode):
  2355.         try:
  2356.             mode = 1 if mode == 0 else mode
  2357.             types = [1,
  2358.              3,
  2359.              8,
  2360.              9,
  2361.              11,
  2362.              2,
  2363.              10,
  2364.              18,
  2365.              16]
  2366.             p = ByteArray().writeByte(len(types))
  2367.             for roomType in types:
  2368.                 p.writeByte(roomType)
  2369.  
  2370.             p.writeByte(mode)
  2371.             modeInfo = this.server.getPlayersCountMode(mode, this.langue)
  2372.             if not modeInfo[0] == '':
  2373.                 roomsCount = 0
  2374.                 p.writeUnsignedByte(1).writeUnsignedByte(this.langueID).writeUTF(str(modeInfo[0])).writeUTF(str(modeInfo[1])).writeUTF('mjj').writeUTF('1')
  2375.                 for checkRoom in this.server.rooms.values():
  2376.                     if (checkRoom.isNormRoom + checkRoom.isTribeHouse + checkRoom.isVillage + checkRoom.isPokeLua + checkRoom.isTribewar + checkRoom.isExplosionGame + checkRoom.isBallonRace + checkRoom.isFlyGame + checkRoom.isDeathmatch + checkRoom.isTotemEditor + checkRoom.isDoubleMap + checkRoom.isVanilla + checkRoom.isSurvivor + checkRoom.isRacing + checkRoom.isMusic + checkRoom.isBootcamp + checkRoom.isDefilante if mode == 1 else (checkRoom.isVanilla if mode == 3 else (checkRoom.isSurvivor if mode == 8 else (checkRoom.isRacing if mode == 9 else (checkRoom.isMusic if mode == 11 else (checkRoom.isBootcamp if mode == 2 else (checkRoom.isVillage if mode == 16 else checkRoom.isDefilante))))))) and checkRoom.community == this.langue.lower():
  2377.                         roomsCount += 1
  2378.                         p.writeUnsignedByte(0).writeUnsignedByte(this.langueID).writeUTF(checkRoom.roomName).writeUnsignedShort(checkRoom.getPlayerCount()).writeUnsignedByte(checkRoom.maxPlayers).writeBoolean(False)
  2379.  
  2380.                 if roomsCount == 0:
  2381.                     p.writeUnsignedByte(0).writeUnsignedByte(this.langueID).writeUTF(('' if mode == 1 else str(modeInfo[0].split(' ')[1])) + '1').writeUnsignedShort(0).writeUnsignedByte(200).writeBoolean(False)
  2382.             else:
  2383.                 minigamesList = {}
  2384.                 minigames = ['#eventoaventura',
  2385.                  '#fly',
  2386.                  '#ballonrace',
  2387.                  '#invocation',
  2388.                  '#explosion',
  2389.                  '#pokelua',
  2390.                  '#deathmatch',
  2391.                  '#tribewar']
  2392.                 roomsList = {}
  2393.                 for minigame in minigames:
  2394.                     minigamesList[minigame] = 0
  2395.                     for checkRoom in this.server.rooms.values():
  2396.                         if checkRoom.roomName == minigame:
  2397.                             minigamesList[minigame] = minigamesList[minigame] + checkRoom.getPlayerCount()
  2398.                         elif checkRoom.roomName.startswith(minigame) and checkRoom.community == this.langue.lower():
  2399.                             roomsList[checkRoom.roomName] = [checkRoom.getPlayerCount(), checkRoom.maxPlayers]
  2400.  
  2401.                 for minigame, count in minigamesList.items():
  2402.                     p.writeUnsignedByte(1).writeUnsignedByte(this.langueID).writeUTF(str(minigame)).writeUTF(str(count)).writeUTF('mjj').writeUTF(minigame)
  2403.  
  2404.                 for minigame, count in roomsList.items():
  2405.                     p.writeUnsignedByte(0).writeUnsignedByte(this.langueID).writeUTF(minigame).writeShort(count[0]).writeUnsignedByte(count[1]).writeBoolean(False)
  2406.  
  2407.             this.sendPacket(Identifiers.send.Game_Mode, p.toByteArray())
  2408.         except:
  2409.             this.transport.loseConnection()
  2410.  
  2411.     def sendStaffMessage(this, message, othersLangues, tab = False):
  2412.         for client in this.server.players.values():
  2413.             if othersLangues or client.langue == this.langue:
  2414.                 client.sendMessage(message, tab)
  2415.  
  2416.     def sendBulle(this):
  2417.         this.sendPacket(Identifiers.send.Bulle, ByteArray().writeInt(0).writeUTF('x').toByteArray())
  2418.  
  2419.     def sendLogMessage(this, message):
  2420.         this.sendPacket(Identifiers.send.Log_Message, ByteArray().writeByte(0).writeUTF('').writeUnsignedByte(len(message) >> 16 & 255).writeUnsignedByte(len(message) >> 8 & 255).writeUnsignedByte(len(message) & 255).writeBytes(message).toByteArray())
  2421.  
  2422.     def sendAnimZelda(this, type, item = 0, case = '', id = 0):
  2423.         packet = ByteArray().writeInt(this.playerCode).writeByte(type)
  2424.         if type == 7:
  2425.             packet.writeUTF(case).writeUnsignedByte(id)
  2426.         elif type == 5:
  2427.             packet.writeUTF(case)
  2428.         else:
  2429.             packet.writeInt(item)
  2430.         this.room.sendAll(Identifiers.send.Anim_Zelda, packet.toByteArray())
  2431.  
  2432.     def sendAnimZeldaInventory(this, id1, id2, count):
  2433.         if id1 == 4:
  2434.             this.sendPacket([100, 67], ByteArray().writeByte(0).writeShort(id2).writeShort(count).toByteArray())
  2435.         this.room.sendAll([8, 44], ByteArray().writeInt(this.playerCode).writeByte(id1).writeInt(id2).toByteArray())
  2436.  
  2437.     def checkElection(this, fur):
  2438.         this.Cursor.execute('SELECT fur from election WHERE name = ?', [this.playerName])
  2439.         rrf = this.Cursor.fetchone()
  2440.         if rrf is None:
  2441.             pass
  2442.         elif this.server.election == 0:
  2443.             this.Cursor.execute('UPDATE election SET fur = ? WHERE name = ?', [fur, this.playerName])
  2444.         return
  2445.  
  2446.     def sendSelectPresidente(this):
  2447.         this.Cursor.execute('SELECT name FROM election WHERE rank = ? ORDER BY votes DESC LIMIT 1', [1])
  2448.         rrf = this.Cursor.fetchone()
  2449.         if rrf is None:
  2450.             pass
  2451.         else:
  2452.             name = rrf[0]
  2453.             this.Cursor.execute('SELECT Mayor FROM users WHERE Username = ?', [name])
  2454.             rrf2 = this.Cursor.fetchone()[0]
  2455.             votemayor, candidatar, mayor, presidente, votepresidente, addpresidente = rrf2.split('#')
  2456.             presidente = '1'
  2457.             a = '#'.join([votemayor,
  2458.              candidatar,
  2459.              mayor,
  2460.              presidente,
  2461.              votepresidente,
  2462.              addpresidente])
  2463.             this.Cursor.execute('UPDATE users SET Mayor = ? WHERE Username = ?', [a, name])
  2464.             this.Cursor.execute('UPDATE election SET presidente = ? WHERE name = ?', [1, name])
  2465.             this.server.presidente = 1
  2466.         this.sendMessage('<J>Presidente escolhido', True)
  2467.         return
  2468.  
  2469.     def sendSelectMayors(this):
  2470.         shop = this.server.shopList
  2471.         furs = [1]
  2472.         for item in shop:
  2473.             classes = item.split(',')
  2474.             if int(classes[0]) == 22:
  2475.                 furs.append(int(classes[1]))
  2476.  
  2477.         for fur in furs:
  2478.             this.Cursor.execute('SELECT name FROM election WHERE fur = ? AND rank = ? ORDER BY votes DESC LIMIT 1', [fur, 0])
  2479.             rrf = this.Cursor.fetchone()
  2480.             if rrf is None:
  2481.                 pass
  2482.             else:
  2483.                 name = rrf[0]
  2484.                 this.Cursor.execute('SELECT mayor FROM users WHERE Username = ?', [name])
  2485.                 rrf2 = this.Cursor.fetchone()[0]
  2486.                 votemayor, candidatar, mayor, presidente, votepresidente, addpresidente = rrf2.split('#')
  2487.                 mayor = '1'
  2488.                 a = '#'.join([votemayor,
  2489.                  candidatar,
  2490.                  mayor,
  2491.                  presidente,
  2492.                  votepresidente,
  2493.                  addpresidente])
  2494.                 this.Cursor.execute('UPDATE users SET Mayor = ? WHERE Username = ?', [a, name])
  2495.                 this.Cursor.execute('UPDATE election SET mayor = ? WHERE name = ?', [1, name])
  2496.                 fur = this.getLookUser(name).split(';')[0]
  2497.                 this.Cursor.execute('INSERT INTO election (name, fur, text1, text2, votes, rank, mayor, presidente) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', [name,
  2498.                  fur,
  2499.                  '',
  2500.                  '',
  2501.                  0,
  2502.                  1,
  2503.                  0,
  2504.                  0])
  2505.  
  2506.         this.server.election = 2
  2507.         this.sendMessage('<J>Prefeitos escolhidos', True)
  2508.         return
  2509.  
  2510.     def sendResetarElection(this):
  2511.         this.Cursor.execute('DELETE FROM election WHERE rank = ?', [0])
  2512.         this.Cursor.execute('SELECT name FROM election where presidente = ?', [1])
  2513.         presidente = this.Cursor.fetchone()[0]
  2514.         this.Cursor.execute('DELETE from election WHERE name != ?', [presidente])
  2515.         this.Cursor.execute('UPDATE users SET Mayor = ? where Username != ?', ['0#0#0#0#0#0', presidente])
  2516.         this.Cursor.execute('UPDATE users SET Mayor = ? WHERE Username = ?', ['0#0#0#1#0#0', presidente])
  2517.         this.server.election = 0
  2518.         this.server.presidente = 0
  2519.         this.sendMessage('<J>Elei\xc3\xa7\xc3\xa3o resetada', True)
  2520.  
  2521.     def sendResetarPresidente(this):
  2522.         this.Cursor.execute('SELECT name FROM election where presidente = ?', [1])
  2523.         presidente = this.Cursor.fetchone()[0]
  2524.         this.Cursor.execute('DELETE FROM election where rank = ?', [1])
  2525.         this.Cursor.execute('UPDATE users SET Mayor = ? where Username = ?', ['0#0#0#0#0#0', presidente])
  2526.         this.sendMessage('<J>Presidente resetado', True)
  2527.  
  2528.     def sendMayor(this):
  2529.         p = ByteArray().writeByte(this.server.election)
  2530.         fur = this.playerLook.split(';')[0]
  2531.         if this.server.election == 0:
  2532.             if this.votemayor == 0:
  2533.                 p.writeByte(1)
  2534.             else:
  2535.                 p.writeByte(0)
  2536.             if this.candidatar == 0:
  2537.                 p.writeByte(1)
  2538.             else:
  2539.                 p.writeByte(0)
  2540.             time = '1-1'
  2541.             p.writeUTF(time)
  2542.             this.Cursor.execute('SELECT * FROM election WHERE rank = ? AND presidente = ?', [1, 1])
  2543.             rrf = this.Cursor.fetchone()
  2544.             if rrf is None:
  2545.                 p.writeByte(0)
  2546.             else:
  2547.                 name = rrf[0]
  2548.                 text1 = rrf[2]
  2549.                 text2 = rrf[3]
  2550.                 votes = rrf[4]
  2551.                 look = this.getLookUser(name)
  2552.                 furlook = look.split(';')[0]
  2553.                 p.writeByte(1)
  2554.                 p.writeUTF(name)
  2555.                 p.writeByte(2)
  2556.                 p.writeInt(furlook)
  2557.                 p.writeInt(votes)
  2558.                 p.writeByte(0)
  2559.                 p.writeUTF(look)
  2560.                 p.writeUTF(text1)
  2561.                 p.writeUTF(text2)
  2562.             this.Cursor.execute('SELECT * FROM election WHERE fur = ? AND rank = ?', [fur, 0])
  2563.             rrfs = this.Cursor.fetchall()
  2564.             if len(rrfs) == 0:
  2565.                 pass
  2566.             else:
  2567.                 for rrf in rrfs:
  2568.                     name = rrf[0]
  2569.                     text1 = rrf[2]
  2570.                     text2 = rrf[3]
  2571.                     votes = rrf[4]
  2572.                     look = this.getLookUser(name)
  2573.                     furlook = look.split(';')[0]
  2574.                     p.writeByte(1)
  2575.                     p.writeUTF(name)
  2576.                     p.writeByte(1)
  2577.                     p.writeInt(furlook)
  2578.                     p.writeInt(votes)
  2579.                     p.writeByte(0)
  2580.                     p.writeUTF(look)
  2581.                     p.writeUTF(text1)
  2582.                     p.writeUTF(text2)
  2583.  
  2584.             this.sendPacket([100, 80], p.toByteArray())
  2585.         elif this.server.election == 2:
  2586.             if this.isMayor == 1 and this.server.presidente == 0:
  2587.                 this.sendPresidente()
  2588.             else:
  2589.                 p.writeShort(0)
  2590.                 time = 'you like-my dick for'
  2591.                 p.writeUTF(time)
  2592.                 this.Cursor.execute('SELECT * FROM election WHERE fur = ? AND rank = ? AND mayor = ?', [fur, 0, 1])
  2593.                 rrf = this.Cursor.fetchone()
  2594.                 nonemayor = False
  2595.                 if rrf is None:
  2596.                     p.writeByte(0)
  2597.                     nonemayor = True
  2598.                 else:
  2599.                     name = rrf[0]
  2600.                     text1 = rrf[2]
  2601.                     text2 = rrf[3]
  2602.                     votes = rrf[4]
  2603.                     look = this.getLookUser(name)
  2604.                     furlook = look.split(';')[0]
  2605.                     p.writeByte(1)
  2606.                     p.writeUTF(name)
  2607.                     p.writeByte(1)
  2608.                     p.writeInt(furlook)
  2609.                     p.writeInt(votes)
  2610.                     p.writeByte(0)
  2611.                     p.writeUTF(look)
  2612.                     p.writeUTF(text1)
  2613.                     p.writeUTF(text2)
  2614.                 this.Cursor.execute('SELECT * FROM election WHERE rank = ? AND presidente = ?', [1, 1])
  2615.                 rrf = this.Cursor.fetchone()
  2616.                 if rrf is None:
  2617.                     p.writeByte(0)
  2618.                 else:
  2619.                     name = rrf[0]
  2620.                     text1 = rrf[2]
  2621.                     text2 = rrf[3]
  2622.                     votes = rrf[4]
  2623.                     look = this.getLookUser(name)
  2624.                     furlook = look.split(';')[0]
  2625.                     p.writeByte(1)
  2626.                     p.writeUTF(name)
  2627.                     p.writeByte(1)
  2628.                     p.writeInt(furlook)
  2629.                     p.writeInt(votes)
  2630.                     p.writeByte(0)
  2631.                     p.writeUTF(look)
  2632.                     p.writeUTF(text1)
  2633.                     p.writeUTF(text2)
  2634.                 this.sendPacket([100, 80], p.toByteArray())
  2635.         return
  2636.  
  2637.     def sendPresidente(this):
  2638.         p = ByteArray().writeByte(1)
  2639.         fur = this.playerLook.split(';')[0]
  2640.         if this.votepresidente == 0:
  2641.             p.writeByte(1)
  2642.         else:
  2643.             p.writeByte(0)
  2644.         p.writeByte(0)
  2645.         time = 'you like-my dick for'
  2646.         p.writeUTF(time)
  2647.         this.Cursor.execute('SELECT * FROM election WHERE fur = ? AND rank = ? AND mayor = ?', [fur, 0, 1])
  2648.         rrf = this.Cursor.fetchone()
  2649.         nonemayor = False
  2650.         if rrf is None:
  2651.             p.writeByte(0)
  2652.             nonemayor = True
  2653.         else:
  2654.             name = rrf[0]
  2655.             text1 = rrf[2]
  2656.             text2 = rrf[3]
  2657.             votes = rrf[4]
  2658.             look = this.getLookUser(name)
  2659.             furlook = look.split(';')[0]
  2660.             p.writeByte(1)
  2661.             p.writeUTF(name)
  2662.             p.writeByte(1)
  2663.             p.writeInt(furlook)
  2664.             p.writeInt(votes)
  2665.             p.writeByte(0)
  2666.             p.writeUTF(look)
  2667.             p.writeUTF(text1)
  2668.             p.writeUTF(text2)
  2669.         this.Cursor.execute('SELECT * FROM election WHERE rank = ?', [1])
  2670.         rrfs = this.Cursor.fetchall()
  2671.         if len(rrfs) == 0:
  2672.             pass
  2673.         else:
  2674.             for rrf in rrfs:
  2675.                 name = rrf[0]
  2676.                 text1 = rrf[2]
  2677.                 text2 = rrf[3]
  2678.                 votes = rrf[4]
  2679.                 look = this.getLookUser(name)
  2680.                 furlook = look.split(';')[0]
  2681.                 p.writeByte(1)
  2682.                 p.writeUTF(name)
  2683.                 p.writeByte(1)
  2684.                 p.writeInt(furlook)
  2685.                 p.writeInt(votes)
  2686.                 p.writeByte(0)
  2687.                 p.writeUTF(look)
  2688.                 p.writeUTF(text1)
  2689.                 p.writeUTF(text2)
  2690.  
  2691.         this.sendPacket([100, 80], p.toByteArray())
  2692.         return
  2693.  
  2694.     def getLookUser(this, name):
  2695.         for room in this.server.rooms.values():
  2696.             for client in room.clients.values():
  2697.                 if client.playerName == name:
  2698.                     return client.playerLook
  2699.  
  2700.         this.Cursor.execute('SELECT Look FROM users WHERE Username = ?', [name])
  2701.         return this.Cursor.fetchone()[0]
  2702.  
  2703.     def sendInventoryConsumables(this):
  2704.         packet = ByteArray().writeShort(len(this.playerConsumables))
  2705.         for id in this.playerConsumables.items():
  2706.             packet.writeShort(id[0]).writeUnsignedByte(250 if id[1] > 250 else id[1]).writeByte(0).writeBoolean(True).writeBoolean(True).writeBoolean(True).writeBoolean(True).writeBoolean(True).writeBoolean(False).writeBoolean(False).writeByte(this.equipedConsumables.index(id[0]) + 1 if id[0] in this.equipedConsumables else 0)
  2707.  
  2708.         this.sendPacket(Identifiers.send.Inventory, packet.toByteArray())
  2709.  
  2710.     def updateInventoryConsumable(this, id, count):
  2711.         this.sendPacket(Identifiers.send.Update_Inventory_Consumable, ByteArray().writeShort(id).writeUnsignedByte(250 if count > 250 else count).toByteArray())
  2712.  
  2713.     def useInventoryConsumable(this, id):
  2714.         if id in (29, 30, 2241, 2330):
  2715.             this.sendPacket(Identifiers.send.Use_Inventory_Consumable, ByteArray().writeInt(this.playerCode).writeShort(id).toByteArray())
  2716.         else:
  2717.             this.room.sendAll(Identifiers.send.Use_Inventory_Consumable, ByteArray().writeInt(this.playerCode).writeShort(id).toByteArray())
  2718.  
  2719.     def sendTradeResult(this, playerName, result):
  2720.         this.sendPacket(Identifiers.send.Trade_Result, ByteArray().writeUTF(playerName).writeByte(result).toByteArray())
  2721.  
  2722.     def sendTradeInvite(this, playerCode):
  2723.         this.sendPacket(Identifiers.send.Trade_Invite, ByteArray().writeInt(playerCode).toByteArray())
  2724.  
  2725.     def sendTradeStart(this, playerCode):
  2726.         this.sendPacket(Identifiers.send.Trade_Start, ByteArray().writeInt(playerCode).toByteArray())
  2727.  
  2728.     def premioVillage(this, coisa):
  2729.         if coisa[0] == 1:
  2730.             medal = coisa[1]
  2731.             if this.playerConsumables[coisa[4]] >= coisa[5]:
  2732.                 if int(medal) not in this.shopBadges:
  2733.                     this.parseShop.sendUnlockedBadge(medal)
  2734.                     this.shopBadges.append(str(medal))
  2735.                     this.playerConsumables[coisa[4]] -= coisa[5]
  2736.         elif coisa[0] == 2:
  2737.             symbol = str(coisa[1])
  2738.             if symbol not in this.shamanBadges:
  2739.                 if this.shamanBadges == '':
  2740.                     this.shamanBadges = [symbol]
  2741.                 else:
  2742.                     test = [symbol]
  2743.                     this.shamanBadges = this.shamanBadges + test
  2744.                 this.playerConsumables[coisa[4]] -= coisa[5]
  2745.                 this.sendAnimZeldaInventory(6, coisa[1], 1)
  2746.         elif coisa[0] == 3:
  2747.             titles = [str(coisa[1]) + '.1']
  2748.             title = random.choice(titles)
  2749.             if this.playerConsumables[coisa[4]] >= coisa[5]:
  2750.                 while title in this.titleList:
  2751.                     try:
  2752.                         titles.remove(title)
  2753.                         title = random.choice(titles)
  2754.                     except:
  2755.                         break
  2756.  
  2757.                 if title not in this.titleList:
  2758.                     stitle = title.split('.')
  2759.                     this.specialTitleList = this.specialTitleList + [float(title)]
  2760.                     this.sendUnlockedTitle(stitle[0], stitle[1])
  2761.                     this.sendCompleteTitleList()
  2762.                     this.sendTitleList()
  2763.                     this.playerConsumables[coisa[4]] -= coisa[5]
  2764.         elif coisa[0] == 4:
  2765.             if this.playerConsumables[coisa[4]] >= coisa[5]:
  2766.                 id = coisa[1]
  2767.                 if id not in this.playerConsumables:
  2768.                     this.playerConsumables[id] = coisa[2]
  2769.                 else:
  2770.                     count = this.playerConsumables[id] + coisa[2]
  2771.                     this.playerConsumables[id] = count
  2772.                 this.playerConsumables[coisa[4]] -= coisa[5]
  2773.                 this.sendAnimZeldaInventory(4, id, coisa[2])
  2774.         this.BotsVillage(this.botVillage)
  2775.  
  2776.     def BotsVillage(this, bot):
  2777.         itens = list()
  2778.         for item in this.itensBots[bot]:
  2779.             if item[0] == 1 and str(item[1]) in this.shopBadges:
  2780.                 itens.append(item)
  2781.             elif item[0] == 2 and str(item[1]) in this.shamanBadges:
  2782.                 itens.append(item)
  2783.             elif item[0] == 3 and float(str(item[1]) + '.1') in this.titleList:
  2784.                 itens.append(item)
  2785.  
  2786.         for item in itens:
  2787.             this.itensBots[bot].remove(item)
  2788.  
  2789.         p = ByteArray()
  2790.         for items in this.itensBots[bot]:
  2791.             count = items[5]
  2792.             if items[4] in this.playerConsumables:
  2793.                 one = 0 if this.playerConsumables[items[4]] >= count else 1
  2794.             else:
  2795.                 one = 1
  2796.             p.writeByte(one).writeByte(items[0]).writeShort(items[1]).writeShort(items[2]).writeByte(items[3]).writeShort(items[4]).writeShort(items[5])
  2797.  
  2798.         this.sendPacket([26, 38], ByteArray().writeUTF(bot).writeByte(len(this.itensBots[bot])).toByteArray() + p.toByteArray())
  2799.  
  2800.     def tradeInvite(this, playerName):
  2801.         client = this.room.clients.get(playerName)
  2802.         if client != None and (not this.ipAddress == client.ipAddress or this.privLevel == 10 or client.privLevel == 11) and this.privLevel != 0 and client.privLevel != 0:
  2803.             if not client.isTrade:
  2804.                 if not client.room.name == this.room.name:
  2805.                     this.sendTradeResult(playerName, 3)
  2806.                 elif client.isTrade:
  2807.                     this.sendTradeResult(playerName, 0)
  2808.                 else:
  2809.                     this.sendLangueMessage('', '$Demande_Envoy\xc3\xa9e')
  2810.                     client.sendTradeInvite(this.playerCode)
  2811.                 this.tradeName = playerName
  2812.                 this.isTrade = True
  2813.             else:
  2814.                 this.tradeName = playerName
  2815.                 this.isTrade = True
  2816.                 this.sendTradeStart(client.playerCode)
  2817.                 client.sendTradeStart(this.playerCode)
  2818.         return
  2819.  
  2820.     def cancelTrade(this, playerName):
  2821.         client = this.room.clients.get(playerName)
  2822.         if client != None:
  2823.             this.tradeName = ''
  2824.             this.isTrade = False
  2825.             this.tradeConsumables = {}
  2826.             this.tradeConfirm = False
  2827.             client.tradeName = ''
  2828.             client.isTrade = False
  2829.             client.tradeConsumables = {}
  2830.             client.tradeConfirm = False
  2831.             client.sendTradeResult(this.playerName, 2)
  2832.         return
  2833.  
  2834.     def tradeAddConsumable(this, id, isAdd):
  2835.         client = this.room.clients.get(this.tradeName)
  2836.         if client != None and client.isTrade and client.tradeName == this.playerName:
  2837.             if isAdd:
  2838.                 if this.tradeConsumables.has_key(id):
  2839.                     this.tradeConsumables[id] += 1
  2840.                 else:
  2841.                     this.tradeConsumables[id] = 1
  2842.             else:
  2843.                 count = this.tradeConsumables[id] - 1
  2844.                 if count > 0:
  2845.                     this.tradeConsumables[id] = count
  2846.                 else:
  2847.                     del this.tradeConsumables[id]
  2848.             client.sendPacket(Identifiers.send.Trade_Add_Consumable, ByteArray().writeBoolean(False).writeShort(id).writeBoolean(isAdd).writeByte(1).writeBoolean(False).toByteArray())
  2849.             this.sendPacket(Identifiers.send.Trade_Add_Consumable, ByteArray().writeBoolean(True).writeShort(id).writeBoolean(isAdd).writeByte(1).writeBoolean(False).toByteArray())
  2850.         return
  2851.  
  2852.     def tradeResult(this, isAccept):
  2853.         client = this.room.clients.get(this.tradeName)
  2854.         if client != None and client.isTrade and client.tradeName == this.playerName:
  2855.             this.tradeConfirm = isAccept
  2856.             client.sendPacket(Identifiers.send.Trade_Confirm, ByteArray().writeBoolean(False).writeBoolean(isAccept).toByteArray())
  2857.             this.sendPacket(Identifiers.send.Trade_Confirm, ByteArray().writeBoolean(True).writeBoolean(isAccept).toByteArray())
  2858.             if this.tradeConfirm and client.tradeConfirm:
  2859.                 for consumable in client.tradeConsumables.items():
  2860.                     if this.playerConsumables.has_key(consumable[0]):
  2861.                         this.playerConsumables[consumable[0]] += consumable[1]
  2862.                     else:
  2863.                         this.playerConsumables[consumable[0]] = consumable[1]
  2864.                     count = client.playerConsumables[consumable[0]] - consumable[1]
  2865.                     if count <= 0:
  2866.                         del client.playerConsumables[consumable[0]]
  2867.                         if consumable[0] in client.equipedConsumables:
  2868.                             client.equipedConsumables.remove(consumable[0])
  2869.                     else:
  2870.                         client.playerConsumables[consumable[0]] = count
  2871.  
  2872.                 for consumable in this.tradeConsumables.items():
  2873.                     if client.playerConsumables.has_key(consumable[0]):
  2874.                         client.playerConsumables[consumable[0]] += consumable[1]
  2875.                     else:
  2876.                         client.playerConsumables[consumable[0]] = consumable[1]
  2877.                     count = this.playerConsumables[consumable[0]] - consumable[1]
  2878.                     if count <= 0:
  2879.                         del this.playerConsumables[consumable[0]]
  2880.                         if consumable[0] in this.equipedConsumables:
  2881.                             this.equipedConsumables.remove(consumable[0])
  2882.                     else:
  2883.                         this.playerConsumables[consumable[0]] = count
  2884.  
  2885.                 client.tradeName = ''
  2886.                 client.isTrade = False
  2887.                 client.tradeConsumables = {}
  2888.                 client.tradeConfirm = False
  2889.                 client.sendPacket(Identifiers.send.Trade_Close)
  2890.                 client.sendInventoryConsumables()
  2891.                 this.tradeName = ''
  2892.                 this.isTrade = False
  2893.                 this.tradeConsumables = {}
  2894.                 this.tradeConfirm = False
  2895.                 this.sendPacket(Identifiers.send.Trade_Close)
  2896.                 this.sendInventoryConsumables()
  2897.         return
  2898.  
  2899.     def sendGiveConsumables(this, id, amount = 80, limit = 80):
  2900.         this.sendAnimZelda(4, id)
  2901.         this.sendNewConsumable(id, amount)
  2902.         sum = (this.playerConsumables[id] if this.playerConsumables.has_key(id) else 0) + amount
  2903.         if limit != -1 and sum > limit:
  2904.             sum = limit
  2905.         if this.playerConsumables.has_key(id):
  2906.             this.playerConsumables[id] = sum
  2907.             this.updateInventoryConsumable(id, sum)
  2908.         else:
  2909.             this.playerConsumables[id] = sum
  2910.             this.updateInventoryConsumable(id, sum)
  2911.  
  2912.     def sendNewConsumable(this, consumable, count):
  2913.         this.sendPacket(Identifiers.send.New_Consumable, ByteArray().writeByte(0).writeShort(consumable).writeShort(count).toByteArray())
  2914.  
  2915.     def getFullItemID(this, category, itemID):
  2916.         if itemID >= 100:
  2917.             return itemID + 10000 + 1000 * category
  2918.         return itemID + 100 * category
  2919.  
  2920.     def getSimpleItemID(this, category, itemID):
  2921.         if itemID >= 10000:
  2922.             return itemID - 10000 - 1000 * category
  2923.         return itemID - 100 * category
  2924.  
  2925.     def getItemInfo(this, category, itemID):
  2926.         shop = map(lambda x: map(int, x.split(',')), this.server.shopList)
  2927.         return filter(lambda x: x[0] == category and x[1] == itemID, shop)[0] + ([20] if category != 22 else [0])
  2928.  
  2929.  
  2930. class Server(protocol.ServerFactory):
  2931.     protocol = Client
  2932.  
  2933.     def __init__(this):
  2934.         this.ac_config = open('./cheat/anticheat_config.txt', 'r').read()
  2935.         this.ac_enabled = True
  2936.         this.ac_c = json.loads(this.ac_config)
  2937.         this.learning = this.ac_c['learning']
  2938.         this.bantimes = this.ac_c['ban_times']
  2939.         this.s_list = open('./cheat/anticheat_allow', 'r').read()
  2940.         if this.s_list != '':
  2941.             this.s_list = this.s_list.split(',')
  2942.             this.s_list.remove('')
  2943.         else:
  2944.             this.s_list = []
  2945.         this.miceName = str(this.config('game.miceName'))
  2946.         this.isDebug = bool(int(this.config('game.debug')))
  2947.         this.adventureIMG = this.config('game.adventureIMG')
  2948.         this.lastChatID = int(this.config('ids.lastChatID'))
  2949.         this.serverURL = this.config('server.url').split(', ')
  2950.         this.adventureID = int(this.config('game.adventureID'))
  2951.         this.needToFirst = int(this.config('game.needToFirst'))
  2952.         this.lastPlayerID = int(this.config('ids.lastPlayerID'))
  2953.         this.initialCheeses = int(this.config('game.initialCheeses'))
  2954.         this.initialFraises = int(this.config('game.initialFraises'))
  2955.         this.EmailAddress = this.config('game.email')
  2956.         this.recordPlayers = int(this.config('game.Record'))
  2957.         this.lastMapEditeurCode = int(this.config('game.lastMapCodeId'))
  2958.         this.timeEvent = int(this.config('game.timeevent'))
  2959.         this.calendarioSystem = eval(this.config('game.calendario'))
  2960.         this.calendarioCount = eval(this.config('game.calendarioCount'))
  2961.         this.newVisuList = eval(this.configShop('shop.visuDone'))
  2962.         this.election = int(this.config('election.election'))
  2963.         this.presidente = int(this.config('election.presidente'))
  2964.         this.electionTime = int(this.config('election.time'))
  2965.         this.shopList = this.configShop('shop.shopList').split(';')
  2966.         this.shamanShopList = this.configShop('shop.shamanShopList').split(';')
  2967.         this.STARTTIME = datetime.today()
  2968.         this.lastGiftID = 0
  2969.         this.lastPlayerCode = 0
  2970.         this.startServer = datetime.today()
  2971.         this.activeStaffChat = 0
  2972.         this.rebootTimer = None
  2973.         this.rankingTimer = None
  2974.         this.packetKeys = [0,
  2975.          26,
  2976.          37,
  2977.          36,
  2978.          24,
  2979.          59,
  2980.          22,
  2981.          35,
  2982.          56,
  2983.          34,
  2984.          121,
  2985.          120,
  2986.          68,
  2987.          103,
  2988.          114,
  2989.          71,
  2990.          92,
  2991.          70,
  2992.          113,
  2993.          112]
  2994.         this.loginKeys = [5204292,
  2995.          13207023,
  2996.          1024,
  2997.          2097152,
  2998.          1024,
  2999.          2543425,
  3000.          10182091,
  3001.          16280609,
  3002.          16384,
  3003.          67108864,
  3004.          13037573,
  3005.          8858369,
  3006.          2597112]
  3007.         this.tempIPBanList = []
  3008.         this.userMuteCache = []
  3009.         this.shopPromotions = []
  3010.         this.IPTempBanCache = []
  3011.         this.IPPermaBanCache = []
  3012.         this.userTempBanCache = []
  3013.         this.userPermaBanCache = []
  3014.         this.staffChat = []
  3015.         this.ranking = [{},
  3016.          {},
  3017.          {},
  3018.          {}]
  3019.         this.rankingsList = [{},
  3020.          {},
  3021.          {},
  3022.          {}]
  3023.         this.rooms = {}
  3024.         this.players = {}
  3025.         this.shopGifts = {}
  3026.         this.vanillaMaps = {}
  3027.         this.chatMessages = {}
  3028.         this.shopListCheck = {}
  3029.         this.connectedCounts = {}
  3030.         this.reports = {'names': []}
  3031.         this.shamanShopListCheck = {}
  3032.         this.statsclient = {'racingCount': [1500,
  3033.                          10000,
  3034.                          10000,
  3035.                          10000],
  3036.          'survivorCount': [1000,
  3037.                            800,
  3038.                            20000,
  3039.                            10000],
  3040.          'racingBadges': [124,
  3041.                           125,
  3042.                           126,
  3043.                           127],
  3044.          'survivorBadges''./include/files/infoSWF.json')
  3045.         this.captchaList = this.parseFile('./include/files/captchas.json')
  3046.         this.promotions = this.parseFile('./include/files/promotions.json')
  3047.         this.serverList = this.parseFile('./include/files/serverList.json')
  3048.         this.CursorCafe = CursorCafe
  3049.         this.parseFunctions()
  3050.         this.getVanillaMaps()
  3051.         this.parsePromotions()
  3052.         this.rankingTimer = reactor.callLater(1, this.getRanking)
  3053.         this.menu = this.parseMenu()
  3054.         this.resetDDoS = Cursor.execute('delete from ddos where ip')
  3055.         return None
  3056.  
  3057.     def checkMessage(this, client, message):
  3058.         blackList = this.serverList['blacklist']
  3059.         suspectWords = this.serverList['suspectwords']
  3060.         whiteList = this.serverList['whitelist']
  3061.         isSuspect = False
  3062.         i = 0
  3063.         while i < len(blackList):
  3064.             if re.search('[^a-zA-Z]*'.join(blackList[i]), message.lower()):
  3065.                 this.sendStaffMessage(7, '[<V>ANTI-DV</V>][<J>%s</J>][<V>%s</V>][<R>%s</R>] Est\xc3\xa1 enviando um link da blacklist, portanto esta mensagem n\xc3\xa3o aparece para outros jogadores.' % (client.ipAddress, client.playerName, message))
  3066.                 isSuspect = True
  3067.                 return True
  3068.             i += 1
  3069.  
  3070.         if not isSuspect:
  3071.             if filter(lambda word: word in message.lower(), suspectWords) and not filter(lambda white: white in message.lower(), whiteList):
  3072.                 this.sendStaffMessage(7, '[<V>ANTI-DV</V>][<J>%s</J>][<V>%s</V>][<J>%s</J>] Enviou uma mensagem suspeita com link, digite <V>/addtext blacklist link</V> para adicionar na <b>/blacklist</b> caso o link seja de outro servidor.' % (client.ipAddress, client.playerName, message))
  3073.         return False
  3074.  
  3075.     def getPointsColor(this, playerName, aventure, itemID, itemType, itemNeeded):
  3076.         for client in this.players.values():
  3077.             if client.playerName == playerName:
  3078.                 if int(itemID) in client.aventureCounts.keys():
  3079.                     if client.aventureCounts[int(itemID)][1] >= int(itemNeeded):
  3080.                         return 1
  3081.  
  3082.         return 0
  3083.  
  3084.     def getAventureCounts(this, playerName, aventure, itemID, itemType):
  3085.         for client in this.players.values():
  3086.             if client.playerName == playerName:
  3087.                 if int(itemID) in client.aventureCounts.keys():
  3088.                     return client.aventureCounts[int(itemID)][1]
  3089.  
  3090.         return 0
  3091.  
  3092.     def getAventureItems(this, playerName, aventure, itemType, itemID):
  3093.         c = 0
  3094.         for client in this.players.values():
  3095.             if client.playerName == playerName:
  3096.                 if aventure == 24:
  3097.                     if itemType == 0 and itemID == 1:
  3098.                         return client.aventureSaves
  3099.                     if itemType == 0 and itemID == 2:
  3100.                         for item in client.aventureCounts.keys():
  3101.                             if item in range(38, 44):
  3102.                                 c += client.aventureCounts[item][1]
  3103.  
  3104.                         return c
  3105.  
  3106.         return 0
  3107.  
  3108.     def parseFunctions(this):
  3109.         data = this.parseSWF
  3110.         this.CKEY = data['key']
  3111.         this.Version = data['version']
  3112.         for item in this.shopList:
  3113.             values = item.split(',')
  3114.             this.shopListCheck[values[0] + '|' + values[1]] = [int(values[5]), int(values[6])]
  3115.  
  3116.         for item in this.shamanShopList:
  3117.             values = item.split(',')
  3118.             this.shamanShopListCheck[values[0]] = [int(values[3]), int(values[4])]
  3119.  
  3120.         Cursor.execute('select ip from IPPermaBan')
  3121.         rs = Cursor.fetchone()
  3122.         if rs:
  3123.             this.IPPermaBanCache.append(rs['ip'])
  3124.         Cursor.execute('select Username from UserPermaBan')
  3125.         rs = Cursor.fetchone()
  3126.         if rs:
  3127.             this.userPermaBanCache.append(rs['Username'])
  3128.         Cursor.execute('select Username from UserTempBan')
  3129.         rs = Cursor.fetchone()
  3130.         if rs:
  3131.             this.userTempBanCache.append(rs['Username'])
  3132.         Cursor.execute('select Username from UserTempMute')
  3133.         rs = Cursor.fetchone()
  3134.         if rs:
  3135.             this.userMuteCache.append(rs['Username'])
  3136.  
  3137.     def config(this, setting):
  3138.         return config.get('configGame', setting, 0)
  3139.  
  3140.     def configShop(this, setting):
  3141.         return config.get('configShop', setting, 0)
  3142.  
  3143.     def configs(this, setting, value):
  3144.         config.set('configGame', setting, value)
  3145.         with open('./include/configs.properties', 'w') as f:
  3146.             config.write(f)
  3147.  
  3148.     def updateServerList(this):
  3149.         with open('./include/files/serverList.json', 'w') as f:
  3150.             f.write(str(this.serverList))
  3151.  
  3152.     def parseMenu(this):
  3153.         with open('./include/files/menu.json', 'r') as f:
  3154.             T = eval(f.read())
  3155.         return T
  3156.  
  3157.     def parseFile(this, directory):
  3158.         with open(directory, 'r') as f:
  3159.             return eval(f.read())
  3160.  
  3161.     def updateBlackList(this):
  3162.         with open('./include/files/serverList.json', 'w') as f:
  3163.             json.dump(this.serverList, f)
  3164.  
  3165.     def getVanillaMaps(this):
  3166.         for fileName in os.listdir('./include/maps/vanilla'):
  3167.             with open('./include/maps/vanilla/' + fileName) as f:
  3168.                 this.vanillaMaps[int(fileName[:-4])] = f.read()
  3169.  
  3170.     def sendServerRestart(this, no, sec):
  3171.         if sec > 0 or no != 5:
  3172.             this.sendServerRestartSEC(120 if no == 0 else (60 if no == 1 else (30 if no == 2 else (20 if no == 3 else (10 if no == 4 else sec)))))
  3173.             if this.rebootTimer != None:
  3174.                 this.rebootTimer.cancel()
  3175.             this.rebootTimer = reactor.callLater(60 if no == 0 else (30 if no == 1 else (10 if no == 2 or no == 3 else 1)), lambda : this.sendServerRestart(no if no == 5 else no + 1, 9 if no == 4 else (sec - 1 if no == 5 else 0)))
  3176.         return
  3177.  
  3178.     def sendServerRestartSEC(this, seconds):
  3179.         this.sendPanelRestartMessage(seconds)
  3180.         this.sendWholeServer(Identifiers.send.Server_Restart, ByteArray().writeInt(seconds * 1000).toByteArray())
  3181.  
  3182.     def sendPanelRestartMessage(this, seconds):
  3183.         if seconds == 120:
  3184.             print '[%s] [SERVER] The server will restart in 2 minutes.' % time.strftime('%H:%M:%S')
  3185.         elif seconds < 120 and seconds > 1:
  3186.             print '[%s] [SERVER] The server will restart in %s seconds.' % (time.strftime('%H:%M:%S'), seconds)
  3187.         else:
  3188.             print '[%s] [SERVER] The server will restart in 1 second.' % time.strftime('%H:%M:%S')
  3189.             for client in this.players.values():
  3190.                 client.updateDatabase()
  3191.  
  3192.             os._exit(0)
  3193.  
  3194.     def buildCaptchaCode(this):
  3195.         CC = ''.join([ random.choice(this.captchaList.keys()) for x in range(4) ])
  3196.         words, px, py, lines = (list(CC),
  3197.          0,
  3198.          1,
  3199.          [])
  3200.         for count in range(1, 17):
  3201.             wc, values = 1, []
  3202.             for word in words:
  3203.                 ws = this.captchaList[word]
  3204.                 if count > len(ws):
  3205.                     count = len(ws)
  3206.                 ws = ws[str(count)]
  3207.                 values += ws.split(',')[1 if wc > 1 else 0:]
  3208.                 wc += 1
  3209.  
  3210.             lines += [','.join(map(str, values))]
  3211.             if px < len(values):
  3212.                 px = len(values)
  3213.             py += 1
  3214.  
  3215.         return [CC,
  3216.          px + 2,
  3217.          17,
  3218.          lines]
  3219.  
  3220.     def checkAlreadyExistingGuest(this, playerName):
  3221.         if not playerName:
  3222.             playerName = 'Souris'
  3223.         if this.checkConnectedAccount(playerName):
  3224.             playerName += '_%s' % ''.join([ random.choice(string.ascii_lowercase) for x in range(4) ])
  3225.         return playerName
  3226.  
  3227.     def checkConnectedAccount(this, playerName):
  3228.         return this.players.has_key(playerName)
  3229.  
  3230.     def disconnectIPAddress(this, ip):
  3231.         for client in this.players.values():
  3232.             if client.ipAddress == ip:
  3233.                 client.transport.loseConnection()
  3234.  
  3235.     def checkExistingUser(this, playerName):
  3236.         Cursor.execute('select 1 from Users where Username = ?', [playerName])
  3237.         return Cursor.fetchone() != None
  3238.  
  3239.     def recommendRoom(this, langue, prefix = ''):
  3240.         count = 0
  3241.         result = ''
  3242.         while result == '':
  3243.             count += 1
  3244.             if this.rooms.has_key('%s-%s' % (langue, count) if prefix == '' else '%s-%s%s' % (langue, prefix, count)):
  3245.                 if this.rooms['%s-%s' % (langue, count) if prefix == '' else '%s-%s%s' % (langue, prefix, count)].getPlayerCount() < 25:
  3246.                     result = str(count)
  3247.             else:
  3248.                 result = str(count)
  3249.  
  3250.         return result
  3251.  
  3252.     def checkRoom(this, roomName, langue):
  3253.         found = False
  3254.         x = 0
  3255.         result = roomName
  3256.         if this.rooms.has_key(not roomName.startswith('*') and ('%s-%s' % (langue, roomName) if roomName[0] != chr(3) else roomName)):
  3257.             room = this.rooms.get('%s-%s' % (langue, roomName) if not roomName.startswith('*') and roomName[0] != chr(3) else roomName)
  3258.             if room.getPlayerCount() < room.maxPlayers if room.maxPlayers != -1 else True:
  3259.                 found = True
  3260.         else:
  3261.             found = True
  3262.         while not found:
  3263.             x += 1
  3264.             if this.rooms.has_key(not roomName.startswith('*') and ('%s-%s' % (langue, roomName) if roomName[0] != chr(3) else roomName) + str(x)):
  3265.                 room = this.rooms.get(('%s-%s' % (langue, roomName) if not roomName.startswith('*') and roomName[0] != chr(3) else roomName) + str(x))
  3266.                 if room.getPlayerCount() < room.maxPlayers if room.maxPlayers != -1 else True:
  3267.                     found = True
  3268.                     result += str(x)
  3269.             else:
  3270.                 found = True
  3271.                 result += str(x)
  3272.  
  3273.         return result
  3274.  
  3275.     def addClientToRoom(this, client, roomName):
  3276.         if this.rooms.has_key(roomName):
  3277.             this.rooms[roomName].addClient(client)
  3278.         else:
  3279.             room = Room(this, roomName)
  3280.             this.rooms[roomName] = room
  3281.             room.addClient(client, True)
  3282.             room.mapChange()
  3283.  
  3284.     def banPlayer(this, playerName, bantime, reason, modName, silent):
  3285.         found = False
  3286.         client = this.players.get(playerName)
  3287.         if client != None:
  3288.             found = True
  3289.             if not modName == 'Server':
  3290.                 client.banHours += bantime
  3291.                 Cursor.execute("insert into BanLog values (?, ?, ?, ?, ?, 'Online', ?)", [playerName,
  3292.                  modName,
  3293.                  bantime,
  3294.                  reason,
  3295.                  int(time.time() / 10),
  3296.                  client.ipAddress])
  3297.             else:
  3298.                 this.sendStaffMessage(5, '<V>Servidor <BL>baniu o jogador <V>%s<BL> por <V>1 <BL> hora. Motivo: <V>Vote Populaire<BL>.' % playerName)
  3299.             Cursor.execute('update Users set BanHours = ?, UnRanked = 1 where Username = ?', [bantime, playerName])
  3300.             if bantime >= 361 or client.banHours >= 361:
  3301.                 this.userPermaBanCache.append(playerName)
  3302.                 Cursor.execute('insert into UserPermaBan values (?, ?, ?)', [playerName, reason, modName])
  3303.             if client.banHours >= 361:
  3304.                 this.IPPermaBanCache.append(client.ipAddress)
  3305.                 Cursor.execute('insert into IPPermaBan values (?, ?, ?)', [client.ipAddress, modName, reason])
  3306.             if bantime >= 1 and bantime <= 360:
  3307.                 this.tempBanUser(playerName, bantime, reason)
  3308.                 this.tempBanIP(client.ipAddress, bantime)
  3309.             if playerName in this.reports['names']:
  3310.                 this.reports[playerName]['status'] = 'banned'
  3311.                 this.reports[playerName]['status'] = 'modname'
  3312.                 this.reports[playerName]['status'] = str(bantime)
  3313.                 this.reports[playerName]['banreason'] = 'hack'
  3314.             client.sendPlayerBan(bantime, reason, silent)
  3315.         if not found and this.checkExistingUser(playerName) and not modName == 'Server' and bantime >= 1:
  3316.             found = True
  3317.             totalBanTime = this.getTotalBanHours(playerName) + bantime
  3318.             if totalBanTime >= 361 and bantime <= 360 or bantime >= 361:
  3319.                 this.userPermaBanCache.append(playerName)
  3320.                 Cursor.execute('insert into UserPermaBan values (?, ?, ?)', [playerName, reason, modName])
  3321.             if bantime >= 1 and bantime <= 360:
  3322.                 this.tempBanUser(playerName, bantime, reason)
  3323.             Cursor.execute('update Users set BanHours = ?, UnRanked = 1 where Username = ?', [bantime, playerName])
  3324.             Cursor.execute("insert into BanLog values (?, ?, ?, ?, ?, 'Offline', 'Offline')", [playerName,
  3325.              modName,
  3326.              str(bantime),
  3327.              reason,
  3328.              int(time.time() / 10)])
  3329.         return found
  3330.  
  3331.     def checkTempBan(this, playerName):
  3332.         Cursor.execute('select 1 from UserTempBan where Username = ?', [playerName])
  3333.         return Cursor.fetchone() != None
  3334.  
  3335.     def removeTempBan(this, playerName):
  3336.         if playerName in this.userTempBanCache:
  3337.             this.userTempBanCache.remove(playerName)
  3338.         Cursor.execute('delete from UserTempBan where Username = ?', [playerName])
  3339.  
  3340.     def tempBanUser(this, playerName, bantime, reason):
  3341.         if this.checkTempBan(playerName):
  3342.             this.removeTempBan(playerName)
  3343.         this.userTempBanCache.append(playerName)
  3344.         Cursor.execute('insert into UserTempBan values (?, ?, ?)', [playerName, reason, str(Utils.getTime() + bantime * 60 * 60)])
  3345.  
  3346.     def getTempBanInfo(this, playerName):
  3347.         Cursor.execute('select Reason, Time from UserTempBan where Username = ?', [playerName])
  3348.         for rs in Cursor.fetchall():
  3349.             return [rs['Reason'], rs['Time']]
  3350.         else:
  3351.             return ['Without a reason', 0]
  3352.  
  3353.     def getPermBanInfo(this, playerName):
  3354.         Cursor.execute('select Reason from UserPermaBan where Username = ?', [playerName])
  3355.         for rs in Cursor.fetchall():
  3356.             return rs['Reason']
  3357.         else:
  3358.             return 'Without a reason'
  3359.  
  3360.     def checkPermaBan(this, playerName):
  3361.         Cursor.execute('select 1 from UserPermaBan where Username = ?', [playerName])
  3362.         return Cursor.fetchone() != None
  3363.  
  3364.     def removePermaBan(this, playerName):
  3365.         if playerName in this.userPermaBanCache:
  3366.             this.userPermaBanCache.remove(playerName)
  3367.         Cursor.execute('delete from UserPermaBan where Username = ?', [playerName])
  3368.         Cursor.execute('update Users set UnRanked = 0 where Username = ?', [playerName])
  3369.  
  3370.     def tempBanIP(this, ip, time):
  3371.         if ip not in this.IPTempBanCache:
  3372.             this.IPTempBanCache.append(ip)
  3373.             if ip in this.IPTempBanCache:
  3374.                 reactor.callLater(time, lambda : this.IPTempBanCache.remove(ip))
  3375.  
  3376.     def getTotalBanHours(this, playerName):
  3377.         Cursor.execute('select BanHours from Users where Username = ?', [playerName])
  3378.         rs = Cursor.fetchone()
  3379.         if rs:
  3380.             return rs['BanHours']
  3381.         else:
  3382.             return 0
  3383.  
  3384.     def voteBanPopulaire(this, playerName, playerVoted, ip):
  3385.         client = this.players.get(playerName)
  3386.         if client != None and client.privLevel == 1 and ip not in client.voteBan:
  3387.             client.voteBan.append(ip)
  3388.             if len(client.voteBan) == 10:
  3389.                 this.banPlayer(playerName, 1, 'Vote Populaire', 'Server', False)
  3390.             this.sendStaffMessage(7, 'O jogador <V>%s</V> est\xc3\xa1 votando contra <V>%s</V> [<R>%s</R>/10]' % (playerVoted, playerName, len(client.voteBan)))
  3391.         return
  3392.  
  3393.     def muteUser(this, playerName, mutetime, reason):
  3394.         this.userMuteCache.append(playerName)
  3395.         Cursor.execute('insert into UserTempMute values (?, ?, ?)', [playerName, str(Utils.getTime() + mutetime * 60 * 60), reason])
  3396.  
  3397.     def removeModMute(this, playerName):
  3398.         if playerName in this.userMuteCache:
  3399.             this.userMuteCache.remove(playerName)
  3400.         Cursor.execute('delete from UserTempMute where Username = ?', [playerName])
  3401.  
  3402.     def getModMuteInfo(this, playerName):
  3403.         Cursor.execute('select Reason, Time from UserTempMute where Username = ?', [playerName])
  3404.         rs = Cursor.fetchone()
  3405.         if rs:
  3406.             return [rs['Reason'], rs['Time']]
  3407.         else:
  3408.             return ['Without a reason', 0]
  3409.  
  3410.     def mutePlayer(this, playerName, hours, reason, modName):
  3411.         client = this.players.get(playerName)
  3412.         if client != None:
  3413.             this.sendStaffMessage(5, '<V>%s</V> deixou <V>%s</V> sem falar por <V>%s</V> %s pelo seguinte motivo: <V>%s</V>' % (modName,
  3414.              playerName,
  3415.              hours,
  3416.              'hora' if hours == 1 else 'horas',
  3417.              reason))
  3418.             if playerName in this.userMuteCache:
  3419.                 this.removeModMute(playerName)
  3420.             client.isMute = True
  3421.             client.sendModMute(playerName, hours, reason, False)
  3422.             client.sendModMute(playerName, hours, reason, True)
  3423.             this.muteUser(playerName, hours, reason)
  3424.         return
  3425.  
  3426.     def desmutePlayer(this, playerName, modName):
  3427.         client = this.players.get(playerName)
  3428.         if client != None:
  3429.             this.sendStaffMessage(5, '<V>%s</V> desmutou <V>%s</V>.' % (modName, playerName))
  3430.             this.removeModMute(playerName)
  3431.             client.isMute = False
  3432.         return
  3433.  
  3434.     def sendStaffChat(this, type, langue, playerName, message, sender):
  3435.         playerName = sender.playerName if type == -1 else ('' if type == 0 else ('Message Serveur' if type == 1 else sender.langue.upper() + '][' + {11: 'Admin][',
  3436.          10: 'Admin][',
  3437.          9: 'Coord][',
  3438.          8: 'Smod][',
  3439.          7: 'Mod][',
  3440.          6: 'MapCrew][',
  3441.          5: 'Helper][',
  3442.          4: 'DV][',
  3443.          3: 'LUA]['}[sender.privLevel]))
  3444.         if '][' in playerName:
  3445.             playerName += sender.playerName
  3446.         for client in (sender.room.clients if type == 0 else this.players).values():
  3447.             if (type == -1 or type == 0 or type == 1 or (type == 2 or type == 5) and client.privLevel >= 5 or (type == 3 or type == 4) and client.privLevel >= 7 or (type == 6 or type == 7) and client.privLevel >= 6 or type == 8 and client.privLevel >= 3 or type == 9 and client.privLevel >= 4) and (client.langue == langue or type == -1 or type == 1 or type == 4 or type == 5 or type == 6):
  3448.                 client.sendPacket(Identifiers.send.Staff_Chat, ByteArray().writeByte(1 if type == -1 else type).writeUTF(playerName).writeUTF(message).writeShort(0).writeByte(0).toByteArray())
  3449.  
  3450.     def getplayerAvatar(this, playerName):
  3451.         if playerName.startswith('*'):
  3452.             return 0
  3453.         else:
  3454.             Cursor.execute('select avatar from Users where Username = ?', [playerName])
  3455.             rrf = Cursor.fetchone()
  3456.             if rrf is None:
  3457.                 return 0
  3458.             if rrf[0] == 'None':
  3459.                 return 0
  3460.             return int(rrf[0])
  3461.             return
  3462.  
  3463.     def getShamanType(this, playerCode):
  3464.         for client in this.players.values():
  3465.             if client.playerCode == playerCode:
  3466.                 return client.shamanType
  3467.  
  3468.         return 0
  3469.  
  3470.     def getShamanLevel(this, playerCode):
  3471.         for client in this.players.values():
  3472.             if client.playerCode == playerCode:
  3473.                 return client.shamanLevel
  3474.  
  3475.         return 0
  3476.  
  3477.     def getShamanBadge(this, playerCode):
  3478.         for client in this.players.values():
  3479.             if client.playerCode == playerCode:
  3480.                 return client.parseSkill.getShamanBadge()
  3481.  
  3482.         return 0
  3483.  
  3484.     def getTribeHouse(this, tribeName):
  3485.         Cursor.execute('select House from Tribe where Name = ?', [tribeName])
  3486.         rs = Cursor.fetchone()
  3487.         if rs:
  3488.             return rs['House']
  3489.         else:
  3490.             return -1
  3491.  
  3492.     def getPlayerID(this, playerName):
  3493.         if playerName.startswith('*'):
  3494.             return 0
  3495.         elif this.players.has_key(playerName):
  3496.             return this.players[playerName].playerID
  3497.         Cursor.execute('select PlayerID from Users where Username = ?', [playerName])
  3498.         rs = Cursor.fetchone()
  3499.         if rs:
  3500.             return rs['PlayerID']
  3501.         else:
  3502.             return 0
  3503.  
  3504.     def getPlayerPrivlevel(this, playerName):
  3505.         if playerName.startswith('*'):
  3506.             return 0
  3507.         elif this.players.has_key(playerName):
  3508.             return this.players[playerName].privLevel
  3509.         Cursor.execute('select PrivLevel from Users where Username = ?', [playerName])
  3510.         rs = Cursor.fetchone()
  3511.         if rs:
  3512.             return rs['PrivLevel']
  3513.         else:
  3514.             return 0
  3515.  
  3516.     def getPlayerName(this, playerID):
  3517.         Cursor.execute('select Username from Users where PlayerID = ?', [playerID])
  3518.         rs = Cursor.fetchone()
  3519.         if rs:
  3520.             return rs['Username']
  3521.         else:
  3522.             return ''
  3523.  
  3524.     def getPlayerRoomName(this, playerName):
  3525.         if this.players.has_key(playerName):
  3526.             return this.players[playerName].roomName
  3527.         else:
  3528.             return ''
  3529.  
  3530.     def checkDuplicateEmail(this, email):
  3531.         Cursor.execute('select Username from Users where Email = ?', [email])
  3532.         if Cursor.fetchone():
  3533.             return True
  3534.         return False
  3535.  
  3536.     def checkEmailAddress(this, playerName, email):
  3537.         Cursor.execute('select Email from Users where Username = ?', [playerName])
  3538.         rs = Cursor.fetchone()
  3539.         if rs:
  3540.             return rs['Email'] == email
  3541.         return False
  3542.  
  3543.     def getPlayersCountMode(this, mode, langue):
  3544.         modeName = 'TsunaMice' if mode == 1 else ('TsunaMice vanilla' if mode == 3 else ('TsunaMice survivor' if mode == 8 else ('TsunaMice racing' if mode == 9 else ('TsunaMice music' if mode == 11 else ('TsunaMice bootcamp' if mode == 2 else ('TsunaMice defilante' if mode == 10 else ('TsunaMice village' if mode == 16 else ('' if mode == 18 else 'TsunaMice Module'))))))))
  3545.         playerCount = 0
  3546.         for room in this.rooms.values():
  3547.             if (room.isNormRoom or room.isTribeHouse or room.isTribewar or room.isBallonRace or room.isFlyGame or room.isDeathmatch or room.isPokeLua or room.isExplosionGame or room.isVillage or room.isTotemEditor or room.isTutorial or room.isDoubleMap or room.isVillage or room.isVanilla or room.isSurvivor or room.isRacing or room.isMusic or room.isBootcamp or room.isDefilante if mode == 1 else (room.isVanilla if mode == 3 else (room.isSurvivor if mode == 8 else (room.isRacing if mode == 9 else (room.isMusic if mode == 11 else (room.isBootcamp if mode == 2 else (room.isDefilante if mode == 10 else (room.isVillage if mode == 16 else True)))))))) and room.community == langue.lower():
  3548.                 playerCount += room.getPlayerCount()
  3549.  
  3550.         return [modeName, playerCount]
  3551.  
  3552.     def parsePromotions(this):
  3553.         needUpdate = False
  3554.         i = 0
  3555.         while i < len(this.promotions):
  3556.             item = this.promotions[i]
  3557.             if item[3] < 1000:
  3558.                 item[3] = Utils.getTime() + item[3] * 86400 + 30
  3559.                 needUpdate = True
  3560.             this.shopPromotions.append([item[0],
  3561.              item[1],
  3562.              item[2],
  3563.              item[3]])
  3564.             i += 1
  3565.  
  3566.         if needUpdate:
  3567.             with open('./include/files/promotions.json', 'w') as f:
  3568.                 json.dump(this.promotions, f)
  3569.         this.checkPromotionsEnd()
  3570.  
  3571.     def checkPromotionsEnd(this):
  3572.         needUpdate = False
  3573.         for promotion in this.shopPromotions:
  3574.             if Utils.getHoursDiff(promotion[3]) <= 0:
  3575.                 this.shopPromotions.remove(promotion)
  3576.                 needUpdate = True
  3577.                 i = 0
  3578.                 while i < len(this.promotions):
  3579.                     if this.promotions[i][0] == promotion[0] and this.promotions[i][1] == promotion[1]:
  3580.                         del this.promotions[i]
  3581.                     i += 1
  3582.  
  3583.         if needUpdate:
  3584.             with open('./include/files/promotions.json', 'w') as f:
  3585.                 json.dump(this.promotions, f)
  3586.  
  3587.     def sendWholeServer(this, identifiers, result):
  3588.         for client in this.players.values():
  3589.             client.sendPacket(identifiers, result)
  3590.  
  3591.     def setVip(this, playerName, days):
  3592.         client = this.players.get(playerName)
  3593.         if client != None:
  3594.             if client.privLevel == 1:
  3595.                 Cursor.execute('update Users SET VipTime = ? WHERE Username = ?', [Utils.getTime() + 24 * days * 3600, playerName])
  3596.                 client.privLevel = 2
  3597.                 this.sendModMessage(7, '<V>' + playerName + '<BL> se tornou <ROSE>VIP <BL>do <ROSE>TsunaMice<BL> por <V>' + str(days) + '<BL> dias.')
  3598.         else:
  3599.             Cursor.execute('update Users SET VipTime = ?, PrivLevel = 2 WHERE Username = ?', [Utils.getTime() + 24 * days * 3600, playerName])
  3600.             Cursor.fetchall()
  3601.             this.sendModMessage(7, '<V>' + playerName + '<BL> se tornou VIP do <ROSE>TsunaMice<BL> por <V>' + str(days) + '<BL> dias.')
  3602.         return
  3603.  
  3604.     def getPlayerCode(this, playerName):
  3605.         client = this.players.get(Utils.parsePlayerName(playerName))
  3606.         if client != None:
  3607.             return client.playerCode
  3608.         else:
  3609.             return 0
  3610.  
  3611.     def sendStaffMessage(this, minLevel, message, tab = False):
  3612.         for client in this.players.values():
  3613.             if client.privLevel >= minLevel:
  3614.                 client.sendMessage(message, tab)
  3615.  
  3616.     def sendModMessage(this, minLevel, message):
  3617.         for client in this.players.values():
  3618.             if client.privLevel >= minLevel:
  3619.                 client.sendPacket([6, 20], ByteArray().writeByte(0).writeUTF(message).writeShort(0).toByteArray())
  3620.  
  3621.     def getRanking(this):
  3622.         this.rankingTimer = reactor.callLater(300, this.getRanking)
  3623.         this.rankingsList = [{},
  3624.          {},
  3625.          {},
  3626.          {},
  3627.          {},
  3628.          {},
  3629.          {}]
  3630.         Cursor.execute('select Username, FirstCount from Users where PrivLevel < 3 order by FirstCount desc limit 0, 13')
  3631.         count = 1
  3632.         for rs in Cursor.fetchall():
  3633.             playerName = rs['Username']
  3634.             this.rankingsList[0][count] = [playerName, this.players[playerName].firstCount if this.checkConnectedAccount(playerName) else rs['FirstCount']]
  3635.             count += 1
  3636.  
  3637.         Cursor.execute('select Username, CheeseCount from Users where PrivLevel < 3 order by CheeseCount desc limit 0, 13')
  3638.         count = 1
  3639.         for rs in Cursor.fetchall():
  3640.             playerName = rs['Username']
  3641.             this.rankingsList[1][count] = [playerName, this.players[playerName].cheeseCount if this.checkConnectedAccount(playerName) else rs['CheeseCount']]
  3642.             count += 1
  3643.  
  3644.         Cursor.execute('select Username, ShamanSaves from Users where PrivLevel < 3 order by ShamanSaves desc limit 0, 13')
  3645.         count = 1
  3646.         for rs in Cursor.fetchall():
  3647.             playerName = rs['Username']
  3648.             this.rankingsList[2][count] = [playerName, this.players[playerName].shamanSaves if this.checkConnectedAccount(playerName) else rs['ShamanSaves']]
  3649.             count += 1
  3650.  
  3651.         Cursor.execute('select Username, BootcampCount from Users where PrivLevel < 3 order by BootcampCount desc limit 0, 13')
  3652.         count = 1
  3653.         for rs in Cursor.fetchall():
  3654.             playerName = rs['Username']
  3655.             this.rankingsList[3][count] = [playerName, this.players[playerName].bootcampCount if this.checkConnectedAccount(playerName) else rs['BootcampCount']]
  3656.             count += 1
  3657.  
  3658.         Cursor.execute('select Username, XDCoins from Users where PrivLevel < 3 order by XDCoins desc limit 0, 13')
  3659.         count = 1
  3660.         for rs in Cursor.fetchall():
  3661.             playerName = rs['Username']
  3662.             this.rankingsList[4][count] = [playerName, this.players[playerName].XDCoins if this.checkConnectedAccount(playerName) else rs['XDCoins']]
  3663.             count += 1
  3664.  
  3665.         Cursor.execute('select Username, DeathCount from Users where PrivLevel < 3 order by DeathCount desc limit 0, 13')
  3666.         count = 1
  3667.         for rs in Cursor.fetchall():
  3668.             playerName = rs['Username']
  3669.             this.rankingsList[5][count] = [playerName, this.players[playerName].deathCount if this.checkConnectedAccount(playerName) else rs['DeathCount']]
  3670.             count += 1
  3671.  
  3672.         Cursor.execute('select Name, Points from tribe ORDER By Points DESC LIMIT 0, 13')
  3673.         count = 1
  3674.         for rs in Cursor.fetchall():
  3675.             playerName = rs['Name']
  3676.             this.rankingsList[6][count] = [playerName, this.players[playerName].tribePoints if this.checkConnectedAccount(playerName) else rs['Points']]
  3677.             count += 1
  3678.  
  3679.  
  3680. class Room():
  3681.  
  3682.     def __init__(this, server, name):
  3683.         this.mapXML = ''
  3684.         this.mapName = ''
  3685.         this.EMapXML = ''
  3686.         this.roomPassword = ''
  3687.         this.forceNextMap = '-1'
  3688.         this.currentSyncName = ''
  3689.         this.currentShamanName = ''
  3690.         this.currentSecondShamanName = ''
  3691.         this.addTime = 0
  3692.         this.mapCode = -1
  3693.         this.cloudID = -1
  3694.         this.EMapCode = 0
  3695.         this.objectID = 0
  3696.         this.redCount = 0
  3697.         this.mapPerma = -1
  3698.         this.blueCount = 0
  3699.         this.mapStatus = -1
  3700.         this.mapNoVotes = 0
  3701.         this.currentMap = 0
  3702.         this.receivedNo = 0
  3703.         this.EMapLoaded = 0
  3704.         this.roundTime = 120
  3705.         this.mapYesVotes = 0
  3706.         this.receivedYes = 0
  3707.         this.roundsCount = -1
  3708.         this.maxPlayers = 20
  3709.         this.numCompleted = 0
  3710.         this.numGetCheese = 0
  3711.         this.companionBox = -1
  3712.         this.gameStartTime = 0
  3713.         this.lastRoundCode = 0
  3714.         this.FSnumCompleted = 0
  3715.         this.SSnumCompleted = 0
  3716.         this.forceNextShaman = -1
  3717.         this.currentSyncCode = -1
  3718.         this.changeMapAttemps = 0
  3719.         this.currentShamanCode = -1
  3720.         this.currentShamanType = -1
  3721.         this.gameStartTimeMillis = 0
  3722.         this.currentSecondShamanCode = -1
  3723.         this.currentSecondShamanType = -1
  3724.         this.isMusic = False
  3725.         this.isClosed = False
  3726.         this.noShaman = False
  3727.         this.isEditor = False
  3728.         this.isRacing = False
  3729.         this.isSnowing = False
  3730.         this.isVillage = False
  3731.         this.isVanilla = False
  3732.         this.is801Room = False
  3733.         this.countStats = True
  3734.         this.isFixedMap = False
  3735.         this.isNormRoom = False
  3736.         this.isEventoAventura = False
  3737.         this.isTribewar = False
  3738.         this.isMinigame = False
  3739.         this.canCannon = False
  3740.         this.isDeathmatch = False
  3741.         this.isPokeLua = False
  3742.         this.isExplosionGame = False
  3743.         this.isInvocationGame = False
  3744.         this.isBallonRace = False
  3745.         this.isFlyGame = False
  3746.         this.isTutorial = False
  3747.         this.isBootcamp = False
  3748.         this.isSurvivor = False
  3749.         this.isVotingBox = False
  3750.         this.autoRespawn = False
  3751.         this.noAutoScore = False
  3752.         this.isDoubleMap = False
  3753.         this.specificMap = False
  3754.         this.mapInverted = False
  3755.         this.isDefilante = False
  3756.         this.canChangeMap = True
  3757.         this.isVotingMode = False
  3758.         this.isTribeHouse = False
  3759.         this.isNoShamanMap = False
  3760.         this.EMapValidated = False
  3761.         this.isTotemEditor = False
  3762.         this.initVotingMode = True
  3763.         this.disableAfkKill = False
  3764.         this.noShamanSkills = False
  3765.         this.isSurvivorVamp = False
  3766.         this.never20secTimer = False
  3767.         this.isTribeHouseMap = False
  3768.         this.changed20secTimer = False
  3769.         this.catchTheCheeseMap = False
  3770.         this.killAfkTimer = None
  3771.         this.endSnowTimer = None
  3772.         this.changeMapTimer = None
  3773.         this.contagemDeath = None
  3774.         this.voteCloseTimer = None
  3775.         this.startTimerLeft = None
  3776.         this.autoRespawnTimer = None
  3777.         this.anchors = []
  3778.         this.redTeam = []
  3779.         this.blueTeam = []
  3780.         this.roomTimers = []
  3781.         this.lastHandymouse = [-1, -1]
  3782.         this.noShamanMaps = [7,
  3783.          8,
  3784.          14,
  3785.          22,
  3786.          23,
  3787.          28,
  3788.          29,
  3789.          54,
  3790.          55,
  3791.          57,
  3792.          58,
  3793.          59,
  3794.          60,
  3795.          61,
  3796.          70,
  3797.          77,
  3798.          78,
  3799.          87,
  3800.          88,
  3801.          92,
  3802.          122,
  3803.          123,
  3804.          124,
  3805.          125,
  3806.          126,
  3807.          1007,
  3808.          888,
  3809.          200,
  3810.          201,
  3811.          202,
  3812.          203,
  3813.          204,
  3814.          205,
  3815.          206,
  3816.          207,
  3817.          208,
  3818.          209,
  3819.          210]
  3820.         this.mapList = [0,
  3821.          1,
  3822.          2,
  3823.          3,
  3824.          4,
  3825.          5,
  3826.          6,
  3827.          7,
  3828.          8,
  3829.          9,
  3830.          10,
  3831.          11,
  3832.          12,
  3833.          13,
  3834.          14,
  3835.          15,
  3836.          16,
  3837.          17,
  3838.          18,
  3839.          19,
  3840.          20,
  3841.          21,
  3842.          22,
  3843.          23,
  3844.          24,
  3845.          25,
  3846.          26,
  3847.          27,
  3848.          28,
  3849.          29,
  3850.          30,
  3851.          31,
  3852.          32,
  3853.          33,
  3854.          34,
  3855.          35,
  3856.          36,
  3857.          37,
  3858.          38,
  3859.          39,
  3860.          40,
  3861.          41,
  3862.          42,
  3863.          43,
  3864.          44,
  3865.          45,
  3866.          46,
  3867.          47,
  3868.          48,
  3869.          49,
  3870.          50,
  3871.          51,
  3872.          52,
  3873.          53,
  3874.          54,
  3875.          55,
  3876.          56,
  3877.          57,
  3878.          58,
  3879.          59,
  3880.          60,
  3881.          61,
  3882.          62,
  3883.          63,
  3884.          64,
  3885.          65,
  3886.          66,
  3887.          67,
  3888.          68,
  3889.          69,
  3890.          70,
  3891.          71,
  3892.          72,
  3893.          73,
  3894.          74,
  3895.          75,
  3896.          76,
  3897.          77,
  3898.          78,
  3899.          79,
  3900.          80,
  3901.          81,
  3902.          82,
  3903.          83,
  3904.          84,
  3905.          85,
  3906.          86,
  3907.          87,
  3908.          88,
  3909.          89,
  3910.          90,
  3911.          91,
  3912.          92,
  3913.          93,
  3914.          94,
  3915.          95,
  3916.          96,
  3917.          97,
  3918.          98,
  3919.          99,
  3920.          100,
  3921.          101,
  3922.          102,
  3923.          103,
  3924.          104,
  3925.          105,
  3926.          106,
  3927.          107,
  3928.          108,
  3929.          109,
  3930.          110,
  3931.          111,
  3932.          112,
  3933.          113,
  3934.          114,
  3935.          115,
  3936.          116,
  3937.          117,
  3938.          118,
  3939.          119,
  3940.          120,
  3941.          121,
  3942.          122,
  3943.          123,
  3944.          124,
  3945.          125,
  3946.          126,
  3947.          127,
  3948.          128,
  3949.          129,
  3950.          130,
  3951.          131,
  3952.          132,
  3953.          133,
  3954.          134,
  3955.          136,
  3956.          137,
  3957.          138,
  3958.          139,
  3959.          140,
  3960.          141,
  3961.          142,
  3962.          143,
  3963.          200,
  3964.          201,
  3965.          202,
  3966.          203,
  3967.          204,
  3968.          205,
  3969.          206,
  3970.          207,
  3971.          208,
  3972.          209,
  3973.          210]
  3974.         this.clients = {}
  3975.         this.currentTimers = {}
  3976.         this.currentShamanSkills = {}
  3977.         this.currentSecondShamanSkills = {}
  3978.         this.name = name
  3979.         this.server = server
  3980.         this.CursorMaps = CursorMaps
  3981.         this.recordTimer = reactor.callLater(5, this.recordAPI)
  3982.         if this.name.startswith('*'):
  3983.             this.community = 'xx'
  3984.             this.roomName = this.name
  3985.         else:
  3986.             this.community = this.name.split('-')[0].lower()
  3987.             this.roomName = this.name.split('-')[1]
  3988.         roomNameCheck = this.roomName[1:] if this.roomName.startswith('*') else this.roomName
  3989.         if this.roomName.startswith('\x03[Editeur] '):
  3990.             this.countStats = False
  3991.             this.isEditor = True
  3992.             this.never20secTimer = True
  3993.         elif this.roomName.startswith('\x03[Tutorial] '):
  3994.             this.countStats = False
  3995.             this.currentMap = 900
  3996.             this.specificMap = True
  3997.             this.noShaman = True
  3998.             this.never20secTimer = True
  3999.             this.isTutorial = True
  4000.         elif this.roomName.startswith('\x03[Totem] '):
  4001.             this.countStats = False
  4002.             this.specificMap = True
  4003.             this.currentMap = 444
  4004.             this.isTotemEditor = True
  4005.             this.never20secTimer = True
  4006.         elif this.roomName.startswith('*\x03'):
  4007.             this.countStats = False
  4008.             this.isTribeHouse = True
  4009.             this.autoRespawn = True
  4010.             this.never20secTimer = True
  4011.             this.noShaman = True
  4012.             this.disableAfkKill = True
  4013.             this.isFixedMap = True
  4014.             this.roundTime = 0
  4015.         elif re.search('racing', name.lower()):
  4016.             this.isRacing = True
  4017.             this.noShaman = True
  4018.             this.noAutoScore = True
  4019.             this.roundTime = 63
  4020.         elif re.search('bootcamp', name.lower()):
  4021.             this.isBootcamp = True
  4022.             this.countStats = False
  4023.             this.roundTime = 360
  4024.             this.never20secTimer = True
  4025.             this.autoRespawn = True
  4026.             this.noShaman = True
  4027.         elif re.search('vanilla', name.lower()):
  4028.             this.isVanilla = True
  4029.         elif re.search('eventoaventura', name.lower()):
  4030.             this.isNormRoom = True
  4031.             this.isEventoAventura = True
  4032.         elif re.search('vamp', name.lower()):
  4033.             this.isVillage = True
  4034.             this.noShaman = True
  4035.             this.isFixedMap = True
  4036.             this.roundTime = 0
  4037.         elif re.search('survivor', name.lower()):
  4038.             this.isSurvivor = True
  4039.             this.roundTime = 90
  4040.         elif re.search('defilante', name.lower()):
  4041.             this.isDefilante = True
  4042.             this.noShaman = True
  4043.             this.countStats = False
  4044.             this.noAutoScore = True
  4045.         elif re.search('#ballonrace', name.lower()):
  4046.             this.isBallonRace = True
  4047.             this.isVanilla = True
  4048.             this.isMinigame = True
  4049.             this.maxPlayers = 25
  4050.             this.roundTime = 120
  4051.             this.noShaman = True
  4052.         elif re.search('#deathmatch', name.lower()):
  4053.             this.countStats = True
  4054.             this.isDeathmatch = True
  4055.             this.isMinigame = True
  4056.             this.maxPlayers = 25
  4057.             this.roundTime = 120
  4058.             this.noShaman = True
  4059.             this.never20secTimer = True
  4060.         elif re.search('#fly', name.lower()):
  4061.             this.isFlyGame = True
  4062.             this.isVanilla = True
  4063.             this.isMinigame = True
  4064.             this.maxPlayers = 25
  4065.             this.roundTime = 120
  4066.             this.noShaman = True
  4067.         elif re.search('#pokelua', name.lower()):
  4068.             this.isPokeLua = True
  4069.             this.isVanilla = True
  4070.             this.isMinigame = True
  4071.             this.maxPlayers = 30
  4072.             this.roundTime = 120
  4073.         elif re.search('#tribewar', name.lower()):
  4074.             this.isTribewar = True
  4075.             this.isRacing = True
  4076.             this.noShaman = True
  4077.             this.roundTime = 63
  4078.             this.never20secTimer = True
  4079.         elif re.search('#explosion', name.lower()):
  4080.             this.isExplosionGame = True
  4081.             this.isVanilla = True
  4082.             this.isMinigame = True
  4083.             this.maxPlayers = 25
  4084.             this.roundTime = 120
  4085.             this.noShaman = True
  4086.         elif roomNameCheck.startswith('801') or roomNameCheck.startswith('village'):
  4087.             if roomNameCheck.startswith('village'):
  4088.                 this.isVillage = True
  4089.             else:
  4090.                 this.is801Room = True
  4091.             this.roundTime = 0
  4092.             this.never20secTimer = True
  4093.             this.autoRespawn = True
  4094.             this.countStats = False
  4095.             this.noShaman = True
  4096.             this.isFixedMap = True
  4097.             this.disableAfkKill = True
  4098.         else:
  4099.             this.isNormRoom = True
  4100.         this.mapChange()
  4101.         return None
  4102.  
  4103.     def addTextPopUpStaff(this, id, type, text, targetPlayer, x, y, width):
  4104.         p = ByteArray().writeInt(id).writeByte(type).writeUTF(text).writeShort(x).writeShort(y).writeShort(width).writeByte(4)
  4105.         if targetPlayer == '':
  4106.             this.sendAll([29, 23], p.toByteArray())
  4107.         else:
  4108.             player = this.clients.get(targetPlayer)
  4109.             if player != None:
  4110.                 player.sendPacket([29, 23], p.toByteArray())
  4111.         return
  4112.  
  4113.     def startTimer(this):
  4114.         for client in this.clients.values():
  4115.             client.sendMapStartTimer(False)
  4116.  
  4117.     def recordAPI(this):
  4118.         for client in this.clients.values():
  4119.             players = client.getConnectedPlayerCount()
  4120.             if players > this.server.recordPlayers:
  4121.                 this.server.recordPlayers = players
  4122.                 client.sendMessage('<R>Batemos nosso novo recorde de ' + str(players) + ' jogadores conectados.\nTodos jogadores online ganharam: 2 firsts e 10 moedas.')
  4123.                 client.firstCount += 2
  4124.                 client.cheeseCount += 2
  4125.                 client.XDCoins += 10
  4126.                 client.updateConfig()
  4127.  
  4128.         this.recordTimer = reactor.callLater(15, this.recordAPI)
  4129.  
  4130.     def checkIfOneFewRemaining(this):
  4131.         counts = [0, 0]
  4132.         for clientCode, client in this.clients.items():
  4133.             if client.isDead:
  4134.                 counts[0] = counts[0] + 1
  4135.             else:
  4136.                 counts[1] = counts[1] + 1
  4137.  
  4138.         if this.getPlayerCount >= 1:
  4139.             if counts[1] <= 1:
  4140.                 return True
  4141.         return False
  4142.  
  4143.     def mapChange(this):
  4144.         if this.changeMapTimer != None:
  4145.             this.changeMapTimer.cancel()
  4146.         for client in this.clients.values():
  4147.             client.activeArtefact = 0
  4148.  
  4149.         for room in this.server.rooms.values():
  4150.             for playerCode, client in room.clients.items():
  4151.                 if this.isDeathmatch:
  4152.                     if this.contagemDeath is not None:
  4153.                         this.contagemDeath.cancel()
  4154.  
  4155.         if not this.canChangeMap:
  4156.             this.changeMapAttemps += 1
  4157.             if this.changeMapAttemps < 5:
  4158.                 this.changeMapTimer = reactor.callLater(1, this.mapChange)
  4159.                 return
  4160.         for timer in this.roomTimers:
  4161.             timer.cancel()
  4162.  
  4163.         this.roomTimers = []
  4164.         for timer in [this.voteCloseTimer,
  4165.          this.killAfkTimer,
  4166.          this.autoRespawnTimer,
  4167.          this.startTimerLeft]:
  4168.             if timer != None:
  4169.                 timer.cancel()
  4170.  
  4171.         if this.initVotingMode:
  4172.             if not this.isVotingBox and this.mapPerma == 0 and this.mapCode != -1 and this.getPlayerCount() >= 2:
  4173.                 this.isVotingMode = True
  4174.                 this.isVotingBox = True
  4175.                 this.voteCloseTimer = reactor.callLater(8, this.closeVoting)
  4176.                 for client in this.clients.values():
  4177.                     client.sendPacket(Identifiers.old.send.Vote_Box, [this.mapName, this.mapYesVotes, this.mapNoVotes])
  4178.  
  4179.             else:
  4180.                 this.votingMode = False
  4181.                 this.closeVoting()
  4182.         elif this.isTribeHouse and this.isTribeHouseMap:
  4183.             pass
  4184.         else:
  4185.             if this.isVotingMode:
  4186.                 TotalYes = this.mapYesVotes + this.receivedYes
  4187.                 TotalNo = this.mapNoVotes + this.receivedNo
  4188.                 isDel = False
  4189.                 if TotalYes + TotalNo >= 100:
  4190.                     TotalVotes = TotalYes + TotalNo
  4191.                     Rating = 1.0 * TotalYes / TotalNo * 100
  4192.                     rate = str(Rating).split('.')
  4193.                     if int(rate[0]) < 50:
  4194.                         isDel = True
  4195.                 CursorMaps.execute('update Maps set YesVotes = ?, NoVotes = ?, Perma = 44 where Code = ?' if isDel else 'update Maps set YesVotes = ?, NoVotes = ? where Code = ?', [TotalYes, TotalNo, this.mapCode])
  4196.                 this.isVotingMode = False
  4197.                 this.receivedNo = 0
  4198.                 this.receivedYes = 0
  4199.                 for client in this.clients.values():
  4200.                     client.qualifiedVoted = False
  4201.                     client.isVoted = False
  4202.  
  4203.             this.initVotingMode = True
  4204.             this.lastRoundCode = (this.lastRoundCode + 1) % 127
  4205.             if this.isSurvivor:
  4206.                 for client in this.clients.values():
  4207.                     if not client.isDead and (not client.isVampire if this.mapStatus == 0 else not client.isShaman):
  4208.                         if not this.noAutoScore:
  4209.                             client.playerScore += 10
  4210.  
  4211.             if this.catchTheCheeseMap:
  4212.                 this.catchTheCheeseMap = False
  4213.             else:
  4214.                 numCom = this.FSnumCompleted - 1 if this.isDoubleMap else this.numCompleted - 1
  4215.                 numCom2 = this.SSnumCompleted - 1 if this.isDoubleMap else 0
  4216.                 if numCom < 0:
  4217.                     numCom = 0
  4218.                 if numCom2 < 0:
  4219.                     numCom2 = 0
  4220.                 client = this.clients.get(this.currentShamanName)
  4221.                 if client != None:
  4222.                     this.sendAll(Identifiers.old.send.Shaman_Perfomance, [this.currentShamanName, numCom])
  4223.                     if not this.noAutoScore:
  4224.                         client.playerScore = numCom
  4225.                     if numCom > 0:
  4226.                         client.parseSkill.earnExp(True, numCom)
  4227.                 player2 = this.clients.get(this.currentSecondShamanName)
  4228.                 if player2 != None:
  4229.                     this.sendAll(Identifiers.old.send.Shaman_Perfomance, [this.currentSecondShamanName, numCom2])
  4230.                     if not this.noAutoScore:
  4231.                         player2.playerScore = numCom2
  4232.                     if numCom2 > 0:
  4233.                         player2.parseSkill.earnExp(True, numCom2)
  4234.             if this.getPlayerCount() >= this.server.needToFirst:
  4235.                 this.giveSurvivorStats() if this.isSurvivor else (this.giveRacingStats() if this.isRacing else None)
  4236.             this.currentSyncCode = -1
  4237.             this.currentShamanCode = -1
  4238.             this.currentShamanType = -1
  4239.             this.currentSecondShamanCode = -1
  4240.             this.currentSecondShamanType = -1
  4241.             this.currentSyncName = ''
  4242.             this.currentShamanName = ''
  4243.             this.currentSecondShamanName = ''
  4244.             this.currentShamanSkills = {}
  4245.             this.currentSecondShamanSkills = {}
  4246.             this.changed20secTimer = False
  4247.             this.isDoubleMap = False
  4248.             this.isNoShamanMap = False
  4249.             this.FSnumCompleted = 0
  4250.             this.SSnumCompleted = 0
  4251.             this.objectID = 0
  4252.             this.numGetCheese = 0
  4253.             this.addTime = 0
  4254.             this.cloudID = -1
  4255.             this.companionBox = -1
  4256.             this.lastHandymouse = [-1, -1]
  4257.             this.isTribeHouseMap = False
  4258.             this.canChangeMap = True
  4259.             this.changeMapAttemps = 0
  4260.             this.getSyncCode()
  4261.             this.anchors = []
  4262.             this.mapStatus = (this.mapStatus + 1) % 10
  4263.             this.numCompleted = 0
  4264.             this.currentMap = this.selectMap()
  4265.             this.checkMapXML()
  4266.             if this.currentMap in [range(44, 54), range(138, 144)] or this.mapPerma == 8 and this.getPlayerCount() >= 3:
  4267.                 this.isDoubleMap = True
  4268.             if this.mapPerma in (7, 17, 42) or this.isSurvivor and this.mapStatus == 0:
  4269.                 this.isNoShamanMap = True
  4270.             if this.currentMap in range(108, 114):
  4271.                 this.catchTheCheeseMap = True
  4272.             this.gameStartTime = Utils.getTime()
  4273.             this.gameStartTimeMillis = time.time()
  4274.             for client in this.clients.values():
  4275.                 client.resetPlay()
  4276.  
  4277.             for client in this.clients.values():
  4278.                 client.startPlay()
  4279.                 if client.isHidden:
  4280.                     client.sendPlayerDisconnect()
  4281.  
  4282.             for client in this.clients.values():
  4283.                 if client.pet != 0:
  4284.                     if Utils.getSecondsDiff(client.petEnd) >= 0:
  4285.                         client.pet = 0
  4286.                         client.petEnd = 0
  4287.                     else:
  4288.                         this.sendAll(Identifiers.send.Pet, ByteArray().writeInt(client.playerCode).writeUnsignedByte(client.pet).toByteArray())
  4289.  
  4290.             if this.mapCode not in (-1, 31, 41, 42, 54, 55, 59, 60, 62, 89, 92, 99, 114, 801):
  4291.                 CursorMaps.execute('select TopTime,TopTimeNick from maps where code = ?', [this.mapCode])
  4292.                 rs = CursorMaps.fetchone()
  4293.                 try:
  4294.                     if rs[0] > 0:
  4295.                         if rs[0] > 100:
  4296.                             t = rs[0] / 100.0
  4297.                         else:
  4298.                             t = rs[0] / 10.0
  4299.                         for client in this.clients.values():
  4300.                             client.sendMessage('<BL>Este mapa' '<J> @' + str(this.mapCode) + '<BL> tem record de <J>' + str(t) + 's<BL> por <J>' + str(rs[1]) + '<BL>.')
  4301.                     else: client.sendMessage('<BL>Este mapa' '<J> @' + str(this.mapCode) + '<BL> não possui record, faça o tempo mais rápido''<BL>.')
  4302.                 except: pass
  4303.  
  4304.             if this.getPlayerCount() >= this.server.needToFirst:
  4305.                 if this.isEventoAventura:
  4306.                     anyone = random.choice([0, 1])
  4307.                     itemID = random.choice([7462, 7463, 7464, 7465, 7466, 7467])
  4308.                     positionY = random.randint(0, 30)
  4309.                     if itemID == 7462:
  4310.                         idI = 1
  4311.                     elif itemID == 7463:
  4312.                         idI = 2
  4313.                     elif itemID == 7464:
  4314.                         idI = 3
  4315.                     elif itemID == 7465:
  4316.                         idI = 4
  4317.                     elif itemID == 7466:
  4318.                         idI = 5
  4319.                     elif itemID == 7467:
  4320.                         idI = 6
  4321.                     for player in this.clients.values():
  4322.                         if anyone == 1:
  4323.                             p = ByteArray()
  4324.                             p.writeByte(24)
  4325.                             p.writeByte(idI)
  4326.                             p.writeShort(itemID)
  4327.                             p.writeShort(positionY)
  4328.                             p.writeShort(-100)
  4329.                             player.sendPacket([5, 51], p.toByteArray())
  4330.                         player.sendPacket([100, 101], "\x01\x01")
  4331.  
  4332.             if this.isDeathmatch:
  4333.                 this.PlayerDeathVivo = False
  4334.                 this.canCannon = False
  4335.                 for client in this.clients.values():
  4336.                     client.closedDeathWin()
  4337.                     client.sendContagem()
  4338.  
  4339.             if this.isRacing or this.isDefilante:
  4340.                 this.roundsCount = (this.roundsCount + 1) % 10
  4341.                 client = this.clients.get(this.getHighestScore())
  4342.                 this.sendAll(Identifiers.send.Rounds_Count, ByteArray().writeByte(this.roundsCount).writeInt(client.playerCode if client != None else 0).toByteArray())
  4343.             this.startTimerLeft = reactor.callLater(3, this.startTimer)
  4344.             if not this.isFixedMap and not this.isTribeHouse and not this.isTribeHouseMap:
  4345.                 this.changeMapTimer = reactor.callLater(this.roundTime + this.addTime, this.mapChange)
  4346.             this.killAfkTimer = reactor.callLater(30, this.killAfk)
  4347.             if this.autoRespawn or this.isTribeHouseMap:
  4348.                 this.autoRespawnTimer = reactor.callLater(2, this.respawnMice)
  4349.         return
  4350.  
  4351.     def getPlayerCount(this):
  4352.         return len(filter(lambda client: not client.isHidden, this.clients.values()))
  4353.  
  4354.     def getPlayerCountUnique(this):
  4355.         ipList = []
  4356.         for client in this.clients.values():
  4357.             if client.ipAddress not in ipList:
  4358.                 ipList.append(client.ipAddress)
  4359.  
  4360.         return len(ipList)
  4361.  
  4362.     def getPlayerList(this):
  4363.         result = []
  4364.         for client in this.clients.values():
  4365.             if not client.isHidden:
  4366.                 result.append(client.getPlayerData())
  4367.  
  4368.         return result
  4369.  
  4370.     def addClient(this, client, newRoom = False):
  4371.         this.clients[client.playerName] = client
  4372.         client.room = this
  4373.         if not newRoom:
  4374.             client.isDead = True
  4375.             this.sendAllOthers(client, Identifiers.old.send.Player_Respawn, [client.getPlayerData()])
  4376.             client.startPlay()
  4377.  
  4378.     def removeClient(this, client):
  4379.         if client.playerName in this.clients:
  4380.             del this.clients[client.playerName]
  4381.             client.resetPlay()
  4382.             client.isDead = True
  4383.             client.playerScore = 0
  4384.             client.sendPlayerDisconnect()
  4385.             if len(this.clients) == 0:
  4386.                 for timer in [this.autoRespawnTimer,
  4387.                  this.changeMapTimer,
  4388.                  this.endSnowTimer,
  4389.                  this.killAfkTimer,
  4390.                  this.voteCloseTimer]:
  4391.                     if timer != None:
  4392.                         timer.cancel()
  4393.  
  4394.                 del this.server.rooms[this.name]
  4395.             else:
  4396.                 if client.playerCode == this.currentSyncCode:
  4397.                     this.currentSyncCode = -1
  4398.                     this.currentSyncName = ''
  4399.                     this.getSyncCode()
  4400.                 this.checkChangeMap()
  4401.         return
  4402.  
  4403.     def checkChangeMap(this):
  4404.         if not (this.isBootcamp or this.autoRespawn or this.isTribeHouse and this.isTribeHouseMap or this.isFixedMap):
  4405.             alivePeople = filter(lambda client: not client.isDead, this.clients.values())
  4406.             if not alivePeople:
  4407.                 this.mapChange()
  4408.  
  4409.     def sendMessage(this, message1, message2, AP, *args):
  4410.         for client in this.clients.values():
  4411.             if client.playerName != AP:
  4412.                 client.sendLangueMessage(message1, message2, *args)
  4413.  
  4414.     def sendAll(this, identifiers, packet = ''):
  4415.         for client in this.clients.values():
  4416.             client.sendPacket(identifiers, packet)
  4417.  
  4418.     def sendAllOthers(this, senderClient, identifiers, packet = ''):
  4419.         for client in this.clients.values():
  4420.             if not client == senderClient:
  4421.                 client.sendPacket(identifiers, packet)
  4422.  
  4423.     def sendAllChat(this, playerCode, playerName, message, langueID, isOnly):
  4424.         packet = ByteArray().writeInt(playerCode).writeUTF(playerName).writeByte(langueID).writeUTF(message)
  4425.         if not isOnly:
  4426.             for client in this.clients.values():
  4427.                 if playerName not in client.ignoredsList:
  4428.                     client.sendPacket(Identifiers.send.Chat_Message, packet.toByteArray())
  4429.  
  4430.         else:
  4431.             client = this.clients.get(playerName)
  4432.             if client != None:
  4433.                 client.sendPacket(Identifiers.send.Chat_Message, packet.toByteArray())
  4434.         return
  4435.  
  4436.     def getSyncCode(this):
  4437.         if this.getPlayerCount() > 0:
  4438.             if this.currentSyncCode == -1:
  4439.                 client = random.choice(this.clients.values())
  4440.                 this.currentSyncCode = client.playerCode
  4441.                 this.currentSyncName = client.playerName
  4442.         elif this.currentSyncCode == -1:
  4443.             this.currentSyncCode = 0
  4444.             this.currentSyncName = ''
  4445.         return this.currentSyncCode
  4446.  
  4447.     def selectMap(this):
  4448.         if not this.forceNextMap == '-1':
  4449.             force = this.forceNextMap
  4450.             this.forceNextMap = '-1'
  4451.             this.mapCode = -1
  4452.             if force.isdigit():
  4453.                 return this.selectMapSpecificic(force, 'Vanilla')
  4454.             elif force.startswith('@'):
  4455.                 return this.selectMapSpecificic(force[1:], 'Custom')
  4456.             elif force.startswith('#'):
  4457.                 return this.selectMapSpecificic(force[1:], 'Perm')
  4458.             elif force.startswith('<'):
  4459.                 return this.selectMapSpecificic(force, 'Xml')
  4460.             else:
  4461.                 return 0
  4462.         else:
  4463.             if this.specificMap:
  4464.                 this.mapCode = -1
  4465.                 return this.currentMap
  4466.             if this.isEditor:
  4467.                 return this.EMapCode
  4468.             if this.isTribeHouse:
  4469.                 tribeName = this.roomName[2:]
  4470.                 runMap = this.server.getTribeHouse(tribeName)
  4471.                 if runMap == 0:
  4472.                     this.mapCode = 0
  4473.                     this.mapName = 'Danshweger'
  4474.                     this.mapXML = '<C><P /><Z><S><S Y="360" T="0" P="0,0,0.3,0.2,0,0,0,0" L="800" H="80" X="400" /></S><D><P Y="0" T="34" P="0,0" X="0" C="719b9f" /><T Y="320" X="49" /><P Y="320" T="16" X="224" P="0,0" /><P Y="319" T="17" X="311" P="0,0" /><P Y="284" T="18" P="1,0" X="337" C="57703e,e7c3d6" /><P Y="284" T="21" X="294" P="0,0" /><P Y="134" T="23" X="135" P="0,0" /><P Y="320" T="24" P="0,1" X="677" C="46788e" /><P Y="320" T="26" X="588" P="1,0" /><P Y="193" T="14" P="0,0" X="562" C="95311e,bde8f3,faf1b3" /></D><O /></Z></C>'
  4475.                     this.mapYesVotes = 0
  4476.                     this.mapNoVotes = 0
  4477.                     this.mapPerma = 22
  4478.                     this.mapInverted = False
  4479.                 else:
  4480.                     run = this.selectMapSpecificic(runMap, 'Custom')
  4481.                     if run != -1:
  4482.                         this.mapCode = 0
  4483.                         this.mapName = 'Danshweger'
  4484.                         this.mapXML = '<C><P /><Z><S><S Y="360" T="0" P="0,0,0.3,0.2,0,0,0,0" L="800" H="80" X="400" /></S><D><P Y="0" T="34" P="0,0" X="0" C="719b9f" /><T Y="320" X="49" /><P Y="320" T="16" X="224" P="0,0" /><P Y="319" T="17" X="311" P="0,0" /><P Y="284" T="18" P="1,0" X="337" C="57703e,e7c3d6" /><P Y="284" T="21" X="294" P="0,0" /><P Y="134" T="23" X="135" P="0,0" /><P Y="320" T="24" P="0,1" X="677" C="46788e" /><P Y="320" T="26" X="588" P="1,0" /><P Y="193" T="14" P="0,0" X="562" C="95311e,bde8f3,faf1b3" /></D><O /></Z></C>'
  4485.                         this.mapYesVotes = 0
  4486.                         this.mapNoVotes = 0
  4487.                         this.mapPerma = 22
  4488.                         this.mapInverted = False
  4489.             else:
  4490.                 if this.is801Room or this.isVillage:
  4491.                     return 801
  4492.                 if this.isVanilla:
  4493.                     this.mapCode = -1
  4494.                     this.mapName = 'Invalid'
  4495.                     this.mapXML = '<C><P /><Z><S /><D /><O /></Z></C>'
  4496.                     this.mapYesVotes = 0
  4497.                     this.mapNoVotes = 0
  4498.                     this.mapPerma = -1
  4499.                     this.mapInverted = False
  4500.                     map = random.choice(this.mapList)
  4501.                     while map == this.currentMap:
  4502.                         map = random.choice(this.mapList)
  4503.  
  4504.                     return map
  4505.                 this.mapCode = -1
  4506.                 this.mapName = 'Invalid'
  4507.                 this.mapXML = '<C><P /><Z><S /><D /><O /></Z></C>'
  4508.                 this.mapYesVotes = 0
  4509.                 this.mapNoVotes = 0
  4510.                 this.mapPerma = -1
  4511.                 this.mapInverted = False
  4512.                 return this.selectMapStatus()
  4513.         return -1
  4514.  
  4515.     def selectMapStatus(this):
  4516.         maps = [0,
  4517.          -1,
  4518.          4,
  4519.          9,
  4520.          5,
  4521.          0,
  4522.          -1,
  4523.          8,
  4524.          6,
  4525.          7]
  4526.         selectPerma = (17 if this.mapStatus % 2 == 0 else 17) if this.isRacing else ((13 if this.mapStatus % 2 == 0 else 3) if this.isBootcamp else (18 if this.isDefilante else ((11 if this.mapStatus == 0 else 10) if this.isSurvivor else (31 if this.isDeathmatch else (19 if this.isMusic and this.mapStatus % 2 == 0 else 0)))))
  4527.         isMultiple = False
  4528.         if this.isNormRoom:
  4529.             if this.mapStatus < len(maps) and maps[this.mapStatus] != -1:
  4530.                 isMultiple = maps[this.mapStatus] == 0
  4531.                 selectPerma = maps[this.mapStatus]
  4532.             else:
  4533.                 map = random.choice(this.mapList)
  4534.                 while map == this.currentMap:
  4535.                     map = random.choice(this.mapList)
  4536.  
  4537.                 return map
  4538.         elif this.isDeathmatch:
  4539.             CursorMaps.execute('select Code from maps where Perma = 31 ORDER BY RANDOM() LIMIT 1')
  4540.             r = CursorMaps.fetchall()
  4541.             for rs in r:
  4542.                 this.mapList.append(rs[0])
  4543.  
  4544.         elif this.isVanilla or this.isMusic and this.mapStatus % 2 != 0:
  4545.             map = random.choice(this.mapList)
  4546.             while map == this.currentMap:
  4547.                 map = random.choice(this.mapList)
  4548.  
  4549.             return map
  4550.         CursorMaps.execute('select * from Maps where Code != ' + str(this.currentMap) + ' and Perma = 0 or Perma = 1 ORDER BY RANDOM() LIMIT 1' if isMultiple else 'select * from Maps where Code != ' + str(this.currentMap) + ' and Perma = ' + str(selectPerma) + ' order by random() limit 1')
  4551.         rs = CursorMaps.fetchone()
  4552.         if rs:
  4553.             this.mapCode = rs['Code']
  4554.             this.mapName = rs['Name']
  4555.             this.mapXML = rs['XML']
  4556.             this.mapYesVotes = rs['YesVotes']
  4557.             this.mapNoVotes = rs['NoVotes']
  4558.             this.mapPerma = rs['Perma']
  4559.             this.mapInverted = random.randint(0, 100) > 85
  4560.         else:
  4561.             map = random.choice(this.mapList)
  4562.             while map == this.currentMap:
  4563.                 map = random.choice(this.mapList)
  4564.  
  4565.             return map
  4566.         return -1
  4567.  
  4568.     def selectMapSpecificic(this, code, type):
  4569.         if type == 'Vanilla':
  4570.             return int(code)
  4571.         else:
  4572.             if type == 'Custom':
  4573.                 mapInfo = this.getMapInfo(int(code))
  4574.                 if mapInfo[0] == None:
  4575.                     return 0
  4576.                 else:
  4577.                     this.mapCode = int(code)
  4578.                     this.mapName = str(mapInfo[0])
  4579.                     this.mapXML = str(mapInfo[1])
  4580.                     this.mapYesVotes = int(mapInfo[2])
  4581.                     this.mapNoVotes = int(mapInfo[3])
  4582.                     this.mapPerma = int(mapInfo[4])
  4583.                     this.mapInverted = False
  4584.                     return -1
  4585.             elif type == 'Perm':
  4586.                 mapList = []
  4587.                 CursorMaps.execute('select Code from Maps where Perma = ?', [int(str(code))])
  4588.                 for rs in CursorMaps.fetchall():
  4589.                     mapList.append(rs['Code'])
  4590.  
  4591.                 if len(mapList) >= 1:
  4592.                     runMap = random.choice(mapList)
  4593.                 else:
  4594.                     runMap = 0
  4595.                 if len(mapList) >= 2:
  4596.                     while runMap == this.currentMap:
  4597.                         runMap = random.choice(mapList)
  4598.  
  4599.                 if runMap == 0:
  4600.                     map = random.choice(this.MapList)
  4601.                     while map == this.currentMap:
  4602.                         map = random.choice(this.MapList)
  4603.  
  4604.                     return map
  4605.                 else:
  4606.                     mapInfo = this.getMapInfo(runMap)
  4607.                     this.mapCode = runMap
  4608.                     this.mapName = str(mapInfo[0])
  4609.                     this.mapXML = str(mapInfo[1])
  4610.                     this.mapYesVotes = int(mapInfo[2])
  4611.                     this.mapNoVotes = int(mapInfo[3])
  4612.                     this.mapPerma = int(mapInfo[4])
  4613.                     this.mapInverted = False
  4614.                     return -1
  4615.             elif type == 'Xml':
  4616.                 this.mapCode = 0
  4617.                 this.mapName = '#Module'
  4618.                 this.mapXML = str(code)
  4619.                 this.mapYesVotes = 0
  4620.                 this.mapNoVotes = 0
  4621.                 this.mapPerma = 22
  4622.                 this.mapInverted = False
  4623.                 return -1
  4624.             return
  4625.  
  4626.     def getMapInfo(this, mapCode):
  4627.         mapInfo = ['',
  4628.          '',
  4629.          0,
  4630.          0,
  4631.          0]
  4632.         CursorMaps.execute('select Name, XML, YesVotes, NoVotes, Perma from Maps where Code = ?', [mapCode])
  4633.         rs = CursorMaps.fetchone()
  4634.         if rs:
  4635.             mapInfo = (rs['Name'],
  4636.              rs['XML'],
  4637.              rs['YesVotes'],
  4638.              rs['NoVotes'],
  4639.              rs['Perma'])
  4640.         return mapInfo
  4641.  
  4642.     def checkIfDeathMouse(this):
  4643.         return len(filter(lambda client: not client.isDead, this.clients.values())) <= 1
  4644.  
  4645.     def checkIfTooFewRemaining(this):
  4646.         return len(filter(lambda client: not client.isDead, this.clients.values())) <= 2
  4647.  
  4648.     def getAliveCount(this):
  4649.         return len(filter(lambda client: not client.isDead, this.clients.values()))
  4650.  
  4651.     def getDeathCountNoShaman(this):
  4652.         return len(filter(lambda client: not client.isShaman and not client.isDead, this.clients.values()))
  4653.  
  4654.     def getHighestScore(this):
  4655.         playerScores = []
  4656.         playerID = 0
  4657.         for client in this.clients.values():
  4658.             playerScores.append(client.playerScore)
  4659.  
  4660.         for client in this.clients.values():
  4661.             if client.playerScore == max(playerScores):
  4662.                 playerID = client.playerCode
  4663.  
  4664.         return playerID
  4665.  
  4666.     def getSecondHighestScore(this):
  4667.         playerScores = []
  4668.         playerID = 0
  4669.         for client in this.clients.values():
  4670.             playerScores.append(client.playerScore)
  4671.  
  4672.         playerScores.remove(max(playerScores))
  4673.         if len(playerScores) >= 1:
  4674.             for client in this.clients.values():
  4675.                 if client.playerScore == max(playerScores):
  4676.                     playerID = client.playerCode
  4677.  
  4678.         return playerID
  4679.  
  4680.     def getShamanCode(this):
  4681.         if this.currentShamanCode == -1:
  4682.             if this.currentMap in this.noShamanMaps or this.isNoShamanMap or this.noShaman:
  4683.                 pass
  4684.             elif this.forceNextShaman > 0:
  4685.                 this.currentShamanCode = this.forceNextShaman
  4686.                 this.forceNextShaman = 0
  4687.             else:
  4688.                 this.currentShamanCode = this.getHighestScore()
  4689.             if this.currentShamanCode == -1:
  4690.                 this.currentShamanName = ''
  4691.             else:
  4692.                 for client in this.clients.values():
  4693.                     if client.playerCode == this.currentShamanCode:
  4694.                         this.currentShamanName = client.playerName
  4695.                         this.currentShamanType = client.shamanType
  4696.                         this.currentShamanSkills = client.playerSkills
  4697.                         break
  4698.  
  4699.         return this.currentShamanCode
  4700.  
  4701.     def getDoubleShamanCode(this):
  4702.         if this.currentShamanCode == -1 and this.currentSecondShamanCode == -1:
  4703.             if this.forceNextShaman > 0:
  4704.                 this.currentShamanCode = this.forceNextShaman
  4705.                 this.forceNextShaman = 0
  4706.             else:
  4707.                 this.currentShamanCode = this.getHighestScore()
  4708.             if this.currentSecondShamanCode == -1:
  4709.                 this.currentSecondShamanCode = this.getSecondHighestScore()
  4710.             if this.currentSecondShamanCode == this.currentShamanCode:
  4711.                 tempClient = random.choice(this.clients.values())
  4712.                 this.currentSecondShamanCode = tempClient.playerCode
  4713.             for client in this.clients.values():
  4714.                 if client.playerCode == this.currentShamanCode:
  4715.                     this.currentShamanName = client.playerName
  4716.                     this.currentShamanType = client.shamanType
  4717.                     this.currentShamanSkills = client.playerSkills
  4718.                     break
  4719.                 if client.playerCode == this.currentSecondShamanCode:
  4720.                     this.currentSecondShamanName = client.playerName
  4721.                     this.currentSecondShamanType = client.shamanType
  4722.                     this.currentSecondShamanSkills = client.playerSkills
  4723.                     break
  4724.  
  4725.         return [this.currentShamanCode, this.currentSecondShamanCode]
  4726.  
  4727.     def closeVoting(this):
  4728.         this.initVotingMode = False
  4729.         this.isVotingBox = False
  4730.         if this.voteCloseTimer != None:
  4731.             this.voteCloseTimer.cancel()
  4732.         this.mapChange()
  4733.         return
  4734.  
  4735.     def killShaman(this):
  4736.         for client in this.clients.values():
  4737.             if client.playerCode == this.currentShamanCode:
  4738.                 client.isDead = True
  4739.                 client.sendPlayerDied()
  4740.  
  4741.         this.checkChangeMap()
  4742.  
  4743.     def killAfk(this):
  4744.         if this.isEditor or this.isTotemEditor or this.isBootcamp or this.isTribeHouseMap or this.disableAfkKill:
  4745.             return
  4746.         if Utils.getTime() - this.gameStartTime < 32 and Utils.getTime() - this.gameStartTime > 28:
  4747.             for client in this.clients.values():
  4748.                 if not client.isDead and client.isAfk:
  4749.                     client.isDead = True
  4750.                     if not this.noAutoScore:
  4751.                         client.playerScore += 1
  4752.                     client.sendPlayerDied()
  4753.  
  4754.             this.checkChangeMap()
  4755.  
  4756.     def checkIfDoubleShamansAreDead(this):
  4757.         player1 = this.clients.get(this.currentShamanName)
  4758.         player2 = this.clients.get(this.currentSecondShamanName)
  4759.         return (False if player1 == None else player1.isDead) and (False if player2 == None else player2.isDead)
  4760.  
  4761.     def checkIfShamanIsDead(this):
  4762.         client = this.clients.get(this.currentShamanName)
  4763.         if client == None:
  4764.             return False
  4765.         else:
  4766.             return client.isDead
  4767.  
  4768.     def checkIfShamanCanGoIn(this):
  4769.         for client in this.clients.values():
  4770.             if client.playerCode != this.currentShamanCode and client.playerCode != this.currentSecondShamanCode and not client.isDead:
  4771.                 return False
  4772.  
  4773.         return True
  4774.  
  4775.     def giveShamanSave(this, shamanName, type):
  4776.         if not this.countStats:
  4777.             return
  4778.         else:
  4779.             client = this.clients.get(shamanName)
  4780.             if client != None:
  4781.                 if type == 0:
  4782.                     client.shamanSaves += 1
  4783.                 elif type == 1:
  4784.                     client.hardModeSaves += 1
  4785.                 elif type == 2:
  4786.                     client.divineModeSaves += 1
  4787.                 if client.privLevel != 0:
  4788.                     counts = [client.shamanSaves, client.hardModeSaves, client.divineModeSaves]
  4789.                     titles = [this.server.shamanTitleList, this.server.hardModeTitleList, this.server.divineModeTitleList]
  4790.                     rebuilds = ['shaman', 'hardmode', 'divinemode']
  4791.                     if titles[type].has_key(counts[type]):
  4792.                         title = titles[type][counts[type]]
  4793.                         client.checkAndRebuildTitleList(rebuilds[type])
  4794.                         client.sendUnlockedTitle(int(title - title % 1), int(round(title % 1 * 10)))
  4795.                         client.sendCompleteTitleList()
  4796.                         client.sendTitleList()
  4797.             return
  4798.  
  4799.     def respawnMice(this):
  4800.         for client in this.clients.values():
  4801.             if client.isDead:
  4802.                 client.isDead = False
  4803.                 client.playerStartTimeMillis = time.time()
  4804.                 this.sendAll(Identifiers.old.send.Player_Respawn, [client.getPlayerData(), 0 if this.isBootcamp else 1])
  4805.  
  4806.         if this.autoRespawn or this.isTribeHouseMap:
  4807.             this.autoRespawnTimer = reactor.callLater(2, this.respawnMice)
  4808.  
  4809.     def respawnSpecific(this, playerName):
  4810.         client = this.clients.get(playerName)
  4811.         if client != None and client.isDead:
  4812.             client.resetPlay()
  4813.             client.isAfk = False
  4814.             client.playerStartTimeMillis = time.time()
  4815.             this.sendAll(Identifiers.old.send.Player_Respawn, [client.getPlayerData(), 0 if this.isBootcamp else 1])
  4816.         return
  4817.  
  4818.     def checkMapXML(this):
  4819.         if int(this.currentMap) in this.server.vanillaMaps:
  4820.             this.mapCode = int(this.currentMap)
  4821.             this.mapName = '_Atelier 801' if this.mapCode == 801 else 'Transformice'
  4822.             this.mapXML = str(this.server.vanillaMaps[int(this.currentMap)])
  4823.             this.mapYesVotes = 0
  4824.             this.mapNoVotes = 0
  4825.             this.mapPerma = 41
  4826.             this.currentMap = -1
  4827.             this.mapInverted = False
  4828.  
  4829.     def sendVampireMode(this):
  4830.         client = this.clients.get(this.currentSyncName)
  4831.         if client != None:
  4832.             client.sendVampireMode(False)
  4833.         return
  4834.  
  4835.     def addPhysicObject(this, id, x, y, bodyDef):
  4836.         this.sendAll(Identifiers.send.Add_Physic_Object, ByteArray().writeShort(id).writeBoolean(bool(bodyDef['dynamic']) if bodyDef.has_key('dynamic') else False).writeByte(int(bodyDef['type']) if bodyDef.has_key('type') else 0).writeShort(x).writeShort(y).writeShort(int(bodyDef['width']) if bodyDef.has_key('width') else 0).writeShort(int(bodyDef['height']) if bodyDef.has_key('height') else 0).writeBoolean(bool(bodyDef['foreground']) if bodyDef.has_key('foreground') else False).writeShort(int(bodyDef['friction']) if bodyDef.has_key('friction') else 0).writeShort(int(bodyDef['restitution']) if bodyDef.has_key('restitution') else 0).writeShort(int(bodyDef['angle']) if bodyDef.has_key('angle') else 0).writeBoolean(bodyDef.has_key('color')).writeInt(int(bodyDef['color']) if bodyDef.has_key('color') else 0).writeBoolean(bool(bodyDef['miceCollision']) if bodyDef.has_key('miceCollision') else True).writeBoolean(bool(bodyDef['groundCollision']) if bodyDef.has_key('groundCollision') else True).writeBoolean(bool(bodyDef['fixedRotation']) if bodyDef.has_key('fixedRotation') else False).writeShort(int(bodyDef['mass']) if bodyDef.has_key('mass') else 0).writeShort(int(bodyDef['linearDamping']) if bodyDef.has_key('linearDamping') else 0).writeShort(int(bodyDef['angularDamping']) if bodyDef.has_key('angularDamping') else 0).writeBoolean(False).writeUTF('').toByteArray())
  4837.  
  4838.     def removeObject(this, objectId):
  4839.         this.sendAll(Identifiers.send.Remove_Object, ByteArray().writeInt(objectId).writeBoolean(True).toByteArray())
  4840.  
  4841.     def bindKeyBoard(this, playerName, key, down, yes):
  4842.         client = this.clients.get(playerName)
  4843.         if client != None:
  4844.             client.sendPacket(Identifiers.send.Bind_Key_Board, ByteArray().writeShort(key).writeBoolean(down).writeBoolean(yes).toByteArray())
  4845.         return
  4846.  
  4847.     def movePlayer(this, playerName, xPosition, yPosition, pOffSet, xSpeed, ySpeed, sOffSet):
  4848.         client = this.clients.get(playerName)
  4849.         if client != None:
  4850.             client.sendPacket(Identifiers.send.Move_Player, ByteArray().writeShort(xPosition).writeShort(yPosition).writeBoolean(pOffSet).writeShort(xSpeed).writeShort(ySpeed).writeBoolean(sOffSet).toByteArray())
  4851.         return
  4852.  
  4853.     def setNameColor(this, playerName, color):
  4854.         if this.clients.has_key(playerName):
  4855.             this.sendAll(Identifiers.send.Set_Name_Color, ByteArray().writeInt(this.clients.get(playerName).playerCode).writeInt(color).toByteArray())
  4856.  
  4857.     def addPopup(this, id, type, text, targetPlayer, x, y, width, fixedPos):
  4858.         p = ByteArray().writeInt(id).writeByte(type).writeUTF(text).writeShort(x).writeShort(y).writeShort(width).writeBoolean(fixedPos)
  4859.         if targetPlayer == '':
  4860.             this.sendAllBin([29, 23], p.toByteArray())
  4861.         else:
  4862.             client = this.clients.get(targetPlayer)
  4863.             if client != None:
  4864.                 client.sendPacket([29, 23], p.toByteArray())
  4865.         return
  4866.  
  4867.     def addTextArea(this, id, text, targetPlayer, x, y, width, height, backgroundColor, borderColor, backgroundAlpha, fixedPos):
  4868.         p = ByteArray().writeInt(id).writeUTF(text).writeShort(x).writeShort(y).writeShort(width).writeShort(height).writeInt(backgroundColor).writeInt(borderColor).writeByte(100 if backgroundAlpha > 100 else backgroundAlpha).writeBoolean(fixedPos)
  4869.         if targetPlayer == '':
  4870.             this.sendAll(Identifiers.send.Add_Text_Area, p.toByteArray())
  4871.         else:
  4872.             client = this.clients.get(targetPlayer)
  4873.             if client != None:
  4874.                 client.sendPacket(Identifiers.send.Add_Text_Area, p.toByteArray())
  4875.         return
  4876.  
  4877.     def removeTextArea(this, id, targetPlayer):
  4878.         p = ByteArray().writeInt(id)
  4879.         if targetPlayer == '':
  4880.             this.sendAll(Identifiers.send.Remove_Text_Area, p.toByteArray())
  4881.         else:
  4882.             client = this.clients.get(targetPlayer)
  4883.             if client != None:
  4884.                 client.sendPacket(Identifiers.send.Remove_Text_Area, p.toByteArray())
  4885.         return
  4886.  
  4887.     def updateTextArea(this, id, text, targetPlayer):
  4888.         p = ByteArray().writeInt(id).writeUTF(text)
  4889.         if targetPlayer == '':
  4890.             this.sendAllBin([29, 21], p.toByteArray())
  4891.         else:
  4892.             client = this.clients.get(targetPlayer)
  4893.             if client != None:
  4894.                 client.sendPacket([29, 21], p.toByteArray())
  4895.         return
  4896.  
  4897.     def bindMouse(this, playerName, yes):
  4898.         client = this.clients.get(playerName)
  4899.         if client != None:
  4900.             client.sendPacket(Identifiers.send.Bind_Mouse, ByteArray().writeBoolean(yes).toByteArray())
  4901.         return
  4902.  
  4903.     def showColorPicker(this, id, targetPlayer, defaultColor, title):
  4904.         packet = ByteArray().writeInt(id).writeInt(defaultColor).writeUTF(title)
  4905.         if targetPlayer == '':
  4906.             this.sendAll(Identifiers.send.Show_Color_Picker, packet.toByteArray())
  4907.         else:
  4908.             client = this.clients.get(targetPlayer)
  4909.             if client != None:
  4910.                 client.sendPacket(Identifiers.send.Show_Color_Picker, packet.toByteArray())
  4911.         return
  4912.  
  4913.     def startSnowSchedule(this, power):
  4914.         if this.isSnowing:
  4915.             this.startSnow(0, power, False)
  4916.  
  4917.     def startSnow(this, millis, power, enabled):
  4918.         this.isSnowing = enabled
  4919.         this.sendAll(Identifiers.send.Snow, ByteArray().writeBoolean(enabled).writeShort(power).toByteArray())
  4920.         if enabled:
  4921.             this.endSnowTimer = reactor.callLater(millis, lambda : this.startSnowSchedule(power))
  4922.  
  4923.     def giveSurvivorStats(this):
  4924.         for player in this.clients.values():
  4925.             player.survivorStats[0] += 1
  4926.             if player.isShaman:
  4927.                 player.survivorStats[1] += 1
  4928.                 player.survivorStats[2] += this.getDeathCountNoShaman()
  4929.             elif not player.isDead:
  4930.                 player.survivorStats[3] += 1
  4931.  
  4932.     def giveRacingStats(this):
  4933.         for player in this.clients.values():
  4934.             player.racingStats[0] += 1
  4935.             if player.hasCheese or player.hasEnter:
  4936.                 player.racingStats[1] += 1
  4937.             if player.hasEnter:
  4938.                 if player.currentPlace <= 3:
  4939.                     player.racingStats[2] += 1
  4940.                 if player.currentPlace == 1:
  4941.                     player.racingStats[3] += 1
  4942.  
  4943.     def send20SecRemainingTimer(this):
  4944.         if not this.changed20secTimer:
  4945.             if not this.never20secTimer and this.roundTime + (this.gameStartTime - Utils.getTime()) > 21:
  4946.                 this.changed20secTimer = True
  4947.                 this.changeMapTimers(20)
  4948.                 for client in this.clients.values():
  4949.                     client.sendRoundTime(20)
  4950.  
  4951.     def changeMapTimers(this, seconds):
  4952.         if this.changeMapTimer != None:
  4953.             this.changeMapTimer.cancel()
  4954.         this.changeMapTimer = reactor.callLater(seconds, this.mapChange)
  4955.         return
  4956.  
  4957.     def newConsumableTimer(this, code):
  4958.         this.roomTimers.append(reactor.callLater(10, lambda : this.sendAll(Identifiers.send.Remove_Object, ByteArray().writeInt(code).writeBoolean(False).toByteArray())))
  4959.  
  4960.  
  4961. if __name__ == '__main__':
  4962.     config = ConfigParser.ConfigParser()
  4963.     config.read('./include/configs.properties')
  4964.     Database, Cursor = (None, None)
  4965.     Database = sqlite3.connect('./database/Users.db', check_same_thread=False)
  4966.     Database.text_factory = str
  4967.     Database.isolation_level = None
  4968.     Database.row_factory = sqlite3.Row
  4969.     Cursor = Database.cursor()
  4970.     DatabaseCafe, CursorCafe = (None, None)
  4971.     DatabaseCafe = sqlite3.connect('./database/Cafe.db', check_same_thread=False)
  4972.     DatabaseCafe.text_factory = str
  4973.     DatabaseCafe.isolation_level = None
  4974.     DatabaseCafe.row_factory = sqlite3.Row
  4975.     CursorCafe = DatabaseCafe.cursor()
  4976.     DatabaseMaps, CursorMaps = (None, None)
  4977.     DatabaseMaps = sqlite3.connect('./database/Maps.db', check_same_thread=False)
  4978.     DatabaseMaps.text_factory = str
  4979.     DatabaseMaps.isolation_level = None
  4980.     DatabaseMaps.row_factory = sqlite3.Row
  4981.     CursorMaps = DatabaseMaps.cursor()
  4982.     dateNow = datetime.now()
  4983.     os.system('title Source TsunaMice - 1.391')
  4984.     validPorts = []
  4985.     S = Server()
  4986.     for port in [443,
  4987.      6112,
  4988.      5555,
  4989.      44440,
  4990.      44444,
  4991.      3724]:
  4992.         try:
  4993.             reactor.listenTCP(port, S)
  4994.             validPorts.append(port)
  4995.         except:
  4996.             print 'Portas falharam > ' + str(port)
  4997.  
  4998.     if not validPorts == []:
  4999.         print '[%s] %s serveur running.' % (time.strftime('%H:%M:%S'), config.get('configGame', 'game.miceName'))
  5000.     reactor.run()# decompiled 0 files: 0 okay, 1 failed, 0 verify failed
  5001. # 2017.06.19 20:29:16 Hora oficial do Brasil
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement