Advertisement
Guest User

Untitled

a guest
May 14th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 192.24 KB | None | 0 0
  1. #coding: utf-8
  2.  
  3. import os, sys, json, time, random, ftplib, sqlite3, threading, urllib2, binascii, traceback, ConfigParser
  4.  
  5.  
  6.  
  7. # Compiler Files
  8.  
  9. sys.dont_write_bytecode = True
  10.  
  11.  
  12.  
  13. # Modules
  14.  
  15. from modules import *
  16.  
  17.  
  18.  
  19. # Utils
  20.  
  21. from utils import *
  22.  
  23.  
  24.  
  25. # Library
  26.  
  27. from twisted.internet import reactor, protocol
  28.  
  29. from datetime import datetime
  30.  
  31.  
  32.  
  33. from datetime import timedelta
  34.  
  35.  
  36.  
  37. class Client(ClientHandler):
  38.  
  39. def __init__(this):
  40.  
  41. # String
  42.  
  43. this.Username = ""
  44.  
  45. this.Langue = "BR"
  46.  
  47. this.realLangue = "BR"
  48.  
  49. this.MouseColor = "78583a"
  50.  
  51. this.ShamanColor = "95d9d6"
  52.  
  53. this.roomName = ""
  54.  
  55. this.shopItems = ""
  56.  
  57. this.shamanItems = ""
  58.  
  59. this.playerLook = "1;0,0,0,0,0,0,0,0,0"
  60.  
  61. this.shamanLook = "0,0,0,0,0,0,0,0,0,0"
  62.  
  63. this.lastMessage = ""
  64.  
  65. this.modoPwetLangue = "ALL"
  66.  
  67. this.silenceMessage = ""
  68.  
  69. this.marriage = ""
  70.  
  71. this.tribeName = ""
  72.  
  73. this.nameColor = ""
  74.  
  75. this.tradeName = ""
  76.  
  77. this.tempMouseColor = ""
  78.  
  79. this.mouseName = ""
  80.  
  81. this.botVillage = ""
  82.  
  83.  
  84.  
  85. # Integer
  86.  
  87. this.lastPacketID = random.randint(0, 99)
  88.  
  89. this.authKey = random.randint(0, 2147483647)
  90.  
  91. this.langueByte = 0
  92.  
  93. this.playerScore = 0
  94.  
  95. this.playerCode = 0
  96.  
  97. this.privLevel = 0
  98.  
  99. this.playerID = 0
  100.  
  101. this.TitleNumber = 0
  102.  
  103. this.TitleStars = 0
  104.  
  105. this.posX = 0
  106.  
  107. this.posY = 0
  108.  
  109. this.velX = 0
  110.  
  111. this.velY = 0
  112.  
  113. this.firstCount = 0
  114.  
  115. this.cheeseCount = 0
  116.  
  117. this.shamanCheeses = 0
  118.  
  119. this.shopCheeses = 100
  120.  
  121. this.shopFraises = 0
  122.  
  123. this.shamanSaves = 0
  124.  
  125. this.hardModeSaves = 0
  126.  
  127. this.divineModeSaves = 0
  128.  
  129. this.bootcampCount = 0
  130.  
  131. this.shamanType = 0
  132.  
  133. this.regDate = 0
  134.  
  135. this.banHours = 0
  136.  
  137. this.shamanLevel = 1
  138.  
  139. this.shamanExp = 0
  140.  
  141. this.shamanExpNext = 32
  142.  
  143. this.ambulanceCount = 0
  144.  
  145. this.bubblesCount = 0
  146.  
  147. this.lastOn = 0
  148.  
  149. this.silenceType = 0
  150.  
  151. this.gender = 0
  152.  
  153. this.lastDivorceTimer = 0
  154.  
  155. this.tribeCode = 0
  156.  
  157. this.tribeRank = 0
  158.  
  159. this.tribeJoined = 0
  160.  
  161. this.tribePoints = 0
  162.  
  163. this.defilantePoints = 0
  164.  
  165. this.iceCount = 2
  166.  
  167. this.lastGameMode = 0
  168.  
  169. this.nowCoins = 0
  170.  
  171. this.nowTokens = 0
  172.  
  173. this.currentPlace = 0
  174.  
  175. this.equipedShamanBadge = 0
  176.  
  177. this.pet = 0
  178.  
  179. this.petEnd = 0
  180.  
  181. this.numGiveCheese = 0
  182.  
  183. this.racingRounds = 0
  184.  
  185. this.bootcampRounds = 0
  186.  
  187. this.survivorDeath = 0
  188.  
  189. this.priceDoneVisu = 0
  190.  
  191.  
  192.  
  193. this.playerStartTimeMillis = 0
  194.  
  195.  
  196.  
  197. # Bool
  198.  
  199. this.isClosed = False
  200.  
  201. this.validatingVersion = False
  202.  
  203. this.isGuest = False
  204.  
  205. this.isReceivedDummy = False
  206.  
  207. this.isDead = False
  208.  
  209. this.hasCheese = False
  210.  
  211. this.hasEnter = False
  212.  
  213. this.isMovingRight = False
  214.  
  215. this.isMovingLeft = False
  216.  
  217. this.isJumping = False
  218.  
  219. this.isShaman = False
  220.  
  221. this.isSuspect = False
  222.  
  223. this.isAfk = False
  224.  
  225. this.isVoted = False
  226.  
  227. this.qualifiedVoted = False
  228.  
  229. this.isMute = False
  230.  
  231. this.RTotem = False
  232.  
  233. this.UTotem = False
  234.  
  235. this.LoadCountTotem = False
  236.  
  237. this.modoPwet = False
  238.  
  239. this.canResSkill = False
  240.  
  241. this.canShamanRespawn = False
  242.  
  243. this.isOpportunist = False
  244.  
  245. this.desintegration = False
  246.  
  247. this.sendMusic = True
  248.  
  249. this.isCafe = False
  250.  
  251. this.canSkipMusic = False
  252.  
  253. this.isHidden = False
  254.  
  255. this.isTeleport = False
  256.  
  257. this.isFly = False
  258.  
  259. this.isExplosion = False
  260.  
  261. this.isFFA = False
  262.  
  263. this.canSpawnCN = True
  264.  
  265. this.isSpeed = False
  266.  
  267. this.isNewPlayer = False
  268.  
  269. this.isVampire = False
  270.  
  271. this.isLuaAdmin = False
  272.  
  273. this.isTrade = False
  274.  
  275. this.tradeConfirm = False
  276.  
  277. this.canUseConsumable = True
  278.  
  279. this.canRespawn = False
  280.  
  281. this.isSkill = False
  282.  
  283. this.showButtons = True
  284.  
  285. this.hasBolo = False
  286.  
  287. this.hasBolo2 = False
  288.  
  289.  
  290.  
  291. # Others
  292.  
  293. this.Cursor = Cursor
  294.  
  295. this.TFMUtils = TFMUtils
  296.  
  297. this.apiToken = TFMUtils.getRandomChars(50)
  298.  
  299.  
  300.  
  301. # Nonetype
  302.  
  303. this.room = None
  304.  
  305. this.resSkillsTimer = None
  306.  
  307. this.consumablesTimer = None
  308.  
  309. this.skipMusicTimer = None
  310.  
  311.  
  312.  
  313. # List
  314.  
  315. this.STotem = [0, ""]
  316.  
  317. this.Totem = [0, ""]
  318.  
  319. this.survivorStats = [0] * 4
  320.  
  321. this.racingStats = [0] * 4
  322.  
  323. this.marriageInvite = []
  324.  
  325. this.tribeData = ["", "", 0, None]
  326.  
  327. this.tribeInvite = []
  328.  
  329. this.mulodromePos = []
  330.  
  331. this.canLogin = [False, False]
  332.  
  333. this.cheeseTitleList = []
  334.  
  335. this.firstTitleList = []
  336.  
  337. this.shamanTitleList = []
  338.  
  339. this.shopTitleList = []
  340.  
  341. this.bootcampTitleList = []
  342.  
  343. this.hardModeTitleList = []
  344.  
  345. this.divineModeTitleList = []
  346.  
  347. this.specialTitleList = []
  348.  
  349. this.titleList = []
  350.  
  351. this.clothes = []
  352.  
  353. this.shopBadges = []
  354.  
  355. this.friendsList = []
  356.  
  357. this.ignoredsList = []
  358.  
  359. this.ignoredMarriageInvites = []
  360.  
  361. this.ignoredTribeInvites = []
  362.  
  363. this.chats = []
  364.  
  365. this.voteBan = []
  366.  
  367. this.shamanBadges = []
  368.  
  369. this.equipedConsumables = []
  370.  
  371. this.custom = []
  372.  
  373.  
  374.  
  375. # Dict
  376.  
  377. this.playerSkills = {}
  378.  
  379. this.playerConsumables = {}
  380.  
  381. this.tradeConsumables = {}
  382.  
  383. this.itensBots = {"Papaille": [(4, 800, 50, 4, 2253, 50), (4, 800, 50, 4, 2254, 50), (4, 800, 50, 4, 2257, 50), (4, 800, 50, 4, 2260, 50), (4, 800, 50, 4, 2261, 50)], "Buffy": [(1, 147, 1, 4, 2254, 200), (2, 17, 1, 4, 2254, 150), (2, 18, 1, 4, 2254, 150), (2, 19, 1, 4, 2254, 150), (3, 398, 1, 4, 2254, 150), (3, 392, 1, 4, 2254, 50)], "Indiana Mouse": [(3, 255, 1, 4, 2257, 50), (3, 394, 1, 4, 2257, 50), (3, 395, 1, 4, 2257, 50), (3, 320, 1, 4, 2257, 50), (3, 393, 1, 4, 2257, 50), (3, 402, 1, 4, 2257, 50), (3, 397, 1, 4, 2257, 50), (3, 341, 1, 4, 2257, 50), (3, 335, 1, 4, 2257, 25), (3, 403, 1, 4, 2257, 50), (1, 6, 1, 4, 2257, 50), (1, 17, 1, 4, 2257, 50)], "Elise": [(4, 31, 2, 4, 2261, 5), (4, 2256, 2, 4, 2261, 5), (4, 2232, 2, 4, 2253, 1), (4, 21, 5, 4, 2253, 1), (4, 33, 2, 4, 2260, 1), (4, 33, 2, 4, 2254, 1)], "Oracle": [(1, 145, 1, 4, 2253, 200), (2, 16, 1, 4, 2253, 150), (2, 21, 1, 4, 2253, 150), (2, 24, 1, 4, 2253, 150), (2, 20, 1, 4, 2253, 150), (3, 390, 1, 4, 2253, 50), (3, 391, 1, 4, 2253, 200), (3, 399, 1, 4, 2253, 150)], "Prof": [(4, 800, 20, 4, 2257, 10), (4, 19, 2, 4, 2257, 5), (4, 2258, 2, 4, 2257, 4), (4, 2262, 5, 4, 2257, 2), (4, 2259, 10, 4, 2257, 1), (4, 20, 1, 4, 2257, 2)], "Cassidy": [(1, 154, 1, 4, 2261, 200), (2, 23, 1, 4, 2261, 150), (3, 400, 1, 4, 2261, 100)], "Von Drekkemouse": [(2, 22, 1, 4, 2260, 150), (1, 153, 1, 4, 2260, 200), (3, 401, 1, 4, 2260, 100)], "Tod": [(4, 2259, 10, 4, 2257, 1), (4, 2258, 10, 4, 2254, 230), (3, 401, 1, 4, 2260, 100)]}
  384.  
  385.  
  386.  
  387. def connectionMade(this):
  388.  
  389. this.ipAddress = this.transport.getPeer().host
  390.  
  391. this.server = this.factory
  392.  
  393.  
  394.  
  395. this.parsePackets = ParsePackets(this, this.server)
  396.  
  397. this.parseCommands = ParseCommands(this, this.server)
  398.  
  399. this.shopModule = ShopModule(this, this.server)
  400.  
  401. this.ModoPwet = ModoPwet(this, this.server)
  402.  
  403. this.skillModule = SkillModule(this, this.server)
  404.  
  405. this.tribulle = Tribulle(this, this.server)
  406.  
  407.  
  408.  
  409. # Menu
  410.  
  411. this.shop = shop(this, this.server)
  412.  
  413. this.spinTheWheel = spinTheWheel(this, this.server)
  414.  
  415. this.consumablesShop = consumablesShop(this, this.server)
  416.  
  417. this.Utility = Utility(this, this.server)
  418.  
  419.  
  420.  
  421. if this.server.getIPPermaBan(this.ipAddress) or this.ipAddress in this.server.tempIPBanList:
  422.  
  423. this.transport.loseConnection()
  424.  
  425. return
  426.  
  427.  
  428.  
  429. if this.server.connectedCounts.has_key(this.ipAddress):
  430.  
  431. this.server.connectedCounts[this.ipAddress] += 1
  432.  
  433. else:
  434.  
  435. this.server.connectedCounts[this.ipAddress] = 1
  436.  
  437.  
  438.  
  439. if this.server.connectedCounts[this.ipAddress] >= 5:
  440.  
  441. this.server.tempIPBanList.append(this.ipAddress)
  442.  
  443. this.server.sendOutput("Attack DDOS blocked in IP: "+str(this.ipAddress))
  444.  
  445. this.server.sendStaffMessage(7, "<R>Attack DDOS</R>: <J>["+str(this.ipAddress)+"]</J>")
  446.  
  447. this.server.disconnectIPAddress(this.ipAddress)
  448.  
  449. del this.server.connectedCounts[this.ipAddress]
  450.  
  451. this.transport.loseConnection()
  452.  
  453.  
  454.  
  455. def connectionLost(this, remove=True):
  456.  
  457. this.isClosed = True
  458.  
  459. for timer in [this.resSkillsTimer, this.consumablesTimer, this.skipMusicTimer]:
  460.  
  461. if timer != None:
  462.  
  463. timer.cancel()
  464.  
  465.  
  466.  
  467. if this.server.connectedCounts.has_key(this.ipAddress):
  468.  
  469. count = this.server.connectedCounts[this.ipAddress] - 1
  470.  
  471. if count <= 0:
  472.  
  473. del this.server.connectedCounts[this.ipAddress]
  474.  
  475. else:
  476.  
  477. this.server.connectedCounts[this.ipAddress] = count
  478.  
  479.  
  480.  
  481. if not this.Username == "":
  482.  
  483. if not this.isGuest:
  484.  
  485. this.updateDatabase()
  486.  
  487.  
  488.  
  489. if this.isTrade:
  490.  
  491. this.cancelTrade(this.tradeName)
  492.  
  493.  
  494.  
  495. if this.server.players.has_key(this.Username) and remove:
  496.  
  497. del this.server.players[this.Username]
  498.  
  499.  
  500.  
  501. if this.ModoPwet.checkReport(this.server.reports["names"], this.Username):
  502.  
  503. if not this.server.reports[this.Username]["status"] == "banned":
  504.  
  505. this.server.reports[this.Username]["status"] = "disconnected"
  506.  
  507. this.ModoPwet.updateModoPwet()
  508.  
  509.  
  510.  
  511. if this.server.chatMessages.has_key(this.Username):
  512.  
  513. this.server.chatMessages[this.Username] = {}
  514.  
  515. del this.server.chatMessages[this.Username]
  516.  
  517.  
  518.  
  519. for client in this.server.players.values():
  520.  
  521. if this.Username and client.Username in this.friendsList and client.friendsList:
  522.  
  523. client.tribulle.sendFriendDisconnected(this.Username)
  524.  
  525.  
  526.  
  527. if not this.tribeName == "":
  528.  
  529. this.tribulle.sendTribeMemberDisconnected()
  530.  
  531.  
  532.  
  533. if this.privLevel >= 5:
  534.  
  535. this.server.sendStaffMessage(5, "<ROSE>" + ("[Fundador]" if this.privLevel == 11 else "[Admin]" if this.privLevel == 10 else "[Coord]" if this.privLevel == 9 else "[Smod]" if this.privLevel == 8 else "[Mod]" if this.privLevel == 7 else "[MapCrew]" if this.privLevel == 6 else "[Helper]" if this.privLevel == 5 else "") + "["+this.Langue+"] <CH>" + this.Username + " <N>is offline.")
  536.  
  537. this.sendStaffLogin(True)
  538.  
  539.  
  540.  
  541. if this.room != None:
  542.  
  543. this.room.removeClient(this)
  544.  
  545.  
  546.  
  547. def sendPacket(this, identifiers, packet=""):
  548.  
  549. if this.isClosed:
  550.  
  551. return
  552.  
  553.  
  554.  
  555. p = ByteArray().writeBytes("".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)))
  556.  
  557. if not this.isClosed:
  558.  
  559. this.transport.write((ByteArray().writeByte(1).writeUnsignedByte(p.getLength()) if p.getLength() <= 0xFF else ByteArray().writeByte(2).writeUnsignedShort(p.getLength()) if p.getLength() <= 0xFFFF else ByteArray().writeByte(3).writeUnsignedByte((p.getLength() >> 16) & 0xFF).writeUnsignedByte((p.getLength() >> 8) & 0xFF).writeUnsignedByte(p.getLength() & 0xFF) if p.getLength() <= 0xFFFFFF else 0).writeBytes(p.toByteArray()).toByteArray())
  560.  
  561.  
  562.  
  563. def parseString(this, packet):
  564.  
  565. if this.isClosed:
  566.  
  567. return
  568.  
  569.  
  570.  
  571. if packet in ["", " ", "\x00", "\x01"]:
  572.  
  573. this.server.tempIPBanList.append(this.ipAddress)
  574.  
  575. this.server.sendOutput("Attack DDOS blocked in IP: "+str(this.ipAddress))
  576.  
  577. this.server.sendStaffMessage(7, "<R>Attack DDOS</R>: <J>["+str(this.ipAddress)+"]</J>")
  578.  
  579. this.server.disconnectIPAddress(this.ipAddress)
  580.  
  581. this.transport.loseConnection()
  582.  
  583. this.block()
  584.  
  585.  
  586.  
  587. p = ByteArray(packet)
  588.  
  589. if not this.validatingVersion:
  590.  
  591. C, CC = p.readShort(), p.readByte()
  592.  
  593. if C == 0x1c and CC == 0x1:
  594.  
  595. version = p.readShort()
  596.  
  597. ckey = p.readUTF()
  598.  
  599. client = p.readUTF() #
  600.  
  601. h = p.readUTF() #
  602.  
  603.  
  604.  
  605. if not ckey == this.server.CKEY and version != this.server.Version:
  606.  
  607. this.server.sendOutput("WARNING: Invalid CKEY ("+ckey+") and version ("+str(version)+")")
  608.  
  609. this.transport.loseConnection()
  610.  
  611.  
  612.  
  613. else:
  614.  
  615. this.validatingVersion = True
  616.  
  617. this.sendCorrectVersion()
  618.  
  619. else:
  620.  
  621. try:
  622.  
  623. checkPacketID = (this.lastPacketID % 99)
  624.  
  625. checkPacketID += 0 if checkPacketID == 0 else 1
  626.  
  627. packetID = p.readByte()
  628.  
  629. this.lastPacketID = packetID
  630.  
  631.  
  632.  
  633. C, CC = p.readByte(), p.readByte()
  634.  
  635. this.parsePackets.parsePacket(packetID, C, CC, ByteArray(packet[3:]))
  636.  
  637.  
  638.  
  639. except Exception as ERROR:
  640.  
  641. c = open("./include/errors.log", "a")
  642.  
  643. c.write("\n" + "=" * 60 + "\n- Time: %s\n- Player: %s\n- Error: \n" %(time.strftime("%d/%m/%Y - %H:%M:%S"), this.Username))
  644.  
  645. traceback.print_exc(file=c)
  646.  
  647. c.close()
  648.  
  649.  
  650.  
  651. def loginPlayer(this, playerName, password, startRoom):
  652.  
  653. playerName = "Souris" if playerName == "" else playerName
  654.  
  655. if password == "":
  656.  
  657. playerName = this.server.checkAlreadyExistingGuest("*" + (playerName[0].isdigit() or len(playerName) > 12 or len(playerName) < 3 or "Souris" if "+" in playerName else playerName))
  658.  
  659.  
  660.  
  661. if not this.canLogin[0] and not this.canLogin[1]:
  662.  
  663. this.transport.loseConnection()
  664.  
  665. return
  666.  
  667.  
  668.  
  669. if not this.isGuest and playerName in this.server.userPermaBanCache:
  670.  
  671. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [])
  672.  
  673. this.transport.loseConnection()
  674.  
  675. return
  676.  
  677.  
  678.  
  679. if not this.isGuest and playerName in this.server.userTempBanCache:
  680.  
  681. banInfo = this.server.getTempBanInfo(playerName)
  682.  
  683. timeCalc = TFMUtils.getHoursDiff(int(banInfo[0]))
  684.  
  685. if timeCalc <= 0:
  686.  
  687. this.server.removeTempBan(playerName)
  688.  
  689. else:
  690.  
  691. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [timeCalc * 3600000, str(banInfo[1])])
  692.  
  693. this.transport.loseConnection()
  694.  
  695. return
  696.  
  697.  
  698.  
  699. if this.server.checkConnectedAccount(playerName):
  700.  
  701. this.sendPacket(Identifiers.send.Login_Result, chr(1))
  702.  
  703. else:
  704.  
  705. vipTime, letters, gifts, messages = 0, "", "", ""
  706.  
  707. if not this.isGuest:
  708.  
  709. this.Cursor.execute("select * from Users where Username = ? and Password = ?", [playerName, password])
  710.  
  711. rs = this.Cursor.fetchone()
  712.  
  713. if rs:
  714.  
  715. this.privLevel = rs["PrivLevel"]
  716.  
  717. this.playerID = rs["PlayerID"]
  718.  
  719. this.TitleNumber = rs["TitleNumber"]
  720.  
  721. this.firstCount = rs["FirstCount"]
  722.  
  723. this.cheeseCount = rs["CheeseCount"]
  724.  
  725. this.shamanCheeses = rs["ShamanCheeses"]
  726.  
  727. this.shopCheeses = rs["ShopCheeses"]
  728.  
  729. this.shopFraises = rs["ShopFraises"]
  730.  
  731. this.shamanSaves = rs["ShamanSaves"]
  732.  
  733. this.hardModeSaves = rs["HardModeSaves"]
  734.  
  735. this.divineModeSaves = rs["DivineModeSaves"]
  736.  
  737. this.bootcampCount = rs["BootcampCount"]
  738.  
  739. this.shamanType = rs["ShamanType"]
  740.  
  741. this.shopItems = rs["ShopItems"]
  742.  
  743. this.shamanItems = rs["ShamanItems"]
  744.  
  745. this.clothes = rs["Clothes"].split("|")
  746.  
  747. this.playerLook = rs["Look"]
  748.  
  749. this.shamanLook = rs["ShamanLook"]
  750.  
  751. this.MouseColor = rs["MouseColor"]
  752.  
  753. this.ShamanColor = rs["ShamanColor"]
  754.  
  755. this.regDate = rs["RegDate"]
  756.  
  757. this.shopBadges = rs["Badges"].split(",")
  758.  
  759. this.cheeseTitleList = rs["CheeseTitleList"].split(",")
  760.  
  761. this.firstTitleList = rs["FirstTitleList"].split(",")
  762.  
  763. this.shamanTitleList = rs["ShamanTitleList"].split(",")
  764.  
  765. this.shopTitleList = rs["ShopTitleList"].split(",")
  766.  
  767. this.bootcampTitleList = rs["BootcampTitleList"].split(",")
  768.  
  769. this.hardModeTitleList = rs["HardModeTitleList"].split(",")
  770.  
  771. this.divineModeTitleList = rs["DivineModeTitleList"].split(",")
  772.  
  773. this.specialTitleList = rs["SpecialTitleList"].split(",")
  774.  
  775. this.banHours = rs["BanHours"]
  776.  
  777. level = rs["ShamanLevel"].split("/")
  778.  
  779. this.shamanLevel = int(level[0])
  780.  
  781. this.shamanExp = int(level[1])
  782.  
  783. this.shamanExpNext = int(level[2])
  784.  
  785. for skill in rs["Skills"].split(";"):
  786.  
  787. values = skill.split(":")
  788.  
  789. if len(values) >= 2:
  790.  
  791. this.playerSkills[int(values[0])] = int(values[1])
  792.  
  793. this.lastOn = rs["LastOn"]
  794.  
  795. this.friendsList = rs["FriendsList"].split(",")
  796.  
  797. this.ignoredsList = rs["IgnoredsList"].split(",")
  798.  
  799. this.gender = rs["Gender"]
  800.  
  801. this.lastDivorceTimer = rs["LastDivorceTimer"]
  802.  
  803. this.marriage = rs["Marriage"]
  804.  
  805.  
  806.  
  807. tribeInfo = rs["TribeInfo"].split("#")
  808.  
  809. if len(tribeInfo) == 3:
  810.  
  811. this.tribeCode = int(tribeInfo[0])
  812.  
  813. this.tribeRank = int(tribeInfo[1])
  814.  
  815. this.tribeJoined = int(tribeInfo[2])
  816.  
  817. this.tribeData = this.server.getTribeInfo(this.tribeCode)
  818.  
  819. this.tribeName = this.tribeData[0]
  820.  
  821.  
  822.  
  823. this.survivorStats = map(int, rs["SurvivorStats"].split(","))
  824.  
  825. this.racingStats = map(int, rs["RacingStats"].split(","))
  826.  
  827. this.nowCoins = rs["NowCoins"]
  828.  
  829. this.nowTokens = rs["NowTokens"]
  830.  
  831. for consumable in rs["Consumables"].split(";"):
  832.  
  833. values = consumable.split(":")
  834.  
  835. if len(values) >= 2:
  836.  
  837. this.playerConsumables[int(values[0])] = int(values[1])
  838.  
  839. this.equipedConsumables = rs["EquipedConsumables"].split("|")
  840.  
  841. letters = rs["Letters"]
  842.  
  843. this.pet = rs["Pet"]
  844.  
  845. this.petEnd = 0 if this.pet == 0 else TFMUtils.getTime() + rs["PetEnd"]
  846.  
  847. this.shamanBadges = rs["ShamanBadges"].split(",")
  848.  
  849. this.equipedShamanBadge = rs["EquipedShamanBadge"]
  850.  
  851. totem = this.server.getTotemData(playerName)
  852.  
  853. if len(totem) == 2: this.STotem = [int(totem[0]), totem[1]]
  854.  
  855. gifts = rs["Gifts"]
  856.  
  857. message = rs["Messages"]
  858.  
  859. vipTime = rs["VipTime"]
  860.  
  861. this.visuDone = eval(rs["visuDone"])
  862.  
  863. this.custom = rs["customItens"].split(",")
  864.  
  865. else:
  866.  
  867. reactor.callLater(5, lambda: this.sendPacket(Identifiers.send.Login_Result, chr(2)))
  868.  
  869. return
  870.  
  871.  
  872.  
  873. if this.privLevel == -1:
  874.  
  875. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [0, "Account Locked."])
  876.  
  877. this.transport.loseConnection()
  878.  
  879. return
  880.  
  881.  
  882.  
  883. this.server.lastPlayerCode += 1
  884.  
  885. this.Username = playerName
  886.  
  887. this.playerCode = this.server.lastPlayerCode
  888.  
  889. this.Cursor.execute("insert into LoginLog select ?, ? where not exists (select 1 from LoginLog where Username = ? and IP = ?)", [playerName, this.ipAddress, playerName, this.ipAddress])
  890.  
  891.  
  892.  
  893. this.clothes = filter(None, this.clothes)
  894.  
  895. this.shopBadges = filter(None, this.shopBadges)
  896.  
  897. this.custom = filter(None, this.custom)
  898.  
  899. this.shamanBadges = filter(None, this.shamanBadges)
  900.  
  901. this.shopTitleList = filter(None, this.shopTitleList)
  902.  
  903. this.firstTitleList = filter(None, this.firstTitleList)
  904.  
  905. this.cheeseTitleList = filter(None, this.cheeseTitleList)
  906.  
  907. this.shamanTitleList = filter(None, this.shamanTitleList)
  908.  
  909. this.specialTitleList = filter(None, this.specialTitleList)
  910.  
  911. this.bootcampTitleList = filter(None, this.bootcampTitleList)
  912.  
  913. this.hardModeTitleList = filter(None, this.hardModeTitleList)
  914.  
  915. this.divineModeTitleList = filter(None, this.divineModeTitleList)
  916.  
  917.  
  918.  
  919. for name in ["cheese", "first", "shaman", "shop", "bootcamp", "hardmode", "divinemode"]:
  920.  
  921. this.checkAndRebuildTitleList(name)
  922.  
  923.  
  924.  
  925. this.sendCompleteTitleList()
  926.  
  927. this.shopModule.checkAndRebuildBadges()
  928.  
  929.  
  930.  
  931. for title in this.titleList:
  932.  
  933. if str(title).split(".")[0] == str(this.TitleNumber):
  934.  
  935. this.TitleStars = int(str(title).split(".")[1])
  936.  
  937. break
  938.  
  939.  
  940.  
  941. this.isMute = playerName in this.server.userMuteCache
  942.  
  943. this.server.players[this.Username] = this
  944.  
  945. this.skillModule.sendShamanSkills()
  946.  
  947. this.skillModule.sendExp(this.shamanLevel, this.shamanExp, this.shamanExpNext)
  948.  
  949. this.sendLogin()
  950.  
  951. this.sendPlayerIdentification()
  952.  
  953. this.shopModule.sendShamanItems()
  954.  
  955. if this.shamanSaves >= 500:
  956.  
  957. this.sendShamanType(this.shamanType, (this.shamanSaves >= 2500 and this.hardModeSaves >= 1000))
  958.  
  959.  
  960.  
  961. this.server.checkPromotionsEnd()
  962.  
  963. this.sendTimeStamp()
  964.  
  965. this.sendPromotions()
  966.  
  967. this.sendPacket(Identifiers.send.Email_Confirmed, chr(1))
  968.  
  969.  
  970.  
  971. if this.privLevel == 2:
  972.  
  973. this.checkVip(vipTime)
  974.  
  975.  
  976.  
  977. this.tribulle.sendPlayerInfo()
  978.  
  979. this.tribulle.sendFriendsList(None)
  980.  
  981. this.tribulle.sendIgnoredsList()
  982.  
  983. this.tribulle.sendTribe(False)
  984.  
  985.  
  986.  
  987. for client in this.server.players.values():
  988.  
  989. if this.Username in client.friendsList and client.Username in this.friendsList:
  990.  
  991. client.tribulle.sendFriendConnected(this.Username)
  992.  
  993.  
  994.  
  995. if not this.tribeName == "":
  996.  
  997. this.tribulle.sendTribeMemberConnected()
  998.  
  999.  
  1000.  
  1001. if this.privLevel >= 5:
  1002.  
  1003. this.server.sendStaffMessage(5, "<ROSE>" + ("[Fundador]" if this.privLevel == 11 else "[Admin]" if this.privLevel == 10 else "[Coord]" if this.privLevel == 9 else "[Smod]" if this.privLevel == 8 else "[Mod]" if this.privLevel == 7 else "[MapCrew]" if this.privLevel == 6 else "[Helper]" if this.privLevel == 5 else "") + "["+this.Langue+"] <CH>" + this.Username + " <N>is online.")
  1004.  
  1005. this.sendStaffLogin(False)
  1006.  
  1007.  
  1008.  
  1009. this.sendInventoryConsumables()
  1010.  
  1011. this.checkLetters(letters)
  1012.  
  1013. this.shopModule.checkGiftsAndMessages(gifts, messages)
  1014.  
  1015.  
  1016.  
  1017. if not startRoom == "" and not startRoom == "1":
  1018.  
  1019. this.enterRoom(this.server.checkRoom(startRoom, this.Langue))
  1020.  
  1021. else:
  1022.  
  1023. this.enterRoom(this.server.recommendRoom(this.Langue))
  1024.  
  1025.  
  1026.  
  1027. this.resSkillsTimer = reactor.callLater(600, setattr, this, "canResSkill", True)
  1028.  
  1029.  
  1030.  
  1031. def showButtonsOnlines4(this):
  1032.  
  1033. if this.privLevel >= 1:
  1034.  
  1035. reactor.callLater(0.5, this.showButtonsOnlines3)
  1036.  
  1037.  
  1038.  
  1039. def showButtonsOnlines3(this):
  1040.  
  1041. if this.privLevel >= 1:
  1042.  
  1043. text = "<font color='#eeeeeee' size='9'> Salas: <font color='#00FF7F'><b>" + str(this.server.getRoomsCount() ) + "</b></font></font>"
  1044.  
  1045. this.room.addTextArea(100544, str(text), this.Username, 705, 360, 90, 16, 0x97714C, 0x27373f, 100, False)
  1046.  
  1047. reactor.callLater(20, this.showButtonsOnlines4)
  1048.  
  1049.  
  1050.  
  1051. def showButtonsOnlines2(this):
  1052.  
  1053. if this.privLevel >= 1:
  1054.  
  1055. reactor.callLater(0.5, this.showButtonsOnlines)
  1056.  
  1057.  
  1058.  
  1059. def showButtonsOnlines(this):
  1060.  
  1061. if this.privLevel >= 1:
  1062.  
  1063. text = "<font color='#eeeeeee' size='9'> Jogadores: <font color='#00FF7F'><b>" + str(this.server.getConnectedPlayerCount() ) + "</b></font></font>"
  1064.  
  1065. this.room.addTextArea(100543, str(text), this.Username, 705, 385, 90, 16, 0x97714C, 0x27373f, 100, False)
  1066.  
  1067. reactor.callLater(20, this.showButtonsOnlines2)
  1068.  
  1069.  
  1070.  
  1071. def createAccount(this, playerName, password):
  1072.  
  1073. this.server.lastPlayerID += 1
  1074.  
  1075. this.Cursor.execute("insert into Users values (?, ?, ?, 1, 0, 0, 0, 0, ?, ?, 0, 0, 0, 0, 0, '', '', '', '1;0,0,0,0,0,0,0,0,0', '0,0,0,0,0,0,0,0,0,0', '78583a', '95d9d6', ?, '', '', '', '', '', '', '', '', '', 0, '200/0/100000', '', 0, '', '', 0, 0, '', '', '', '', '0,0,0,0', '0,0,0,0', 0, '', '', 0, 0, 0, 0, '', 0, '', 0, ?, '')", [playerName, password, this.server.lastPlayerID, this.server.initialCheeses, this.server.initialFraises, TFMUtils.getTime(), '{18: ["56;124_ff7830+ebebeb+efe8df+c469ff+f44a80+ff7c36+eee7dc+f44d82,0,1_c469ff,35_c469ff+eee7dc+ff7c36,0,21_ffc6a8+eee7dc+ff7c36+c469ff+eee7dc+c469ff,3_c469ff,0,0"], 20: ["32;124_72add3+72add3+a9cce2+72add3+72add3+72add3+f3f7f6+72add3,0,0,37_72add3+c1e4fc,2_72add3,3_72add3,27_72add3+f3f7f6,0,0"]}'])
  1076.  
  1077. this.sendNewConsumable(23, 10)
  1078.  
  1079. this.sendAccountTime()
  1080.  
  1081.  
  1082.  
  1083. this.server.updateConfig()
  1084.  
  1085.  
  1086.  
  1087. def checkAndRebuildTitleList(this, type):
  1088.  
  1089. titlesLists = [this.cheeseTitleList, this.firstTitleList, this.shamanTitleList, this.shopTitleList, this.bootcampTitleList, this.hardModeTitleList, this.divineModeTitleList]
  1090.  
  1091. titles = [this.server.cheeseTitleList, this.server.firstTitleList, this.server.shamanTitleList, this.server.shopTitleList, this.server.bootcampTitleList, this.server.hardModeTitleList, this.server.divineModeTitleList]
  1092.  
  1093. 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
  1094.  
  1095. count = this.cheeseCount if type == "cheese" else this.firstCount if type == "first" else this.shamanSaves if type == "shaman" else this.shopModule.getShopLength() if type == "shop" else this.bootcampCount if type == "bootcamp" else this.hardModeSaves if type == "hardmode" else this.divineModeSaves if type == "divinemode" else 0
  1096.  
  1097. tempCount = count
  1098.  
  1099. rebuild = False
  1100.  
  1101. while tempCount > 0:
  1102.  
  1103. if titles[typeID].has_key(tempCount):
  1104.  
  1105. if not titles[typeID][tempCount] in titlesLists[typeID]:
  1106.  
  1107. rebuild = True
  1108.  
  1109. break
  1110.  
  1111.  
  1112.  
  1113. tempCount -= 1
  1114.  
  1115.  
  1116.  
  1117. if rebuild:
  1118.  
  1119. titlesLists[typeID] = []
  1120.  
  1121. x = 0
  1122.  
  1123. while x <= count:
  1124.  
  1125. if titles[typeID].has_key(x):
  1126.  
  1127. title = titles[typeID][x]
  1128.  
  1129. i = 0
  1130.  
  1131. while i < len(titlesLists[typeID]):
  1132.  
  1133. if str(titlesLists[typeID][i]).startswith(str(title).split(".")[0]):
  1134.  
  1135. del titlesLists[typeID][i]
  1136.  
  1137. i += 1
  1138.  
  1139. titlesLists[typeID].append(title)
  1140.  
  1141. x += 1
  1142.  
  1143.  
  1144.  
  1145. this.cheeseTitleList = titlesLists[0]
  1146.  
  1147. this.firstTitleList = titlesLists[1]
  1148.  
  1149. this.shamanTitleList = titlesLists[2]
  1150.  
  1151. this.shopTitleList = titlesLists[3]
  1152.  
  1153. this.bootcampTitleList = titlesLists[4]
  1154.  
  1155. this.hardModeTitleList = titlesLists[5]
  1156.  
  1157. this.divineModeTitleList = titlesLists[6]
  1158.  
  1159.  
  1160.  
  1161. def updateDatabase(this):
  1162.  
  1163. this.updateTribePoints()
  1164.  
  1165. this.Cursor.execute("update Users set PrivLevel = ?, TitleNumber = ?, FirstCount = ?, CheeseCount = ?, ShamanCheeses = ?, ShopCheeses = ?, ShopFraises = ?, ShamanSaves = ?, HardModeSaves = ?, DivineModeSaves = ?, BootcampCount = ?, ShamanType = ?, ShopItems = ?, ShamanItems = ?, Clothes = ?, Look = ?, ShamanLook = ?, MouseColor = ?, ShamanColor = ?, RegDate = ?, Badges = ?, CheeseTitleList = ?, FirstTitleList = ?, BootcampTitleList = ?, ShamanTitleList = ?, HardModeTitleList = ?, DivineModeTitleList = ?, ShopTitleList = ?, SpecialTitleList = ?, BanHours = ?, ShamanLevel = ?, Skills = ?, FriendsList = ?, IgnoredsList = ?, Gender = ?, LastDivorceTimer = ?, Marriage = ?, TribeInfo = ?, SurvivorStats = ?, RacingStats = ?, Consumables = ?, EquipedConsumables = ?, LastOn = ?, Pet = ?, PetEnd = ?, NowCoins = ?, NowTokens = ?, ShamanBadges = ?, EquipedShamanBadge = ?, visuDone = ?, customItens = ? where Username = ?", [this.privLevel, this.TitleNumber, this.firstCount, this.cheeseCount, this.shamanCheeses, this.shopCheeses, this.shopFraises, this.shamanSaves, this.hardModeSaves, this.divineModeSaves, this.bootcampCount, this.shamanType, this.shopItems, this.shamanItems, "|".join(map(str, this.clothes)), this.playerLook, this.shamanLook, this.MouseColor, this.ShamanColor, this.regDate, ",".join(map(str, this.shopBadges)), ",".join(map(str, this.cheeseTitleList)), ",".join(map(str, this.firstTitleList)), ",".join(map(str, this.bootcampTitleList)), ",".join(map(str, this.shamanTitleList)), ",".join(map(str, this.hardModeTitleList)), ",".join(map(str, this.divineModeTitleList)), ",".join(map(str, this.shopTitleList)), ",".join(map(str, this.specialTitleList)), this.banHours, "/".join(map(str, [this.shamanLevel, this.shamanExp, this.shamanExpNext])), ";".join(map(lambda skill: str(skill[0]) + ":" + str(skill[1]), this.playerSkills.items())), ",".join(map(str, this.friendsList)), ",".join(map(str, this.ignoredsList)), this.gender, this.lastDivorceTimer, this.marriage, "" if this.tribeName == "" else "#".join(map(str, [this.tribeCode, this.tribeRank, this.tribeJoined])), ",".join(map(str, this.survivorStats)), ",".join(map(str, this.racingStats)), ";".join(map(lambda consumable: str(consumable[0]) + ":" + str(consumable[1]), this.playerConsumables.items())), ",".join(map(str, this.equipedConsumables)), this.tribulle.getTime(), this.pet, abs(TFMUtils.getSecondsDiff(this.petEnd)), this.nowCoins, this.nowTokens, ",".join(map(str, this.shamanBadges)), this.equipedShamanBadge, str(this.visuDone), ",".join(map(str, this.custom)), this.Username])
  1166.  
  1167.  
  1168.  
  1169. def reloadRanking(this):
  1170.  
  1171. Userlist = []
  1172.  
  1173. lists = "<V><p align='center'><b>Top Players</font></p>"
  1174.  
  1175. lists += "<p align='left'><font size='12'>"
  1176.  
  1177. this.Cursor.execute("select Username, CheeseCount, FirstCount, BootcampCount, ShamanSaves, HardModeSaves, DivineModeSaves, TitleNumber from Users where PrivLevel < 6 ORDER By FirstCount DESC LIMIT 10")
  1178.  
  1179. rs = this.Cursor.fetchall()
  1180.  
  1181. pos = 1
  1182.  
  1183. this.updateDatabase()
  1184.  
  1185. for rrf in rs:
  1186.  
  1187. playerName = str(rrf[0])
  1188.  
  1189. CheeseCount = rrf[1]
  1190.  
  1191. FirstCount = rrf[2]
  1192.  
  1193. BootcampCount = rrf[3]
  1194.  
  1195. ShamanSaves = rrf[4]
  1196.  
  1197. HardModeSaves = rrf[5]
  1198.  
  1199. DivineModeSaves = rrf[6]
  1200.  
  1201. TitleNumber = rrf[7]
  1202.  
  1203. if pos == 1:
  1204.  
  1205. lists += "<font color='#FADE55'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>\n"
  1206.  
  1207. elif pos == 2:
  1208.  
  1209. lists += "<font color='#EFEBE0'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>\n"
  1210.  
  1211. elif pos == 3:
  1212.  
  1213. lists += "<font color='#B44F0D'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>\n"
  1214.  
  1215. else:
  1216.  
  1217. lists += "<font color='#606090'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>"
  1218.  
  1219. lists += "<br />"
  1220.  
  1221. lists += " <font color='#6A7495'>• Current title:</font> <font color='#009d9d'>"+str(TitleNumber)+"</font>"
  1222.  
  1223. lists += "<br />"
  1224.  
  1225. lists += " <font color='#6A7495'>• Saves:</font> <font color='#009d9d'>"+str(ShamanSaves)+" / "+"<font color='#FADE55'>"+str(HardModeSaves)+" / "+"<font color='#F52331'>"+str(DivineModeSaves)+"</font>"
  1226.  
  1227. lists += "<br />"
  1228.  
  1229. lists += " <font color='#6A7495'>• Firsts:</font> <font color='#6C77C1'>"+str(FirstCount)+"</font>"
  1230.  
  1231. lists += "<br />"
  1232.  
  1233. lists += " <font color='#6A7495'>• Collected cheeses:</font> <font color='#6C77C1'>"+str(CheeseCount)+"</font>"
  1234.  
  1235. lists += "<br />"
  1236.  
  1237. lists += " <font color='#6A7495'>• Bootcamps:</font> <font color='#6C77C1'>"+str(BootcampCount)+"</font>"
  1238.  
  1239. lists += "<br />"
  1240.  
  1241. pos += 1
  1242.  
  1243.  
  1244.  
  1245. this.sendLogMessage(lists + "</font></p>")
  1246.  
  1247.  
  1248.  
  1249. def enterRoom(this, roomName):
  1250.  
  1251. if this.isTrade:
  1252.  
  1253. this.cancelTrade(this.tradeName)
  1254.  
  1255.  
  1256.  
  1257. if this.server.DEBUG:
  1258.  
  1259. this.sendPacket([29, 1], "")
  1260.  
  1261.  
  1262.  
  1263. roomName = roomName.replace("<", "&lt;")
  1264.  
  1265. for room in ["racing", "bootcamp", "survivor", "defilate"]:
  1266.  
  1267. if room in roomName:
  1268.  
  1269. this.sendMessage("<V>Menu closed.")
  1270.  
  1271.  
  1272.  
  1273. if roomName.startswith(chr(3) + "[Editeur] ") or roomName.startswith(chr(3)+ "[Totem] ") or roomName.startswith(chr(3) + "[Tutorial] "):
  1274.  
  1275. if not this.Username == roomName.split(" ")[1]:
  1276.  
  1277. roomName = this.Langue + "-" + this.Username
  1278.  
  1279.  
  1280.  
  1281. if not roomName.startswith("*") and not (len(roomName) > 3 and roomName[2] == '-' and this.privLevel >= 7):
  1282.  
  1283. roomName = this.Langue + "-" + roomName
  1284.  
  1285.  
  1286.  
  1287. nomSalon = ["#utility0%s" % (this.Username or this.tribeName), "#utility00%s" % (this.Username or this.tribeName)]
  1288.  
  1289. if roomName == nomSalon[0] or nomSalon[1]:
  1290.  
  1291. if re.search(this.Username, roomName):
  1292.  
  1293. reactor.callLater(0.1, this.Utility.moreSettings, "giveAdmin")
  1294.  
  1295. else:
  1296.  
  1297. try:
  1298.  
  1299. if re.search(this.tribeName, roomName):
  1300.  
  1301. reactor.callLater(0.1, this.Utility.moreSettings, "giveAdmin")
  1302.  
  1303. except:
  1304.  
  1305. pass
  1306.  
  1307.  
  1308.  
  1309. if re.search("#utility", roomName):
  1310.  
  1311. reactor.callLater(0.1, this.Utility.moreSettings, "join")
  1312.  
  1313. reactor.callLater(1.5, this.Utility.moreSettings, "removePopups")
  1314.  
  1315.  
  1316.  
  1317. if this.room != None:
  1318.  
  1319. this.room.removeClient(this)
  1320.  
  1321.  
  1322.  
  1323. this.roomName = roomName
  1324.  
  1325. this.sendGameType(11 if "music" in roomName else 1 if "madchees" in roomName else 4, 4 if "madchees" in roomName else 0)
  1326.  
  1327. this.sendEnterRoom(roomName)
  1328.  
  1329. this.server.addClientToRoom(this, roomName)
  1330.  
  1331. this.sendPacket(Identifiers.old.send.Anchors, this.room.anchors)
  1332.  
  1333. #this.showButtonsOnlines4()
  1334.  
  1335. this.showButtonsOnlines2()
  1336.  
  1337. this.LoadCountTotem = False
  1338.  
  1339.  
  1340.  
  1341. for client in this.server.players.values():
  1342.  
  1343. if this.Username and client.Username in this.friendsList and client.friendsList:
  1344.  
  1345. client.tribulle.sendFriendChangedRoom(this.Username, this.langueByte)
  1346.  
  1347.  
  1348.  
  1349. if not this.tribeName == "":
  1350.  
  1351. this.tribulle.sendTribeMemberChangeRoom()
  1352.  
  1353.  
  1354.  
  1355. if this.room.isMusic and this.room.isPlayingMusic:
  1356.  
  1357. this.sendMusicVideo(False)
  1358.  
  1359.  
  1360.  
  1361. if roomName.startswith("music") or roomName.startswith("*music"):
  1362.  
  1363. this.canSkipMusic = False
  1364.  
  1365. if this.skipMusicTimer != None:
  1366.  
  1367. this.skipMusicTimer.cancel()
  1368.  
  1369.  
  1370.  
  1371. this.skipMusicTimer = reactor.callLater(900, setattr, this, "canSkipMusic", True)
  1372.  
  1373.  
  1374.  
  1375. if not this.room.isTotemEditeur and not this.room.isEditeur and not this.room.isRacing and not this.room.isBootcamp and not this.room.isSurvivor and not this.room.isVillage and not this.room.isDefilante:
  1376.  
  1377. this.sendMenu()
  1378.  
  1379.  
  1380.  
  1381. if this.room.isFuncorp:
  1382.  
  1383. this.sendLangueMessage("", "<FC>$FunCorpActive</FC>")
  1384.  
  1385.  
  1386.  
  1387. def resetPlay(this, hasCheese=True):
  1388.  
  1389. this.isDead = False
  1390.  
  1391. this.isAfk = True
  1392.  
  1393. this.isShaman = False
  1394.  
  1395. this.isSuspect = False
  1396.  
  1397. this.hasEnter = False
  1398.  
  1399. this.UTotem = False
  1400.  
  1401. this.canShamanRespawn = False
  1402.  
  1403. this.ambulanceCount = 0
  1404.  
  1405. this.bubblesCount = 0
  1406.  
  1407. this.isOpportunist = False
  1408.  
  1409. this.desintegration = False
  1410.  
  1411. this.canRespawn = False
  1412.  
  1413. this.defilantePoints = 0
  1414.  
  1415. this.iceCount = 2
  1416.  
  1417. this.isNewPlayer = False
  1418.  
  1419. this.currentPlace = 0
  1420.  
  1421. this.isVampire = False
  1422.  
  1423. this.numGiveCheese = 0
  1424.  
  1425. this.bootcampRounds = 0
  1426.  
  1427. this.hasBolo = False
  1428.  
  1429. this.hasBolo2 = False
  1430.  
  1431. if hasCheese:
  1432.  
  1433. this.hasCheese = False
  1434.  
  1435.  
  1436.  
  1437. def sendAccountTime(this):
  1438.  
  1439.  
  1440.  
  1441. eventTime = 1
  1442.  
  1443.  
  1444.  
  1445. date = datetime.now() + timedelta(hours=int(eventTime))
  1446.  
  1447.  
  1448.  
  1449. timetuple = date.timetuple()
  1450.  
  1451.  
  1452.  
  1453. eventTime_ = int(str(thetime.mktime(timetuple)).split(".")[0])
  1454.  
  1455.  
  1456.  
  1457. this.Cursor.execute('select IP from Account where IP = ?', [this.ipAddress])
  1458.  
  1459.  
  1460.  
  1461. rrf = this.Cursor.fetchone()
  1462.  
  1463.  
  1464.  
  1465. if rrf is None:
  1466.  
  1467.  
  1468.  
  1469. this.Cursor.execute('insert into Account values (?, ?)', [this.ipAddress, eventTime_])
  1470.  
  1471.  
  1472.  
  1473. else:
  1474.  
  1475.  
  1476.  
  1477. this.Cursor.execute('update Account set Time = ? where IP = ?', [eventTime_, this.ipAddress])
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487. def checkTimeAccount(this):
  1488.  
  1489.  
  1490.  
  1491. this.Cursor.execute('SELECT Time FROM Account WHERE IP = ?', [this.ipAddress])
  1492.  
  1493.  
  1494.  
  1495. rrf = this.Cursor.fetchone()
  1496.  
  1497.  
  1498.  
  1499. if rrf is None:
  1500.  
  1501.  
  1502.  
  1503. return True
  1504.  
  1505.  
  1506.  
  1507. else:
  1508.  
  1509.  
  1510.  
  1511. if (int(str(thetime.time()).split(".")[0]) >= int(rrf[0])):
  1512.  
  1513.  
  1514.  
  1515. return True
  1516.  
  1517.  
  1518.  
  1519. else:
  1520.  
  1521.  
  1522.  
  1523. return False
  1524.  
  1525.  
  1526.  
  1527. def startPlay(this):
  1528.  
  1529. this.playerStartTimeMillis = this.room.gameStartTimeMillis
  1530.  
  1531. this.isNewPlayer = this.room.isCurrentlyPlay
  1532.  
  1533. this.sendMap(False, True) if this.room.mapCode != -1 else this.sendMap() if this.room.isEditeur and this.room.EMapCode != 0 else this.sendMap(True)
  1534.  
  1535.  
  1536.  
  1537. shamanCode2 = 0
  1538.  
  1539. if this.room.isDoubleMap:
  1540.  
  1541. shamans = this.room.getDoubleShamanCode()
  1542.  
  1543. shamanCode = shamans[0]
  1544.  
  1545. shamanCode2 = shamans[1]
  1546.  
  1547. else:
  1548.  
  1549. shamanCode = this.room.getShamanCode()
  1550.  
  1551.  
  1552.  
  1553. if this.playerCode == shamanCode or this.playerCode == shamanCode2:
  1554.  
  1555. this.isShaman = True
  1556.  
  1557.  
  1558.  
  1559. if this.isShaman and not this.room.noShamanSkills:
  1560.  
  1561. this.skillModule.getkills()
  1562.  
  1563.  
  1564.  
  1565. if this.room.currentShamanName != "" and not this.room.noShamanSkills:
  1566.  
  1567. this.skillModule.getPlayerSkills(this.room.currentShamanSkills)
  1568.  
  1569.  
  1570.  
  1571. if this.room.currentSecondShamanName != "" and not this.room.noShamanSkills:
  1572.  
  1573. this.skillModule.getPlayerSkills(this.room.currentSecondShamanSkills)
  1574.  
  1575.  
  1576.  
  1577. this.sendPlayerList()
  1578.  
  1579. if this.room.catchTheCheeseMap and not this.room.noShamanSkills:
  1580.  
  1581. this.sendPacket(Identifiers.old.send.Catch_The_Cheese_Map, [shamanCode])
  1582.  
  1583. this.sendPacket(Identifiers.old.send.Player_Get_Cheese, [shamanCode])
  1584.  
  1585. if not this.room.currentMap in [108, 109]:
  1586.  
  1587. this.sendShamanCode(shamanCode, shamanCode2)
  1588.  
  1589. else:
  1590.  
  1591. this.sendShamanCode(shamanCode, shamanCode2)
  1592.  
  1593.  
  1594.  
  1595. this.sendSync(this.room.getSyncCode())
  1596.  
  1597. this.sendRoundTime(this.room.roundTime + (this.room.gameStartTime - TFMUtils.getTime()) + this.room.addTime)
  1598.  
  1599. this.sendMapStartTimerEnd() if this.room.isCurrentlyPlay or this.room.isTutorial or this.room.isTotemEditeur or this.room.isBootcamp or this.room.isDefilante or this.room.getPlayerCountUnique() <= 2 else this.sendMapStartTimer()
  1600.  
  1601. if this.room.isTotemEditeur:
  1602.  
  1603. this.initTotemEditeur()
  1604.  
  1605.  
  1606.  
  1607. if this.room.currentMap in range(200, 211) and not this.isShaman:
  1608.  
  1609. this.sendPacket(Identifiers.send.Can_Transformation, chr(1))
  1610.  
  1611.  
  1612.  
  1613. if this.room.isSurvivor and this.isShaman:
  1614.  
  1615. this.sendPacket(Identifiers.send.Can_Meep, chr(1))
  1616.  
  1617.  
  1618.  
  1619. if this.room.isVillage:
  1620.  
  1621. reactor.callLater(0.2, this.sendBotsVillage)
  1622.  
  1623.  
  1624.  
  1625. if this.room.mapCode == 2018:
  1626.  
  1627. this.room.isNoShamanMap = True
  1628.  
  1629.  
  1630.  
  1631. if this.room.mapCode == 2008:
  1632.  
  1633. this.sendPacket([100, 70], "\x00\x04\x074\x04")
  1634.  
  1635. this.sendPacket([100, 70], "\x00\x04\x14\xf2\x02")
  1636.  
  1637. this.sendPacket([100, 70], "\x00\x01\xea\x9e\x06")
  1638.  
  1639. #this.sendPacket([5, 51], "\t\x00n\x07\x00i\x07\xb2")
  1640.  
  1641. #this.sendPacket([5, 51], "\t\x00o\x07\x00\xc3\x07\xb2")
  1642.  
  1643. #this.sendPacket([5, 51], "\t\x00p\x07\x00\xcd\x07\xb2")
  1644.  
  1645. #this.sendPacket([5, 51], "\t\x00q\x08\x011\x07\xb2")
  1646.  
  1647. #this.sendPacket([5, 51], "\t\x00r\x08\x01\x8b\x07\xb2")
  1648.  
  1649. #this.sendPacket([5, 51], "\t\x00s\x08\x01\x90\x07\xc1")
  1650.  
  1651. #this.sendPacket([5, 51], "\t\x00t\x08\x01\x95\x07\xb2")
  1652.  
  1653. #this.sendPacket([5, 51], "\t\x00u\x08\x01\xf9\x07\xb2")
  1654.  
  1655. #this.sendPacket([5, 51], "\t\x00v\x07\x02S\x07\xb2")
  1656.  
  1657. #this.sendPacket([5, 51], "\t\x00w\x07\x02]\x07\xb2")
  1658.  
  1659. #this.sendPacket([5, 51], "\t\x00x\x07\x02\xc1\x07\xb2")
  1660.  
  1661. this.sendPacket([5, 51], ByteArray().writeByte(9).writeShort(31).writeByte(7).writeShort(96).writeShort(1972).toByteArray())
  1662.  
  1663. this.sendPacket([5, 51], ByteArray().writeByte(9).writeShort(32).writeByte(7).writeShort(196).writeShort(1972).toByteArray())
  1664.  
  1665. this.sendPacket([5, 51], ByteArray().writeByte(9).writeShort(33).writeByte(8).writeShort(296).writeShort(1972).toByteArray())
  1666.  
  1667. this.sendPacket([5, 51], ByteArray().writeByte(9).writeShort(34).writeByte(8).writeShort(396).writeShort(1972).toByteArray())
  1668.  
  1669. this.sendPacket([5, 51], ByteArray().writeByte(9).writeShort(35).writeByte(8).writeShort(496).writeShort(1972).toByteArray())
  1670.  
  1671. this.sendPacket([5, 51], ByteArray().writeByte(9).writeShort(36).writeByte(7).writeShort(596).writeShort(1972).toByteArray())
  1672.  
  1673. this.sendPacket([5, 51], ByteArray().writeByte(9).writeShort(37).writeByte(7).writeShort(696).writeShort(1972).toByteArray())
  1674.  
  1675.  
  1676.  
  1677. if this.room.mapCode == 2005:
  1678.  
  1679. this.sendPacket([5, 51], ByteArray().writeByte(2).writeShort(23).writeByte(6).writeShort(132).writeShort(316).toByteArray())
  1680.  
  1681. this.sendPacket([5, 51], ByteArray().writeByte(2).writeShort(24).writeByte(5).writeShort(152).writeShort(106).toByteArray())
  1682.  
  1683. #this.sendPacket([5, 51], "\x02\x00\x17\x06\x00\x82\x00\xf6")
  1684.  
  1685. #this.sendPacket([5, 51], "\x02\x00\x18\x05\x00\x82\xff\x9c")
  1686.  
  1687.  
  1688.  
  1689. def sendBotsVillage(this):
  1690.  
  1691. 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")
  1692.  
  1693. 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")
  1694.  
  1695. 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")
  1696.  
  1697. this.sendPacket([8, 30], "\xff\xff\xff\xfc\x00\x05Buffy\x01[\x00\x06$Buffy\x07t\x01\xf3\x00\x0b\x00\x00")
  1698.  
  1699. 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")
  1700.  
  1701. this.sendPacket([8, 30], "\xff\xff\xff\xfa\x00\x04Prof\x01G\x00\n$Proviseur\x01!\x02\xcb\x00\x0b\x00\x00")
  1702.  
  1703. this.sendPacket([8, 30], "\xff\xff\xff\xf9\x00\x07Cassidy\x01\x18\x00\x07$Barman\n\xd2\x02%\x00\x0b\x00\x00")
  1704.  
  1705. this.sendPacket([8, 30], "\xff\xff\xff\xf8\x00\x0fVon Drekkemouse\x01\x1f\x00\n$Halloween\x06\x88\x01z\x00\x0b\x00\x00")
  1706.  
  1707. this.sendNPC(1, 1, "Finger", 336, "82;132,0,0,0,0,0,0,1,0", 2964, 700, 11, 0)
  1708.  
  1709. this.sendNPC(1, 2, "Wreft", 336, "83;132,0,0,0,0,0,0,1,0", 2999, 700, 11, 0)
  1710.  
  1711. this.sendNPC(1, 3, "Xgoku_pr0zao", 336, "84;132,0,0,0,0,0,0,0,0", 2010, 767, 11, 0)
  1712.  
  1713.  
  1714.  
  1715. def sendNPC(this, id, id2, name, title, look, px, py, mode, end):
  1716.  
  1717. this.sendPacket([8, 30], ByteArray().writeShort(id).writeShort(id2).writeUTF(name).writeShort(title).writeUTF(look).writeShort(px).writeShort(py).writeShort(mode).writeShort(end).toByteArray())
  1718.  
  1719.  
  1720.  
  1721. def getPlayerData(this):
  1722.  
  1723. return "#".join(map(str, [this.Username if this.mouseName == "" else this.mouseName, this.playerCode, 1, 1 if this.isDead else 0, this.playerScore, 1 if this.hasCheese else 0, str(this.TitleNumber) + "," + str(this.TitleStars), 0, this.playerLook if not this.room.isBootcamp else "1;0,0,0,0,0,0,0,0,0", 0, this.tempMouseColor if not this.tempMouseColor == "" else this.MouseColor, this.ShamanColor, 0]))
  1724.  
  1725.  
  1726.  
  1727. def sendShamanCode(this, shamanCode, shamanCode2):
  1728.  
  1729. 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))
  1730.  
  1731.  
  1732.  
  1733. def sendDoubleShamanCode(this, shamanCode, shamanCodeTwo):
  1734.  
  1735. this.sendShaman(shamanCode, shamanCodeTwo, this.room.currentShamanType, this.room.currentSecondShamanType, this.server.getPlayerLevel(this.room.currentShamanName), this.server.getPlayerLevel(this.room.currentSecondShamanName), this.skillModule.getShamanBadge(this.room.currentShamanSkills, this.room.currentShamanCode), this.skillModule.getShamanBadge(this.room.currentSecondShamanSkills, this.room.currentSecondShamanCode))
  1736.  
  1737.  
  1738.  
  1739. def sendCorrectVersion(this):
  1740.  
  1741. this.sendPacket(Identifiers.send.Correct_Version, ByteArray().writeInt(this.server.getConnectedPlayerCount()).writeByte(this.lastPacketID).writeUTF("br").writeUTF("br").writeInt(this.authKey).toByteArray())
  1742.  
  1743. this.sendPacket(Identifiers.send.Banner_Login, ByteArray().writeShort(564).writeByte(2).writeByte(1).writeByte(0).toByteArray())
  1744.  
  1745. this.sendPacket([100, 99], ByteArray().writeUTF("x_papaque_2015.jpg").toByteArray())
  1746.  
  1747. this.sendPacket(Identifiers.send.Undefined, ByteArray().writeByte(0).toByteArray())
  1748.  
  1749.  
  1750.  
  1751. def sendLogin(this):
  1752.  
  1753. this.sendPacket(Identifiers.old.send.Login, [this.Username, this.playerCode, this.privLevel, 30, 1 if this.isGuest else 0, 0, 0, 0])
  1754.  
  1755. if this.isGuest:
  1756.  
  1757. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(1).writeByte(10).toByteArray())
  1758.  
  1759. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(2).writeByte(5).toByteArray())
  1760.  
  1761. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(3).writeByte(15).toByteArray())
  1762.  
  1763. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(4).writeUnsignedByte(200).toByteArray())
  1764.  
  1765.  
  1766.  
  1767. def sendPlayerIdentification(this):
  1768.  
  1769. if this.isGuest:
  1770.  
  1771. this.sendPacket(Identifiers.send.Player_Identification, ByteArray().writeInt(this.playerID).writeUTF(this.Username).writeInt(60000).writeByte(this.langueByte).writeInt(this.playerCode).writeByte(this.privLevel).writeByte(0).writeByte(0).writeBool(False).toByteArray())
  1772.  
  1773. this.sendPacket([100, 6], "\x00\x00")
  1774.  
  1775. else:
  1776.  
  1777. this.sendPacket(Identifiers.send.Player_Identification, ByteArray().writeInt(this.playerID).writeUTF(this.Username).writeInt(60000).writeByte(this.langueByte).writeInt(this.playerCode).writeByte(this.privLevel).writeByte(0).writeByte(0).writeBool(False).toByteArray())
  1778.  
  1779. this.sendPacket([100, 6], "\x00\x00")
  1780.  
  1781.  
  1782.  
  1783. def sendTimeStamp(this):
  1784.  
  1785. this.sendPacket(Identifiers.send.Time_Stamp, ByteArray().writeInt(TFMUtils.getTime()).toByteArray())
  1786.  
  1787.  
  1788.  
  1789. def enableSpawnCN(this):
  1790.  
  1791. this.canSpawnCN = True
  1792.  
  1793.  
  1794.  
  1795. def fireworksUtility(this):
  1796.  
  1797. if this.room.isUtility and this.Utility.isFireworks == True:
  1798.  
  1799. this.Utility.newCoordsConj()
  1800.  
  1801. reactor.callLater(0.2, this.Utility.buildConj)
  1802.  
  1803. reactor.callLater(1, this.Utility.removeConj)
  1804.  
  1805. reactor.callLater(1.5, this.fireworksUtility)
  1806.  
  1807.  
  1808.  
  1809. def discoUtility(this):
  1810.  
  1811. if this.room.isUtility == True:
  1812.  
  1813. colors = ["000000", "FF0000", "17B700", "F2FF00", "FFB900", "00C0D9", "F600A8", "850000", "62532B", "EFEAE1", "201E1C"]
  1814.  
  1815. sColor = random.choice(colors)
  1816.  
  1817. data = struct.pack("!i", this.playerCode)
  1818.  
  1819. data += struct.pack("!i", int(sColor, 16))
  1820.  
  1821. this.room.sendAll([29, 4], data)
  1822.  
  1823. if this.room.discoRoom == True:
  1824.  
  1825. this.reactorDisco()
  1826.  
  1827.  
  1828.  
  1829. def reactorDisco(this):
  1830.  
  1831. if this.room.isUtility == True:
  1832.  
  1833. if this.room.discoRoom == True:
  1834.  
  1835. reactor.callLater(0.7, this.discoUtility)
  1836.  
  1837.  
  1838.  
  1839. def sendPromotions(this):
  1840.  
  1841. for promotion in this.server.shopPromotions:
  1842.  
  1843. 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())
  1844.  
  1845.  
  1846.  
  1847. if len(this.server.shopPromotions) > 0:
  1848.  
  1849. promotion = this.server.shopPromotions[0]
  1850.  
  1851. item = promotion[0] * (10000 if promotion[1] > 99 else 100) + promotion[1] + (10000 if promotion[1] > 99 else 0)
  1852.  
  1853. this.sendPacket(Identifiers.send.Promotion_Popup, ByteArray().writeByte(promotion[0]).writeByte(promotion[1]).writeByte(promotion[2]).writeShort(this.server.shopBadges.get(item, 0)).toByteArray())
  1854.  
  1855.  
  1856.  
  1857. def sendGameType(this, gameType, serverType):
  1858.  
  1859. this.sendPacket(Identifiers.send.Room_Type, ByteArray().writeByte(gameType).toByteArray())
  1860.  
  1861. this.sendPacket(Identifiers.send.Room_Server, ByteArray().writeByte(serverType).toByteArray())
  1862.  
  1863.  
  1864.  
  1865. def sendEnterRoom(this, roomName):
  1866.  
  1867. this.sendPacket(Identifiers.send.Enter_Room, ByteArray().writeBool(roomName.startswith("*") or roomName.startswith(str(chr(3)))).writeUTF(roomName).toByteArray())
  1868.  
  1869.  
  1870.  
  1871. def sendMap(this, newMap=False, newMapCustom=False):
  1872.  
  1873. 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).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).writeBool(this.room.mapInverted if newMapCustom else False).toByteArray())
  1874.  
  1875.  
  1876.  
  1877. def sendPlayerList(this):
  1878.  
  1879. this.sendPacket(Identifiers.old.send.Player_List, this.room.getPlayerList())
  1880.  
  1881.  
  1882.  
  1883. def sendSync(this, playerCode):
  1884.  
  1885. if this.room.mapCode != 1 or this.room.EMapCode != 0:
  1886.  
  1887. this.sendPacket(Identifiers.old.send.Sync, [playerCode, ""])
  1888.  
  1889. else:
  1890.  
  1891. this.sendPacket(Identifiers.old.send.Sync, [playerCode])
  1892.  
  1893.  
  1894.  
  1895. def sendRoundTime(this, time):
  1896.  
  1897. try:
  1898.  
  1899. this.sendPacket(Identifiers.send.Round_Time, ByteArray().writeShort(time).toByteArray())
  1900.  
  1901.  
  1902.  
  1903. except:
  1904.  
  1905.  
  1906.  
  1907. print(time)
  1908.  
  1909.  
  1910.  
  1911. def sendMapStartTimer(this):
  1912.  
  1913. this.sendPacket(Identifiers.send.Map_Start_Timer, chr(1))
  1914.  
  1915.  
  1916.  
  1917. def sendMapStartTimerEnd(this):
  1918.  
  1919. if this.hasCheese:
  1920.  
  1921. this.hasCheese = False
  1922.  
  1923. this.room.sendAll(Identifiers.send.Remove_Cheese, ByteArray().writeInt(this.playerCode).toByteArray())
  1924.  
  1925.  
  1926.  
  1927. this.sendPacket(Identifiers.send.Map_Start_Timer, chr(0))
  1928.  
  1929.  
  1930.  
  1931. def sendPlayerDisconnect(this):
  1932.  
  1933. this.room.sendAll(Identifiers.old.send.Player_Disconnect, [this.playerCode])
  1934.  
  1935.  
  1936.  
  1937. def sendPlayerDied(this):
  1938.  
  1939. this.room.sendAll(Identifiers.old.send.Player_Died, [this.playerCode, 0, this.playerScore])
  1940.  
  1941.  
  1942.  
  1943. if this.room.isBootcamp:
  1944.  
  1945. this.hasCheese = False
  1946.  
  1947.  
  1948.  
  1949. if this.room.isRacing:
  1950.  
  1951. this.racingRounds = 0
  1952.  
  1953.  
  1954.  
  1955. if this.room.getAliveCount() < 1 or this.room.catchTheCheeseMap or this.isAfk:
  1956.  
  1957. this.canShamanRespawn = False
  1958.  
  1959.  
  1960.  
  1961. if ((this.room.checkIfTooFewRemaining() and not this.canShamanRespawn) or (this.room.checkIfShamanIsDead() and not this.canShamanRespawn) or (this.room.checkIfDoubleShamansAreDead())):
  1962.  
  1963. this.room.send20SecRemainingTimer()
  1964.  
  1965.  
  1966.  
  1967. if this.canShamanRespawn:
  1968.  
  1969. this.isDead = False
  1970.  
  1971. this.isAfk = False
  1972.  
  1973. this.hasCheese = False
  1974.  
  1975. this.hasEnter = False
  1976.  
  1977. this.canShamanRespawn = False
  1978.  
  1979. this.playerStartTimeMillis = time.time()
  1980.  
  1981. this.room.sendAll(Identifiers.old.send.Player_Respawn, [this.getPlayerData(), 1])
  1982.  
  1983. if this.hasCheese:
  1984.  
  1985. this.hasCheese = False
  1986.  
  1987. this.sendGiveCheese()
  1988.  
  1989. for client in this.room.clients.values():
  1990.  
  1991. client.sendShamanCode(this.playerCode, 0)
  1992.  
  1993.  
  1994.  
  1995. def sendShaman(this, shamanCode, shamanCode2, shamanType, shamanType2, shamanLevel, shamanLevel2, shamanBadge, shamanBadge2):
  1996.  
  1997. this.sendPacket(Identifiers.send.Shaman_Info, ByteArray().writeInt(shamanCode).writeInt(shamanCode2).writeByte(shamanType).writeByte(shamanType2).writeShort(shamanLevel).writeShort(shamanLevel2).writeShort(shamanBadge).writeShort(shamanBadge2).toByteArray())
  1998.  
  1999.  
  2000.  
  2001. def sendConjurationDestroy(this, x, y):
  2002.  
  2003. this.room.sendAll(Identifiers.old.send.Conjuration_Destroy, [x, y])
  2004.  
  2005.  
  2006.  
  2007. def sendGiveCheese(this, distance=-1):
  2008.  
  2009. if distance != -1 and distance != 1000 and not this.room.catchTheCheeseMap and this.room.countStats:
  2010.  
  2011. if distance >= 30:
  2012.  
  2013. this.isSuspect = True
  2014.  
  2015.  
  2016.  
  2017. this.room.canChangeMap = False
  2018.  
  2019. if not this.hasCheese:
  2020.  
  2021. this.room.sendAll(Identifiers.old.send.Player_Get_Cheese, [this.playerCode])
  2022.  
  2023. this.numGiveCheese += 1
  2024.  
  2025. this.hasCheese = True
  2026.  
  2027. if this.room.isTutorial:
  2028.  
  2029. this.sendPacket(Identifiers.send.Tutorial, chr(1))
  2030.  
  2031. if this.room.currentMap in range(108, 114):
  2032.  
  2033. if this.numGiveCheese >= 10:
  2034.  
  2035. this.room.killShaman()
  2036.  
  2037.  
  2038.  
  2039. this.room.canChangeMap = True
  2040.  
  2041.  
  2042.  
  2043. def playerWin(this, holeType, distance=-1):
  2044.  
  2045. if distance != -1 and distance != 1000 and this.isSuspect and this.room.countStats:
  2046.  
  2047. if distance >= 30:
  2048.  
  2049. this.server.sendStaffMessage(7, "[<V>ANTI-HACK</V>][<J>%s</J>][<V>%s</V>] Instant win detected by distance." %(this.ipAddress, this.Username))
  2050.  
  2051. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [0, "Instant win detected by distance."])
  2052.  
  2053. this.transport.loseConnection()
  2054.  
  2055. return
  2056.  
  2057.  
  2058.  
  2059. this.room.canChangeMap = False
  2060.  
  2061. canGo = this.room.checkIfShamanCanGoIn() if this.isShaman else True
  2062.  
  2063. if not canGo:
  2064.  
  2065. this.sendSaveRemainingMiceMessage()
  2066.  
  2067.  
  2068.  
  2069. if this.isDead or not this.hasCheese and not this.isOpportunist:
  2070.  
  2071. canGo = False
  2072.  
  2073.  
  2074.  
  2075. if this.room.isTutorial:
  2076.  
  2077. this.sendPacket(Identifiers.send.Tutorial, chr(2))
  2078.  
  2079. this.hasCheese = False
  2080.  
  2081. reactor.callLater(10, lambda: this.enterRoom(this.server.recommendRoom(this.Langue)))
  2082.  
  2083. this.sendRoundTime(10)
  2084.  
  2085. return
  2086.  
  2087.  
  2088.  
  2089. if this.room.isEditeur:
  2090.  
  2091. if not this.room.EMapValidated and this.room.EMapCode != 0:
  2092.  
  2093. this.room.EMapValidated = True
  2094.  
  2095. this.sendPacket(Identifiers.old.send.Map_Validated, [""])
  2096.  
  2097.  
  2098.  
  2099. if canGo:
  2100.  
  2101. this.isDead = True
  2102.  
  2103. this.hasCheese = False
  2104.  
  2105. this.hasEnter = True
  2106.  
  2107. this.isOpportunist = False
  2108.  
  2109. this.room.numCompleted += 1
  2110.  
  2111. place = this.room.numCompleted
  2112.  
  2113. if this.room.isDoubleMap:
  2114.  
  2115. if holeType == 1:
  2116.  
  2117. this.room.FSnumCompleted += 1
  2118.  
  2119. elif holeType == 2:
  2120.  
  2121. this.room.SSnumCompleted += 1
  2122.  
  2123. else:
  2124.  
  2125. this.room.FSnumCompleted += 1
  2126.  
  2127. this.room.SSnumCompleted += 1
  2128.  
  2129.  
  2130.  
  2131. timeTaken = int((time.time() - (this.playerStartTimeMillis if this.room.autoRespawn else this.room.gameStartTimeMillis)) * 100)
  2132.  
  2133. this.currentPlace = place
  2134.  
  2135. if place == 1:
  2136.  
  2137. if this.room.isBootcamp:
  2138.  
  2139. if this.room.mapCode == 2018:
  2140.  
  2141. for player in this.room.clients.values():
  2142.  
  2143. player.sendLangueMessage("", "<N>Parabéns a <BV>"+str(this.Username)+"<N> por completar o Evento!")
  2144.  
  2145.  
  2146.  
  2147. if this.room.mapCode == 2018:
  2148.  
  2149. for player in this.room.clients.values():
  2150.  
  2151. player.sendLangueMessage("", "<FC>Trocando de Mapa em 10 segundos.")
  2152.  
  2153. player.sendRoundTime(10)
  2154.  
  2155. this.room.changeMapTimers(10)
  2156.  
  2157. this.playerScore += (4 if this.room.isRacing else 16) if not this.room.noAutoScore else 0
  2158.  
  2159. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn and not this.isGuest:
  2160.  
  2161. this.sendMessage('<BV>[M] <N>Congratulations to <BV>'+str(this.Username)+'<N> came first and received <BV>+3<N> coins.')
  2162.  
  2163. if not this.server.isNowEvent:
  2164.  
  2165. this.firstCount += 15
  2166.  
  2167. this.nowCoins += 15
  2168.  
  2169. else:
  2170.  
  2171. this.firstCount += 15
  2172.  
  2173. this.cheeseCount += 15
  2174.  
  2175. this.nowCoins += 15
  2176.  
  2177.  
  2178.  
  2179. if not this.tribeName == "":
  2180.  
  2181. this.tribePoints += 15
  2182.  
  2183.  
  2184.  
  2185. if not this.isGuest:
  2186.  
  2187. this.sendMessage("You won <V>" + str(6 if this.server.isNowEvent else 3) + "</V> coins!")
  2188.  
  2189.  
  2190.  
  2191. if this.room.mapCode == 2018:
  2192.  
  2193. for player in this.room.clients.values():
  2194.  
  2195. player.sendLangueMessage("", "<N>Parabéns a <BV>"+str(this.Username)+"<N> por completar o Evento!")
  2196.  
  2197.  
  2198.  
  2199. for player in this.room.clients.values():
  2200.  
  2201. player.sendLangueMessage("", "<FC>Trocando de Mapa em 10 segundos.")
  2202.  
  2203. player.sendRoundTime(10)
  2204.  
  2205. this.room.changeMapTimers(10)
  2206.  
  2207.  
  2208.  
  2209. elif place == 2:
  2210.  
  2211. this.playerScore += (3 if this.room.isRacing else 14) if not this.room.noAutoScore else 0
  2212.  
  2213. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn and not this.isGuest:
  2214.  
  2215. this.sendMessage('<BV>[M] <N>Congratulations to <BV>'+str(this.Username)+'<N> came first and received <BV>+3<N> coins.')
  2216.  
  2217. if not this.server.isNowEvent:
  2218.  
  2219. this.firstCount += 10
  2220.  
  2221. this.nowCoins += 10
  2222.  
  2223. else:
  2224.  
  2225. this.firstCount += 10
  2226.  
  2227. this.cheeseCount += 10
  2228.  
  2229. this.nowCoins += 10
  2230.  
  2231.  
  2232.  
  2233. if not this.tribeName == "":
  2234.  
  2235. this.tribePoints += 10
  2236.  
  2237.  
  2238.  
  2239. if not this.isGuest:
  2240.  
  2241. this.sendMessage("You won <V>" + str(6 if this.server.isNowEvent else 3) + "</V> coins!")
  2242.  
  2243. elif place == 3:
  2244.  
  2245. this.playerScore += (2 if this.room.isRacing else 12) if not this.room.noAutoScore else 0
  2246.  
  2247. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn and not this.isGuest:
  2248.  
  2249. this.sendMessage('<BV>[M] <N>Congratulations to <BV>'+str(this.Username)+'<N> came first and received <BV>+3<N> coins.')
  2250.  
  2251. if not this.server.isNowEvent:
  2252.  
  2253. this.firstCount += 5
  2254.  
  2255. this.nowCoins += 5
  2256.  
  2257. else:
  2258.  
  2259. this.firstCount += 5
  2260.  
  2261. this.cheeseCount += 5
  2262.  
  2263. this.nowCoins += 5
  2264.  
  2265.  
  2266.  
  2267. if not this.tribeName == "":
  2268.  
  2269. this.tribePoints += 5
  2270.  
  2271.  
  2272.  
  2273. if not this.isGuest:
  2274.  
  2275. this.sendMessage("You won <V>" + str(6 if this.server.isNowEvent else 3) + "</V> coins!")
  2276.  
  2277. else:
  2278.  
  2279. this.playerScore += (1 if this.room.isRacing else 10) if not this.room.noAutoScore else 0
  2280.  
  2281.  
  2282.  
  2283. if this.room.isMulodrome:
  2284.  
  2285. if this.Username in this.room.redTeam:
  2286.  
  2287. this.room.redCount += 4 if place == 1 else 3 if place == 2 else 2 if place == 2 else 1
  2288.  
  2289.  
  2290.  
  2291. elif this.Username in this.room.blueTeam:
  2292.  
  2293. this.room.blueCount += 4 if place == 1 else 3 if place == 2 else 2 if place == 2 else 1
  2294.  
  2295.  
  2296.  
  2297. this.room.sendMulodromeRound()
  2298.  
  2299.  
  2300.  
  2301. if this.room.isDefilante:
  2302.  
  2303. if not this.room.noAutoScore: this.playerScore += this.defilantePoints
  2304.  
  2305. id = 2257
  2306.  
  2307. if not id in this.playerConsumables:
  2308.  
  2309. this.playerConsumables[id] = 1
  2310.  
  2311. else:
  2312.  
  2313. count = this.playerConsumables[id] + 1
  2314.  
  2315. this.playerConsumables[id] = count
  2316.  
  2317. this.sendAnimZeldaInventory(4, id, 1)
  2318.  
  2319.  
  2320.  
  2321. if this.room.isRacing:
  2322.  
  2323. id = 2254
  2324.  
  2325. this.racingRounds += 1
  2326.  
  2327. if this.racingRounds >= 5:
  2328.  
  2329. if not id in this.playerConsumables:
  2330.  
  2331. this.playerConsumables[id] = 1
  2332.  
  2333. else:
  2334.  
  2335. count = this.playerConsumables[id] + 1
  2336.  
  2337. this.playerConsumables[id] = count
  2338.  
  2339. this.sendAnimZeldaInventory(4, id, 1)
  2340.  
  2341. this.racingRounds = 0
  2342.  
  2343.  
  2344.  
  2345. if this.room.isBootcamp:
  2346.  
  2347. id = 2261
  2348.  
  2349. this.bootcampRounds += 1
  2350.  
  2351. if this.bootcampRounds == 5:
  2352.  
  2353. if not id in this.playerConsumables:
  2354.  
  2355. this.playerConsumables[id] = 1
  2356.  
  2357. else:
  2358.  
  2359. count = this.playerConsumables[id] + 1
  2360.  
  2361. this.playerConsumables[id] = count
  2362.  
  2363. this.sendAnimZeldaInventory(4, id, 1)
  2364.  
  2365.  
  2366.  
  2367. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.room.isBootcamp and not this.isGuest:
  2368.  
  2369. if this.playerCode == this.room.currentShamanCode or this.playerCode == this.room.currentSecondShamanCode:
  2370.  
  2371. this.shamanCheeses += 1
  2372.  
  2373. this.sendAnimZelda(4, 2253)
  2374.  
  2375. this.sendNewConsumable(2253, 1)
  2376.  
  2377. if this.playerConsumables.has_key(2253):
  2378.  
  2379. this.playerConsumables[2253] += 1
  2380.  
  2381. else:
  2382.  
  2383. this.playerConsumables[2253] = 1
  2384.  
  2385. else:
  2386.  
  2387. this.cheeseCount += 1
  2388.  
  2389.  
  2390.  
  2391. count = 4 if place == 1 else 3 if place == 2 else 2 if place == 2 else 1
  2392.  
  2393. this.shopCheeses += count
  2394.  
  2395. this.shopFraises += count
  2396.  
  2397.  
  2398.  
  2399. this.sendGiveCurrency(0, 1)
  2400.  
  2401. this.skillModule.earnExp(False, 20)
  2402.  
  2403. if not this.isGuest:
  2404.  
  2405. if place == 1 and this.server.firstTitleList.has_key(this.firstCount):
  2406.  
  2407. title = this.server.firstTitleList[this.firstCount]
  2408.  
  2409. this.checkAndRebuildTitleList("first")
  2410.  
  2411. this.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  2412.  
  2413. this.sendCompleteTitleList()
  2414.  
  2415. this.sendTitleList()
  2416.  
  2417.  
  2418.  
  2419. if this.server.cheeseTitleList.has_key(this.cheeseCount):
  2420.  
  2421. title = this.server.cheeseTitleList[this.cheeseCount]
  2422.  
  2423. this.checkAndRebuildTitleList("cheese")
  2424.  
  2425. this.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  2426.  
  2427. this.sendCompleteTitleList()
  2428.  
  2429. this.sendTitleList()
  2430.  
  2431.  
  2432.  
  2433. elif this.room.getPlayerCountUnique() >= this.server.needToBootcamp and this.room.isBootcamp and not this.isGuest:
  2434.  
  2435. if not this.server.isNowEvent:
  2436.  
  2437. this.bootcampCount += 1
  2438.  
  2439. else:
  2440.  
  2441. this.bootcampCount += 3
  2442.  
  2443.  
  2444.  
  2445. if this.server.bootcampTitleList.has_key(this.bootcampCount):
  2446.  
  2447. title = this.server.bootcampTitleList[this.bootcampCount]
  2448.  
  2449. this.checkAndRebuildTitleList("bootcamp")
  2450.  
  2451. this.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  2452.  
  2453. this.sendCompleteTitleList()
  2454.  
  2455. this.sendTitleList()
  2456.  
  2457.  
  2458.  
  2459. this.room.giveShamanSave(this.room.currentSecondShamanName if holeType == 2 and this.room.isDoubleMap else this.room.currentShamanName, 0)
  2460.  
  2461. if this.room.currentShamanType != 0:
  2462.  
  2463. this.room.giveShamanSave(this.room.currentShamanName, this.room.currentShamanType)
  2464.  
  2465.  
  2466.  
  2467. if this.room.currentSecondShamanType != 0:
  2468.  
  2469. this.room.giveShamanSave(this.room.currentSecondShamanName, this.room.currentSecondShamanType)
  2470.  
  2471.  
  2472.  
  2473. this.sendPlayerWin(place, timeTaken)
  2474.  
  2475.  
  2476.  
  2477. if this.room.getPlayerCount() >= 2 and this.room.checkIfTooFewRemaining() and not this.room.isDoubleMap and this.room.currentShamanName != "" and this.isOpportunist:
  2478.  
  2479. this.playerWin(0)
  2480.  
  2481. else:
  2482.  
  2483. this.room.checkShouldChangeMap()
  2484.  
  2485.  
  2486.  
  2487. this.room.canChangeMap = True
  2488.  
  2489.  
  2490.  
  2491. def sendSaveRemainingMiceMessage(this):
  2492.  
  2493. this.sendPacket(Identifiers.old.send.Save_Remaining, [])
  2494.  
  2495.  
  2496.  
  2497. def sendGiveCurrency(this, type, count):
  2498.  
  2499. this.sendPacket(Identifiers.send.Give_Currency, ByteArray().writeByte(type).writeByte(count).toByteArray())
  2500.  
  2501.  
  2502.  
  2503. def sendPlayerWin(this, place, timeTaken):
  2504.  
  2505. this.room.sendAll(Identifiers.send.Player_Win, ByteArray().writeByte(1 if this.room.isDefilante else 0).writeInt(this.playerCode).writeShort(this.playerScore).writeUnsignedByte(place).writeUnsignedShort(timeTaken).toByteArray())
  2506.  
  2507. this.hasCheese = False
  2508.  
  2509.  
  2510.  
  2511. def sendCompleteTitleList(this):
  2512.  
  2513. this.titleList = []
  2514.  
  2515. this.titleList.append(0.1)
  2516.  
  2517. this.titleList.extend(this.cheeseTitleList)
  2518.  
  2519. this.titleList.extend(this.firstTitleList)
  2520.  
  2521. this.titleList.extend(this.shamanTitleList)
  2522.  
  2523. this.titleList.extend(this.shopTitleList)
  2524.  
  2525. this.titleList.extend(this.bootcampTitleList)
  2526.  
  2527. this.titleList.extend(this.hardModeTitleList)
  2528.  
  2529. this.titleList.extend(this.divineModeTitleList)
  2530.  
  2531. this.titleList.extend(this.specialTitleList)
  2532.  
  2533.  
  2534.  
  2535. if this.privLevel >= 2:
  2536.  
  2537. this.titleList.append(1100.9)
  2538.  
  2539.  
  2540.  
  2541. if this.privLevel == 11:
  2542.  
  2543. this.titleList.extend([440.9, 442.9, 444.9, 445.9, 446.9, 447.9, 448.9, 449.9, 450.9, 451.9, 452.9, 453.9, 201.9, 1113.9 if this.gender in [2, 0] else 1114.9])
  2544.  
  2545.  
  2546.  
  2547. if this.privLevel >= 5:
  2548.  
  2549. this.titleList.append(1103.9 if this.gender in [2, 0] else 1104.9)
  2550.  
  2551.  
  2552.  
  2553. if this.privLevel >= 6:
  2554.  
  2555. this.titleList.append(1105.9 if this.gender in [2, 0] else 1106.9)
  2556.  
  2557.  
  2558.  
  2559. if this.privLevel >= 7:
  2560.  
  2561. this.titleList.append(1107.9 if this.gender in [2, 0] else 1108.9)
  2562.  
  2563.  
  2564.  
  2565. if this.privLevel >= 8:
  2566.  
  2567. this.titleList.append(1109.9 if this.gender in [2, 0] else 1110.9)
  2568.  
  2569.  
  2570.  
  2571. if this.privLevel >= 9:
  2572.  
  2573. this.titleList.append(1111.9 if this.gender in [2, 0] else 1112.9)
  2574.  
  2575.  
  2576.  
  2577. if this.privLevel == 10:
  2578.  
  2579. this.titleList.extend([440.9, 442.9, 444.9, 445.9, 446.9, 447.9, 448.9, 449.9, 450.9, 451.9, 452.9, 453.9, 1113.9 if this.gender in [2, 0] else 1114.9])
  2580.  
  2581.  
  2582.  
  2583. def sendTitleList(this):
  2584.  
  2585. this.sendPacket(Identifiers.old.send.Titles_List, [this.titleList])
  2586.  
  2587.  
  2588.  
  2589. def sendUnlockedTitle(this, title, stars):
  2590.  
  2591. this.room.sendAll(Identifiers.old.send.Unlocked_Title, [this.playerCode, title, stars])
  2592.  
  2593.  
  2594.  
  2595. def sendMessage(this, message, tab=False):
  2596.  
  2597. this.sendPacket(Identifiers.send.Recv_Message, ByteArray().writeBool(tab).writeUTF(message).writeByte(0).writeUTF("").toByteArray())
  2598.  
  2599.  
  2600.  
  2601. def sendProfile(this, playerName):
  2602.  
  2603. player = this.server.players.get(playerName)
  2604.  
  2605.  
  2606.  
  2607. if player != None and not player.isGuest:
  2608.  
  2609. p = ByteArray().writeInt(player.playerID).writeUTF(player.Username if player.mouseName == "" else this.mouseName)
  2610.  
  2611. for stat in [player.shamanSaves, player.shamanCheeses, player.firstCount, player.cheeseCount, player.hardModeSaves, player.bootcampCount, player.divineModeSaves]:
  2612.  
  2613. p.writeInt(stat)
  2614.  
  2615.  
  2616.  
  2617. p.writeShort(player.TitleNumber)
  2618.  
  2619. titles = ByteArray()
  2620.  
  2621. for title in player.titleList:
  2622.  
  2623. titleInfo = str(title).split(".")
  2624.  
  2625. titles.writeShort(int(titleInfo[0])).writeByte(int(titleInfo[1]))
  2626.  
  2627.  
  2628.  
  2629. titlesResult = titles.toByteArray()
  2630.  
  2631.  
  2632.  
  2633. p.writeShort(len(player.titleList))
  2634.  
  2635. p.write(titlesResult)
  2636.  
  2637. p.writeUTF(player.playerLook)
  2638.  
  2639. p.writeUTF(player.tribeName)
  2640.  
  2641. p.writeInt(str(player.regDate)[:10])
  2642.  
  2643. p.writeInt(int(player.MouseColor, 16))
  2644.  
  2645. p.writeShort(player.shamanLevel)
  2646.  
  2647. p.writeByte(player.gender)
  2648.  
  2649. p.writeByte(1 if player.privLevel <= 2 else 21 if player.privLevel <= 5 else 20 if player.privLevel <= 6 else 6 if player.privLevel <= 9 else 10)
  2650.  
  2651. p.writeBool(True)
  2652.  
  2653. p.writeUTF(player.marriage)
  2654.  
  2655. p.writeUnsignedByte(len(player.shopBadges) * 2)
  2656.  
  2657.  
  2658.  
  2659. badges = map(int, player.shopBadges)
  2660.  
  2661. for badge in [120, 121, 122, 123, 124, 125, 126, 127, 145, 42, 54, 55, 0, 1, 6, 7, 9, 16, 17, 18, 28, 29, 30, 33, 34, 35, 46, 47, 50, 51, 57, 58, 59, 64, 65, 69, 71, 73, 129, 130, 131, 132, 133, 134, 139, 142, 144, 147, 153, 154, 158]:
  2662.  
  2663. if badge in badges:
  2664.  
  2665. p.writeUnsignedByte(badge).writeByte(0)
  2666.  
  2667. badges.remove(int(badge))
  2668.  
  2669.  
  2670.  
  2671. for badge in badges:
  2672.  
  2673. p.writeUnsignedByte(badge).writeByte(0)
  2674.  
  2675.  
  2676.  
  2677. stats = [[30, player.racingStats[0], 1500, 124], [31, player.racingStats[1], 10000, 125], [33, player.racingStats[2], 10000, 127], [32, player.racingStats[3], 10000, 126], [26, player.survivorStats[0], 1000, 120], [27, player.survivorStats[1], 800, 121], [28, player.survivorStats[2], 20000, 122], [29, player.survivorStats[3], 10000, 123]]
  2678.  
  2679. p.writeByte(len(stats))
  2680.  
  2681. for stat in stats:
  2682.  
  2683. p.writeByte(stat[0]).writeInt(stat[1]).writeInt(stat[2]).writeByte(stat[3])
  2684.  
  2685.  
  2686.  
  2687. p.writeByte(player.equipedShamanBadge).writeByte(len(player.shamanBadges))
  2688.  
  2689. for shamanBadge in player.shamanBadges:
  2690.  
  2691. p.writeByte(shamanBadge)
  2692.  
  2693.  
  2694.  
  2695. this.sendPacket(Identifiers.send.Profile, p.toByteArray())
  2696.  
  2697.  
  2698.  
  2699. def sendPlayerBan(this, hours, reason, silent):
  2700.  
  2701. this.sendPacket(Identifiers.old.send.Player_Ban, [3600000 * hours, reason])
  2702.  
  2703. if not silent and this.room != None:
  2704.  
  2705. for player in this.room.clients.values():
  2706.  
  2707. player.sendLangueMessage("", "<ROSE>$Message_Ban", this.Username, str(hours), reason)
  2708.  
  2709.  
  2710.  
  2711. this.server.disconnectIPAddress(this.ipAddress)
  2712.  
  2713.  
  2714.  
  2715. def sendPlayerEmote(this, emoteID, flag, others, lua):
  2716.  
  2717. p = ByteArray().writeInt(this.playerCode).writeByte(emoteID)
  2718.  
  2719. if not flag == "": p.writeUTF(flag)
  2720.  
  2721. result = p.writeBool(lua).toByteArray()
  2722.  
  2723.  
  2724.  
  2725. this.room.sendAllOthers(this, Identifiers.send.Player_Emote, result) if others else this.room.sendAll(Identifiers.send.Player_Emote, result)
  2726.  
  2727.  
  2728.  
  2729. def sendEmotion(this, emotion):
  2730.  
  2731. this.room.sendAllOthers(this, Identifiers.send.Emotion, ByteArray().writeInt(this.playerCode).writeByte(emotion).toByteArray())
  2732.  
  2733.  
  2734.  
  2735. def sendPlaceObject(this, objectID, code, px, py, angle, vx, vy, dur, sendAll):
  2736.  
  2737. p = ByteArray().writeInt(objectID).writeShort(code).writeShort(px).writeShort(py).writeShort(angle).writeByte(vx).writeByte(vy).writeBool(dur)
  2738.  
  2739. p.writeByte(0) if this.isGuest or sendAll else p.writeBytes(this.shopModule.getShamanItemCustom(code))
  2740.  
  2741.  
  2742.  
  2743. if not sendAll:
  2744.  
  2745. this.room.sendAllOthers(this, Identifiers.send.Spawn_Object, p.toByteArray())
  2746.  
  2747. this.room.objectID = objectID
  2748.  
  2749. else:
  2750.  
  2751. this.room.sendAll(Identifiers.send.Spawn_Object, p.toByteArray())
  2752.  
  2753.  
  2754.  
  2755. def sendAllModerationChat(this, type, message):
  2756.  
  2757. playerName = this.Username if type == -1 else "" if type == 0 else "Message Serveur" if type == 1 else this.Langue.upper() + "][" + ("Fundador][" if this.privLevel == 11 else "Admin][" if this.privLevel == 10 else "Coord][" if this.privLevel == 9 else "Smod][" if this.privLevel == 8 else "Mod][" if this.privLevel == 7 else "MapCrew][" if this.privLevel == 6 else "Helper][" if this.privLevel == 5 else "LUA][" if this.privLevel == 3 else "")
  2758.  
  2759. if "][" in playerName: playerName += this.Username
  2760.  
  2761. this.server.sendStaffChat(type, this.Langue, Identifiers.send.Staff_Chat, ByteArray().writeByte(1 if type == -1 else type).writeUTF(playerName).writeUTF(message).writeShort(0).writeShort(0).toByteArray())
  2762.  
  2763.  
  2764.  
  2765. def sendStaffLogin(this, isDisconnect):
  2766.  
  2767. playerName = "Server][" + ("Fundador" if this.privLevel == 11 else "Admin" if this.privLevel == 10 else "Coord" if this.privLevel == 9 else "SMod" if this.privLevel == 8 else "Mod" if this.privLevel == 7 else "MapCrew" if this.privLevel == 6 else "Helper" if this.privLevel == 5 else "")
  2768.  
  2769. this.server.sendStaffChat(2, this.Langue, Identifiers.send.Staff_Chat, ByteArray().writeByte(2).writeUTF(playerName).writeUTF(this.Username + " is offline." if isDisconnect else this.Username + " is online.").writeShort(0).writeShort(0).toByteArray())
  2770.  
  2771.  
  2772.  
  2773. def sendTotem(this, totem, x, y, playerCode):
  2774.  
  2775. this.sendPacket(Identifiers.old.send.Totem, [str(playerCode) + "#" + str(x) + "#" + str(y) + totem])
  2776.  
  2777.  
  2778.  
  2779. def sendTotemItemCount(this, number):
  2780.  
  2781. if this.room.isTotemEditeur:
  2782.  
  2783. this.sendPacket(Identifiers.old.send.Totem_Item_Count, ByteArray().writeShort(number * 2).writeShort(0).toByteArray())
  2784.  
  2785.  
  2786.  
  2787. def initTotemEditeur(this):
  2788.  
  2789. if this.RTotem:
  2790.  
  2791. this.sendTotemItemCount(0)
  2792.  
  2793. this.RTotem = False
  2794.  
  2795. else:
  2796.  
  2797. if not this.STotem[1] == "":
  2798.  
  2799. this.Totem[0] = this.STotem[0]
  2800.  
  2801. this.Totem[1] = this.STotem[1]
  2802.  
  2803. this.sendTotemItemCount(int(this.STotem[0]))
  2804.  
  2805. this.sendTotem(this.STotem[1], 400, 202, this.playerCode)
  2806.  
  2807. else:
  2808.  
  2809. this.sendTotemItemCount(0)
  2810.  
  2811.  
  2812.  
  2813. def sendShamanType(this, mode, canDivine):
  2814.  
  2815. this.sendPacket(Identifiers.send.Shaman_Type, ByteArray().writeByte(mode).writeBool(canDivine).writeInt(int(this.ShamanColor, 16)).toByteArray())
  2816.  
  2817.  
  2818.  
  2819. def sendBanConsideration(this):
  2820.  
  2821. this.sendPacket(Identifiers.old.send.Ban_Consideration, ["0"])
  2822.  
  2823.  
  2824.  
  2825. def sendShamanPosition(this, direction):
  2826.  
  2827. this.room.sendAll(Identifiers.send.Shaman_Position, ByteArray().writeInt(this.playerCode).writeBool(direction).toByteArray())
  2828.  
  2829.  
  2830.  
  2831. def loadCafeMode(this):
  2832.  
  2833. can = this.privLevel >= 5 or (this.Langue.upper() == this.realLangue and this.privLevel != 0 and this.cheeseCount >= 100)
  2834.  
  2835. if not can:
  2836.  
  2837. this.sendLangueMessage("", "<ROSE>$PasAutoriseParlerSurServeur")
  2838.  
  2839.  
  2840.  
  2841. this.sendPacket(Identifiers.send.Open_Cafe, ByteArray().writeBool(can).toByteArray())
  2842.  
  2843. p = ByteArray()
  2844.  
  2845. this.Cursor.execute("select * from CafeTopics where Langue = ? order by Date desc limit 0, 20", [this.Langue])
  2846.  
  2847. r = this.Cursor.fetchall()
  2848.  
  2849. for rs in r:
  2850.  
  2851. p.writeInt(rs["TopicID"]).writeUTF(rs["Title"]).writeInt(this.server.getPlayerID(rs["Author"])).writeInt(rs["Posts"]).writeUTF(rs["LastPostName"]).writeInt(TFMUtils.getSecondsDiff(rs["Date"]))
  2852.  
  2853. this.sendPacket(Identifiers.send.Cafe_Topics_List, p.toByteArray())
  2854.  
  2855.  
  2856.  
  2857. def openCafeTopic(this, topicID):
  2858.  
  2859. p = ByteArray().writeBool(True).writeInt(topicID)
  2860.  
  2861. this.Cursor.execute("select * from CafePosts where TopicID = ? order by PostID asc", [topicID])
  2862.  
  2863. r = this.Cursor.fetchall()
  2864.  
  2865. for rs in r:
  2866.  
  2867. p.writeInt(rs["PostID"]).writeInt(this.server.getPlayerID(rs["Name"])).writeInt(TFMUtils.getSecondsDiff(rs["Date"])).writeUTF(rs["Name"]).writeUTF(rs["Post"]).writeBool(str(this.playerCode) not in rs["Votes"].split(",")).writeShort(rs["Points"])
  2868.  
  2869. this.sendPacket(Identifiers.send.Open_Cafe_Topic, p.toByteArray())
  2870.  
  2871.  
  2872.  
  2873. def createNewCafeTopic(this, title, message):
  2874.  
  2875. this.server.lastTopicID += 1
  2876.  
  2877. this.Cursor.execute("insert into CafeTopics values (?, ?, ?, '', 0, ?, ?)", [this.server.lastTopicID, title, this.Username, TFMUtils.getTime(), this.Langue])
  2878.  
  2879. this.server.updateConfig()
  2880.  
  2881. this.createNewCafePost(this.server.lastTopicID, message)
  2882.  
  2883. this.loadCafeMode()
  2884.  
  2885.  
  2886.  
  2887. def createNewCafePost(this, topicID, message):
  2888.  
  2889. commentsCount = 0
  2890.  
  2891. this.server.lastPostID += 1
  2892.  
  2893. this.Cursor.execute("insert into CafePosts values (?, ?, ?, ?, ?, 0, ?)", [this.server.lastPostID, topicID, this.Username, message, TFMUtils.getTime(), str(this.playerCode)])
  2894.  
  2895. this.Cursor.execute("update CafeTopics set Posts = Posts + 1, LastPostName = ?, Date = ? where TopicID = ?", [this.Username, TFMUtils.getTime(), topicID])
  2896.  
  2897. this.Cursor.execute("select count(*) as count from CafePosts where TopicID = ?", [topicID])
  2898.  
  2899. rs = this.Cursor.fetchone()
  2900.  
  2901. commentsCount = rs["count"]
  2902.  
  2903. this.openCafeTopic(topicID)
  2904.  
  2905. for client in this.server.players.values():
  2906.  
  2907. if client.isCafe:
  2908.  
  2909. client.sendPacket(Identifiers.send.Cafe_New_Post, ByteArray().writeInt(topicID).writeUTF(this.Username).writeInt(commentsCount).toByteArray())
  2910.  
  2911.  
  2912.  
  2913. def voteCafePost(this, topicID, postID, mode):
  2914.  
  2915. this.Cursor.execute("update cafeposts set Points = Points %s 1, Votes = (case when Votes = '' then ? else (Votes || ?) end) where TopicID = ? and PostID = ?" %("+" if mode else "-"), [this.playerCode, this.playerCode, topicID, postID])
  2916.  
  2917.  
  2918.  
  2919. def sendLangueMessage(this, message1, message2, *args):
  2920.  
  2921. p = ByteArray().writeUTF(message1).writeUTF(message2).writeByte(len(args))
  2922.  
  2923. for arg in args:
  2924.  
  2925. p.writeUTF(arg)
  2926.  
  2927. this.sendPacket(Identifiers.send.Message_Langue, p.toByteArray())
  2928.  
  2929.  
  2930.  
  2931. def sendVampireMode(this, others):
  2932.  
  2933. this.isVampire = True
  2934.  
  2935. p = ByteArray().writeInt(this.playerCode)
  2936.  
  2937. if others:
  2938.  
  2939. this.room.sendAllOthers(this, Identifiers.send.Vampire_Mode, p.toByteArray())
  2940.  
  2941. else:
  2942.  
  2943. this.room.sendAll(Identifiers.send.Vampire_Mode, p.toByteArray())
  2944.  
  2945.  
  2946.  
  2947. def sendRemoveCheese(this):
  2948.  
  2949. this.room.sendAll(Identifiers.send.Remove_Cheese, ByteArray().writeInt(this.playerCode).toByteArray())
  2950.  
  2951.  
  2952.  
  2953. def sendLuaMessage(this, message):
  2954.  
  2955. this.sendPacket(Identifiers.send.Lua_Message, ByteArray().writeUTF(message).toByteArray())
  2956.  
  2957.  
  2958.  
  2959. def sendGameMode(this, mode):
  2960.  
  2961. mode = 1 if mode == 0 else mode
  2962.  
  2963. types = [1, 3, 8, 9, 11, 2, 10, 18, 16]
  2964.  
  2965. p = ByteArray().writeByte(len(types))
  2966.  
  2967. for roomType in types:
  2968.  
  2969. p.writeByte(roomType)
  2970.  
  2971.  
  2972.  
  2973. p.writeByte(mode)
  2974.  
  2975. modeInfo = this.server.getPlayersCountMode(mode, this.Langue)
  2976.  
  2977. if not modeInfo[0] == "":
  2978.  
  2979. roomsCount = 0
  2980.  
  2981. p.writeUnsignedByte(1).writeUnsignedByte(this.langueByte).writeUTF(str(modeInfo[0])).writeUTF(str(modeInfo[1])).writeUTF("mjj").writeUTF("1")
  2982.  
  2983. for checkRoom in this.server.rooms.values():
  2984.  
  2985. if (checkRoom.isNormRoom 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.isDefilante if mode == 10 else checkRoom.isVillage) and checkRoom.community == this.Langue.lower():
  2986.  
  2987. roomsCount +=1
  2988.  
  2989. p.writeUnsignedByte(0).writeUnsignedByte(this.langueByte).writeUTF(checkRoom.roomName).writeUnsignedShort(checkRoom.getPlayerCount()).writeUnsignedByte(checkRoom.maxPlayers).writeBool(checkRoom.isFuncorp)
  2990.  
  2991.  
  2992.  
  2993. if roomsCount == 0:
  2994.  
  2995. p.writeUnsignedByte(0).writeUnsignedByte(this.langueByte).writeUTF(("" if mode == 1 else str(modeInfo[0].split(" ")[1])) + "1").writeUnsignedShort(0).writeUnsignedByte(200).writeBool(False)
  2996.  
  2997.  
  2998.  
  2999. if mode == 18:
  3000.  
  3001. minigameList = ["#deathmatch", "#utility"]
  3002.  
  3003. moduleCount = {"#deathmatch": 0, "#utility": 0}
  3004.  
  3005. moduleMjj = {"#deathmatch": "#deathmatch", "#utility": "#utility0%s" % (this.Username)}
  3006.  
  3007. for checkRoom in this.server.rooms.values():
  3008.  
  3009. if checkRoom.isUtility:
  3010.  
  3011. moduleCount["#utility"] += checkRoom.getPlayerCount()
  3012.  
  3013. elif checkRoom.isDeathmatch:
  3014.  
  3015. moduleCount["#deathmatch"] += checkRoom.getPlayerCount()
  3016.  
  3017. for minigame in minigameList:
  3018.  
  3019. p.writeUnsignedByte(1).writeUnsignedByte(this.langueByte).writeUTF(str(minigame)).writeUTF(str(moduleCount[minigame])).writeUTF("mjj").writeUTF(str(moduleMjj[minigame]))
  3020.  
  3021. for checkRoom in this.server.rooms.values():
  3022.  
  3023. if checkRoom.isUtility or checkRoom.isDeathmatch:
  3024.  
  3025. p.writeUnsignedByte(0).writeUnsignedByte(this.langueByte).writeUTF(checkRoom.roomName).writeUnsignedShort(checkRoom.getPlayerCount()).writeUnsignedByte(checkRoom.maxPlayers).writeBool(checkRoom.isFuncorp)
  3026.  
  3027.  
  3028.  
  3029. this.sendPacket(Identifiers.send.Game_Mode, p.toByteArray())
  3030.  
  3031.  
  3032.  
  3033. def sendMusicVideo(this, sendAll):
  3034.  
  3035. music = this.room.musicVideos[0]
  3036.  
  3037. p = ByteArray().writeUTF(str(music["VideoID"].encode("UTF-8"))).writeUTF(str(music["Title"].encode("UTF-8"))).writeShort(this.room.musicTime).writeUTF(str(music["By"].encode("UTF-8")))
  3038.  
  3039. if sendAll:
  3040.  
  3041. this.room.musicSkipVotes = 0
  3042.  
  3043. this.room.sendAll(Identifiers.send.Music_Video, p.toByteArray())
  3044.  
  3045. else:
  3046.  
  3047. this.sendPacket(Identifiers.send.Music_Video, p.toByteArray())
  3048.  
  3049.  
  3050.  
  3051. def checkMusicSkip(this):
  3052.  
  3053. if this.room.isMusic and this.room.isPlayingMusic:
  3054.  
  3055. count = this.room.getPlayersCount()
  3056.  
  3057. count = count if count % 2 == 0 else count + 1
  3058.  
  3059. if this.room.musicSkipVotes == count / 2:
  3060.  
  3061. this.room.musicVideos.remove(0)
  3062.  
  3063. this.sendMusicVideo(True)
  3064.  
  3065.  
  3066.  
  3067. def sendStaffMessage(this, message, othersLangues):
  3068.  
  3069. for player in this.server.players.values():
  3070.  
  3071. if othersLangues or player.Langue == this.Langue:
  3072.  
  3073. player.sendMessage(message, True)
  3074.  
  3075.  
  3076.  
  3077. def checkVip(this, vipTime):
  3078.  
  3079. days = TFMUtils.getDiffDays(vipTime)
  3080.  
  3081. if days >= 0:
  3082.  
  3083. this.privLevel = 1
  3084.  
  3085. if this.TitleNumber == 1100:
  3086.  
  3087. this.TitleNumber = 0
  3088.  
  3089.  
  3090.  
  3091. this.sendMessage("O seu VIP se estogou.")
  3092.  
  3093. this.Cursor.execute("update users set VipTime = 0 where Username = ?", [this.Username])
  3094.  
  3095. else:
  3096.  
  3097. this.sendMessage("Você ainda tem <V>"+str(days)+"</V> dias de VIP!")
  3098.  
  3099.  
  3100.  
  3101. def sendMenu(this):
  3102.  
  3103. if this.privLevel >= 1:
  3104.  
  3105. if this.showButtons:
  3106.  
  3107. text = "<a href='event:showButtons'><font color='#FA5858'>â–²</font></a> <font color='#FFFFFF' size='10'>Menu</font>\n"
  3108.  
  3109. text += "\n<a href='event:shop:open'><img src='http://crewmicebr.com.br/images/menu/shop.png' align='right' hspace='5' vspace='3'></a>"
  3110.  
  3111. text += "\n<a href='event:spinTheWheel:open'><img src='http://crewmicebr.com.br/images/menu/roleta.png' align='right' hspace='5' vspace='3'></a>"
  3112.  
  3113. text += "\n<a href='event:vipInfo:open'><img src='http://crewmicebr.com.br/images/menu/vipInfo.png' align='right' hspace='5' vspace='3'></a>"
  3114.  
  3115. text += "\n<a href='event:consumablesShop:open'><img src='http://crewmicebr.com.br/images/menu/consumablesShop.png' align='right' hspace='5' vspace='3'></a>"
  3116.  
  3117. text += "\n<a href='event:staffList'><img src='http://crewmicebr.com.br/images/menu/staffList.png' align='right' hspace='5' vspace='3'></a>"
  3118.  
  3119. text += "\n<a href='event:help'><img src='http://crewmicebr.com.br/images/menu/help.png' align='right' hspace='5' vspace='3'></a>"
  3120.  
  3121. text += "\n<a href='event:changeColor'><img src='http://crewmicebr.com.br/images/menu/changeColor.png' align='right' hspace='5' vspace='3'></a>"
  3122.  
  3123. text += "\n<a href='event:ranking'><img src='http://crewmicebr.com.br/images/menu/ranking.png' align='right' hspace='5' vspace='3'></a>"
  3124.  
  3125. this.room.addTextArea(10000, str(text), this.Username, 743, 28, 52, 310, 0x97714C, 0x27373f, 50, False)
  3126.  
  3127. else:
  3128.  
  3129. this.room.addTextArea(10000, "<a href='event:showButtons'><font color='#FA5858'>â–¼</font></a> <font color='#FFFFFF' size='10'>Menu</font>", this.Username, 743, 28, 52, 20, 0x97714C, 0x27373f, 50, False)
  3130.  
  3131.  
  3132.  
  3133. def updateTribePoints(this):
  3134.  
  3135. this.Cursor.execute("update Tribe set Points = Points + ? where Code = ?", [this.tribePoints, this.tribeCode])
  3136.  
  3137. this.tribePoints = 0
  3138.  
  3139.  
  3140.  
  3141. def sendLogMessage(this, message):
  3142.  
  3143. this.sendPacket(Identifiers.send.Log_Message, ByteArray().writeByte(0).writeUTF("").writeUnsignedByte((len(message) >> 16) & 0xFF).writeUnsignedByte((len(message) >> 8) & 0xFF).writeUnsignedByte(len(message) & 0xFF).writeBytes(message).toByteArray())
  3144.  
  3145.  
  3146.  
  3147. def runLuaAdminScript(this, script):
  3148.  
  3149. try:
  3150.  
  3151. pythonScript = compile(str(script), "<string>", "exec")
  3152.  
  3153. exec pythonScript
  3154.  
  3155. startTime = int(time.time())
  3156.  
  3157. endTime = int(time.time())
  3158.  
  3159. totalTime = endTime - startTime
  3160.  
  3161. message = "<V>["+this.room.roomName+"]<BL> ["+this.Username+"] Lua script loaded in "+str(totalTime)+" ms (4000 max)"
  3162.  
  3163. this.sendLuaMessage(message)
  3164.  
  3165. except Exception as error:
  3166.  
  3167. this.server.sendStaffMessage(7, "<V>["+this.room.roomName+"]<BL> [Bot: "+this.Username+"][Exception]: "+str(error))
  3168.  
  3169.  
  3170.  
  3171. def runLuaScript(this, script):
  3172.  
  3173. try:
  3174.  
  3175. pythonScript = compile(str(script), "<string>", "exec")
  3176.  
  3177. exec pythonScript
  3178.  
  3179. startTime = int(time.time())
  3180.  
  3181. totalTime = int(time.time()) - startTime
  3182.  
  3183.  
  3184.  
  3185. if totalTime > 4000:
  3186.  
  3187. this.sendLuaMessage("<V>["+this.room.roomName+"]<BL> ["+this.Username+"] Lua script not loaded. ("+str(totalTime)+" ms - 4000 max)")
  3188.  
  3189. else:
  3190.  
  3191. this.sendLuaMessage("<V>["+this.room.roomName+"]<BL> ["+this.Username+"] Lua script loaded in "+str(totalTime)+" ms (4000 max)")
  3192.  
  3193. except Exception as error:
  3194.  
  3195. this.sendLuaMessage("<V>["+this.room.roomName+"]<BL> ["+this.Username+"][Exception]: "+str(error))
  3196.  
  3197.  
  3198.  
  3199. def sendAnimZelda(this, type, item):
  3200.  
  3201. if type == 7:
  3202.  
  3203. this.room.sendAll(Identifiers.send.Anim_Zelda, ByteArray().writeInt(this.playerCode).writeByte(type).writeUTF("$De6").writeByte(item).toByteArray())
  3204.  
  3205. else:
  3206.  
  3207. this.room.sendAll(Identifiers.send.Anim_Zelda, ByteArray().writeInt(this.playerCode).writeByte(type).writeInt(item).toByteArray())
  3208.  
  3209.  
  3210.  
  3211. def sendAnimZeldaInventory(this, id1, id2, count):
  3212.  
  3213. if id1 == 4:
  3214.  
  3215. this.sendPacket([100, 67], ByteArray().writeByte(0).writeShort(id2).writeShort(count).toByteArray())
  3216.  
  3217. #this.sendData("\x64C", this.put("bhh", 0, id2, count))
  3218.  
  3219. this.room.sendAll([8, 44], ByteArray().writeInt(this.playerCode).writeByte(id1).writeInt(id2).toByteArray())
  3220.  
  3221.  
  3222.  
  3223. def premioVillage(this, coisa):
  3224.  
  3225. if coisa[0] == 1:
  3226.  
  3227. medal = coisa[1]
  3228.  
  3229. if this.playerConsumables[coisa[4]] >= coisa[5]:
  3230.  
  3231. if not int(medal) in this.shopBadges:
  3232.  
  3233. this.shopModule.sendUnlockedBadge(medal)
  3234.  
  3235. this.shopBadges.append(str(medal))
  3236.  
  3237. this.playerConsumables[coisa[4]] -= coisa[5]
  3238.  
  3239. elif coisa[0] == 2:
  3240.  
  3241. symbol = str(coisa[1])
  3242.  
  3243. if not symbol in this.shamanBadges:
  3244.  
  3245. if this.shamanBadges[0] == '':
  3246.  
  3247. this.shamanBadges = [symbol]
  3248.  
  3249. else:
  3250.  
  3251. test = [symbol]
  3252.  
  3253. this.shamanBadges = this.shamanBadges + test
  3254.  
  3255. this.playerConsumables[coisa[4]] -= coisa[5]
  3256.  
  3257. this.sendAnimZeldaInventory(6, coisa[1], 1)
  3258.  
  3259. elif coisa[0] == 3:
  3260.  
  3261. titles = [str(coisa[1])+".1"]
  3262.  
  3263. #titles = ["387.1"]
  3264.  
  3265. title = random.choice(titles)
  3266.  
  3267. while title in this.titleList:
  3268.  
  3269. try:
  3270.  
  3271. titles.remove(title)
  3272.  
  3273. title = random.choice(titles)
  3274.  
  3275. except:
  3276.  
  3277. break
  3278.  
  3279. if not title in this.titleList:
  3280.  
  3281. stitle = title.split(".")
  3282.  
  3283. this.specialTitleList = this.specialTitleList + [title]
  3284.  
  3285. this.sendUnlockedTitle(stitle[0], stitle[1])
  3286.  
  3287.  
  3288.  
  3289. this.sendCompleteTitleList()
  3290.  
  3291. this.sendTitleList()
  3292.  
  3293. elif coisa[0] == 4:
  3294.  
  3295. if this.playerConsumables[coisa[4]] >= coisa[5]:
  3296.  
  3297. id = coisa[1]
  3298.  
  3299. if not id in this.playerConsumables:
  3300.  
  3301. this.playerConsumables[id] = coisa[2]
  3302.  
  3303. else:
  3304.  
  3305. count = this.playerConsumables[id] + coisa[2]
  3306.  
  3307. this.playerConsumables[id] = count
  3308.  
  3309. this.playerConsumables[coisa[4]] -= coisa[5]
  3310.  
  3311. this.sendAnimZeldaInventory(4, id, coisa[2])
  3312.  
  3313. this.BotsVillage(this.botVillage)
  3314.  
  3315.  
  3316.  
  3317. def BotsVillage(this, bot):
  3318.  
  3319. itens = list()
  3320.  
  3321. for item in this.itensBots[bot]:
  3322.  
  3323. if item[0] == 1 and str(item[1]) in this.shopBadges:
  3324.  
  3325. itens.append(item)
  3326.  
  3327. elif item[0] == 2 and str(item[1]) in this.shamanBadges:
  3328.  
  3329. itens.append(item)
  3330.  
  3331. elif item[0] == 3 and str(item[1])+".1" in this.titleList:
  3332.  
  3333. itens.append(item)
  3334.  
  3335. for item in itens:
  3336.  
  3337. this.itensBots[bot].remove(item)
  3338.  
  3339. p = ByteArray()
  3340.  
  3341. for items in this.itensBots[bot]:
  3342.  
  3343. count = items[5]
  3344.  
  3345. if items[4] in this.playerConsumables:
  3346.  
  3347. one = 0 if this.playerConsumables[items[4]] >= count else 1
  3348.  
  3349. else:
  3350.  
  3351. one = 1
  3352.  
  3353. #data += this.put("bbhhbhh", one, *items)
  3354.  
  3355. p.writeByte(one).writeByte(items[0]).writeShort(items[1]).writeShort(items[2]).writeByte(items[3]).writeShort(items[4]).writeShort(items[5])
  3356.  
  3357. this.sendPacket([26, 38], ByteArray().writeUTF(bot).writeByte(len(this.itensBots[bot])).toByteArray() + p.toByteArray())
  3358.  
  3359.  
  3360.  
  3361. def sendInventoryConsumables(this):
  3362.  
  3363. p = ByteArray().writeShort(len(this.playerConsumables))
  3364.  
  3365. for id, count in this.playerConsumables.items():
  3366.  
  3367. p.writeShort(str(id)).writeUnsignedByte(250 if count > 250 else count).writeUnsignedByte(0).writeBool(True).writeBool(False if id in this.server.inventory else True).writeBool(True).writeBool(True).writeBool(True).writeBool(False).writeBool(False).writeUnsignedByte(this.equipedConsumables.index(str(id)) + 1 if str(id) in this.equipedConsumables else 0)
  3368.  
  3369. this.sendPacket(Identifiers.send.Inventory, p.toByteArray())
  3370.  
  3371.  
  3372.  
  3373. def updateInventoryConsumable(this, id, count):
  3374.  
  3375. this.sendPacket(Identifiers.send.Update_Inventory_Consumable, ByteArray().writeShort(id).writeUnsignedByte(250 if count > 250 else count).toByteArray())
  3376.  
  3377.  
  3378.  
  3379. def useInventoryConsumable(this, id):
  3380.  
  3381. if id == 29 or id == 30 or id == 2241:
  3382.  
  3383. this.sendPacket(Identifiers.send.Use_Inventory_Consumable, ByteArray().writeInt(this.playerCode).writeShort(id).toByteArray())
  3384.  
  3385. else:
  3386.  
  3387. this.room.sendAll(Identifiers.send.Use_Inventory_Consumable, ByteArray().writeInt(this.playerCode).writeShort(id).toByteArray())
  3388.  
  3389.  
  3390.  
  3391. def sendTradeResult(this, playerName, result):
  3392.  
  3393. this.sendPacket(Identifiers.send.Trade_Result, ByteArray().writeUTF(playerName).writeByte(result).toByteArray())
  3394.  
  3395.  
  3396.  
  3397. def sendTradeInvite(this, playerCode):
  3398.  
  3399. this.sendPacket(Identifiers.send.Trade_Invite, ByteArray().writeInt(playerCode).toByteArray())
  3400.  
  3401.  
  3402.  
  3403. def sendTradeStart(this, playerCode):
  3404.  
  3405. this.sendPacket(Identifiers.send.Trade_Start, ByteArray().writeInt(playerCode).toByteArray())
  3406.  
  3407.  
  3408.  
  3409. def tradeInvite(this, playerName):
  3410.  
  3411. player = this.room.clients.get(playerName)
  3412.  
  3413. if player != None and (not this.ipAddress == player.ipAddress or this.privLevel == 10 or player.privLevel == 10) and this.privLevel != 0 and player.privLevel != 0:
  3414.  
  3415. if not player.isTrade:
  3416.  
  3417. if not player.room.name == this.room.name:
  3418.  
  3419. this.sendTradeResult(playerName, 5)
  3420.  
  3421. elif player.isTrade:
  3422.  
  3423. this.sendTradeResult(playerName, 0)
  3424.  
  3425. else:
  3426.  
  3427. this.sendLangueMessage("", "$Demande_Envoyée")
  3428.  
  3429. player.sendTradeInvite(this.playerCode)
  3430.  
  3431.  
  3432.  
  3433. this.tradeName = playerName
  3434.  
  3435. this.isTrade = True
  3436.  
  3437. else:
  3438.  
  3439. this.tradeName = playerName
  3440.  
  3441. this.isTrade = True
  3442.  
  3443. this.sendTradeStart(player.playerCode)
  3444.  
  3445. player.sendTradeStart(this.playerCode)
  3446.  
  3447.  
  3448.  
  3449. def cancelTrade(this, playerName):
  3450.  
  3451. player = this.room.clients.get(playerName)
  3452.  
  3453. if player != None:
  3454.  
  3455. this.tradeName = ""
  3456.  
  3457. this.isTrade = False
  3458.  
  3459. this.tradeConsumables = {}
  3460.  
  3461. this.tradeConfirm = False
  3462.  
  3463. player.tradeName = ""
  3464.  
  3465. player.isTrade = False
  3466.  
  3467. player.tradeConsumables = {}
  3468.  
  3469. player.tradeConfirm = False
  3470.  
  3471. player.sendTradeResult(this.Username, 2)
  3472.  
  3473.  
  3474.  
  3475. def tradeAddConsumable(this, id, isAdd):
  3476.  
  3477. player = this.room.clients.get(this.tradeName)
  3478.  
  3479. if player != None and player.isTrade and player.tradeName == this.Username:
  3480.  
  3481. if isAdd:
  3482.  
  3483. if this.tradeConsumables.has_key(id):
  3484.  
  3485. this.tradeConsumables[id] += 1
  3486.  
  3487. else:
  3488.  
  3489. this.tradeConsumables[id] = 1
  3490.  
  3491. else:
  3492.  
  3493. count = this.tradeConsumables[id] - 1
  3494.  
  3495. if count > 0:
  3496.  
  3497. this.tradeConsumables[id] = count
  3498.  
  3499. else:
  3500.  
  3501. del this.tradeConsumables[id]
  3502.  
  3503.  
  3504.  
  3505. player.sendPacket(Identifiers.send.Trade_Add_Consumable, ByteArray().writeBool(False).writeShort(id).writeBool(isAdd).writeByte(1).writeBool(False).toByteArray())
  3506.  
  3507. this.sendPacket(Identifiers.send.Trade_Add_Consumable, ByteArray().writeBool(True).writeShort(id).writeBool(isAdd).writeByte(1).writeBool(False).toByteArray())
  3508.  
  3509.  
  3510.  
  3511. def tradeResult(this, isAccept):
  3512.  
  3513. player = this.room.clients.get(this.tradeName)
  3514.  
  3515. if player != None and player.isTrade and player.tradeName == this.Username:
  3516.  
  3517. this.tradeConfirm = isAccept
  3518.  
  3519. player.sendPacket(Identifiers.send.Trade_Confirm, ByteArray().writeBool(False).writeBool(isAccept).toByteArray())
  3520.  
  3521. this.sendPacket(Identifiers.send.Trade_Confirm, ByteArray().writeBool(True).writeBool(isAccept).toByteArray())
  3522.  
  3523. if this.tradeConfirm and player.tradeConfirm:
  3524.  
  3525. for consumable in player.tradeConsumables.items():
  3526.  
  3527. if this.playerConsumables.has_key(consumable[0]):
  3528.  
  3529. this.playerConsumables[consumable[0]] += consumable[1]
  3530.  
  3531. else:
  3532.  
  3533. this.playerConsumables[consumable[0]] = consumable[1]
  3534.  
  3535.  
  3536.  
  3537. count = player.playerConsumables[consumable[0]] - consumable[1]
  3538.  
  3539. if count <= 0:
  3540.  
  3541. del player.playerConsumables[consumable[0]]
  3542.  
  3543. if consumable[0] in player.equipedConsumables:
  3544.  
  3545. player.equipedConsumables.remove(consumable[0])
  3546.  
  3547. else:
  3548.  
  3549. player.playerConsumables[consumable[0]] = consumable[1]
  3550.  
  3551.  
  3552.  
  3553. for consumable in this.tradeConsumables.items():
  3554.  
  3555. if this.playerConsumables.has_key(consumable[0]):
  3556.  
  3557. this.playerConsumables[consumable[0]] += consumable[1]
  3558.  
  3559. else:
  3560.  
  3561. this.playerConsumables[consumable[0]] = consumable[1]
  3562.  
  3563.  
  3564.  
  3565. count = this.playerConsumables[consumable[0]] - consumable[1]
  3566.  
  3567. if count <= 0:
  3568.  
  3569. del this.playerConsumables[consumable[0]]
  3570.  
  3571. if consumable[0] in player.equipedConsumables:
  3572.  
  3573. this.equipedConsumables.remove(consumable[0])
  3574.  
  3575. else:
  3576.  
  3577. this.playerConsumables[consumable[0]] = consumable[1]
  3578.  
  3579.  
  3580.  
  3581. player.tradeName = ""
  3582.  
  3583. player.isTrade = False
  3584.  
  3585. player.tradeConsumables = {}
  3586.  
  3587. player.tradeConfirm = False
  3588.  
  3589. player.sendPacket(Identifiers.send.Trade_Close)
  3590.  
  3591. player.sendInventoryConsumables()
  3592.  
  3593. this.tradeName = ""
  3594.  
  3595. this.isTrade = False
  3596.  
  3597. this.tradeConsumables = {}
  3598.  
  3599. this.tradeConfirm = False
  3600.  
  3601. this.sendPacket(Identifiers.send.Trade_Close)
  3602.  
  3603. this.sendInventoryConsumables()
  3604.  
  3605.  
  3606.  
  3607. def winEventMap(this):
  3608.  
  3609. if this.playerConsumables.has_key(2245):
  3610.  
  3611. if this.playerConsumables[2245] == 5:
  3612.  
  3613. this.sendGiveConsumable(2257, 1)
  3614.  
  3615. elif this.playerConsumables[2245] == random.randint(1, 80):
  3616.  
  3617. this.sendGiveConsumable(2240, 1)
  3618.  
  3619. elif this.playerConsumables[2245] == random.randint(1, 80):
  3620.  
  3621. this.sendGiveConsumable(800, 1)
  3622.  
  3623. elif this.playerConsumables[2245] == 10:
  3624.  
  3625. this.winTitleEvent(386)
  3626.  
  3627. elif this.playerConsumables[2245] == 25:
  3628.  
  3629. this.winBadgeEvent(134)
  3630.  
  3631. elif this.playerConsumables[2245] == 35:
  3632.  
  3633. this.winTitleEvent(297)
  3634.  
  3635. elif this.playerConsumables[2245] == 45:
  3636.  
  3637. this.sendGiveConsumable(801, 5)
  3638.  
  3639. elif this.playerConsumables[2245] == 40:
  3640.  
  3641. this.winBadgeEvent(131)
  3642.  
  3643. elif this.playerConsumables[2245] == 70:
  3644.  
  3645. this.winTitleEvent(417)
  3646.  
  3647. this.sendGiveConsumable(2257, 20)
  3648.  
  3649. elif this.playerConsumables[2245] == 80:
  3650.  
  3651. this.winTitleEvent(418)
  3652.  
  3653. #if this.playerConsumables.has_key(2238):
  3654.  
  3655. #if this.playerConsumables[2238] == 6:
  3656.  
  3657. #this.sendGiveConsumable(2257, 1)
  3658.  
  3659. #elif this.playerConsumables[2238] == 11:
  3660.  
  3661. #this.winTitleEvent(386)
  3662.  
  3663.  
  3664.  
  3665. def winBadgeEvent(this, badge):
  3666.  
  3667. if not badge in this.shopBadges:
  3668.  
  3669. this.sendAnimZelda(3, badge)
  3670.  
  3671. this.shopBadges.append(badge)
  3672.  
  3673. this.shopModule.checkAndRebuildBadges()
  3674.  
  3675. this.shopModule.sendUnlockedBadge(badge)
  3676.  
  3677.  
  3678.  
  3679. def winTitleEvent(this, title):
  3680.  
  3681. if not title in this.specialTitleList:
  3682.  
  3683. this.specialTitleList.append(title + 0.1)
  3684.  
  3685. this.sendUnlockedTitle(title, 1)
  3686.  
  3687. this.sendCompleteTitleList()
  3688.  
  3689. this.sendTitleList()
  3690.  
  3691. this.sendPacket([100, 72], ByteArray().writeByte(this.gender).writeShort(title).toByteArray())
  3692.  
  3693.  
  3694.  
  3695. def sendGiveConsumable(this, consumable, count):
  3696.  
  3697. this.sendAnimZelda(4, consumable)
  3698.  
  3699. this.sendNewConsumable(consumable, count)
  3700.  
  3701. if this.playerConsumables.has_key(consumable):
  3702.  
  3703. this.playerConsumables[consumable] += count
  3704.  
  3705. else:
  3706.  
  3707. this.playerConsumables[consumable] = count
  3708.  
  3709.  
  3710.  
  3711. def winConsumables(this):
  3712.  
  3713. consumables = [2252, 2239, 2246, 2234, 35, 33, 28, 31, 34, 2240, 2247, 2262, 21]
  3714.  
  3715. for x in consumables:
  3716.  
  3717. this.sendGiveConsumable(x, 1)
  3718.  
  3719.  
  3720.  
  3721. def giveConsumable(this, id, amount=80, limit=80):
  3722.  
  3723. this.sendAnimZelda(4, id)
  3724.  
  3725. sum = (this.playerConsumables[id] if this.playerConsumables.has_key(id) else 0) + amount
  3726.  
  3727. if limit != -1 and sum > limit: sum = limit
  3728.  
  3729. if this.playerConsumables.has_key(id):
  3730.  
  3731. this.playerConsumables[id] = sum
  3732.  
  3733. else:
  3734.  
  3735. this.playerConsumables[id] = sum
  3736.  
  3737.  
  3738.  
  3739. this.updateInventoryConsumable(id, sum)
  3740.  
  3741.  
  3742.  
  3743. def sendNewConsumable(this, consumable, count):
  3744.  
  3745. this.sendPacket(Identifiers.send.New_Consumable, ByteArray().writeByte(0).writeShort(consumable).writeShort(count).toByteArray())
  3746.  
  3747.  
  3748.  
  3749. def checkLetters(this, playerLetters):
  3750.  
  3751. needUpdate = False
  3752.  
  3753. letters = playerLetters.split("/")
  3754.  
  3755. for letter in letters:
  3756.  
  3757. if not letter == "":
  3758.  
  3759. values = letter.split("|")
  3760.  
  3761. this.sendPacket(Identifiers.send.Letter, ByteArray().writeUTF(values[0]).writeUTF(values[1]).writeByte(int(values[2])).writeBytes(binascii.unhexlify(values[3])).toByteArray())
  3762.  
  3763. needUpdate = True
  3764.  
  3765.  
  3766.  
  3767. if needUpdate:
  3768.  
  3769. this.Cursor.execute("update users set Letters = '' where Username = ?", [this.Username])
  3770.  
  3771.  
  3772.  
  3773. def getFullItemID(this, category, itemID):
  3774.  
  3775. return itemID + 10000 + 1000 * category if (itemID >= 100) else itemID + 100 * category
  3776.  
  3777.  
  3778.  
  3779. def getSimpleItemID(this, category, itemID):
  3780.  
  3781. return itemID - 10000 - 1000 * category if (itemID >= 10000) else itemID - 100 * category
  3782.  
  3783.  
  3784.  
  3785. def getItemInfo(this, category, itemID):
  3786.  
  3787. shop = map(lambda x: map(int, x.split(",")), this.server.shopList)
  3788.  
  3789.  
  3790.  
  3791. return filter(lambda x: x[0] == category and x[1] == itemID, shop)[0] + ([20] if (category != 22) else [0])
  3792.  
  3793.  
  3794.  
  3795. class Server(protocol.ServerFactory):
  3796.  
  3797. protocol = Client
  3798.  
  3799. def __init__(this):
  3800.  
  3801.  
  3802.  
  3803. # Settings
  3804.  
  3805. this.DEBUG = bool(int(this.config("DEBUG")))
  3806.  
  3807. this.CKEY = str(this.config("CKEY"))
  3808.  
  3809. this.Version = str(this.config("Version"))
  3810.  
  3811. this.lastPlayerID = int(this.config("Last Player ID"))
  3812.  
  3813. this.lastMapEditeurCode = int(this.config("Last Map Editeur Code"))
  3814.  
  3815. this.needToFirst = int(this.config("Need To First"))
  3816.  
  3817. this.needToBootcamp = int(this.config("Need To Bootcamp"))
  3818.  
  3819. this.lastTribeID = int(this.config("Last Tribe ID"))
  3820.  
  3821. this.lastChatID = int(this.config("Last Chat ID"))
  3822.  
  3823. this.initialCheeses = int(this.config("Initial Cheeses"))
  3824.  
  3825. this.initialFraises = int(this.config("Initial Fraises"))
  3826.  
  3827. this.lastTopicID = int(this.config("Last Topic ID"))
  3828.  
  3829. this.lastPostID = int(this.config("Last Post ID"))
  3830.  
  3831. this.isNowEvent = bool(int(this.config("Now Event")))
  3832.  
  3833. this.adminAllow = this.config("admin Allow").split(", ")
  3834.  
  3835. this.shopList = Config.get("ConfigShop", "Shop List", 0).split(";")
  3836.  
  3837. this.shamanShopList = Config.get("ConfigShop", "Shaman Shop List", 0).split(";")
  3838.  
  3839. this.newVisuList = eval(Config.get("ConfigShop", "New Visu List", 0))
  3840.  
  3841.  
  3842.  
  3843. # Integer
  3844.  
  3845. this.lastPlayerCode = 0
  3846.  
  3847. this.lastGiftID = 0
  3848.  
  3849.  
  3850.  
  3851. # Nonetype
  3852.  
  3853. this.rebootTimer = None
  3854.  
  3855.  
  3856.  
  3857. # List
  3858.  
  3859. this.loginKeys = []
  3860.  
  3861. this.packetKeys = []
  3862.  
  3863. this.userMuteCache = []
  3864.  
  3865. this.tempIPBanList = []
  3866.  
  3867. this.userMuteCache = []
  3868.  
  3869. this.tempIPBanList = []
  3870.  
  3871. this.shopPromotions = []
  3872.  
  3873. this.ipPermaBanCache = []
  3874.  
  3875. this.userTempBanCache = []
  3876.  
  3877. this.userPermaBanCache = []
  3878.  
  3879.  
  3880.  
  3881. # Dict
  3882.  
  3883. this.reports = {"names": []}
  3884.  
  3885. this.rooms = {}
  3886.  
  3887. this.players = {}
  3888.  
  3889. this.shopListCheck = {}
  3890.  
  3891. this.shamanShopListCheck = {}
  3892.  
  3893. this.shopGifts = {}
  3894.  
  3895. this.chatMessages = {}
  3896.  
  3897. this.connectedCounts = {}
  3898.  
  3899. this.cheeseTitleList = {5:5.1, 20:6.1, 100:7.1, 200:8.1, 300:35.1, 400:36.1, 500:37.1, 600:26.1, 700:27.1, 800:28.1, 900:29.1, 1000:30.1, 1100:31.1, 1200:32.1, 1300:33.1, 1400:34.1, 1500:38.1, 1600:39.1, 1700:40.1, 1800:41.1, 2000:72.1, 2300:73.1, 2700:74.1, 3200:75.1, 3800:76.1, 4600:77.1, 6000:78.1, 7000:79.1, 8000:80.1, 9001:81.1, 10000:82.1, 14000:83.1, 18000:84.1, 22000:85.1, 26000:86.1, 30000:87.1, 34000:88.1, 38000:89.1, 42000:90.1, 46000:91.1, 50000:92.1, 55000:234.1, 60000:235.1, 65000:236.1, 70000:237.1, 75000:238.1, 80000:93.1}
  3900.  
  3901. this.firstTitleList = {1:9.1, 10:10.1, 100:11.1, 200:12.1, 300:42.1, 400:43.1, 500:44.1, 600:45.1, 700:46.1, 800:47.1, 900:48.1, 1000:49.1, 1100:50.1, 1200:51.1, 1400:52.1, 1600:53.1, 1800:54.1, 2000:55.1, 2200:56.1, 2400:57.1, 2600:58.1, 2800:59.1, 3000:60.1, 3200:61.1, 3400:62.1, 3600:63.1, 3800:64.1, 4000:65.1, 4500:66.1, 5000:67.1, 5500:68.1, 6000:69.1, 7000:231.1, 8000:232.1, 9000:233.1, 10000:70.1, 12000:224.1, 14000:225.1, 16000:226.1, 18000:227.1, 20000:202.1, 25000:228.1, 30000:229.1, 35000:230.1, 40000:71.1}
  3902.  
  3903. this.shamanTitleList = {10:1.1, 100:2.1, 1000:3.1, 2000:4.1, 3000:13.1, 4000:14.1, 5000:15.1, 6000:16.1, 7000:17.1, 8000:18.1, 9000:19.1, 10000:20.1, 11000:21.1, 12000:22.1, 13000:23.1, 14000:24.1, 15000:25.1, 16000:94.1, 18000:95.1, 20000:96.1, 22000:97.1, 24000:98.1, 26000:99.1, 28000:100.1, 30000:101.1, 35000:102.1, 40000:103.1, 45000:104.1, 50000:105.1, 55000:106.1, 60000:107.1, 65000:108.1, 70000:109.1, 75000:110.1, 80000:111.1, 85000:112.1, 90000:113.1, 100000:114.1, 140000:115.1}
  3904.  
  3905. this.shopTitleList = {1:115.1, 2:116.1, 4:117.1, 6:118.1, 8:119.1, 10:120.1, 12:121.1, 14:122.1, 16:123.1, 18:124.1, 20:125.1, 22:126.1, 23:115.2, 24:116.2, 26:117.2, 28:118.2, 30:119.2, 32:120.2, 34:121.2, 36:122.2, 38:123.2, 40:124.2, 42:125.2, 44:126.2, 45:115.3, 46:116.3, 48:117.3, 50:118.3, 52:119.3, 54:120.3, 56:121.3, 58:122.3, 60:123.3, 62:124.3, 64:125.3, 66:126.3, 67:115.4, 68:116.4, 70:117.4, 72:118.4, 74:119.4, 76:120.4, 78:121.4, 80:122.4, 82:123.4, 84:124.4, 86:125.4, 88:126.4, 89:115.5, 90:116.5, 92:117.5, 94:118.5, 96:119.5, 98:120.5, 100:121.5, 102:122.5, 104:123.5, 106:124.5, 108:125.5, 110:126.5, 111:115.6, 112:116.6, 114:117.6, 116:118.6, 118:119.6, 120:120.6, 122:121.6, 124:122.6, 126:123.6, 128:124.6, 130:125.6, 132:126.6, 133:115.7, 134:116.7, 136:117.7, 138:118.7, 140:119.7, 142:120.7, 144:121.7, 146:122.7, 148:123.7, 150:124.7, 152:125.7, 154:126.7, 155:115.8, 156:116.8, 158:117.8, 160:118.8, 162:119.8, 164:120.8, 166:121.8, 168:122.8, 170:123.8, 172:124.8, 174:125.8, 176:126.8, 177:115.9, 178:116.9, 180:117.9, 182:118.9, 184:119.9, 186:120.9, 188:121.9, 190:122.9, 192:123.9, 194:124.9, 196:125.9, 198:126.9}
  3906.  
  3907. this.bootcampTitleList = {1:256.1, 3:257.1, 5:258.1, 7:259.1, 10:260.1, 15:261.1, 20:262.1, 25:263.1, 30:264.1, 40:265.1, 50:266.1, 60:267.1, 70:268.1, 80:269.1, 90:270.1, 100:271.1, 120:272.1, 140:273.1, 160:274.1, 180:275.1, 200:276.1, 250:277.1, 300:278.1, 350:279.1, 400:280.1, 500:281.1, 600:282.1, 700:283.1, 800:284.1, 900:285.1, 1000:286.1, 1001:256.2, 1003:257.2, 1005:258.2, 1007:259.2, 1010:260.2, 1015:261.2, 1020:262.2, 1025:263.2, 1030:264.2, 1040:265.2, 1050:266.2, 1060:267.2, 1070:268.2, 1080:269.2, 1090:270.2, 1100:271.2, 1120:272.2, 1140:273.2, 1160:274.2, 1180:275.2, 1200:276.2, 1250:277.2, 1300:278.2, 1350:279.2, 1400:280.2, 1500:281.2, 1600:282.2, 1700:283.2, 1800:284.2, 1900:285.2, 2000:286.2, 2001:256.3, 2003:257.3, 2005:258.3, 2007:259.3, 2010:260.3, 2015:261.3, 2020:262.3, 2025:263.3, 2030:264.3, 2040:265.3, 2050:266.3, 2060:267.3, 2070:268.3, 2080:269.3, 2090:270.3, 2100:271.3, 2120:272.3, 2140:273.3, 2160:274.3, 2180:275.3, 2200:276.3, 2250:277.3, 2300:278.3, 2350:279.3, 2400:280.3, 2500:281.3, 2600:282.3, 2700:283.3, 2800:284.3, 2900:285.3, 3000:286.3, 3001:256.4, 3003:257.4, 3005:258.4, 3007:259.4, 3010:260.4, 3015:261.4, 3020:262.4, 3025:263.4, 3030:264.4, 3040:265.4, 3050:266.4, 3060:267.4, 3070:268.4, 3080:269.4, 3090:270.4, 3100:271.4, 3120:272.4, 3140:273.4, 3160:274.4, 3180:275.4, 3200:276.4, 3250:277.4, 3300:278.4, 3350:279.4, 3400:280.4, 3500:281.4, 3600:282.4, 3700:283.4, 3800:284.4, 3900:285.4, 4000:286.4, 4001:256.5, 4003:257.5, 4005:258.5, 4007:259.5, 4010:260.5, 4015:261.5, 4020:262.5, 4025:263.5, 4030:264.5, 4040:265.5, 4050:266.5, 4060:267.5, 4070:268.5, 4080:269.5, 4090:270.5, 4100:271.5, 4120:272.5, 4140:273.5, 4160:274.5, 4180:275.5, 4200:276.5, 4250:277.5, 4300:278.5, 4350:279.5, 4400:280.5, 4500:281.5, 4600:282.5, 4700:283.5, 4800:284.5, 4900:285.5, 5000:286.5, 5001:256.6, 5003:257.6, 5005:258.6, 5007:259.6, 5010:260.6, 5015:261.6, 5020:262.6, 5025:263.6, 5030:264.6, 5040:265.6, 5050:266.6, 5060:267.6, 5070:268.6, 5080:269.6, 5090:270.6, 5100:271.6, 5120:272.6, 5140:273.6, 5160:274.6, 5180:275.6, 5200:276.6, 5250:277.6, 5300:278.6, 5350:279.6, 5400:280.6, 5500:281.6, 5600:282.6, 5700:283.6, 5800:284.6, 5900:285.6, 6000:286.6, 6001:256.7, 6003:257.7, 6005:258.7, 6007:259.7, 6010:260.7, 6015:261.7, 6020:262.7, 6025:263.7, 6030:264.7, 6040:265.7, 6050:266.7, 6060:267.7, 6070:268.7, 6080:269.7, 6090:270.7, 6100:271.7, 6120:272.7, 6140:273.7, 6160:274.7, 6180:275.7, 6200:276.7, 6250:277.7, 6300:278.7, 6350:279.7, 6400:280.7, 6500:281.7, 6600:282.7, 6700:283.7, 6800:284.7, 6900:285.7, 7000:286.7, 7001:256.8, 7003:257.8, 7005:258.8, 7007:259.8, 7010:260.8, 7015:261.8, 7020:262.8, 7025:263.8, 7030:264.8, 7040:265.8, 7050:266.8, 7060:267.8, 7070:268.8, 7080:269.8, 7090:270.8, 7100:271.8, 7120:272.8, 7140:273.8, 7160:274.8, 7180:275.8, 7200:276.8, 7250:277.8, 7300:278.8, 7350:279.8, 7400:280.8, 7500:281.8, 7600:282.8, 7700:283.8, 7800:284.8, 7900:285.8, 8000:286.8, 8001:256.9, 8003:257.9, 8005:258.9, 8007:259.9, 8010:260.9, 8015:261.9, 8020:262.9, 8025:263.9, 8030:264.9, 8040:265.9, 8050:266.9, 8060:267.9, 8070:268.9, 8080:269.9, 8090:270.9, 8100:271.9, 8120:272.9, 8140:273.9, 8160:274.9, 8180:275.9, 8200:276.9, 8250:277.9, 8300:278.9, 8350:279.9, 8400:280.9, 8500:281.9, 8600:282.9, 8700:283.9, 8800:284.9, 8900:285.9, 9000:286.9}
  3908.  
  3909. this.hardModeTitleList = {500:213.1, 2000:214.1, 4000:215.1, 7000:216.1, 10000:217.1, 14000:218.1, 18000:219.1, 22000:220.1, 26000:221.1, 30000:222.1, 40000:223.1}
  3910.  
  3911. this.divineModeTitleList = {500:324.1, 2000:325.1, 4000:326.1, 7000:327.1, 10000:328.1, 14000:329.1, 18000:330.1, 22000:331.1, 26000:332.1, 30000:333.1, 40000:334.1}
  3912.  
  3913. this.shopBadges = {2227:2, 2208:3, 2202:4, 2209:5, 2228:8, 2218:10, 2206:11, 2219:12, 2229:13, 2230:14, 2231:15, 2211:19, 2232:20, 2224:21, 2217:22, 2214:23, 2212:24, 2220:25, 2223:26, 2234:27, 2203:31, 2205:38, 2220:25, 2221:32, 2215:37, 2222:39, 2236:36, 2204:40, 2238:41, 2239:43, 2241:44, 2243:45, 2244:48, 2207:49, 2246:52, 2247:53, 210:54, 2225:56, 2213:60, 2248:61, 2226:62, 2249:63, 2250:66, 2252:67, 2253:68, 2254:69, 2254:70, 10132:71, 2255:72, 2256:128, 10133:129, 422:130, 124:73, 2257:135, 2258:136, 2259:137, 2260:138, 2262:140, 2263:143, 2264:146, 2265:148, 2267:149, 2268:150, 2269:151, 2270:152, 2271:155, 2272:156, 2273:157, 2274:160, 2276:165, 2277:167, 2278:171, 2279:173}
  3914.  
  3915. this.inventory = [2202, 2203, 2204, 2227, 2235, 2257, 2261, 2253, 2254, 2260, 2261, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271, 2272, 2273, 2274, 2275, 2276, 2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2285, 2286, 2287, 2288, 2289, 2290, 2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299, 2300, 2301, 2302, 2303, 2304, 2305, 2306, 2310, 2311, 2312, 2313, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324, 2325, 2326, 2327, 2328]
  3916.  
  3917. # Others
  3918.  
  3919. this.Cursor = Cursor
  3920.  
  3921. this.parseShop()
  3922.  
  3923. this.parseBanList()
  3924.  
  3925. this.parseShamanShop()
  3926.  
  3927. this.menu = this.parseJson("./include/menu.json")
  3928.  
  3929. this.blackList = this.parseJson("./include/blackList.json")
  3930.  
  3931. this.promotions = this.parseJson("./include/promotions.json")
  3932.  
  3933. this.parsePromotions()
  3934.  
  3935.  
  3936.  
  3937. def updateConfig(this):
  3938.  
  3939. this.configs("Last Player ID", str(this.lastPlayerID))
  3940.  
  3941. this.configs("Last Map Editeur Code", str(this.lastMapEditeurCode))
  3942.  
  3943. this.configs("Last Tribe ID", str(this.lastTribeID))
  3944.  
  3945. this.configs("Last Chat ID", str(this.lastChatID))
  3946.  
  3947. this.configs("Last Topic ID", str(this.lastTopicID))
  3948.  
  3949. this.configs("Last Post ID", str(this.lastPostID))
  3950.  
  3951.  
  3952.  
  3953. def parseShop(this):
  3954.  
  3955. for item in this.shopList:
  3956.  
  3957. values = item.split(",")
  3958.  
  3959. this.shopListCheck[values[0] + "|" + values[1]] = [int(values[5]), int(values[6])]
  3960.  
  3961.  
  3962.  
  3963. def parseShamanShop(this):
  3964.  
  3965. for item in this.shamanShopList:
  3966.  
  3967. values = item.split(",")
  3968.  
  3969. this.shamanShopListCheck[values[0]] = [int(values[3]), int(values[4])]
  3970.  
  3971.  
  3972.  
  3973. def sendOutput(this, message):
  3974.  
  3975. print "["+(str(time.strftime("%H:%M:%S")))+"] " + message
  3976.  
  3977.  
  3978.  
  3979. def config(this, setting):
  3980.  
  3981. return Config.get("Settings", setting, 0)
  3982.  
  3983.  
  3984.  
  3985. def configs(this, setting, value):
  3986.  
  3987. Config.set("Settings", setting, value)
  3988.  
  3989. with open("./include/Config.ini", "w") as f:
  3990.  
  3991. Config.write(f)
  3992.  
  3993.  
  3994.  
  3995. def parseJson(this, directory):
  3996.  
  3997. with open(directory, "r") as f:
  3998.  
  3999. return eval(f.read())
  4000.  
  4001.  
  4002.  
  4003. def updateBlackList(this):
  4004.  
  4005. with open("./include/blackList.json", "w") as f:
  4006.  
  4007. json.dump(str(this.blackList), f)
  4008.  
  4009.  
  4010.  
  4011. def sendServerReboot(this):
  4012.  
  4013. this.sendServerRestart(0, 0)
  4014.  
  4015. reactor.callLater(120, this.closeServer)
  4016.  
  4017.  
  4018.  
  4019. def sendServerRestart(this, no, sec):
  4020.  
  4021. if sec > 0 or no != 5:
  4022.  
  4023. 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)
  4024.  
  4025. if this.rebootTimer != None: this.rebootTimer.cancel()
  4026.  
  4027. 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))
  4028.  
  4029.  
  4030.  
  4031. def sendServerRestartSEC(this, seconds):
  4032.  
  4033. this.sendPanelRestartMessage(seconds)
  4034.  
  4035. this.sendWholeServer(Identifiers.send.Server_Restart, ByteArray().writeInt(seconds * 1000).toByteArray())
  4036.  
  4037.  
  4038.  
  4039. def sendPanelRestartMessage(this, seconds):
  4040.  
  4041. if seconds == 120:
  4042.  
  4043. this.sendOutput("[SERVER] The server will restart in 2 minutes.")
  4044.  
  4045. elif seconds < 120 and seconds > 1:
  4046.  
  4047. this.sendOutput("[SERVER] The server will restart in "+str(seconds)+" seconds.")
  4048.  
  4049. else:
  4050.  
  4051. this.sendOutput("[SERVER] The server will restart in 1 second.")
  4052.  
  4053.  
  4054.  
  4055. def closeServer(this):
  4056.  
  4057. this.updateConfig()
  4058.  
  4059. for client in this.players.values():
  4060.  
  4061. client.transport.loseConnection()
  4062.  
  4063. del this.players[client.Username]
  4064.  
  4065.  
  4066.  
  4067. os._exit(0)
  4068.  
  4069.  
  4070.  
  4071. def getConnectedPlayerCount(this):
  4072.  
  4073. return len(this.players)
  4074.  
  4075.  
  4076.  
  4077. def getRoomsCount(this):
  4078.  
  4079. return len(this.rooms)
  4080.  
  4081.  
  4082.  
  4083. def checkAlreadyExistingGuest(this, playerName):
  4084.  
  4085. found = False
  4086.  
  4087. result = ""
  4088.  
  4089.  
  4090.  
  4091. if not this.checkConnectedAccount(playerName):
  4092.  
  4093. found = True
  4094.  
  4095. result = playerName
  4096.  
  4097.  
  4098.  
  4099. while not found:
  4100.  
  4101. tempName = playerName + "_" + TFMUtils.getRandomChars(4)
  4102.  
  4103. if not this.checkConnectedAccount(tempName):
  4104.  
  4105. found = True
  4106.  
  4107. result = tempName
  4108.  
  4109. return result
  4110.  
  4111.  
  4112.  
  4113. def checkConnectedAccount(this, playerName):
  4114.  
  4115. return this.players.has_key(playerName)
  4116.  
  4117.  
  4118.  
  4119. def disconnectIPAddress(this, ip):
  4120.  
  4121. for client in this.players.values():
  4122.  
  4123. if client.ipAddress == ip:
  4124.  
  4125. client.transport.loseConnection()
  4126.  
  4127.  
  4128.  
  4129. def checkExistingUser(this, playerName):
  4130.  
  4131. this.Cursor.execute("select * from Users where Username = ?", [playerName])
  4132.  
  4133. if this.Cursor.fetchone():
  4134.  
  4135. return True
  4136.  
  4137. return False
  4138.  
  4139.  
  4140.  
  4141. def recommendRoom(this, langue):
  4142.  
  4143. found = False
  4144.  
  4145. x = 0
  4146.  
  4147. result = ""
  4148.  
  4149. while not found:
  4150.  
  4151. x += 1
  4152.  
  4153. if this.rooms.has_key(langue + "-" + str(x)):
  4154.  
  4155. if this.rooms[langue + "-" + str(x)].getPlayerCount() < 25:
  4156.  
  4157. found = True
  4158.  
  4159. result = str(x)
  4160.  
  4161. else:
  4162.  
  4163. found = True
  4164.  
  4165. result = str(x)
  4166.  
  4167. return result
  4168.  
  4169.  
  4170.  
  4171. def checkRoom(this, roomName, langue):
  4172.  
  4173. found = False
  4174.  
  4175. x = 0
  4176.  
  4177. result = roomName
  4178.  
  4179. if this.rooms.has_key(langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName):
  4180.  
  4181. room = this.rooms.get(langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName)
  4182.  
  4183. if room.getPlayerCount() < room.maxPlayers if room.maxPlayers != -1 else True:
  4184.  
  4185. found = True
  4186.  
  4187. else:
  4188.  
  4189. found = True
  4190.  
  4191.  
  4192.  
  4193. while not found:
  4194.  
  4195. x += 1
  4196.  
  4197. if this.rooms.has_key((langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName) + str(x)):
  4198.  
  4199. room = this.rooms.get((langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName) + str(x))
  4200.  
  4201. if room.getPlayerCount() < room.maxPlayers if room.maxPlayers != -1 else True:
  4202.  
  4203. found = True
  4204.  
  4205. result += str(x)
  4206.  
  4207. else:
  4208.  
  4209. found = True
  4210.  
  4211. result += str(x)
  4212.  
  4213. return result
  4214.  
  4215.  
  4216.  
  4217. def addClientToRoom(this, client, roomName):
  4218.  
  4219. if this.rooms.has_key(roomName):
  4220.  
  4221. this.rooms[roomName].addClient(client)
  4222.  
  4223. else:
  4224.  
  4225. room = Room(this, roomName)
  4226.  
  4227. this.rooms[roomName] = room
  4228.  
  4229. room.addClient(client)
  4230.  
  4231.  
  4232.  
  4233. def getIPPermaBan(this, ip):
  4234.  
  4235. return ip in this.ipPermaBanCache
  4236.  
  4237.  
  4238.  
  4239. def checkReport(this, array, playerName):
  4240.  
  4241. return playerName in array
  4242.  
  4243.  
  4244.  
  4245. def banPlayer(this, playerName, bantime, reason, modname, silent):
  4246.  
  4247. found = False
  4248.  
  4249.  
  4250.  
  4251. client = this.players.get(playerName)
  4252.  
  4253. if client != None:
  4254.  
  4255. found = True
  4256.  
  4257. if not modname == "Server":
  4258.  
  4259. client.banHours += bantime
  4260.  
  4261. ban = str(time.time())
  4262.  
  4263. bandate = ban[:len(ban) - 4]
  4264.  
  4265. this.Cursor.execute("insert into BanLog values (?, ?, ?, ?, ?, 'Online', ?, ?)", [playerName, modname, str(bantime), reason, bandate, client.roomName, client.ipAddress])
  4266.  
  4267. else:
  4268.  
  4269. this.sendStaffMessage(5, "<V>Server <BL>banned player <V>"+playerName+"<BL> for <V>1 <BL> hour. Reason: <V>Vote Populaire<BL>.")
  4270.  
  4271.  
  4272.  
  4273. this.Cursor.execute("update Users SET BanHours = ? WHERE Username = ?", [bantime, playerName])
  4274.  
  4275.  
  4276.  
  4277. if bantime >= 361 or client.banHours >= 361:
  4278.  
  4279. this.userPermaBanCache.append(playerName)
  4280.  
  4281. this.Cursor.execute("insert into UserPermaBan values (?, ?, ?)", [playerName, modname, reason])
  4282.  
  4283.  
  4284.  
  4285. if client.banHours >= 361:
  4286.  
  4287. this.ipPermaBanCache.append(client.ipAddress)
  4288.  
  4289. this.Cursor.execute("insert into IPPermaBan values (?, ?, ?)", [client.ipAddress, modname, reason])
  4290.  
  4291.  
  4292.  
  4293. if bantime >= 1 and bantime <= 360:
  4294.  
  4295. this.tempBanUser(playerName, bantime, reason)
  4296.  
  4297. this.tempBanIP(client.ipAddress, bantime)
  4298.  
  4299.  
  4300.  
  4301. if this.checkReport(this.reports["names"], playerName):
  4302.  
  4303. this.reports[playerName]["status"] = "banned"
  4304.  
  4305. this.reports[playerName]["status"] = "modname"
  4306.  
  4307. this.reports[playerName]["status"] = str(bantime)
  4308.  
  4309. this.reports[playerName]["banreason"] = "hack"
  4310.  
  4311.  
  4312.  
  4313. client.sendPlayerBan(bantime, reason, silent)
  4314.  
  4315.  
  4316.  
  4317. if not found and this.checkExistingUser(playerName) and not modname == "Server" and bantime >= 1:
  4318.  
  4319. found = True
  4320.  
  4321. totalBanTime = this.getTotalBanHours(playerName) + bantime
  4322.  
  4323. if (totalBanTime >= 361 and bantime <= 360) or bantime >= 361:
  4324.  
  4325. this.userPermaBanCache.append(playerName)
  4326.  
  4327. this.Cursor.execute("insert into UserPermaBan values (?, ?, ?)", [playerName, modname, reason])
  4328.  
  4329.  
  4330.  
  4331. if bantime >= 1 and bantime <= 360:
  4332.  
  4333. this.tempBanUser(playerName, bantime, reason)
  4334.  
  4335.  
  4336.  
  4337. this.Cursor.execute("update Users SET BanHours = ? WHERE Username = ?", [bantime, playerName])
  4338.  
  4339.  
  4340.  
  4341. ban = str(time.time())
  4342.  
  4343. bandate = ban[:len(ban) - 4]
  4344.  
  4345. this.Cursor.execute("insert into BanLog values (?, ?, ?, ?, ?, 'Offline', '', 'Offline')", [playerName, modname, str(bantime), reason, bandate])
  4346.  
  4347.  
  4348.  
  4349. return found
  4350.  
  4351.  
  4352.  
  4353. def checkTempBan(this, playerName):
  4354.  
  4355. this.Cursor.execute("select * from UserTempBan where Name = ?", [playerName])
  4356.  
  4357. if this.Cursor.fetchone():
  4358.  
  4359. return True
  4360.  
  4361. return False
  4362.  
  4363.  
  4364.  
  4365. def removeTempBan(this, playerName):
  4366.  
  4367. try:
  4368.  
  4369. this.userTempBanCache.remove(playerName)
  4370.  
  4371. this.Cursor.execute("delete from UserTempBan where Name = ?", [playerName])
  4372.  
  4373. except: pass
  4374.  
  4375.  
  4376.  
  4377. def tempBanUser(this, playerName, bantime, reason):
  4378.  
  4379. if this.checkTempBan(playerName):
  4380.  
  4381. this.removeTempBan(playerName)
  4382.  
  4383.  
  4384.  
  4385. this.userTempBanCache.append(playerName)
  4386.  
  4387. this.Cursor.execute("insert into UserTempBan values (?, ?, ?)", [playerName, str(TFMUtils.getTime() + (bantime * 60 * 60)), reason])
  4388.  
  4389.  
  4390.  
  4391. def getTempBanInfo(this, playerName):
  4392.  
  4393. this.Cursor.execute("select Reason, Time from UserTempBan where Name = ?", [playerName])
  4394.  
  4395. r = this.Cursor.fetchall()
  4396.  
  4397. for rs in r:
  4398.  
  4399. return [rs["Reason"], rs["Time"]]
  4400.  
  4401. return ["", 0]
  4402.  
  4403.  
  4404.  
  4405. def checkPermaBan(this, playerName):
  4406.  
  4407. this.Cursor.execute("select * from UserPermaBan where Name = ?", [playerName])
  4408.  
  4409. if this.Cursor.fetchone():
  4410.  
  4411. return True
  4412.  
  4413. return False
  4414.  
  4415.  
  4416.  
  4417. def removePermaBan(this, playerName):
  4418.  
  4419. try:
  4420.  
  4421. this.userPermaBanCache.remove(playerName)
  4422.  
  4423. this.Cursor.execute("delete from UserPermaBan where Name = ?", [playerName])
  4424.  
  4425. except: pass
  4426.  
  4427.  
  4428.  
  4429. def tempBanIP(this, ip, time):
  4430.  
  4431. if not ip in this.tempIPBanList:
  4432.  
  4433. this.tempIPBanList.append(ip)
  4434.  
  4435. reactor.callLater(time, lambda: this.tempIPBanList.remove(ip))
  4436.  
  4437.  
  4438.  
  4439. def getTotalBanHours(this, playerName):
  4440.  
  4441. this.Cursor.execute("select BanHours from Users where Username = ?", [playerName])
  4442.  
  4443. rs = this.Cursor.fetchone()
  4444.  
  4445. if rs:
  4446.  
  4447. return rs["BanHours"]
  4448.  
  4449. return 0
  4450.  
  4451.  
  4452.  
  4453. def parseBanList(this):
  4454.  
  4455. this.Cursor.execute("select ip from IPPermaBan")
  4456.  
  4457. rs = this.Cursor.fetchone()
  4458.  
  4459. if rs:
  4460.  
  4461. this.ipPermaBanCache.append(rs["ip"])
  4462.  
  4463.  
  4464.  
  4465. this.Cursor.execute("select Name from UserPermaBan")
  4466.  
  4467. rs = this.Cursor.fetchone()
  4468.  
  4469. if rs:
  4470.  
  4471. this.userPermaBanCache.append(rs["Name"])
  4472.  
  4473.  
  4474.  
  4475. this.Cursor.execute("select Name from UserTempBan")
  4476.  
  4477. rs = this.Cursor.fetchone()
  4478.  
  4479. if rs:
  4480.  
  4481. this.userTempBanCache.append(rs["Name"])
  4482.  
  4483.  
  4484.  
  4485. this.Cursor.execute("select Name from UserTempMute")
  4486.  
  4487. rs = this.Cursor.fetchone()
  4488.  
  4489. if rs:
  4490.  
  4491. this.userMuteCache.append(rs["Name"])
  4492.  
  4493.  
  4494.  
  4495. def voteBanPopulaire(this, playerName, ip):
  4496.  
  4497. client = this.players.get(playerName)
  4498.  
  4499. if client != None and client.privLevel == 1 and not ip in client.voteBan:
  4500.  
  4501. client.voteBan.append(ip)
  4502.  
  4503. if len(client.voteBan) == 10:
  4504.  
  4505. this.banPlayer(playerName, 1, "Vote Populaire", "Server", False)
  4506.  
  4507.  
  4508.  
  4509. def muteUser(this, playerName, mutetime, reason):
  4510.  
  4511. this.userMuteCache.append(playerName)
  4512.  
  4513. this.Cursor.execute("insert into UserTempMute values (?, ?, ?)", [playerName, str(TFMUtils.getTime() + (mutetime * 60 * 60)), reason])
  4514.  
  4515.  
  4516.  
  4517. def removeModMute(this, playerName):
  4518.  
  4519. try:
  4520.  
  4521. this.userMuteCache.remove(playerName)
  4522.  
  4523. this.Cursor.execute("delete from UserTempMute where Name = ?", [playerName])
  4524.  
  4525. except:pass
  4526.  
  4527.  
  4528.  
  4529. def getModMuteInfo(this, playerName):
  4530.  
  4531. this.Cursor.execute("select Time, Reason from UserTempMute where Name = ?", [playerName])
  4532.  
  4533. rs = this.Cursor.fetchone()
  4534.  
  4535. if rs:
  4536.  
  4537. return [rs["Time"], rs["Reason"]]
  4538.  
  4539. return [0, ""]
  4540.  
  4541.  
  4542.  
  4543. def mutePlayer(this, playerName, time, reason, modname):
  4544.  
  4545. client = this.players.get(playerName)
  4546.  
  4547. if client != None:
  4548.  
  4549. this.sendStaffMessage(5, "<V>"+str(modname)+"<BL> left the player <V>"+playerName+"<BL> without talking for <V>"+str(time)+"<BL> "+str("hora" if time == 1 else "hours")+". Reason: <V>"+str(reason))
  4550.  
  4551. if playerName in this.userMuteCache:
  4552.  
  4553. this.removeModMute(playerName)
  4554.  
  4555.  
  4556.  
  4557. for player in client.room.clients.values():
  4558.  
  4559. if player.Username != playerName:
  4560.  
  4561. player.sendLangueMessage("", "<ROSE>$MuteInfo2", playerName, str(time), reason)
  4562.  
  4563.  
  4564.  
  4565. client.isMute = True
  4566.  
  4567. client.sendLangueMessage("", "<ROSE>$MuteInfo1", str(time), reason)
  4568.  
  4569. this.muteUser(playerName, time, reason)
  4570.  
  4571.  
  4572.  
  4573. def desmutePlayer(this, playerName, modname):
  4574.  
  4575. client = this.players.get(playerName)
  4576.  
  4577. if client != None:
  4578.  
  4579. this.sendStaffMessage(5, "<V>"+str(modname)+"<N> was unmuted <V>"+playerName+"<BL>.")
  4580.  
  4581. this.removeModMute(playerName)
  4582.  
  4583. client.isMute = False
  4584.  
  4585.  
  4586.  
  4587. def sendStaffChat(this, type, langue, identifiers, packet):
  4588.  
  4589. minLevel = 0 if type == -1 or type == 0 else 1 if type == 1 else 7 if type == 3 or type == 4 else 5 if type == 2 or type == 5 else 6 if type == 7 or type == 6 else 3 if type == 8 else 4 if type == 9 else 0
  4590.  
  4591. for client in this.players.values():
  4592.  
  4593. if client.privLevel >= minLevel and client.Langue == langue or type == 1 or type == 4 or type == 5:
  4594.  
  4595. client.sendPacket(identifiers, packet)
  4596.  
  4597.  
  4598.  
  4599. def getTotemData(this, playerName):
  4600.  
  4601. if playerName.startswith("*"):
  4602.  
  4603. return []
  4604.  
  4605. else:
  4606.  
  4607. this.Cursor.execute("select ItemCount, Totem from Totem where Name = ?", [playerName])
  4608.  
  4609. rs = this.Cursor.fetchone()
  4610.  
  4611. if rs:
  4612.  
  4613. itemCount = rs["ItemCount"]
  4614.  
  4615. totem = rs["Totem"]
  4616.  
  4617. totem = totem.replace("%", chr(1))
  4618.  
  4619. return [str(itemCount), totem]
  4620.  
  4621. return []
  4622.  
  4623.  
  4624.  
  4625. def setTotemData(this, playerName, ItemCount, totem):
  4626.  
  4627. if playerName.startswith("*"):
  4628.  
  4629. pass
  4630.  
  4631. else:
  4632.  
  4633. totem = totem.replace(chr(1), "%")
  4634.  
  4635.  
  4636.  
  4637. if len(this.getTotemData(playerName)) != 0:
  4638.  
  4639. this.Cursor.execute("update Totem set ItemCount = ?, Totem = ? where Name = ?", [ItemCount, totem, playerName])
  4640.  
  4641. else:
  4642.  
  4643. this.Cursor.execute("insert into Totem values (?, ?, ?)", [playerName, ItemCount, totem])
  4644.  
  4645.  
  4646.  
  4647. def getShamanType(this, playerCode):
  4648.  
  4649. for player in this.players.values():
  4650.  
  4651. if player.playerCode == playerCode:
  4652.  
  4653. return player.shamanType
  4654.  
  4655.  
  4656.  
  4657. return 0
  4658.  
  4659.  
  4660.  
  4661. def getShamanLevel(this, playerCode):
  4662.  
  4663. for player in this.players.values():
  4664.  
  4665. if player.playerCode == playerCode:
  4666.  
  4667. return player.shamanLevel
  4668.  
  4669. return 0
  4670.  
  4671.  
  4672.  
  4673. def getShamanBadge(this, playerCode):
  4674.  
  4675. for player in this.players.values():
  4676.  
  4677. if player.playerCode == playerCode:
  4678.  
  4679. return player.skillModule.getShamanBadge()
  4680.  
  4681.  
  4682.  
  4683. return 0
  4684.  
  4685.  
  4686.  
  4687. def getPlayerAvatar(this, playerName):
  4688.  
  4689. this.Cursor.execute("select Avatar from Users where Username = ?", [playerName])
  4690.  
  4691. rs = this.Cursor.fetchone()
  4692.  
  4693. if rs:
  4694.  
  4695. return rs["Avatar"]
  4696.  
  4697. return 0
  4698.  
  4699.  
  4700.  
  4701. def getPlayerID(this, playerName):
  4702.  
  4703. if playerName.startswith("*"):
  4704.  
  4705. return 0
  4706.  
  4707.  
  4708.  
  4709. elif this.players.has_key(playerName):
  4710.  
  4711. return this.players[playerName].playerID
  4712.  
  4713. else:
  4714.  
  4715. this.Cursor.execute("select PlayerID from Users where Username = ?", [playerName])
  4716.  
  4717. rs = this.Cursor.fetchone()
  4718.  
  4719. if rs:
  4720.  
  4721. return rs["PlayerID"]
  4722.  
  4723. return 0
  4724.  
  4725.  
  4726.  
  4727. def getPlayerPrivlevel(this, playerName):
  4728.  
  4729. if playerName.startswith("*"):
  4730.  
  4731. return 0
  4732.  
  4733.  
  4734.  
  4735. elif this.players.has_key(playerName):
  4736.  
  4737. return this.players[playerName].privLevel
  4738.  
  4739. else:
  4740.  
  4741. this.Cursor.execute("select PrivLevel from Users where Username = ?", [playerName])
  4742.  
  4743. rs = this.Cursor.fetchone()
  4744.  
  4745. if rs:
  4746.  
  4747. return rs["PrivLevel"]
  4748.  
  4749. return 0
  4750.  
  4751.  
  4752.  
  4753. def getPlayerName(this, playerID):
  4754.  
  4755. this.Cursor.execute("select Username from Users where PlayerID = ?", [playerID])
  4756.  
  4757. rs = this.Cursor.fetchone()
  4758.  
  4759. if rs:
  4760.  
  4761. return rs["Username"]
  4762.  
  4763. return ""
  4764.  
  4765.  
  4766.  
  4767. def getPlayerRoomName(this, playerName):
  4768.  
  4769. if this.players.has_key(playerName):
  4770.  
  4771. return this.players[playerName].roomName
  4772.  
  4773. return ""
  4774.  
  4775.  
  4776.  
  4777. def getTribeInfo(this, tribeCode):
  4778.  
  4779. tribeRankings = {}
  4780.  
  4781. this.Cursor.execute("select * from Tribe where Code = ?", [tribeCode])
  4782.  
  4783. rs = this.Cursor.fetchone()
  4784.  
  4785. if rs:
  4786.  
  4787. for rank in rs["Rankings"].split(";"):
  4788.  
  4789. values = rank.split("|", 1)
  4790.  
  4791. tribeRankings[int(values[0])] = values[1]
  4792.  
  4793. return [rs["Name"], rs["Message"], rs["House"], tribeRankings, rs["Chat"]]
  4794.  
  4795. return ["", "", 0, tribeRankings, 0]
  4796.  
  4797.  
  4798.  
  4799. def getTribeHouse(this, tribeName):
  4800.  
  4801. this.Cursor.execute("select House from Tribe where Name = ?", [tribeName])
  4802.  
  4803. rs = this.Cursor.fetchone()
  4804.  
  4805. if rs:
  4806.  
  4807. return rs["House"]
  4808.  
  4809. return -1
  4810.  
  4811.  
  4812.  
  4813. def getPlayersCountMode(this, mode, langue):
  4814.  
  4815. modeName = "Transformice" if mode == 1 else "Transformice vanilla" if mode == 3 else "Transformice survivor" if mode == 8 else "Transformice racing" if mode == 9 else "Transformice music" if mode == 11 else "Transformice bootcamp" if mode == 2 else "Transformice defilante" if mode == 10 else "Transformice village" if mode == 16 else ""
  4816.  
  4817. playerCount = 0
  4818.  
  4819. for room in this.rooms.values():
  4820.  
  4821. if ((room.isNormRoom 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()):
  4822.  
  4823. playerCount += room.getPlayerCount()
  4824.  
  4825. return [modeName, playerCount]
  4826.  
  4827.  
  4828.  
  4829. def parsePromotions(this):
  4830.  
  4831. needUpdate = False
  4832.  
  4833. i = 0
  4834.  
  4835. while i < len(this.promotions):
  4836.  
  4837. item = this.promotions[i]
  4838.  
  4839. if item[3] < 1000:
  4840.  
  4841. item[3] = TFMUtils.getTime() + item[3] * 86400 + 30
  4842.  
  4843. needUpdate = True
  4844.  
  4845.  
  4846.  
  4847. this.shopPromotions.append([item[0], item[1], item[2], item[3]])
  4848.  
  4849. i += 1
  4850.  
  4851.  
  4852.  
  4853. this.checkPromotionsEnd()
  4854.  
  4855.  
  4856.  
  4857. def checkPromotionsEnd(this):
  4858.  
  4859. needUpdate = False
  4860.  
  4861. for promotion in this.shopPromotions:
  4862.  
  4863. if TFMUtils.getHoursDiff(promotion[3]) <= 0:
  4864.  
  4865. this.shopPromotions.remove(promotion)
  4866.  
  4867. needUpdate = True
  4868.  
  4869. i = 0
  4870.  
  4871. while i < len(this.promotions):
  4872.  
  4873. if this.promotions[i][0] == promotion[0] and this.promotions[i][1] == promotion[1]:
  4874.  
  4875. this.promotions.remove(i)
  4876.  
  4877. i += 1
  4878.  
  4879.  
  4880.  
  4881. def sendWholeServer(this, identifiers, result):
  4882.  
  4883. for client in this.players.values():
  4884.  
  4885. client.sendPacket(identifiers, result)
  4886.  
  4887.  
  4888.  
  4889. def checkMessage(this, client, message):
  4890.  
  4891. list = this.blackList["list"]
  4892.  
  4893. i = 0
  4894.  
  4895. while i < len(list):
  4896.  
  4897. if re.search("[^a-zA-Z]*".join(list[i]), message.lower()):
  4898.  
  4899. this.sendStaffMessage(7, "[<V>" + client.roomName + "</V>][<T>" + client.Username + "</T>] sent a link in the message: [<J>" + str(message) + "</J>].")
  4900.  
  4901. return True
  4902.  
  4903. i += 1
  4904.  
  4905. return False
  4906.  
  4907.  
  4908.  
  4909. def setVip(this, playerName, days):
  4910.  
  4911. player = this.players.get(playerName)
  4912.  
  4913. if ((player != None and player.privLevel == 1) or this.getPlayerPrivlevel(playerName) == 1):
  4914.  
  4915. this.Cursor.execute("update users set VipTime = ? where Username = ?" if player != None else "update users SET VipTime = ?, PrivLevel = 2 where Username = ?", [TFMUtils.getTime() + (days * 24 * 3600), playerName])
  4916.  
  4917. if player != None:
  4918.  
  4919. player.privLevel = 2
  4920.  
  4921.  
  4922.  
  4923. this.sendStaffMessage(7, "<V>"+playerName+"</V> became VIP for <V>"+str(days)+"</V> days.")
  4924.  
  4925. return True
  4926.  
  4927.  
  4928.  
  4929. return False
  4930.  
  4931.  
  4932.  
  4933. def getPlayerCode(this, playerName):
  4934.  
  4935. client = this.players.get(TFMUtils.parsePlayerName(playerName))
  4936.  
  4937. return client.playerCode if player != None else 0
  4938.  
  4939.  
  4940.  
  4941. def sendStaffMessage(this, minLevel, message):
  4942.  
  4943. for client in this.players.values():
  4944.  
  4945. if client.privLevel >= minLevel:
  4946.  
  4947. client.sendMessage(message)
  4948.  
  4949.  
  4950.  
  4951. class Room:
  4952.  
  4953. def __init__(this, server, name):
  4954.  
  4955.  
  4956.  
  4957. # String
  4958.  
  4959. this.currentSyncName = ""
  4960.  
  4961. this.currentShamanName = ""
  4962.  
  4963. this.currentSecondShamanName = ""
  4964.  
  4965. this.forceNextMap = "-1"
  4966.  
  4967. this.mapName = ""
  4968.  
  4969. this.mapXML = ""
  4970.  
  4971. this.EMapXML = ""
  4972.  
  4973. this.roomPassword = ""
  4974.  
  4975.  
  4976.  
  4977. # Integer
  4978.  
  4979. this.maxPlayers = 200
  4980.  
  4981. this.currentMap = 0
  4982.  
  4983. this.lastRoundCode = 0
  4984.  
  4985. this.mapCode = -1
  4986.  
  4987. this.mapYesVotes = 0
  4988.  
  4989. this.mapNoVotes = 0
  4990.  
  4991. this.mapPerma = -1
  4992.  
  4993. this.mapStatus = 0
  4994.  
  4995. this.currentSyncCode = -1
  4996.  
  4997. this.roundTime = 120
  4998.  
  4999. this.gameStartTime = 0
  5000.  
  5001. this.currentShamanCode = -1
  5002.  
  5003. this.currentSecondShamanCode = -1
  5004.  
  5005. this.currentShamanType = -1
  5006.  
  5007. this.currentSecondShamanType = -1
  5008.  
  5009. this.forceNextShaman = -1
  5010.  
  5011. this.numCompleted = 0
  5012.  
  5013. this.FSnumCompleted = 0
  5014.  
  5015. this.SSnumCompleted = 0
  5016.  
  5017. this.receivedNo = 0
  5018.  
  5019. this.receivedYes = 0
  5020.  
  5021. this.EMapLoaded = 0
  5022.  
  5023. this.EMapCode = 0
  5024.  
  5025. this.objectID = 0
  5026.  
  5027. this.tempTotemCount = -1
  5028.  
  5029. this.addTime = 0
  5030.  
  5031. this.cloudID = -1
  5032.  
  5033. this.companionBox = -1
  5034.  
  5035. this.mulodromeRoundCount = 0
  5036.  
  5037. this.redCount = 0
  5038.  
  5039. this.blueCount = 0
  5040.  
  5041. this.musicMapStatus = 0
  5042.  
  5043. this.roundsCount = -1
  5044.  
  5045. this.survivorMapStatus = 0
  5046.  
  5047. this.lastImageID = 0
  5048.  
  5049. this.changeMapAttemps = 0
  5050.  
  5051. this.musicSkipVotes = 0
  5052.  
  5053. this.musicTime = 0
  5054.  
  5055.  
  5056.  
  5057. this.gameStartTimeMillis = 0
  5058.  
  5059.  
  5060.  
  5061. # Bool
  5062.  
  5063. this.discoRoom = False
  5064.  
  5065. this.isClosed = False
  5066.  
  5067. this.isCurrentlyPlay = False
  5068.  
  5069. this.isDoubleMap = False
  5070.  
  5071. this.isNoShamanMap = False
  5072.  
  5073. this.isVotingMode = False
  5074.  
  5075. this.initVotingMode = True
  5076.  
  5077. this.isVotingBox = False
  5078.  
  5079. this.EMapValidated = False
  5080.  
  5081. this.countStats = True
  5082.  
  5083. this.never20secTimer = False
  5084.  
  5085. this.isVanilla = False
  5086.  
  5087. this.isEditeur = False
  5088.  
  5089. this.changed20secTimer = False
  5090.  
  5091. this.specificMap = False
  5092.  
  5093. this.noShaman = False
  5094.  
  5095. this.isTutorial = False
  5096.  
  5097. this.isTotemEditeur = False
  5098.  
  5099. this.autoRespawn = False
  5100.  
  5101. this.noAutoScore = False
  5102.  
  5103. this.catchTheCheeseMap = False
  5104.  
  5105. this.isTribeHouse = False
  5106.  
  5107. this.isTribeHouseMap = False
  5108.  
  5109. this.isMulodrome = False
  5110.  
  5111. this.isRacing = False
  5112.  
  5113. this.isMusic = False
  5114.  
  5115. this.isUtility = False
  5116.  
  5117. this.isDeathmatch = False
  5118.  
  5119. this.isPlayingMusic = False
  5120.  
  5121. this.isRacingP17 = False
  5122.  
  5123. this.isBootcamp = False
  5124.  
  5125. this.isBootcampP13 = False
  5126.  
  5127. this.isSurvivor = False
  5128.  
  5129. this.isSurvivorVamp = False
  5130.  
  5131. this.isDefilante = False
  5132.  
  5133. this.isNormRoom = False
  5134.  
  5135. this.isSnowing = False
  5136.  
  5137. this.canChangeMap = True
  5138.  
  5139. this.disableAfkKill = False
  5140.  
  5141. this.isFixedMap = False
  5142.  
  5143. this.noShamanSkills = False
  5144.  
  5145. this.is801Room = False
  5146.  
  5147. this.mapInverted = False
  5148.  
  5149. this.canChangeMusic = True
  5150.  
  5151. this.isFuncorp = False
  5152.  
  5153. this.isVillage = False
  5154.  
  5155.  
  5156.  
  5157. # Bool
  5158.  
  5159. this.changeMapTimer = None
  5160.  
  5161. this.closeRoomRoundJoinTimer = None
  5162.  
  5163. this.voteCloseTimer = None
  5164.  
  5165. this.killAfkTimer = None
  5166.  
  5167. this.autoRespawnTimer = None
  5168.  
  5169. this.endSnowTimer = None
  5170.  
  5171. this.startTimerLeft = None
  5172.  
  5173.  
  5174.  
  5175. # List Arguments
  5176.  
  5177. this.MapList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 143, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210]
  5178.  
  5179. this.noShamanMaps = [7, 8, 14, 22, 23, 28, 29, 54, 55, 57, 58, 59, 60, 61, 70, 77, 78, 87, 88, 92, 122, 123, 124, 125, 126, 1007, 888, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210]
  5180.  
  5181. this.anchors = []
  5182.  
  5183. this.lastHandymouse = [-1, -1]
  5184.  
  5185. this.musicVideos = []
  5186.  
  5187.  
  5188.  
  5189. # List
  5190.  
  5191. this.redTeam = []
  5192.  
  5193. this.blueTeam = []
  5194.  
  5195. this.roomTimers = []
  5196.  
  5197. this.adminsRoom = []
  5198.  
  5199. this.playersBan = []
  5200.  
  5201.  
  5202.  
  5203. # Dict
  5204.  
  5205. this.clients = {}
  5206.  
  5207. this.currentShamanSkills = {}
  5208.  
  5209. this.currentSecondShamanSkills = {}
  5210.  
  5211. this.currentTimers = {}
  5212.  
  5213.  
  5214.  
  5215. # Others
  5216.  
  5217. this.name = name
  5218.  
  5219. this.server = server
  5220.  
  5221. this.Cursor = Cursor
  5222.  
  5223.  
  5224.  
  5225. if this.name.startswith("*"):
  5226.  
  5227. this.community = "xx"
  5228.  
  5229. this.roomName = this.name
  5230.  
  5231. else:
  5232.  
  5233. this.community = this.name.split("-")[0].lower()
  5234.  
  5235. this.roomName = this.name.split("-")[1]
  5236.  
  5237.  
  5238.  
  5239. if this.roomName.startswith(chr(3) + "[Editeur] "):
  5240.  
  5241. this.countStats = False
  5242.  
  5243. this.isEditeur = True
  5244.  
  5245. this.never20secTimer = True
  5246.  
  5247.  
  5248.  
  5249. elif this.roomName.startswith(chr(3) + "[Tutorial] "):
  5250.  
  5251. this.countStats = False
  5252.  
  5253. this.currentMap = 900
  5254.  
  5255. this.specificMap = True
  5256.  
  5257. this.noShaman = True
  5258.  
  5259. this.never20secTimer = True
  5260.  
  5261. this.isTutorial = True
  5262.  
  5263.  
  5264.  
  5265. elif this.roomName.startswith(chr(3) + "[Totem] "):
  5266.  
  5267. this.countStats = False
  5268.  
  5269. this.specificMap = True
  5270.  
  5271. this.currentMap = 444
  5272.  
  5273. this.isTotemEditeur = True
  5274.  
  5275. this.never20secTimer = True
  5276.  
  5277.  
  5278.  
  5279. elif this.roomName.startswith("*" + chr(3)):
  5280.  
  5281. this.countStats = False
  5282.  
  5283. this.isTribeHouse = True
  5284.  
  5285. this.autoRespawn = True
  5286.  
  5287. this.never20secTimer = True
  5288.  
  5289. this.noShaman = True
  5290.  
  5291.  
  5292.  
  5293. elif this.roomName.startswith("#utility"):
  5294.  
  5295. this.isUtility = True
  5296.  
  5297. this.roundTime = 0
  5298.  
  5299. this.never20secTimer = True
  5300.  
  5301. this.autoRespawn = True
  5302.  
  5303. this.countStats = False
  5304.  
  5305. this.noShaman = True
  5306.  
  5307. this.isFixedMap = True
  5308.  
  5309.  
  5310.  
  5311. elif this.roomName.startswith("music") or this.roomName.startswith("*music"):
  5312.  
  5313. this.isMusic = True
  5314.  
  5315.  
  5316.  
  5317. elif this.roomName.startswith("racing") or this.roomName.startswith("*racing"):
  5318.  
  5319. this.isRacing = True
  5320.  
  5321. this.noShaman = True
  5322.  
  5323. this.roundTime = 63
  5324.  
  5325.  
  5326.  
  5327. elif this.roomName.startswith("bootcamp") or this.roomName.startswith("*bootcamp"):
  5328.  
  5329. this.isBootcamp = True
  5330.  
  5331. this.countStats = False
  5332.  
  5333. this.roundTime = 360
  5334.  
  5335. this.never20secTimer = True
  5336.  
  5337. this.autoRespawn = True
  5338.  
  5339. this.noShaman = True
  5340.  
  5341.  
  5342.  
  5343. elif this.roomName.startswith("vanilla") or this.roomName.startswith("*vanilla"):
  5344.  
  5345. this.isVanilla = True
  5346.  
  5347.  
  5348.  
  5349. elif this.roomName.startswith("survivor") or this.roomName.startswith("*survivor"):
  5350.  
  5351. this.isSurvivor = True
  5352.  
  5353. this.roundTime = 90
  5354.  
  5355.  
  5356.  
  5357. elif this.roomName.startswith("defilante") or this.roomName.startswith("*defilante"):
  5358.  
  5359. this.isDefilante = True
  5360.  
  5361. this.noShaman = True
  5362.  
  5363. this.countStats = False
  5364.  
  5365. this.noAutoScore = True
  5366.  
  5367.  
  5368.  
  5369. elif this.roomName.startswith("village") or this.roomName.startswith("*village"):
  5370.  
  5371. this.isVillage = True
  5372.  
  5373. this.roundTime = 0
  5374.  
  5375. this.never20secTimer = True
  5376.  
  5377. this.autoRespawn = True
  5378.  
  5379. this.countStats = False
  5380.  
  5381. this.noShaman = True
  5382.  
  5383. this.isFixedMap = True
  5384.  
  5385.  
  5386.  
  5387. elif this.roomName.startswith("801") or this.roomName.startswith("*801"):
  5388.  
  5389. this.is801Room = True
  5390.  
  5391. this.roundTime = 0
  5392.  
  5393. this.never20secTimer = True
  5394.  
  5395. this.autoRespawn = True
  5396.  
  5397. this.countStats = False
  5398.  
  5399. this.noShaman = True
  5400.  
  5401. this.isFixedMap = True
  5402.  
  5403. else:
  5404.  
  5405. this.isNormRoom = True
  5406.  
  5407.  
  5408.  
  5409. this.mapChange()
  5410.  
  5411.  
  5412.  
  5413. def startTimer(this):
  5414.  
  5415. for client in this.clients.values():
  5416.  
  5417. client.sendMapStartTimerEnd()
  5418.  
  5419.  
  5420.  
  5421. def mapChange(this):
  5422.  
  5423. if this.changeMapTimer != None: this.changeMapTimer.cancel()
  5424.  
  5425.  
  5426.  
  5427. if not this.canChangeMap:
  5428.  
  5429. this.changeMapAttemps += 1
  5430.  
  5431. if this.changeMapAttemps < 5:
  5432.  
  5433. this.changeMapTimer = reactor.callLater(1, this.mapChange)
  5434.  
  5435. return
  5436.  
  5437.  
  5438.  
  5439. for timer in this.roomTimers:
  5440.  
  5441. timer.cancel()
  5442.  
  5443.  
  5444.  
  5445. this.roomTimers = []
  5446.  
  5447.  
  5448.  
  5449. for timer in [this.voteCloseTimer, this.killAfkTimer, this.autoRespawnTimer, this.startTimerLeft]:
  5450.  
  5451. if timer != None:
  5452.  
  5453. timer.cancel()
  5454.  
  5455.  
  5456.  
  5457. if this.initVotingMode:
  5458.  
  5459. if not this.isVotingBox and (this.mapPerma == 0 and this.mapCode != -1) and this.getPlayerCount() >= 2:
  5460.  
  5461. this.isVotingMode = True
  5462.  
  5463. this.isVotingBox = True
  5464.  
  5465. this.voteCloseTimer = reactor.callLater(8, this.closeVoting)
  5466.  
  5467. for client in this.clients.values():
  5468.  
  5469. client.sendPacket(Identifiers.old.send.Vote_Box, [this.mapName, this.mapYesVotes, this.mapNoVotes])
  5470.  
  5471. else:
  5472.  
  5473. this.votingMode = False
  5474.  
  5475. this.closeVoting()
  5476.  
  5477.  
  5478.  
  5479. elif this.isTribeHouse and this.isTribeHouseMap:
  5480.  
  5481. pass
  5482.  
  5483. else:
  5484.  
  5485. if this.isVotingMode:
  5486.  
  5487. TotalYes = this.mapYesVotes + this.receivedYes
  5488.  
  5489. TotalNo = this.mapNoVotes + this.receivedNo
  5490.  
  5491. isDel = False
  5492.  
  5493.  
  5494.  
  5495. if TotalYes + TotalNo >= 100:
  5496.  
  5497. TotalVotes = TotalYes + TotalNo
  5498.  
  5499. Rating = (1.0 * TotalYes / TotalNo) * 100
  5500.  
  5501. rate = str(Rating).split(".")
  5502.  
  5503. if int(rate[0]) < 50:
  5504.  
  5505. isDel = True
  5506.  
  5507. this.Cursor.execute("update MapEditor set YesVotes = ?, NoVotes = ?, Perma = 44 where Code = ?", [TotalYes, TotalNo, this.mapCode]) if isDel else this.Cursor.execute("update MapEditor set YesVotes = ?, NoVotes = ? where Code = ?", [TotalYes, TotalNo, this.mapCode])
  5508.  
  5509. this.isVotingMode = False
  5510.  
  5511. this.receivedNo = 0
  5512.  
  5513. this.receivedYes = 0
  5514.  
  5515. for client in this.clients.values():
  5516.  
  5517. client.qualifiedVoted = False
  5518.  
  5519. client.isVoted = False
  5520.  
  5521.  
  5522.  
  5523. this.initVotingMode = True
  5524.  
  5525.  
  5526.  
  5527. this.lastRoundCode += 1
  5528.  
  5529. this.lastRoundCode %= 127
  5530.  
  5531.  
  5532.  
  5533. if this.isSurvivor:
  5534.  
  5535. for client in this.clients.values():
  5536.  
  5537. if not client.isDead and (not client.isVampire if this.isSurvivorVamp else not client.isShaman):
  5538.  
  5539. if not this.noAutoScore: client.playerScore += 10
  5540.  
  5541.  
  5542.  
  5543. if this.catchTheCheeseMap:
  5544.  
  5545. this.catchTheCheeseMap = False
  5546.  
  5547. else:
  5548.  
  5549. numCom = this.FSnumCompleted - 1 if this.isDoubleMap else this.numCompleted - 1
  5550.  
  5551. numCom2 = this.SSnumCompleted - 1 if this.isDoubleMap else 0
  5552.  
  5553. if numCom < 0: numCom = 0
  5554.  
  5555. if numCom2 < 0: numCom2 = 0
  5556.  
  5557.  
  5558.  
  5559. player = this.clients.get(this.currentShamanName)
  5560.  
  5561. if player != None:
  5562.  
  5563. this.sendAll(Identifiers.old.send.Shaman_Perfomance, [this.currentShamanName, numCom])
  5564.  
  5565. if not this.noAutoScore: player.playerScore = numCom
  5566.  
  5567. if numCom > 0:
  5568.  
  5569. player.skillModule.earnExp(True, numCom)
  5570.  
  5571.  
  5572.  
  5573. player2 = this.clients.get(this.currentSecondShamanName)
  5574.  
  5575. if player2 != None:
  5576.  
  5577. this.sendAll(Identifiers.old.send.Shaman_Perfomance, [this.currentSecondShamanName, numCom2])
  5578.  
  5579. if not this.noAutoScore: player2.playerScore = numCom2
  5580.  
  5581. if numCom2 > 0:
  5582.  
  5583. player2.skillModule.earnExp(True, numCom2)
  5584.  
  5585.  
  5586.  
  5587. if this.isSurvivor and this.getPlayerCount() >= this.server.needToFirst:
  5588.  
  5589. this.giveSurvivorStats()
  5590.  
  5591. elif this.isRacing and this.getPlayerCount() >= this.server.needToFirst:
  5592.  
  5593. this.giveRacingStats()
  5594.  
  5595.  
  5596.  
  5597. this.currentSyncCode = -1
  5598.  
  5599. this.currentSyncName = ""
  5600.  
  5601. this.currentShamanCode = -1
  5602.  
  5603. this.currentSecondShamanCode = -1
  5604.  
  5605. this.currentShamanName = ""
  5606.  
  5607. this.currentSecondShamanName = ""
  5608.  
  5609. this.currentShamanType = -1
  5610.  
  5611. this.currentSecondShamanType = -1
  5612.  
  5613. this.currentShamanSkills = {}
  5614.  
  5615. this.currentSecondShamanSkills = {}
  5616.  
  5617. this.changed20secTimer = False
  5618.  
  5619. this.isDoubleMap = False
  5620.  
  5621. this.isNoShamanMap = False
  5622.  
  5623. this.FSnumCompleted = 0
  5624.  
  5625. this.SSnumCompleted = 0
  5626.  
  5627. this.objectID = 0
  5628.  
  5629. this.tempTotemCount = -1
  5630.  
  5631. this.addTime = 0
  5632.  
  5633. this.cloudID = -1
  5634.  
  5635. this.companionBox = -1
  5636.  
  5637. this.lastHandymouse = [-1, -1]
  5638.  
  5639. this.isTribeHouseMap = False
  5640.  
  5641. this.canChangeMap = True
  5642.  
  5643. this.changeMapAttemps = 0
  5644.  
  5645.  
  5646.  
  5647. this.getSyncCode()
  5648.  
  5649.  
  5650.  
  5651. this.anchors = []
  5652.  
  5653.  
  5654.  
  5655. this.mapStatus += 1
  5656.  
  5657. this.mapStatus %= 13
  5658.  
  5659. this.musicMapStatus += 1
  5660.  
  5661. this.musicMapStatus %= 6
  5662.  
  5663. this.survivorMapStatus += 1
  5664.  
  5665. this.survivorMapStatus %= 11
  5666.  
  5667.  
  5668.  
  5669. this.isRacingP17 = not this.isRacingP17
  5670.  
  5671. this.isBootcampP13 = not this.isBootcampP13
  5672.  
  5673.  
  5674.  
  5675. this.numCompleted = 0
  5676.  
  5677. this.canChangeMusic = True
  5678.  
  5679.  
  5680.  
  5681. this.currentMap = this.selectMap()
  5682.  
  5683. this.checkVanillaXML()
  5684.  
  5685.  
  5686.  
  5687. if not this.noShamanSkills:
  5688.  
  5689. player = this.clients.get(this.currentShamanName)
  5690.  
  5691. if player != None:
  5692.  
  5693. if this.currentShamanName != None:
  5694.  
  5695. player.skillModule.getTimeSkill()
  5696.  
  5697.  
  5698.  
  5699. if this.currentSecondShamanName != None:
  5700.  
  5701. player.skillModule.getTimeSkill()
  5702.  
  5703.  
  5704.  
  5705. if this.currentMap in [range(44, 54), range(138, 144)] or this.mapPerma == 8 and this.getPlayerCount() >= 2:
  5706.  
  5707. this.isDoubleMap = True
  5708.  
  5709.  
  5710.  
  5711. if this.mapPerma == 7 or this.mapPerma == 42 or this.isSurvivorVamp:
  5712.  
  5713. this.isNoShamanMap = True
  5714.  
  5715.  
  5716.  
  5717. if this.currentMap in range(108, 114):
  5718.  
  5719. this.catchTheCheeseMap = True
  5720.  
  5721.  
  5722.  
  5723. this.gameStartTime = TFMUtils.getTime()
  5724.  
  5725. this.gameStartTimeMillis = time.time()
  5726.  
  5727. this.isCurrentlyPlay = False
  5728.  
  5729.  
  5730.  
  5731. for player in this.clients.values():
  5732.  
  5733. player.resetPlay()
  5734.  
  5735.  
  5736.  
  5737. for player in this.clients.values():
  5738.  
  5739. player.startPlay()
  5740.  
  5741. if player.isHidden:
  5742.  
  5743. player.sendPlayerDisconnect()
  5744.  
  5745.  
  5746.  
  5747. for player in this.clients.values():
  5748.  
  5749. if player.pet != 0:
  5750.  
  5751. if TFMUtils.getSecondsDiff(player.petEnd) >= 0:
  5752.  
  5753. player.pet = 0
  5754.  
  5755. player.petEnd = 0
  5756.  
  5757. else:
  5758.  
  5759. this.sendAll(Identifiers.send.Pet, ByteArray().writeInt(player.playerCode).writeUnsignedByte(player.pet).toByteArray())
  5760.  
  5761.  
  5762.  
  5763. if this.isSurvivorVamp:
  5764.  
  5765. reactor.callLater(5, this.sendVampireMode)
  5766.  
  5767.  
  5768.  
  5769. if this.isMulodrome:
  5770.  
  5771. this.mulodromeRoundCount += 1
  5772.  
  5773. this.sendMulodromeRound()
  5774.  
  5775.  
  5776.  
  5777. if this.mulodromeRoundCount <= 10:
  5778.  
  5779. for client in this.clients.values():
  5780.  
  5781. if client.Username in this.blueTeam:
  5782.  
  5783. this.setNameColor(client.Username, int("979EFF", 16))
  5784.  
  5785. else:
  5786.  
  5787. this.setNameColor(client.Username, int("FF9396", 16))
  5788.  
  5789. else:
  5790.  
  5791. this.sendAll(Identifiers.send.Mulodrome_End)
  5792.  
  5793.  
  5794.  
  5795. if this.isRacing or this.isDefilante:
  5796.  
  5797. this.roundsCount += 1
  5798.  
  5799. this.roundsCount %= 10
  5800.  
  5801. player = this.clients.get(this.getHighestScore())
  5802.  
  5803. this.sendAll(Identifiers.send.Rounds_Count, ByteArray().writeByte(this.roundsCount).writeInt(player.playerCode if player != None else 0).toByteArray())
  5804.  
  5805.  
  5806.  
  5807. this.startTimerLeft = reactor.callLater(3, this.startTimer)
  5808.  
  5809. this.closeRoomRoundJoinTimer = reactor.callLater(3, setattr, this, "isCurrentlyPlay", True)
  5810.  
  5811. if not this.isFixedMap and not this.isTribeHouse and not this.isTribeHouseMap:
  5812.  
  5813. this.changeMapTimer = reactor.callLater(this.roundTime + this.addTime, this.mapChange)
  5814.  
  5815.  
  5816.  
  5817. this.killAfkTimer = reactor.callLater(30, this.killAfk)
  5818.  
  5819. if this.autoRespawn or this.isTribeHouseMap:
  5820.  
  5821. this.autoRespawnTimer = reactor.callLater(2, this.respawnMice)
  5822.  
  5823.  
  5824.  
  5825. def getPlayerCount(this):
  5826.  
  5827. return len(filter(lambda player: not player.isHidden, this.clients.values()))
  5828.  
  5829.  
  5830.  
  5831. def getPlayerCountUnique(this):
  5832.  
  5833. ipList = []
  5834.  
  5835. for client in this.clients.values():
  5836.  
  5837. if not client.ipAddress in ipList:
  5838.  
  5839. ipList.append(client.ipAddress)
  5840.  
  5841. return len(ipList)
  5842.  
  5843.  
  5844.  
  5845. def getPlayerList(this):
  5846.  
  5847. result = []
  5848.  
  5849. for client in this.clients.values():
  5850.  
  5851. if not client.isHidden:
  5852.  
  5853. result.append(client.getPlayerData())
  5854.  
  5855. return result
  5856.  
  5857.  
  5858.  
  5859. def addClient(this, client):
  5860.  
  5861. this.clients[client.Username] = client
  5862.  
  5863.  
  5864.  
  5865. client.room = this
  5866.  
  5867. client.isDead = this.isCurrentlyPlay
  5868.  
  5869. this.sendAllOthers(client, Identifiers.old.send.Player_Respawn, [client.getPlayerData()])
  5870.  
  5871. client.startPlay()
  5872.  
  5873.  
  5874.  
  5875. def removeClient(this, client):
  5876.  
  5877. if client.Username in this.clients:
  5878.  
  5879. del this.clients[client.Username]
  5880.  
  5881. client.resetPlay()
  5882.  
  5883. client.playerScore = 0
  5884.  
  5885. client.sendPlayerDisconnect()
  5886.  
  5887.  
  5888.  
  5889. if this.isMulodrome:
  5890.  
  5891. if client.Username in this.redTeam: this.redTeam.remove(client.Username)
  5892.  
  5893. if client.Username in this.blueTeam: this.blueTeam.remove(client.Username)
  5894.  
  5895.  
  5896.  
  5897. if len(this.redTeam) == 0 and len(this.blueTeam) == 0:
  5898.  
  5899. this.mulodromeRoundCount = 10
  5900.  
  5901. this.sendMulodromeRound()
  5902.  
  5903.  
  5904.  
  5905. if len(this.clients) == 0:
  5906.  
  5907. for timer in [this.autoRespawnTimer, this.changeMapTimer, this.closeRoomRoundJoinTimer, this.endSnowTimer, this.killAfkTimer, this.voteCloseTimer]:
  5908.  
  5909. if timer != None:
  5910.  
  5911. timer.cancel()
  5912.  
  5913.  
  5914.  
  5915. this.isClosed = True
  5916.  
  5917. del this.server.rooms[this.name]
  5918.  
  5919. else:
  5920.  
  5921. if client.playerCode == this.currentSyncCode:
  5922.  
  5923. this.currentSyncCode = -1
  5924.  
  5925. this.currentSyncName = ""
  5926.  
  5927. this.getSyncCode()
  5928.  
  5929. for clientOnline in this.clients.values():
  5930.  
  5931. clientOnline.sendSync(this.currentSyncCode)
  5932.  
  5933. this.checkShouldChangeMap()
  5934.  
  5935.  
  5936.  
  5937. def checkShouldChangeMap(this):
  5938.  
  5939. if this.isBootcamp or this.autoRespawn or (this.isTribeHouse and this.isTribeHouseMap) or this.isFixedMap:
  5940.  
  5941. pass
  5942.  
  5943. else:
  5944.  
  5945. allDead = True
  5946.  
  5947. for client in this.clients.values():
  5948.  
  5949. if not client.isDead:
  5950.  
  5951. allDead = False
  5952.  
  5953.  
  5954.  
  5955. if allDead:
  5956.  
  5957. this.mapChange()
  5958.  
  5959.  
  5960.  
  5961. def sendAll(this, identifiers, packet=""):
  5962.  
  5963. for client in this.clients.values():
  5964.  
  5965. client.sendPacket(identifiers, packet)
  5966.  
  5967.  
  5968.  
  5969. def sendAllOthers(this, senderClient, identifiers, packet=""):
  5970.  
  5971. for client in this.clients.values():
  5972.  
  5973. if not client == senderClient:
  5974.  
  5975. client.sendPacket(identifiers, packet)
  5976.  
  5977.  
  5978.  
  5979. def sendAllChat(this, playerCode, playerName, message, LangueByte, isOnly):
  5980.  
  5981. p = ByteArray().writeInt(playerCode).writeUTF(playerName).writeByte(LangueByte).writeUTF(message)
  5982.  
  5983. if not isOnly:
  5984.  
  5985. for client in this.clients.values():
  5986.  
  5987. client.sendPacket(Identifiers.send.Chat_Message, p.toByteArray())
  5988.  
  5989. else:
  5990.  
  5991. client = this.clients.get(playerName)
  5992.  
  5993. if client != None:
  5994.  
  5995. client.sendPacket(Identifiers.send.Chat_Message, p.toByteArray())
  5996.  
  5997.  
  5998.  
  5999. def getSyncCode(this):
  6000.  
  6001. if this.getPlayerCount() > 0:
  6002.  
  6003. if this.currentSyncCode == -1:
  6004.  
  6005. players = this.clients
  6006.  
  6007. values = players.values()
  6008.  
  6009. client = random.choice(values)
  6010.  
  6011. this.currentSyncCode = client.playerCode
  6012.  
  6013. this.currentSyncName = client.Username
  6014.  
  6015. else:
  6016.  
  6017. if this.currentSyncCode == -1:
  6018.  
  6019. this.currentSyncCode = 0
  6020.  
  6021. this.currentSyncName = ""
  6022.  
  6023.  
  6024.  
  6025. return this.currentSyncCode
  6026.  
  6027.  
  6028.  
  6029. def selectMap(this):
  6030.  
  6031. if not this.forceNextMap == "-1":
  6032.  
  6033. force = this.forceNextMap
  6034.  
  6035. this.forceNextMap = "-1"
  6036.  
  6037. this.mapCode = -1
  6038.  
  6039.  
  6040.  
  6041. if force.isdigit():
  6042.  
  6043. return this.selectMapSpecificic(force, "Vanilla")
  6044.  
  6045. elif force.startswith("@"):
  6046.  
  6047. return this.selectMapSpecificic(force[1:], "Custom")
  6048.  
  6049. elif force.startswith("#"):
  6050.  
  6051. return this.selectMapSpecificic(force[1:], "Perm")
  6052.  
  6053. elif force.startswith("<"):
  6054.  
  6055. return this.selectMapSpecificic(force, "Xml")
  6056.  
  6057. else:
  6058.  
  6059. return 0
  6060.  
  6061.  
  6062.  
  6063. elif this.specificMap:
  6064.  
  6065. this.mapCode = -1
  6066.  
  6067. return this.currentMap
  6068.  
  6069. else:
  6070.  
  6071. if this.isEditeur:
  6072.  
  6073. return this.EMapCode
  6074.  
  6075.  
  6076.  
  6077. elif this.isTribeHouse:
  6078.  
  6079. tribeName = this.roomName[2:]
  6080.  
  6081. runMap = this.server.getTribeHouse(tribeName)
  6082.  
  6083.  
  6084.  
  6085. if runMap == 0:
  6086.  
  6087. this.mapCode = 0
  6088.  
  6089. this.mapName = "Tigrounette"
  6090.  
  6091. 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>"
  6092.  
  6093. this.mapYesVotes = 0
  6094.  
  6095. this.mapNoVotes = 0
  6096.  
  6097. this.mapPerma = 22
  6098.  
  6099. this.mapInverted = False
  6100.  
  6101. else:
  6102.  
  6103. run = this.selectMapSpecificic(runMap, "Custom")
  6104.  
  6105. if run != -1:
  6106.  
  6107. this.mapCode = 0
  6108.  
  6109. this.mapName = "Tigrounette"
  6110.  
  6111. 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>"
  6112.  
  6113. this.mapYesVotes = 0
  6114.  
  6115. this.mapNoVotes = 0
  6116.  
  6117. this.mapPerma = 22
  6118.  
  6119. this.mapInverted = False
  6120.  
  6121.  
  6122.  
  6123. elif this.is801Room or this.isVillage:
  6124.  
  6125. this.getMap801(801, "_Atelier 801")
  6126.  
  6127.  
  6128.  
  6129. elif this.isVanilla:
  6130.  
  6131. this.mapCode = -1
  6132.  
  6133. this.mapName = "Invalid";
  6134.  
  6135. this.mapXML = "<C><P /><Z><S /><D /><O /></Z></C>"
  6136.  
  6137. this.mapYesVotes = 0
  6138.  
  6139. this.mapNoVotes = 0
  6140.  
  6141. this.mapPerma = -1
  6142.  
  6143. this.mapInverted = False
  6144.  
  6145. map = random.choice(this.MapList)
  6146.  
  6147. while map == this.currentMap:
  6148.  
  6149. map = random.choice(this.MapList)
  6150.  
  6151. return map
  6152.  
  6153.  
  6154.  
  6155. else:
  6156.  
  6157. this.mapCode = -1
  6158.  
  6159. this.mapName = "Invalid";
  6160.  
  6161. this.mapXML = "<C><P /><Z><S /><D /><O /></Z></C>"
  6162.  
  6163. this.mapYesVotes = 0
  6164.  
  6165. this.mapNoVotes = 0
  6166.  
  6167. this.mapPerma = -1
  6168.  
  6169. this.mapInverted = False
  6170.  
  6171. return this.selectMapStatus(this.mapStatus)
  6172.  
  6173. return -1
  6174.  
  6175.  
  6176.  
  6177. def selectMapStatus(this, mapStatus):
  6178.  
  6179. customMaps = [0, -1, 4, 9, 5, 0, -1, 8, 6, 7]
  6180.  
  6181. mapList = []
  6182.  
  6183.  
  6184.  
  6185. if this.isVanilla:
  6186.  
  6187. map = random.choice(this.MapList)
  6188.  
  6189. while map == this.currentMap:
  6190.  
  6191. map = random.choice(this.MapList)
  6192.  
  6193. return map
  6194.  
  6195.  
  6196.  
  6197. elif this.isMusic:
  6198.  
  6199. if this.musicMapStatus == 5:
  6200.  
  6201. this.Cursor.execute("select Code from MapEditor where Perma = 19 ORDER BY RANDOM() LIMIT 1")
  6202.  
  6203. r = this.Cursor.fetchall()
  6204.  
  6205. for rs in r:
  6206.  
  6207. mapList.append(rs[0])
  6208.  
  6209.  
  6210.  
  6211. elif this.isUtility:
  6212.  
  6213. this.Cursor.execute("select Code from MapEditor where Perma = 45 ORDER BY RANDOM() LIMIT 1")
  6214.  
  6215. r = this.Cursor.fetchall()
  6216.  
  6217. for rs in r:
  6218.  
  6219. mapList.append(rs[0])
  6220.  
  6221.  
  6222.  
  6223. elif this.isRacing:
  6224.  
  6225. this.Cursor.execute("select Code from MapEditor where Perma = 17 ORDER BY RANDOM() LIMIT 1")
  6226.  
  6227. r = this.Cursor.fetchall()
  6228.  
  6229. for rs in r:
  6230.  
  6231. mapList.append(rs[0])
  6232.  
  6233.  
  6234.  
  6235. elif this.isBootcamp:
  6236.  
  6237. P3List = []
  6238.  
  6239. P13List = []
  6240.  
  6241.  
  6242.  
  6243. this.Cursor.execute("select Code, Perma from MapEditor where Perma = 3 or Perma = 13 ORDER BY RANDOM() LIMIT 1")
  6244.  
  6245. r = this.Cursor.fetchall()
  6246.  
  6247. for rs in r:
  6248.  
  6249. perma = rs[1]
  6250.  
  6251. if perma == 3:
  6252.  
  6253. P3List.append(rs[0])
  6254.  
  6255. else:
  6256.  
  6257. P13List.append(rs[0])
  6258.  
  6259.  
  6260.  
  6261. if this.isBootcampP13:
  6262.  
  6263. mapList = P3List if len(P13List) == 0 else P13List
  6264.  
  6265. else:
  6266.  
  6267. mapList = P13List if len(P3List) == 0 else P3List
  6268.  
  6269.  
  6270.  
  6271. elif this.isSurvivor:
  6272.  
  6273. this.isSurvivorVamp = this.survivorMapStatus == 10
  6274.  
  6275.  
  6276.  
  6277. this.Cursor.execute("select Code from MapEditor where Perma = ?", [11 if this.isSurvivorVamp else 10])
  6278.  
  6279. r = this.Cursor.fetchall()
  6280.  
  6281. for rs in r:
  6282.  
  6283. mapList.append(rs[0])
  6284.  
  6285.  
  6286.  
  6287. elif this.isDefilante:
  6288.  
  6289. this.Cursor.execute("select Code from MapEditor where Perma = 18 ORDER BY RANDOM() LIMIT 1")
  6290.  
  6291. r = this.Cursor.fetchall()
  6292.  
  6293. for rs in r:
  6294.  
  6295. mapList.append(rs[0])
  6296.  
  6297.  
  6298.  
  6299. elif mapStatus in customMaps:
  6300.  
  6301. multiple = False
  6302.  
  6303. selectCode = 0
  6304.  
  6305.  
  6306.  
  6307. if mapStatus == 1 or mapStatus == 9:
  6308.  
  6309. multiple = True
  6310.  
  6311. elif mapStatus == 2:
  6312.  
  6313. selectCode = 5
  6314.  
  6315. elif mapStatus == 3:
  6316.  
  6317. selectCode = 9
  6318.  
  6319. elif mapStatus == 5 or mapStatus == 11:
  6320.  
  6321. selectCode = 6
  6322.  
  6323. elif mapStatus == 6:
  6324.  
  6325. selectCode = 7
  6326.  
  6327. elif mapStatus == 7:
  6328.  
  6329. selectCode = 8
  6330.  
  6331. elif mapStatus == 10:
  6332.  
  6333. selectCode = 4
  6334.  
  6335.  
  6336.  
  6337. if multiple:
  6338.  
  6339. this.Cursor.execute("select Code from MapEditor where Perma = 0 ORDER BY RANDOM() LIMIT 1")
  6340.  
  6341. r = this.Cursor.fetchall()
  6342.  
  6343. for rs in r:
  6344.  
  6345. mapList.append(rs[0])
  6346.  
  6347.  
  6348.  
  6349. this.Cursor.execute("select Code from MapEditor where Perma = 1 ORDER BY RANDOM() LIMIT 1")
  6350.  
  6351. r = this.Cursor.fetchall()
  6352.  
  6353. for rs in r:
  6354.  
  6355. mapList.append(rs[0])
  6356.  
  6357. else:
  6358.  
  6359. this.Cursor.execute("select Code from MapEditor where Perma = ? ORDER BY RANDOM() LIMIT 1", [selectCode])
  6360.  
  6361. r = this.Cursor.fetchall()
  6362.  
  6363. for rs in r:
  6364.  
  6365. mapList.append(rs[0])
  6366.  
  6367. else:
  6368.  
  6369. map = random.choice(this.MapList)
  6370.  
  6371. while map == this.currentMap:
  6372.  
  6373. map = random.choice(this.MapList)
  6374.  
  6375. return map
  6376.  
  6377.  
  6378.  
  6379. if len(mapList) >= 1:
  6380.  
  6381. runMap = random.choice(mapList)
  6382.  
  6383. else:
  6384.  
  6385. runMap = 0
  6386.  
  6387.  
  6388.  
  6389. if len(mapList) >= 2:
  6390.  
  6391. while runMap == this.currentMap:
  6392.  
  6393. runMap = random.choice(mapList)
  6394.  
  6395.  
  6396.  
  6397. if runMap == 0:
  6398.  
  6399. map = random.choice(this.MapList)
  6400.  
  6401. while map == this.currentMap:
  6402.  
  6403. map = random.choice(this.MapList)
  6404.  
  6405. return map
  6406.  
  6407. else:
  6408.  
  6409. mapInfo = this.getMapInfo(runMap)
  6410.  
  6411. this.mapCode = runMap
  6412.  
  6413. this.mapName = str(mapInfo[0])
  6414.  
  6415. this.mapXML = str(mapInfo[1])
  6416.  
  6417. this.mapYesVotes = int(mapInfo[2])
  6418.  
  6419. this.mapNoVotes = int(mapInfo[3])
  6420.  
  6421. this.mapPerma = int(mapInfo[4])
  6422.  
  6423. this.mapInverted = random.randint(0, 100) > 85
  6424.  
  6425. return -1
  6426.  
  6427.  
  6428.  
  6429. def selectMapSpecificic(this, code, type):
  6430.  
  6431. if type == "Vanilla":
  6432.  
  6433. return int(code)
  6434.  
  6435.  
  6436.  
  6437. elif type == "Custom":
  6438.  
  6439. mapInfo = this.getMapInfo(int(code))
  6440.  
  6441. if mapInfo[0] == None:
  6442.  
  6443. return 0
  6444.  
  6445. else:
  6446.  
  6447. this.mapCode = int(code)
  6448.  
  6449. this.mapName = str(mapInfo[0])
  6450.  
  6451. this.mapXML = str(mapInfo[1])
  6452.  
  6453. this.mapYesVotes = int(mapInfo[2])
  6454.  
  6455. this.mapNoVotes = int(mapInfo[3])
  6456.  
  6457. this.mapPerma = int(mapInfo[4])
  6458.  
  6459. this.mapInverted = False
  6460.  
  6461. return -1
  6462.  
  6463.  
  6464.  
  6465. elif type == "Perm":
  6466.  
  6467. mapList = []
  6468.  
  6469. this.Cursor.execute("select Code from MapEditor where Perma = ? ORDER BY RANDOM() LIMIT 1", [int(str(code))])
  6470.  
  6471. r = this.Cursor.fetchall()
  6472.  
  6473. for rs in r:
  6474.  
  6475. mapList.append(rs["Code"])
  6476.  
  6477.  
  6478.  
  6479. if len(mapList) >= 1:
  6480.  
  6481. runMap = random.choice(mapList)
  6482.  
  6483. else:
  6484.  
  6485. runMap = 0
  6486.  
  6487.  
  6488.  
  6489. if len(mapList) >= 2:
  6490.  
  6491. while runMap == this.currentMap:
  6492.  
  6493. runMap = random.choice(mapList)
  6494.  
  6495.  
  6496.  
  6497. if runMap == 0:
  6498.  
  6499. map = random.choice(this.MapList)
  6500.  
  6501. while map == this.currentMap:
  6502.  
  6503. map = random.choice(this.MapList)
  6504.  
  6505. return map
  6506.  
  6507. else:
  6508.  
  6509. mapInfo = this.getMapInfo(runMap)
  6510.  
  6511. this.mapCode = runMap
  6512.  
  6513. this.mapName = str(mapInfo[0])
  6514.  
  6515. this.mapXML = str(mapInfo[1])
  6516.  
  6517. this.mapYesVotes = int(mapInfo[2])
  6518.  
  6519. this.mapNoVotes = int(mapInfo[3])
  6520.  
  6521. this.mapPerma = int(mapInfo[4])
  6522.  
  6523. this.mapInverted = False
  6524.  
  6525. return -1
  6526.  
  6527.  
  6528.  
  6529. elif type == "Xml":
  6530.  
  6531. this.mapCode = 0
  6532.  
  6533. this.mapName = "#Module"
  6534.  
  6535. this.mapXML = str(code)
  6536.  
  6537. this.mapYesVotes = 0
  6538.  
  6539. this.mapNoVotes = 0
  6540.  
  6541. this.mapPerma = 22
  6542.  
  6543. this.mapInverted = False
  6544.  
  6545. return -1
  6546.  
  6547.  
  6548.  
  6549. def getMapInfo(this, mapCode):
  6550.  
  6551. mapInfo = ["", "", 0, 0, 0]
  6552.  
  6553. this.Cursor.execute("select Name, XML, YesVotes, NoVotes, Perma from MapEditor where Code = ? ORDER BY RANDOM() LIMIT 1", [mapCode])
  6554.  
  6555. rs = this.Cursor.fetchone()
  6556.  
  6557. if rs:
  6558.  
  6559. mapInfo = rs["Name"], rs["XML"], rs["YesVotes"], rs["NoVotes"], rs["Perma"]
  6560.  
  6561.  
  6562.  
  6563. return mapInfo
  6564.  
  6565.  
  6566.  
  6567. def checkIfTooFewRemaining(this):
  6568.  
  6569. return len(filter(lambda player: not player.isDead, this.clients.values())) <= 2
  6570.  
  6571.  
  6572.  
  6573. def getAliveCount(this):
  6574.  
  6575. return len(filter(lambda player: not player.isDead, this.clients.values()))
  6576.  
  6577.  
  6578.  
  6579. def getDeathCountNoShaman(this):
  6580.  
  6581. return len(filter(lambda player: not player.isShaman and not player.isDead and not player.isNewPlayer, this.clients.values()))
  6582.  
  6583.  
  6584.  
  6585. def getHighestScore(this):
  6586.  
  6587. scores = []
  6588.  
  6589.  
  6590.  
  6591. for client in this.clients.values():
  6592.  
  6593. scores.append(client.playerScore)
  6594.  
  6595.  
  6596.  
  6597. try:
  6598.  
  6599. for client in this.clients.values():
  6600.  
  6601. if client.playerScore == max(scores):
  6602.  
  6603. return client.playerCode
  6604.  
  6605. except: pass
  6606.  
  6607. return 0
  6608.  
  6609.  
  6610.  
  6611. def getSecondHighestScore(this):
  6612.  
  6613. scores = []
  6614.  
  6615.  
  6616.  
  6617. for client in this.clients.values():
  6618.  
  6619. scores.append(client.playerScore)
  6620.  
  6621.  
  6622.  
  6623. scores.remove(max(scores))
  6624.  
  6625.  
  6626.  
  6627. try:
  6628.  
  6629. for client in this.clients.values():
  6630.  
  6631. if client.playerScore == max(scores):
  6632.  
  6633. return client.playerCode
  6634.  
  6635. except: pass
  6636.  
  6637. return 0
  6638.  
  6639.  
  6640.  
  6641. def getShamanCode(this):
  6642.  
  6643. if this.currentShamanCode == -1:
  6644.  
  6645. if this.currentMap in this.noShamanMaps or this.isNoShamanMap:
  6646.  
  6647. pass
  6648.  
  6649. elif this.noShaman or (this.survivorMapStatus == 7 and this.isSurvivor):
  6650.  
  6651. pass
  6652.  
  6653. else:
  6654.  
  6655. if this.forceNextShaman > 0:
  6656.  
  6657. this.currentShamanCode = this.forceNextShaman
  6658.  
  6659. this.forceNextShaman = 0
  6660.  
  6661. else:
  6662.  
  6663. this.currentShamanCode = this.getHighestScore()
  6664.  
  6665.  
  6666.  
  6667. if this.currentShamanCode == -1:
  6668.  
  6669. this.currentShamanName = ""
  6670.  
  6671. else:
  6672.  
  6673. for client in this.clients.values():
  6674.  
  6675. if client.playerCode == this.currentShamanCode:
  6676.  
  6677. this.currentShamanName = client.Username
  6678.  
  6679. this.currentShamanType = client.shamanType
  6680.  
  6681. this.currentShamanSkills = client.playerSkills
  6682.  
  6683. break
  6684.  
  6685. return this.currentShamanCode
  6686.  
  6687.  
  6688.  
  6689. def getDoubleShamanCode(this):
  6690.  
  6691. if this.currentShamanCode == -1 and this.currentSecondShamanCode == -1:
  6692.  
  6693. if this.forceNextShaman > 0:
  6694.  
  6695. this.currentShamanCode = this.forceNextShaman
  6696.  
  6697. this.forceNextShaman = 0
  6698.  
  6699. else:
  6700.  
  6701. this.currentShamanCode = this.getHighestScore()
  6702.  
  6703.  
  6704.  
  6705. if this.currentSecondShamanCode == -1:
  6706.  
  6707. this.currentSecondShamanCode = this.getSecondHighestScore()
  6708.  
  6709.  
  6710.  
  6711. if this.currentSecondShamanCode == this.currentShamanCode:
  6712.  
  6713. values = this.clients.values()
  6714.  
  6715. tempClient = random.choice(values)
  6716.  
  6717. this.currentSecondShamanCode = tempClient.playerCode
  6718.  
  6719.  
  6720.  
  6721. for client in this.clients.values():
  6722.  
  6723. if client.playerCode == this.currentShamanCode:
  6724.  
  6725. this.currentShamanName = client.Username
  6726.  
  6727. this.currentShamanType = client.shamanType
  6728.  
  6729. this.currentShamanSkills = client.playerSkills
  6730.  
  6731. break
  6732.  
  6733.  
  6734.  
  6735. if client.playerCode == this.currentSecondShamanCode:
  6736.  
  6737. this.currentSecondShamanName = client.Username
  6738.  
  6739. this.currentSecondShamanType = client.shamanType
  6740.  
  6741. this.currentSecondShamanSkills = client.playerSkills
  6742.  
  6743. break
  6744.  
  6745.  
  6746.  
  6747. return [this.currentShamanCode, this.currentSecondShamanCode]
  6748.  
  6749.  
  6750.  
  6751. def closeVoting(this):
  6752.  
  6753. this.initVotingMode = False
  6754.  
  6755. this.isVotingBox = False
  6756.  
  6757. if this.voteCloseTimer != None: this.voteCloseTimer.cancel()
  6758.  
  6759. this.mapChange()
  6760.  
  6761.  
  6762.  
  6763. def killAllNoDie(this):
  6764.  
  6765. for client in this.clients.values():
  6766.  
  6767. if not client.isDead:
  6768.  
  6769. client.isDead = True
  6770.  
  6771. this.checkShouldChangeMap()
  6772.  
  6773.  
  6774.  
  6775. def killAll(this):
  6776.  
  6777. for client in this.clients.values():
  6778.  
  6779. if not client.isDead:
  6780.  
  6781. client.sendPlayerDied()
  6782.  
  6783. client.isDead = True
  6784.  
  6785. this.checkShouldChangeMap()
  6786.  
  6787.  
  6788.  
  6789. def killShaman(this):
  6790.  
  6791. for client in this.clients.values():
  6792.  
  6793. if client.playerCode == this.currentShamanCode:
  6794.  
  6795. client.isDead = True
  6796.  
  6797. client.sendPlayerDied()
  6798.  
  6799. this.checkShouldChangeMap()
  6800.  
  6801.  
  6802.  
  6803. def killAfk(this):
  6804.  
  6805. if not this.isEditeur or not this.isTotemEditeur or not this.isBootcamp or not this.isTribeHouseMap or not this.disableAfkKill:
  6806.  
  6807. if ((TFMUtils.getTime() - this.gameStartTime) < 32 and (TFMUtils.getTime() - this.gameStartTime) > 28):
  6808.  
  6809. for client in this.clients.values():
  6810.  
  6811. if not client.isDead and client.isAfk:
  6812.  
  6813. client.isDead = True
  6814.  
  6815. if not this.noAutoScore: client.playerScore += 1
  6816.  
  6817. client.sendPlayerDied()
  6818.  
  6819. this.checkShouldChangeMap()
  6820.  
  6821.  
  6822.  
  6823. def checkIfDoubleShamansAreDead(this):
  6824.  
  6825. client1 = this.clients.get(this.currentShamanName)
  6826.  
  6827. client2 = this.clients.get(this.currentSecondShamanName)
  6828.  
  6829. return (False if client1 == None else client1.isDead) and (False if client2 == None else client2.isDead)
  6830.  
  6831.  
  6832.  
  6833. def checkIfShamanIsDead(this):
  6834.  
  6835. client = this.clients.get(this.currentShamanName)
  6836.  
  6837. return False if client == None else client.isDead
  6838.  
  6839.  
  6840.  
  6841. def checkIfShamanCanGoIn(this):
  6842.  
  6843. for client in this.clients.values():
  6844.  
  6845. if client.playerCode != this.currentShamanCode and client.playerCode != this.currentSecondShamanCode and not client.isDead:
  6846.  
  6847. return False
  6848.  
  6849. return True
  6850.  
  6851.  
  6852.  
  6853. def giveShamanSave(this, shamanName, type):
  6854.  
  6855. if not this.countStats:
  6856.  
  6857. return
  6858.  
  6859.  
  6860.  
  6861. client = this.clients.get(shamanName)
  6862.  
  6863. if client != None:
  6864.  
  6865. if type == 0:
  6866.  
  6867. client.shamanSaves += 1
  6868.  
  6869. elif type == 1:
  6870.  
  6871. client.hardModeSaves += 1
  6872.  
  6873. elif type == 2:
  6874.  
  6875. client.divineModeSaves += 1
  6876.  
  6877. if client.privLevel != 0:
  6878.  
  6879. counts = [client.shamanSaves, client.hardModeSaves, client.divineModeSaves]
  6880.  
  6881. titles = [this.server.shamanTitleList, this.server.hardModeTitleList, this.server.divineModeTitleList]
  6882.  
  6883. rebuilds = ["shaman", "hardmode", "divinemode"]
  6884.  
  6885. if titles[type].has_key(counts[type]):
  6886.  
  6887. title = titles[type][counts[type]]
  6888.  
  6889. client.checkAndRebuildTitleList(rebuilds[type])
  6890.  
  6891. client.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  6892.  
  6893. client.sendCompleteTitleList()
  6894.  
  6895. client.sendTitleList()
  6896.  
  6897.  
  6898.  
  6899. def respawnMice(this):
  6900.  
  6901. for client in this.clients.values():
  6902.  
  6903. if client.isDead:
  6904.  
  6905. client.isDead = False
  6906.  
  6907. client.playerStartTimeMillis = time.time()
  6908.  
  6909. this.sendAll(Identifiers.old.send.Player_Respawn, [client.getPlayerData(), 0 if this.isBootcamp and this.isUtility else 1])
  6910.  
  6911.  
  6912.  
  6913. if this.autoRespawn or this.isTribeHouseMap:
  6914.  
  6915. this.autoRespawnTimer = reactor.callLater(2, this.respawnMice)
  6916.  
  6917.  
  6918.  
  6919. def respawnSpecific(this, playerName, isResetPlay=False):
  6920.  
  6921. client = this.clients.get(playerName)
  6922.  
  6923. if client != None and client.isDead:
  6924.  
  6925. client.resetPlay(isResetPlay)
  6926.  
  6927. client.isAfk = False
  6928.  
  6929. client.playerStartTimeMillis = time.time()
  6930.  
  6931. this.sendAll(Identifiers.old.send.Player_Respawn, [client.getPlayerData(), 0 if this.isBootcamp else 1])
  6932.  
  6933.  
  6934.  
  6935. def sendMulodromeRound(this):
  6936.  
  6937. this.sendAll(Identifiers.send.Mulodrome_Result, ByteArray().writeByte(this.mulodromeRoundCount).writeShort(this.blueCount).writeShort(this.redCount).toByteArray())
  6938.  
  6939. if this.mulodromeRoundCount > 10:
  6940.  
  6941. this.sendAll(Identifiers.send.Mulodrome_End, "")
  6942.  
  6943. this.sendAll(Identifiers.send.Mulodrome_Winner, ByteArray().writeByte(2 if this.blueCount == this.redCount else (1 if this.blueCount < this.redCount else 0)).writeShort(this.blueCount).writeShort(this.redCount).toByteArray())
  6944.  
  6945. this.isMulodrome = False
  6946.  
  6947. this.mulodromeRoundCount = 0
  6948.  
  6949. this.redCount = 0
  6950.  
  6951. this.blueCount = 0
  6952.  
  6953. this.redTeam = []
  6954.  
  6955. this.blueTeam = []
  6956.  
  6957. this.isRacing = False
  6958.  
  6959. this.mapStatus = 1
  6960.  
  6961. this.never20secTimer = False
  6962.  
  6963. this.noShaman = False
  6964.  
  6965.  
  6966.  
  6967. def checkVanillaXML(this):
  6968.  
  6969. try:
  6970.  
  6971. with open("./include/vanilla/"+str(this.currentMap)+".xml", "r") as f:
  6972.  
  6973. XML = f.read()
  6974.  
  6975. f.close()
  6976.  
  6977.  
  6978.  
  6979. this.mapCode = int(this.currentMap)
  6980.  
  6981. this.mapName = "Transformice"
  6982.  
  6983. this.mapXML = str(XML)
  6984.  
  6985. this.mapYesVotes = 0
  6986.  
  6987. this.mapNoVotes = 0
  6988.  
  6989. this.mapPerma = 2
  6990.  
  6991. this.currentMap = -1
  6992.  
  6993. this.mapInverted = False
  6994.  
  6995. except: pass
  6996.  
  6997.  
  6998.  
  6999. def getMap801(this, code, name):
  7000.  
  7001. try:
  7002.  
  7003. with open("./include/vanilla/801.xml", "r") as f:
  7004.  
  7005. XML = f.read()
  7006.  
  7007. f.close()
  7008.  
  7009.  
  7010.  
  7011. this.mapCode = code
  7012.  
  7013. this.mapName = name
  7014.  
  7015. this.mapXML = str(XML)
  7016.  
  7017. this.mapYesVotes = 0
  7018.  
  7019. this.mapNoVotes = 0
  7020.  
  7021. this.mapPerma = 41
  7022.  
  7023. this.currentMap = -1
  7024.  
  7025. this.mapInverted = False
  7026.  
  7027. except: pass
  7028.  
  7029.  
  7030.  
  7031. def sendVampireMode(this):
  7032.  
  7033. client = this.clients.get(this.currentSyncName)
  7034.  
  7035. if client != None:
  7036.  
  7037. client.sendVampireMode(False)
  7038.  
  7039.  
  7040.  
  7041. def bindKeyBoard(this, playerName, key, down, yes):
  7042.  
  7043. client = this.clients.get(playerName)
  7044.  
  7045. if client != None:
  7046.  
  7047. client.sendPacket(Identifiers.send.Bind_Key_Board, ByteArray().writeShort(key).writeBool(down).writeBool(yes).toByteArray())
  7048.  
  7049.  
  7050.  
  7051. def addPhysicObject(this, id, x, y, bodyDef):
  7052.  
  7053. this.sendAll(Identifiers.send.Add_Physic_Object, ByteArray().writeShort(id).writeBool(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).writeBool(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).writeBool(bodyDef.has_key("color")).writeInt(int(bodyDef["color"]) if bodyDef.has_key("color") else 0).writeBool(bool(bodyDef["miceCollision"]) if bodyDef.has_key("miceCollision") else True).writeBool(bool(bodyDef["groundCollision"]) if bodyDef.has_key("groundCollision") else True).writeBool(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).writeBool(False).writeUTF("").toByteArray())
  7054.  
  7055.  
  7056.  
  7057. def chatMessage(this, message, playerName):
  7058.  
  7059. p = ByteArray().writeUTF(message)
  7060.  
  7061. if playerName == "":
  7062.  
  7063. this.sendAll(Identifiers.send.Message, p.toByteArray())
  7064.  
  7065. else:
  7066.  
  7067. client = this.clients.get(playerName)
  7068.  
  7069. if client != None:
  7070.  
  7071. client.sendPacket(Identifiers.send.Message, p.toByteArray())
  7072.  
  7073.  
  7074.  
  7075. def removeObject(this, objectId):
  7076.  
  7077. this.sendAll(Identifiers.send.Remove_Object, ByteArray().writeInt(objectId).writeBool(True).toByteArray())
  7078.  
  7079.  
  7080.  
  7081. def movePlayer(this, playerName, xPosition, yPosition, pOffSet, xSpeed, ySpeed, sOffSet):
  7082.  
  7083. client = this.clients.get(playerName)
  7084.  
  7085. if client != None:
  7086.  
  7087. client.sendPacket(Identifiers.send.Move_Player, ByteArray().writeShort(xPosition).writeShort(yPosition).writeBool(pOffSet).writeShort(xSpeed).writeShort(ySpeed).writeBool(sOffSet).toByteArray())
  7088.  
  7089.  
  7090.  
  7091. def setNameColor(this, playerName, color):
  7092.  
  7093. if this.clients.has_key(playerName):
  7094.  
  7095. this.sendAll(Identifiers.send.Set_Name_Color, ByteArray().writeInt(this.clients.get(playerName).playerCode).writeInt(color).toByteArray())
  7096.  
  7097.  
  7098.  
  7099. def bindMouse(this, playerName, yes):
  7100.  
  7101. client = this.clients.get(playerName)
  7102.  
  7103. if client != None:
  7104.  
  7105. client.sendPacket(Identifiers.send.Bind_Mouse, ByteArray().writeBool(yes).toByteArray())
  7106.  
  7107.  
  7108.  
  7109. def addPopup(this, id, type, text, targetPlayer, x, y, width, fixedPos):
  7110.  
  7111. p = ByteArray().writeInt(id).writeByte(type).writeUTF(text).writeShort(x).writeShort(y).writeShort(width).writeBool(fixedPos)
  7112.  
  7113. if targetPlayer == "":
  7114.  
  7115. this.sendAll(Identifiers.send.Add_Popup, p.toByteArray())
  7116.  
  7117. else:
  7118.  
  7119. player = this.clients.get(targetPlayer)
  7120.  
  7121. if player != None:
  7122.  
  7123. player.sendPacket(Identifiers.send.Add_Popup, p.toByteArray())
  7124.  
  7125.  
  7126.  
  7127. def addTextArea(this, id, text, targetPlayer, x, y, width, height, backgroundColor, borderColor, backgroundAlpha, fixedPos):
  7128.  
  7129. 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).writeBool(fixedPos)
  7130.  
  7131. if targetPlayer == "":
  7132.  
  7133. this.sendAll(Identifiers.send.Add_Text_Area, p.toByteArray())
  7134.  
  7135. else:
  7136.  
  7137. client = this.clients.get(targetPlayer)
  7138.  
  7139. if client != None:
  7140.  
  7141. client.sendPacket(Identifiers.send.Add_Text_Area, p.toByteArray())
  7142.  
  7143.  
  7144.  
  7145. def removeTextArea(this, id, targetPlayer):
  7146.  
  7147. p = ByteArray().writeInt(id)
  7148.  
  7149. if targetPlayer == "":
  7150.  
  7151. this.sendAll(Identifiers.send.Remove_Text_Area, p.toByteArray())
  7152.  
  7153. else:
  7154.  
  7155. client = this.clients.get(targetPlayer)
  7156.  
  7157. if client != None:
  7158.  
  7159. client.sendPacket(Identifiers.send.Remove_Text_Area, p.toByteArray())
  7160.  
  7161.  
  7162.  
  7163. def updateTextArea(this, id, text, targetPlayer):
  7164.  
  7165. p = ByteArray().writeInt(id).writeUTF(text)
  7166.  
  7167. if targetPlayer == "":
  7168.  
  7169. this.sendAll(Identifiers.send.Update_Text_Area, p.toByteArray())
  7170.  
  7171. else:
  7172.  
  7173. client = this.clients.get(targetPlayer)
  7174.  
  7175. if client != None:
  7176.  
  7177. client.sendPacket(Identifiers.send.Update_Text_Area, p.toByteArray())
  7178.  
  7179.  
  7180.  
  7181. def showColorPicker(this, id, targetPlayer, defaultColor, title):
  7182.  
  7183. p = ByteArray().writeInt(id).writeInt(defaultColor).writeUTF(title)
  7184.  
  7185. if targetPlayer == "":
  7186.  
  7187. this.sendAll(Identifiers.send.Show_Color_Picker, p.toByteArray())
  7188.  
  7189. else:
  7190.  
  7191. client = this.clients.get(targetPlayer)
  7192.  
  7193. if client != None:
  7194.  
  7195. client.sendPacket(Identifiers.send.Show_Color_Picker, p.toByteArray())
  7196.  
  7197.  
  7198.  
  7199. def startSnowSchedule(this, power):
  7200.  
  7201. if this.isSnowing:
  7202.  
  7203. this.startSnow(0, power, False)
  7204.  
  7205.  
  7206.  
  7207. def startSnow(this, millis, power, enabled):
  7208.  
  7209. this.isSnowing = enabled
  7210.  
  7211. this.sendAll(Identifiers.send.Snow, ByteArray().writeBool(enabled).writeShort(power).toByteArray())
  7212.  
  7213. if enabled:
  7214.  
  7215. this.endSnowTimer = reactor.callLater(millis, lambda: this.startSnowSchedule(power))
  7216.  
  7217.  
  7218.  
  7219. def giveSurvivorStats(this):
  7220.  
  7221. for client in this.clients.values():
  7222.  
  7223. if not client.isNewPlayer:
  7224.  
  7225. client.survivorStats[0] += 1
  7226.  
  7227. if client.isShaman:
  7228.  
  7229. client.survivorStats[1] += 1
  7230.  
  7231. client.survivorStats[2] += this.getDeathCountNoShaman()
  7232.  
  7233. elif not client.isDead:
  7234.  
  7235. client.survivorStats[3] += 1
  7236.  
  7237.  
  7238.  
  7239. if client.survivorStats[0] >= 1000 and not str(120) in client.shopBadges:
  7240.  
  7241. client.shopModule.sendUnlockedBadge(str(120))
  7242.  
  7243. client.shopBadges.append(str(120))
  7244.  
  7245. client.shopModule.checkAndRebuildBadges()
  7246.  
  7247.  
  7248.  
  7249. if client.survivorStats[1] >= 800 and not str(121) in client.shopBadges:
  7250.  
  7251. client.shopModule.sendUnlockedBadge(str(121))
  7252.  
  7253. client.shopBadges.append(str(121))
  7254.  
  7255. client.shopModule.checkAndRebuildBadges()
  7256.  
  7257.  
  7258.  
  7259. if client.survivorStats[2] >= 20000 and not str(122) in client.shopBadges:
  7260.  
  7261. client.shopModule.sendUnlockedBadge(str(122))
  7262.  
  7263. client.shopBadges.append(str(122))
  7264.  
  7265. client.shopModule.checkAndRebuildBadges()
  7266.  
  7267.  
  7268.  
  7269. if client.survivorStats[3] >= 10000 and not str(123) in client.shopBadges:
  7270.  
  7271. client.shopModule.sendUnlockedBadge(str(123))
  7272.  
  7273. client.shopBadges.append(str(123))
  7274.  
  7275. client.shopModule.checkAndRebuildBadges()
  7276.  
  7277.  
  7278.  
  7279. def giveRacingStats(this):
  7280.  
  7281. for client in this.clients.values():
  7282.  
  7283. if not client.isNewPlayer:
  7284.  
  7285. client.racingStats[0] += 1
  7286.  
  7287. if client.hasCheese or client.hasEnter:
  7288.  
  7289. client.racingStats[1] += 1
  7290.  
  7291.  
  7292.  
  7293. if client.hasEnter:
  7294.  
  7295. if client.currentPlace <= 3:
  7296.  
  7297. client.racingStats[2] += 1
  7298.  
  7299.  
  7300.  
  7301. if client.currentPlace == 1:
  7302.  
  7303. client.racingStats[3] += 1
  7304.  
  7305.  
  7306.  
  7307. if client.racingStats[0] >= 1500 and not str(124) in client.shopBadges:
  7308.  
  7309. client.shopModule.sendUnlockedBadge(str(124))
  7310.  
  7311. client.shopBadges.append(str(124))
  7312.  
  7313. client.shopModule.checkAndRebuildBadges()
  7314.  
  7315.  
  7316.  
  7317. if client.racingStats[1] >= 10000 and not str(125) in client.shopBadges:
  7318.  
  7319. client.shopModule.sendUnlockedBadge(str(125))
  7320.  
  7321. client.shopBadges.append(str(125))
  7322.  
  7323. client.shopModule.checkAndRebuildBadges()
  7324.  
  7325.  
  7326.  
  7327. if client.racingStats[2] >= 10000 and not str(127) in client.shopBadges:
  7328.  
  7329. client.shopModule.sendUnlockedBadge(str(127))
  7330.  
  7331. client.shopBadges.append(str(127))
  7332.  
  7333. client.shopModule.checkAndRebuildBadges()
  7334.  
  7335.  
  7336.  
  7337. if client.racingStats[3] >= 10000 and not str(126) in client.shopBadges:
  7338.  
  7339. client.shopModule.sendUnlockedBadge(str(126))
  7340.  
  7341. client.shopBadges.append(str(126))
  7342.  
  7343. client.shopModule.checkAndRebuildBadges()
  7344.  
  7345.  
  7346.  
  7347. def send20SecRemainingTimer(this):
  7348.  
  7349. if not this.changed20secTimer:
  7350.  
  7351. if not this.never20secTimer and this.roundTime + (this.gameStartTime - TFMUtils.getTime()) > 21:
  7352.  
  7353. this.changed20secTimer = True
  7354.  
  7355. this.changeMapTimers(20)
  7356.  
  7357. for client in this.clients.values():
  7358.  
  7359. client.sendRoundTime(20)
  7360.  
  7361.  
  7362.  
  7363. def changeMapTimers(this, seconds):
  7364.  
  7365. if this.changeMapTimer != None: this.changeMapTimer.cancel()
  7366.  
  7367. this.changeMapTimer = reactor.callLater(seconds, this.mapChange)
  7368.  
  7369.  
  7370.  
  7371. def newConsumableTimer(this, code):
  7372.  
  7373. this.roomTimers.append(reactor.callLater(10, lambda: this.sendAll(Identifiers.send.Remove_Object, ByteArray().writeInt(code).writeBool(False).toByteArray())))
  7374.  
  7375.  
  7376.  
  7377. if __name__ == "__main__":
  7378.  
  7379. # Connection Settings
  7380.  
  7381. Config = ConfigParser.ConfigParser()
  7382.  
  7383. Config.read("./include/Config.ini")
  7384.  
  7385.  
  7386.  
  7387. # Connection Database
  7388.  
  7389. Database, Cursor = None, None
  7390.  
  7391. Database = sqlite3.connect("./database/Transformice.db", check_same_thread = False)
  7392.  
  7393. Database.text_factory = str
  7394.  
  7395. Database.isolation_level = None
  7396.  
  7397. Database.row_factory = sqlite3.Row
  7398.  
  7399. Cursor = Database.cursor()
  7400.  
  7401.  
  7402.  
  7403. # Connection Server
  7404.  
  7405. validPorts = []
  7406.  
  7407. TFM = Server()
  7408.  
  7409. for port in [443, 44440, 44444, 5555, 3724, 6112]:
  7410.  
  7411. try:
  7412.  
  7413. reactor.listenTCP(port, TFM)
  7414.  
  7415. validPorts.append(port)
  7416.  
  7417. except:
  7418.  
  7419. print "It was not possible to connect to the port: " + str(port)
  7420.  
  7421.  
  7422.  
  7423. if not validPorts == []:
  7424.  
  7425. print "Server running on ports: " + str(validPorts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement