Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 177.10 KB | None | 0 0
  1. #coding: utf-8
  2. import os, sys, json, time, random, ftplib, sqlite3, threading, urllib2, binascii, traceback, ConfigParser
  3.  
  4. # Compiler Files
  5. sys.dont_write_bytecode = True
  6.  
  7. # Modules
  8. from modules import *
  9.  
  10. # Utils
  11. from utils import *
  12.  
  13. # Library
  14. from twisted.internet import reactor, protocol
  15. from datetime import datetime
  16.  
  17. from datetime import timedelta
  18.  
  19. class Client(ClientHandler):
  20. def __init__(this):
  21. # String
  22. this.Username = ""
  23. this.Langue = "BR"
  24. this.realLangue = "BR"
  25. this.MouseColor = "78583a"
  26. this.ShamanColor = "95d9d6"
  27. this.roomName = ""
  28. this.shopItems = ""
  29. this.shamanItems = ""
  30. this.playerLook = "1;0,0,0,0,0,0,0,0,0"
  31. this.shamanLook = "0,0,0,0,0,0,0,0,0,0"
  32. this.lastMessage = ""
  33. this.modoPwetLangue = "ALL"
  34. this.silenceMessage = ""
  35. this.marriage = ""
  36. this.tribeName = ""
  37. this.nameColor = ""
  38. this.tradeName = ""
  39. this.tempMouseColor = ""
  40. this.mouseName = ""
  41. this.botVillage = ""
  42.  
  43. # Integer
  44. this.lastPacketID = random.randint(0, 99)
  45. this.authKey = random.randint(0, 2147483647)
  46. this.langueByte = 0
  47. this.playerScore = 0
  48. this.playerCode = 0
  49. this.privLevel = 0
  50. this.playerID = 0
  51. this.TitleNumber = 0
  52. this.TitleStars = 0
  53. this.posX = 0
  54. this.posY = 0
  55. this.velX = 0
  56. this.velY = 0
  57. this.firstCount = 0
  58. this.cheeseCount = 0
  59. this.shamanCheeses = 0
  60. this.shopCheeses = 100
  61. this.shopFraises = 0
  62. this.shamanSaves = 0
  63. this.hardModeSaves = 0
  64. this.divineModeSaves = 0
  65. this.bootcampCount = 0
  66. this.shamanType = 0
  67. this.regDate = 0
  68. this.banHours = 0
  69. this.shamanLevel = 1
  70. this.shamanExp = 0
  71. this.shamanExpNext = 32
  72. this.ambulanceCount = 0
  73. this.bubblesCount = 0
  74. this.lastOn = 0
  75. this.silenceType = 0
  76. this.gender = 0
  77. this.lastDivorceTimer = 0
  78. this.tribeCode = 0
  79. this.tribeRank = 0
  80. this.tribeJoined = 0
  81. this.tribePoints = 0
  82. this.defilantePoints = 0
  83. this.iceCount = 2
  84. this.lastGameMode = 0
  85. this.nowCoins = 0
  86. this.nowTokens = 0
  87. this.currentPlace = 0
  88. this.equipedShamanBadge = 0
  89. this.pet = 0
  90. this.petEnd = 0
  91. this.numGiveCheese = 0
  92. this.racingRounds = 0
  93. this.bootcampRounds = 0
  94. this.survivorDeath = 0
  95. this.priceDoneVisu = 0
  96.  
  97. this.playerStartTimeMillis = 0
  98.  
  99. # Bool
  100. this.isClosed = False
  101. this.validatingVersion = False
  102. this.isGuest = False
  103. this.isReceivedDummy = False
  104. this.isDead = False
  105. this.hasCheese = False
  106. this.hasEnter = False
  107. this.isMovingRight = False
  108. this.isMovingLeft = False
  109. this.isJumping = False
  110. this.isShaman = False
  111. this.isSuspect = False
  112. this.isAfk = False
  113. this.isVoted = False
  114. this.qualifiedVoted = False
  115. this.isMute = False
  116. this.RTotem = False
  117. this.UTotem = False
  118. this.LoadCountTotem = False
  119. this.modoPwet = False
  120. this.canResSkill = False
  121. this.canShamanRespawn = False
  122. this.isOpportunist = False
  123. this.desintegration = False
  124. this.sendMusic = True
  125. this.isCafe = False
  126. this.canSkipMusic = False
  127. this.isHidden = False
  128. this.isTeleport = False
  129. this.isFly = False
  130. this.isExplosion = False
  131. this.isFFA = False
  132. this.canSpawnCN = True
  133. this.isSpeed = False
  134. this.isNewPlayer = False
  135. this.isVampire = False
  136. this.isLuaAdmin = False
  137. this.isTrade = False
  138. this.tradeConfirm = False
  139. this.canUseConsumable = True
  140. this.canRespawn = False
  141. this.isSkill = False
  142. this.showButtons = True
  143.  
  144. # Others
  145. this.Cursor = Cursor
  146. this.TFMUtils = TFMUtils
  147. this.apiToken = TFMUtils.getRandomChars(50)
  148.  
  149. # Nonetype
  150. this.room = None
  151. this.resSkillsTimer = None
  152. this.consumablesTimer = None
  153. this.skipMusicTimer = None
  154.  
  155. # List
  156. this.STotem = [0, ""]
  157. this.Totem = [0, ""]
  158. this.survivorStats = [0] * 4
  159. this.racingStats = [0] * 4
  160. this.marriageInvite = []
  161. this.tribeData = ["", "", 0, None]
  162. this.tribeInvite = []
  163. this.mulodromePos = []
  164. this.canLogin = [False, False]
  165. this.cheeseTitleList = []
  166. this.firstTitleList = []
  167. this.shamanTitleList = []
  168. this.shopTitleList = []
  169. this.bootcampTitleList = []
  170. this.hardModeTitleList = []
  171. this.divineModeTitleList = []
  172. this.specialTitleList = []
  173. this.titleList = []
  174. this.clothes = []
  175. this.shopBadges = []
  176. this.friendsList = []
  177. this.ignoredsList = []
  178. this.ignoredMarriageInvites = []
  179. this.ignoredTribeInvites = []
  180. this.chats = []
  181. this.voteBan = []
  182. this.shamanBadges = []
  183. this.equipedConsumables = []
  184. this.custom = []
  185.  
  186. # Dict
  187. this.playerSkills = {}
  188. this.playerConsumables = {}
  189. this.tradeConsumables = {}
  190. 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)]}
  191.  
  192. def connectionMade(this):
  193. this.ipAddress = this.transport.getPeer().host
  194. this.server = this.factory
  195.  
  196. this.parsePackets = ParsePackets(this, this.server)
  197. this.parseCommands = ParseCommands(this, this.server)
  198. this.shopModule = ShopModule(this, this.server)
  199. this.ModoPwet = ModoPwet(this, this.server)
  200. this.skillModule = SkillModule(this, this.server)
  201. this.tribulle = Tribulle(this, this.server)
  202.  
  203. # Menu
  204. this.shop = shop(this, this.server)
  205. this.spinTheWheel = spinTheWheel(this, this.server)
  206. this.consumablesShop = consumablesShop(this, this.server)
  207. this.Utility = Utility(this, this.server)
  208.  
  209. if this.server.getIPPermaBan(this.ipAddress) or this.ipAddress in this.server.tempIPBanList:
  210. this.transport.loseConnection()
  211. return
  212.  
  213. if this.server.connectedCounts.has_key(this.ipAddress):
  214. this.server.connectedCounts[this.ipAddress] += 1
  215. else:
  216. this.server.connectedCounts[this.ipAddress] = 1
  217.  
  218. if this.server.connectedCounts[this.ipAddress] >= 5:
  219. this.server.tempIPBanList.append(this.ipAddress)
  220. this.server.sendOutput("Attack DDOS blocked in IP: "+str(this.ipAddress))
  221. this.server.sendStaffMessage(7, "<R>Attack DDOS</R>: <J>["+str(this.ipAddress)+"]</J>")
  222. this.server.disconnectIPAddress(this.ipAddress)
  223. del this.server.connectedCounts[this.ipAddress]
  224. this.transport.loseConnection()
  225.  
  226. def connectionLost(this, remove=True):
  227. this.isClosed = True
  228. for timer in [this.resSkillsTimer, this.consumablesTimer, this.skipMusicTimer]:
  229. if timer != None:
  230. timer.cancel()
  231.  
  232. if this.server.connectedCounts.has_key(this.ipAddress):
  233. count = this.server.connectedCounts[this.ipAddress] - 1
  234. if count <= 0:
  235. del this.server.connectedCounts[this.ipAddress]
  236. else:
  237. this.server.connectedCounts[this.ipAddress] = count
  238.  
  239. if not this.Username == "":
  240. if not this.isGuest:
  241. this.updateDatabase()
  242.  
  243. if this.isTrade:
  244. this.cancelTrade(this.tradeName)
  245.  
  246. if this.server.players.has_key(this.Username) and remove:
  247. del this.server.players[this.Username]
  248.  
  249. if this.ModoPwet.checkReport(this.server.reports["names"], this.Username):
  250. if not this.server.reports[this.Username]["status"] == "banned":
  251. this.server.reports[this.Username]["status"] = "disconnected"
  252. this.ModoPwet.updateModoPwet()
  253.  
  254. if this.server.chatMessages.has_key(this.Username):
  255. this.server.chatMessages[this.Username] = {}
  256. del this.server.chatMessages[this.Username]
  257.  
  258. for client in this.server.players.values():
  259. if this.Username and client.Username in this.friendsList and client.friendsList:
  260. client.tribulle.sendFriendDisconnected(this.Username)
  261.  
  262. if not this.tribeName == "":
  263. this.tribulle.sendTribeMemberDisconnected()
  264.  
  265. if this.privLevel >= 5:
  266. 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.")
  267. this.sendStaffLogin(True)
  268.  
  269. if this.room != None:
  270. this.room.removeClient(this)
  271.  
  272. def sendPacket(this, identifiers, packet=""):
  273. if this.isClosed:
  274. return
  275.  
  276. 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)))
  277. if not this.isClosed:
  278. 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())
  279.  
  280. def parseString(this, packet):
  281. if this.isClosed:
  282. return
  283.  
  284. if packet in ["", " ", "\x00", "\x01"]:
  285. this.server.tempIPBanList.append(this.ipAddress)
  286. this.server.sendOutput("Attack DDOS blocked in IP: "+str(this.ipAddress))
  287. this.server.sendStaffMessage(7, "<R>Attack DDOS</R>: <J>["+str(this.ipAddress)+"]</J>")
  288. this.server.disconnectIPAddress(this.ipAddress)
  289. this.transport.loseConnection()
  290. this.block()
  291.  
  292. p = ByteArray(packet)
  293. if not this.validatingVersion:
  294. C, CC = p.readShort(), p.readByte()
  295. if C == 0x1c and CC == 0x1:
  296. version = p.readShort()
  297. ckey = p.readUTF()
  298. client = p.readUTF() #
  299. h = p.readUTF() #
  300.  
  301. if not ckey == this.server.CKEY and version != this.server.Version:
  302. this.server.sendOutput("WARNING: Invalid CKEY ("+ckey+") and version ("+str(version)+")")
  303. this.transport.loseConnection()
  304.  
  305. else:
  306. this.validatingVersion = True
  307. this.sendCorrectVersion()
  308. else:
  309. try:
  310. checkPacketID = (this.lastPacketID % 99)
  311. checkPacketID += 0 if checkPacketID == 0 else 1
  312. packetID = p.readByte()
  313. this.lastPacketID = packetID
  314.  
  315. C, CC = p.readByte(), p.readByte()
  316. this.parsePackets.parsePacket(packetID, C, CC, ByteArray(packet[3:]))
  317.  
  318. except Exception as ERROR:
  319. c = open("./include/errors.log", "a")
  320. c.write("\n" + "=" * 60 + "\n- Time: %s\n- Player: %s\n- Error: \n" %(time.strftime("%d/%m/%Y - %H:%M:%S"), this.Username))
  321. traceback.print_exc(file=c)
  322. c.close()
  323.  
  324. def loginPlayer(this, playerName, password, startRoom):
  325. playerName = "Souris" if playerName == "" else playerName
  326. if password == "":
  327. playerName = this.server.checkAlreadyExistingGuest("*" + (playerName[0].isdigit() or len(playerName) > 12 or len(playerName) < 3 or "Souris" if "+" in playerName else playerName))
  328.  
  329. if not this.canLogin[0] and not this.canLogin[1]:
  330. this.transport.loseConnection()
  331. return
  332.  
  333. if not this.isGuest and playerName in this.server.userPermaBanCache:
  334. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [])
  335. this.transport.loseConnection()
  336. return
  337.  
  338. if not this.isGuest and playerName in this.server.userTempBanCache:
  339. banInfo = this.server.getTempBanInfo(playerName)
  340. timeCalc = TFMUtils.getHoursDiff(int(banInfo[0]))
  341. if timeCalc <= 0:
  342. this.server.removeTempBan(playerName)
  343. else:
  344. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [timeCalc * 3600000, str(banInfo[1])])
  345. this.transport.loseConnection()
  346. return
  347.  
  348. if this.server.checkConnectedAccount(playerName):
  349. this.sendPacket(Identifiers.send.Login_Result, chr(1))
  350. else:
  351. vipTime, letters, gifts, messages = 0, "", "", ""
  352. if not this.isGuest:
  353. this.Cursor.execute("select * from Users where Username = ? and Password = ?", [playerName, password])
  354. rs = this.Cursor.fetchone()
  355. if rs:
  356. this.privLevel = rs["PrivLevel"]
  357. this.playerID = rs["PlayerID"]
  358. this.TitleNumber = rs["TitleNumber"]
  359. this.firstCount = rs["FirstCount"]
  360. this.cheeseCount = rs["CheeseCount"]
  361. this.shamanCheeses = rs["ShamanCheeses"]
  362. this.shopCheeses = rs["ShopCheeses"]
  363. this.shopFraises = rs["ShopFraises"]
  364. this.shamanSaves = rs["ShamanSaves"]
  365. this.hardModeSaves = rs["HardModeSaves"]
  366. this.divineModeSaves = rs["DivineModeSaves"]
  367. this.bootcampCount = rs["BootcampCount"]
  368. this.shamanType = rs["ShamanType"]
  369. this.shopItems = rs["ShopItems"]
  370. this.shamanItems = rs["ShamanItems"]
  371. this.clothes = rs["Clothes"].split("|")
  372. this.playerLook = rs["Look"]
  373. this.shamanLook = rs["ShamanLook"]
  374. this.MouseColor = rs["MouseColor"]
  375. this.ShamanColor = rs["ShamanColor"]
  376. this.regDate = rs["RegDate"]
  377. this.shopBadges = rs["Badges"].split(",")
  378. this.cheeseTitleList = rs["CheeseTitleList"].split(",")
  379. this.firstTitleList = rs["FirstTitleList"].split(",")
  380. this.shamanTitleList = rs["ShamanTitleList"].split(",")
  381. this.shopTitleList = rs["ShopTitleList"].split(",")
  382. this.bootcampTitleList = rs["BootcampTitleList"].split(",")
  383. this.hardModeTitleList = rs["HardModeTitleList"].split(",")
  384. this.divineModeTitleList = rs["DivineModeTitleList"].split(",")
  385. this.specialTitleList = rs["SpecialTitleList"].split(",")
  386. this.banHours = rs["BanHours"]
  387. level = rs["ShamanLevel"].split("/")
  388. this.shamanLevel = int(level[0])
  389. this.shamanExp = int(level[1])
  390. this.shamanExpNext = int(level[2])
  391. for skill in rs["Skills"].split(";"):
  392. values = skill.split(":")
  393. if len(values) >= 2:
  394. this.playerSkills[int(values[0])] = int(values[1])
  395. this.lastOn = rs["LastOn"]
  396. this.friendsList = rs["FriendsList"].split(",")
  397. this.ignoredsList = rs["IgnoredsList"].split(",")
  398. this.gender = rs["Gender"]
  399. this.lastDivorceTimer = rs["LastDivorceTimer"]
  400. this.marriage = rs["Marriage"]
  401.  
  402. tribeInfo = rs["TribeInfo"].split("#")
  403. if len(tribeInfo) == 3:
  404. this.tribeCode = int(tribeInfo[0])
  405. this.tribeRank = int(tribeInfo[1])
  406. this.tribeJoined = int(tribeInfo[2])
  407. this.tribeData = this.server.getTribeInfo(this.tribeCode)
  408. this.tribeName = this.tribeData[0]
  409.  
  410. this.survivorStats = map(int, rs["SurvivorStats"].split(","))
  411. this.racingStats = map(int, rs["RacingStats"].split(","))
  412. this.nowCoins = rs["NowCoins"]
  413. this.nowTokens = rs["NowTokens"]
  414. for consumable in rs["Consumables"].split(";"):
  415. values = consumable.split(":")
  416. if len(values) >= 2:
  417. this.playerConsumables[int(values[0])] = int(values[1])
  418. this.equipedConsumables = rs["EquipedConsumables"].split("|")
  419. letters = rs["Letters"]
  420. this.pet = rs["Pet"]
  421. this.petEnd = 0 if this.pet == 0 else TFMUtils.getTime() + rs["PetEnd"]
  422. this.shamanBadges = rs["ShamanBadges"].split(",")
  423. this.equipedShamanBadge = rs["EquipedShamanBadge"]
  424. totem = this.server.getTotemData(playerName)
  425. if len(totem) == 2: this.STotem = [int(totem[0]), totem[1]]
  426. gifts = rs["Gifts"]
  427. message = rs["Messages"]
  428. vipTime = rs["VipTime"]
  429. this.visuDone = eval(rs["visuDone"])
  430. this.custom = rs["customItens"].split(",")
  431. else:
  432. reactor.callLater(5, lambda: this.sendPacket(Identifiers.send.Login_Result, chr(2)))
  433. return
  434.  
  435. if this.privLevel == -1:
  436. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [0, "Account Locked."])
  437. this.transport.loseConnection()
  438. return
  439.  
  440. this.server.lastPlayerCode += 1
  441. this.Username = playerName
  442. this.playerCode = this.server.lastPlayerCode
  443. this.Cursor.execute("insert into LoginLog select ?, ? where not exists (select 1 from LoginLog where Username = ? and IP = ?)", [playerName, this.ipAddress, playerName, this.ipAddress])
  444.  
  445. this.clothes = filter(None, this.clothes)
  446. this.shopBadges = filter(None, this.shopBadges)
  447. this.custom = filter(None, this.custom)
  448. this.shamanBadges = filter(None, this.shamanBadges)
  449. this.shopTitleList = filter(None, this.shopTitleList)
  450. this.firstTitleList = filter(None, this.firstTitleList)
  451. this.cheeseTitleList = filter(None, this.cheeseTitleList)
  452. this.shamanTitleList = filter(None, this.shamanTitleList)
  453. this.specialTitleList = filter(None, this.specialTitleList)
  454. this.bootcampTitleList = filter(None, this.bootcampTitleList)
  455. this.hardModeTitleList = filter(None, this.hardModeTitleList)
  456. this.divineModeTitleList = filter(None, this.divineModeTitleList)
  457.  
  458. for name in ["cheese", "first", "shaman", "shop", "bootcamp", "hardmode", "divinemode"]:
  459. this.checkAndRebuildTitleList(name)
  460.  
  461. this.sendCompleteTitleList()
  462. this.shopModule.checkAndRebuildBadges()
  463.  
  464. for title in this.titleList:
  465. if str(title).split(".")[0] == str(this.TitleNumber):
  466. this.TitleStars = int(str(title).split(".")[1])
  467. break
  468.  
  469. this.isMute = playerName in this.server.userMuteCache
  470. this.server.players[this.Username] = this
  471. this.skillModule.sendShamanSkills()
  472. this.skillModule.sendExp(this.shamanLevel, this.shamanExp, this.shamanExpNext)
  473. this.sendLogin()
  474. this.sendPlayerIdentification()
  475. this.shopModule.sendShamanItems()
  476. if this.shamanSaves >= 500:
  477. this.sendShamanType(this.shamanType, (this.shamanSaves >= 2500 and this.hardModeSaves >= 1000))
  478.  
  479. this.server.checkPromotionsEnd()
  480. this.sendTimeStamp()
  481. this.sendPromotions()
  482. this.sendPacket(Identifiers.send.Email_Confirmed, chr(1))
  483.  
  484. if this.privLevel == 2:
  485. this.checkVip(vipTime)
  486.  
  487. this.tribulle.sendPlayerInfo()
  488. this.tribulle.sendFriendsList(None)
  489. this.tribulle.sendIgnoredsList()
  490. this.tribulle.sendTribe(False)
  491.  
  492. for client in this.server.players.values():
  493. if this.Username in client.friendsList and client.Username in this.friendsList:
  494. client.tribulle.sendFriendConnected(this.Username)
  495.  
  496. if not this.tribeName == "":
  497. this.tribulle.sendTribeMemberConnected()
  498.  
  499. if this.privLevel >= 5:
  500. 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.")
  501. this.sendStaffLogin(False)
  502.  
  503. this.sendInventoryConsumables()
  504. this.checkLetters(letters)
  505. this.shopModule.checkGiftsAndMessages(gifts, messages)
  506.  
  507. if not startRoom == "" and not startRoom == "1":
  508. this.enterRoom(this.server.checkRoom(startRoom, this.Langue))
  509. else:
  510. this.enterRoom(this.server.recommendRoom(this.Langue))
  511.  
  512. this.resSkillsTimer = reactor.callLater(600, setattr, this, "canResSkill", True)
  513.  
  514. def createAccount(this, playerName, password):
  515. this.server.lastPlayerID += 1
  516. 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"]}'])
  517. this.sendNewConsumable(23, 10)
  518. this.sendAccountTime()
  519.  
  520. this.server.updateConfig()
  521.  
  522. def checkAndRebuildTitleList(this, type):
  523. titlesLists = [this.cheeseTitleList, this.firstTitleList, this.shamanTitleList, this.shopTitleList, this.bootcampTitleList, this.hardModeTitleList, this.divineModeTitleList]
  524. titles = [this.server.cheeseTitleList, this.server.firstTitleList, this.server.shamanTitleList, this.server.shopTitleList, this.server.bootcampTitleList, this.server.hardModeTitleList, this.server.divineModeTitleList]
  525. 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
  526. 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
  527. tempCount = count
  528. rebuild = False
  529. while tempCount > 0:
  530. if titles[typeID].has_key(tempCount):
  531. if not titles[typeID][tempCount] in titlesLists[typeID]:
  532. rebuild = True
  533. break
  534.  
  535. tempCount -= 1
  536.  
  537. if rebuild:
  538. titlesLists[typeID] = []
  539. x = 0
  540. while x <= count:
  541. if titles[typeID].has_key(x):
  542. title = titles[typeID][x]
  543. i = 0
  544. while i < len(titlesLists[typeID]):
  545. if str(titlesLists[typeID][i]).startswith(str(title).split(".")[0]):
  546. del titlesLists[typeID][i]
  547. i += 1
  548. titlesLists[typeID].append(title)
  549. x += 1
  550.  
  551. this.cheeseTitleList = titlesLists[0]
  552. this.firstTitleList = titlesLists[1]
  553. this.shamanTitleList = titlesLists[2]
  554. this.shopTitleList = titlesLists[3]
  555. this.bootcampTitleList = titlesLists[4]
  556. this.hardModeTitleList = titlesLists[5]
  557. this.divineModeTitleList = titlesLists[6]
  558.  
  559. def updateDatabase(this):
  560. this.updateTribePoints()
  561. 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])
  562.  
  563. def reloadRanking(this):
  564. Userlist = []
  565. lists = "<V><p align='center'><b>Top Players</font></p>"
  566. lists += "<p align='left'><font size='12'>"
  567. this.Cursor.execute("select Username, CheeseCount, FirstCount, BootcampCount, ShamanSaves, HardModeSaves, DivineModeSaves, TitleNumber from Users where PrivLevel < 6 ORDER By FirstCount DESC LIMIT 10")
  568. rs = this.Cursor.fetchall()
  569. pos = 1
  570. this.updateDatabase()
  571. for rrf in rs:
  572. playerName = str(rrf[0])
  573. CheeseCount = rrf[1]
  574. FirstCount = rrf[2]
  575. BootcampCount = rrf[3]
  576. ShamanSaves = rrf[4]
  577. HardModeSaves = rrf[5]
  578. DivineModeSaves = rrf[6]
  579. TitleNumber = rrf[7]
  580. if pos == 1:
  581. lists += "<font color='#FADE55'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>\n"
  582. elif pos == 2:
  583. lists += "<font color='#EFEBE0'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>\n"
  584. elif pos == 3:
  585. lists += "<font color='#B44F0D'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>\n"
  586. else:
  587. lists += "<font color='#606090'>"+str(pos)+"º</font> <font color='#3C5064'>-</font> <font color='#009d9d'>"+str(playerName)+"</font>"
  588. lists += "<br />"
  589. lists += " <font color='#6A7495'>• Current title:</font> <font color='#009d9d'>"+str(TitleNumber)+"</font>"
  590. lists += "<br />"
  591. lists += " <font color='#6A7495'>• Saves:</font> <font color='#009d9d'>"+str(ShamanSaves)+" / "+"<font color='#FADE55'>"+str(HardModeSaves)+" / "+"<font color='#F52331'>"+str(DivineModeSaves)+"</font>"
  592. lists += "<br />"
  593. lists += " <font color='#6A7495'>• Firsts:</font> <font color='#6C77C1'>"+str(FirstCount)+"</font>"
  594. lists += "<br />"
  595. lists += " <font color='#6A7495'>• Collected cheeses:</font> <font color='#6C77C1'>"+str(CheeseCount)+"</font>"
  596. lists += "<br />"
  597. lists += " <font color='#6A7495'>• Bootcamps:</font> <font color='#6C77C1'>"+str(BootcampCount)+"</font>"
  598. lists += "<br />"
  599. pos += 1
  600.  
  601. this.sendLogMessage(lists + "</font></p>")
  602.  
  603. def enterRoom(this, roomName):
  604. if this.isTrade:
  605. this.cancelTrade(this.tradeName)
  606.  
  607. roomName = roomName.replace("<", "&lt;")
  608. for room in ["racing", "bootcamp", "survivor", "defilate"]:
  609. if room in roomName:
  610. this.sendMessage("<V>Menu closed.")
  611.  
  612. if roomName.startswith(chr(3) + "[Editeur] ") or roomName.startswith(chr(3)+ "[Totem] ") or roomName.startswith(chr(3) + "[Tutorial] "):
  613. if not this.Username == roomName.split(" ")[1]:
  614. roomName = this.Langue + "-" + this.Username
  615.  
  616. if not roomName.startswith("*") and not (len(roomName) > 3 and roomName[2] == '-' and this.privLevel >= 7):
  617. roomName = this.Langue + "-" + roomName
  618.  
  619. nomSalon = ["#utility0%s" % (this.Username or this.tribeName), "#utility00%s" % (this.Username or this.tribeName)]
  620. if roomName == nomSalon[0] or nomSalon[1]:
  621. if re.search(this.Username, roomName):
  622. reactor.callLater(0.1, this.Utility.moreSettings, "giveAdmin")
  623. else:
  624. try:
  625. if re.search(this.tribeName, roomName):
  626. reactor.callLater(0.1, this.Utility.moreSettings, "giveAdmin")
  627. except:
  628. pass
  629.  
  630. if re.search("#utility", roomName):
  631. reactor.callLater(0.1, this.Utility.moreSettings, "join")
  632. reactor.callLater(1.5, this.Utility.moreSettings, "removePopups")
  633.  
  634. if this.room != None:
  635. this.room.removeClient(this)
  636.  
  637. this.roomName = roomName
  638. this.sendGameType(11 if "music" in roomName else 1 if "madchees" in roomName else 4, 4 if "madchees" in roomName else 0)
  639. this.sendEnterRoom(roomName)
  640. this.server.addClientToRoom(this, roomName)
  641. this.sendPacket(Identifiers.old.send.Anchors, this.room.anchors)
  642. this.LoadCountTotem = False
  643.  
  644. for client in this.server.players.values():
  645. if this.Username and client.Username in this.friendsList and client.friendsList:
  646. client.tribulle.sendFriendChangedRoom(this.Username, this.langueByte)
  647.  
  648. if not this.tribeName == "":
  649. this.tribulle.sendTribeMemberChangeRoom()
  650.  
  651. if this.room.isMusic and this.room.isPlayingMusic:
  652. this.sendMusicVideo(False)
  653.  
  654. if roomName.startswith("music") or roomName.startswith("*music"):
  655. this.canSkipMusic = False
  656. if this.skipMusicTimer != None:
  657. this.skipMusicTimer.cancel()
  658.  
  659. this.skipMusicTimer = reactor.callLater(900, setattr, this, "canSkipMusic", True)
  660.  
  661. 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:
  662. this.sendMenu()
  663.  
  664. if this.room.isFuncorp:
  665. this.sendLangueMessage("", "<FC>$FunCorpActive</FC>")
  666.  
  667. def resetPlay(this, hasCheese=True):
  668. this.isDead = False
  669. this.isAfk = True
  670. this.isShaman = False
  671. this.isSuspect = False
  672. this.hasEnter = False
  673. this.UTotem = False
  674. this.canShamanRespawn = False
  675. this.ambulanceCount = 0
  676. this.bubblesCount = 0
  677. this.isOpportunist = False
  678. this.desintegration = False
  679. this.canRespawn = False
  680. this.defilantePoints = 0
  681. this.iceCount = 2
  682. this.isNewPlayer = False
  683. this.currentPlace = 0
  684. this.isVampire = False
  685. this.numGiveCheese = 0
  686. this.bootcampRounds = 0
  687. if hasCheese:
  688. this.hasCheese = False
  689.  
  690. def sendAccountTime(this):
  691.  
  692. eventTime = 1
  693.  
  694. date = datetime.now() + timedelta(hours=int(eventTime))
  695.  
  696. timetuple = date.timetuple()
  697.  
  698. eventTime_ = int(str(thetime.mktime(timetuple)).split(".")[0])
  699.  
  700. this.Cursor.execute('select IP from Account where IP = ?', [this.ipAddress])
  701.  
  702. rrf = this.Cursor.fetchone()
  703.  
  704. if rrf is None:
  705.  
  706. this.Cursor.execute('insert into Account values (?, ?)', [this.ipAddress, eventTime_])
  707.  
  708. else:
  709.  
  710. this.Cursor.execute('update Account set Time = ? where IP = ?', [eventTime_, this.ipAddress])
  711.  
  712.  
  713.  
  714.  
  715. def checkTimeAccount(this):
  716.  
  717. this.Cursor.execute('SELECT Time FROM Account WHERE IP = ?', [this.ipAddress])
  718.  
  719. rrf = this.Cursor.fetchone()
  720.  
  721. if rrf is None:
  722.  
  723. return True
  724.  
  725. else:
  726.  
  727. if (int(str(thetime.time()).split(".")[0]) >= int(rrf[0])):
  728.  
  729. return True
  730.  
  731. else:
  732.  
  733. return False
  734.  
  735. def startPlay(this):
  736. this.playerStartTimeMillis = this.room.gameStartTimeMillis
  737. this.isNewPlayer = this.room.isCurrentlyPlay
  738. 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)
  739.  
  740. shamanCode2 = 0
  741. if this.room.isDoubleMap:
  742. shamans = this.room.getDoubleShamanCode()
  743. shamanCode = shamans[0]
  744. shamanCode2 = shamans[1]
  745. else:
  746. shamanCode = this.room.getShamanCode()
  747.  
  748. if this.playerCode == shamanCode or this.playerCode == shamanCode2:
  749. this.isShaman = True
  750.  
  751. if this.isShaman and not this.room.noShamanSkills:
  752. this.skillModule.getkills()
  753.  
  754. if this.room.currentShamanName != "" and not this.room.noShamanSkills:
  755. this.skillModule.getPlayerSkills(this.room.currentShamanSkills)
  756.  
  757. if this.room.currentSecondShamanName != "" and not this.room.noShamanSkills:
  758. this.skillModule.getPlayerSkills(this.room.currentSecondShamanSkills)
  759.  
  760. this.sendPlayerList()
  761. if this.room.catchTheCheeseMap and not this.room.noShamanSkills:
  762. this.sendPacket(Identifiers.old.send.Catch_The_Cheese_Map, [shamanCode])
  763. this.sendPacket(Identifiers.old.send.Player_Get_Cheese, [shamanCode])
  764. if not this.room.currentMap in [108, 109]:
  765. this.sendShamanCode(shamanCode, shamanCode2)
  766. else:
  767. this.sendShamanCode(shamanCode, shamanCode2)
  768.  
  769. this.sendSync(this.room.getSyncCode())
  770. this.sendRoundTime(this.room.roundTime + (this.room.gameStartTime - TFMUtils.getTime()) + this.room.addTime)
  771. 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()
  772. if this.room.isTotemEditeur:
  773. this.initTotemEditeur()
  774.  
  775. if this.room.currentMap in range(200, 211) and not this.isShaman:
  776. this.sendPacket(Identifiers.send.Can_Transformation, chr(1))
  777.  
  778. if this.room.isSurvivor and this.isShaman:
  779. this.sendPacket(Identifiers.send.Can_Meep, chr(1))
  780.  
  781. if this.room.isVillage:
  782. reactor.callLater(0.2, this.sendBotsVillage)
  783.  
  784. def sendBotsVillage(this):
  785. 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")
  786. 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")
  787. 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")
  788. this.sendPacket([8, 30], "\xff\xff\xff\xfc\x00\x05Buffy\x01[\x00\x06$Buffy\x07t\x01\xf3\x00\x0b\x00\x00")
  789. 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")
  790. this.sendPacket([8, 30], "\xff\xff\xff\xfa\x00\x04Prof\x01G\x00\n$Proviseur\x01!\x02\xcb\x00\x0b\x00\x00")
  791. this.sendPacket([8, 30], "\xff\xff\xff\xf9\x00\x07Cassidy\x01\x18\x00\x07$Barman\n\xd2\x02%\x00\x0b\x00\x00")
  792. this.sendPacket([8, 30], "\xff\xff\xff\xf8\x00\x0fVon Drekkemouse\x01\x1f\x00\n$Halloween\x06\x88\x01z\x00\x0b\x00\x00")
  793.  
  794. def getPlayerData(this):
  795. 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]))
  796.  
  797. def sendShamanCode(this, shamanCode, shamanCode2):
  798. 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))
  799.  
  800. def sendDoubleShamanCode(this, shamanCode, shamanCodeTwo):
  801. 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))
  802.  
  803. def sendCorrectVersion(this):
  804. this.sendPacket(Identifiers.send.Correct_Version, ByteArray().writeInt(this.server.getConnectedPlayerCount()).writeByte(this.lastPacketID).writeUTF("br").writeUTF("br").writeInt(this.authKey).toByteArray())
  805. this.sendPacket(Identifiers.send.Banner_Login, ByteArray().writeShort(564).writeByte(1).writeByte(1).writeByte(0).toByteArray())
  806. this.sendPacket([100, 99], ByteArray().writeUTF("x_noel2014.jpg").toByteArray())
  807. this.sendPacket(Identifiers.send.Undefined, ByteArray().writeByte(0).toByteArray())
  808.  
  809. def sendLogin(this):
  810. this.sendPacket(Identifiers.old.send.Login, [this.Username, this.playerCode, this.privLevel, 30, 1 if this.isGuest else 0, 0, 0, 0])
  811. this.sendPacket(Identifiers.send.First_Count, ByteArray().writeInt(this.firstCount).toByteArray())
  812. this.sendPacket(Identifiers.send.Authent, ByteArray().writeUTF("2\x00VMozilla/5.0 (Windows; U; pt-BR) AppleWebKit/533.19.4 (KHTML, like Gecko) AdobeAIR/22.0\x00\x07Desktop\x00\x01-\x00&app:/TransformiceAIR.swf/[[DYNAMIC]]/2\x00\x03ou").toByteArray())
  813. if this.isGuest:
  814. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(1).writeByte(10).toByteArray())
  815. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(2).writeByte(5).toByteArray())
  816. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(3).writeByte(15).toByteArray())
  817. this.sendPacket(Identifiers.send.Login_Souris, ByteArray().writeByte(4).writeUnsignedByte(200).toByteArray())
  818.  
  819. def sendPlayerIdentification(this):
  820. if this.isGuest:
  821. 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())
  822. this.sendPacket([100, 6], "\x00\x00")
  823. else:
  824. 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())
  825. this.sendPacket([100, 6], "\x00\x00")
  826.  
  827. def sendTimeStamp(this):
  828. this.sendPacket(Identifiers.send.Time_Stamp, ByteArray().writeInt(TFMUtils.getTime()).toByteArray())
  829.  
  830. def enableSpawnCN(this):
  831. this.canSpawnCN = True
  832.  
  833. def fireworksUtility(this):
  834. if this.room.isUtility and this.Utility.isFireworks == True:
  835. this.Utility.newCoordsConj()
  836. reactor.callLater(0.2, this.Utility.buildConj)
  837. reactor.callLater(1, this.Utility.removeConj)
  838. reactor.callLater(1.5, this.fireworksUtility)
  839.  
  840. def discoUtility(this):
  841. if this.room.isUtility == True:
  842. colors = ["000000", "FF0000", "17B700", "F2FF00", "FFB900", "00C0D9", "F600A8", "850000", "62532B", "EFEAE1", "201E1C"]
  843. sColor = random.choice(colors)
  844. data = struct.pack("!i", this.playerCode)
  845. data += struct.pack("!i", int(sColor, 16))
  846. this.room.sendAll([29, 4], data)
  847. if this.room.discoRoom == True:
  848. this.reactorDisco()
  849.  
  850. def reactorDisco(this):
  851. if this.room.isUtility == True:
  852. if this.room.discoRoom == True:
  853. reactor.callLater(0.7, this.discoUtility)
  854.  
  855. def sendPromotions(this):
  856. for promotion in this.server.shopPromotions:
  857. 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())
  858.  
  859. if len(this.server.shopPromotions) > 0:
  860. promotion = this.server.shopPromotions[0]
  861. item = promotion[0] * (10000 if promotion[1] > 99 else 100) + promotion[1] + (10000 if promotion[1] > 99 else 0)
  862. this.sendPacket(Identifiers.send.Promotion_Popup, ByteArray().writeByte(promotion[0]).writeByte(promotion[1]).writeByte(promotion[2]).writeShort(this.server.shopBadges.get(item, 0)).toByteArray())
  863.  
  864. def sendGameType(this, gameType, serverType):
  865. this.sendPacket(Identifiers.send.Room_Type, ByteArray().writeByte(gameType).toByteArray())
  866. this.sendPacket(Identifiers.send.Room_Server, ByteArray().writeByte(serverType).toByteArray())
  867.  
  868. def sendEnterRoom(this, roomName):
  869. this.sendPacket(Identifiers.send.Enter_Room, ByteArray().writeBool(roomName.startswith("*") or roomName.startswith(str(chr(3)))).writeUTF(roomName).toByteArray())
  870.  
  871. def sendMap(this, newMap=False, newMapCustom=False):
  872. 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())
  873.  
  874. def sendPlayerList(this):
  875. this.sendPacket(Identifiers.old.send.Player_List, this.room.getPlayerList())
  876.  
  877. def sendSync(this, playerCode):
  878. if this.room.mapCode != 1 or this.room.EMapCode != 0:
  879. this.sendPacket(Identifiers.old.send.Sync, [playerCode, ""])
  880. else:
  881. this.sendPacket(Identifiers.old.send.Sync, [playerCode])
  882.  
  883. def sendRoundTime(this, time):
  884. try:
  885. this.sendPacket(Identifiers.send.Round_Time, ByteArray().writeShort(time).toByteArray())
  886.  
  887. except:
  888.  
  889. print(time)
  890.  
  891. def sendMapStartTimer(this):
  892. this.sendPacket(Identifiers.send.Map_Start_Timer, chr(1))
  893.  
  894. def sendMapStartTimerEnd(this):
  895. if this.hasCheese:
  896. this.hasCheese = False
  897. this.room.sendAll(Identifiers.send.Remove_Cheese, ByteArray().writeInt(this.playerCode).toByteArray())
  898.  
  899. this.sendPacket(Identifiers.send.Map_Start_Timer, chr(0))
  900.  
  901. def sendPlayerDisconnect(this):
  902. this.room.sendAll(Identifiers.old.send.Player_Disconnect, [this.playerCode])
  903.  
  904. def sendPlayerDied(this):
  905. this.room.sendAll(Identifiers.old.send.Player_Died, [this.playerCode, 0, this.playerScore])
  906.  
  907. if this.room.isBootcamp:
  908. this.hasCheese = False
  909.  
  910. if this.room.isRacing:
  911. this.racingRounds = 0
  912.  
  913. if this.room.getAliveCount() < 1 or this.room.catchTheCheeseMap or this.isAfk:
  914. this.canShamanRespawn = False
  915.  
  916. if ((this.room.checkIfTooFewRemaining() and not this.canShamanRespawn) or (this.room.checkIfShamanIsDead() and not this.canShamanRespawn) or (this.room.checkIfDoubleShamansAreDead())):
  917. this.room.send20SecRemainingTimer()
  918.  
  919. if this.canShamanRespawn:
  920. this.isDead = False
  921. this.isAfk = False
  922. this.hasCheese = False
  923. this.hasEnter = False
  924. this.canShamanRespawn = False
  925. this.playerStartTimeMillis = time.time()
  926. this.room.sendAll(Identifiers.old.send.Player_Respawn, [this.getPlayerData(), 1])
  927. if this.hasCheese:
  928. this.hasCheese = False
  929. this.sendGiveCheese()
  930. for client in this.room.clients.values():
  931. client.sendShamanCode(this.playerCode, 0)
  932.  
  933. def sendShaman(this, shamanCode, shamanCode2, shamanType, shamanType2, shamanLevel, shamanLevel2, shamanBadge, shamanBadge2):
  934. this.sendPacket(Identifiers.send.Shaman_Info, ByteArray().writeInt(shamanCode).writeInt(shamanCode2).writeByte(shamanType).writeByte(shamanType2).writeShort(shamanLevel).writeShort(shamanLevel2).writeShort(shamanBadge).writeShort(shamanBadge2).toByteArray())
  935.  
  936. def sendConjurationDestroy(this, x, y):
  937. this.room.sendAll(Identifiers.old.send.Conjuration_Destroy, [x, y])
  938.  
  939. def sendGiveCheese(this, distance=-1):
  940. if distance != -1 and distance != 1000 and not this.room.catchTheCheeseMap and this.room.countStats:
  941. if distance >= 30:
  942. this.isSuspect = True
  943.  
  944. this.room.canChangeMap = False
  945. if not this.hasCheese:
  946. this.room.sendAll(Identifiers.old.send.Player_Get_Cheese, [this.playerCode])
  947. this.numGiveCheese += 1
  948. this.hasCheese = True
  949. if this.room.isTutorial:
  950. this.sendPacket(Identifiers.send.Tutorial, chr(1))
  951. if this.room.currentMap in range(108, 114):
  952. if this.numGiveCheese >= 10:
  953. this.room.killShaman()
  954.  
  955. this.room.canChangeMap = True
  956.  
  957. def playerWin(this, holeType, distance=-1):
  958. if distance != -1 and distance != 1000 and this.isSuspect and this.room.countStats:
  959. if distance >= 30:
  960. this.server.sendStaffMessage(7, "[<V>ANTI-HACK</V>][<J>%s</J>][<V>%s</V>] Instant win detected by distance." %(this.ipAddress, this.Username))
  961. this.sendPacket(Identifiers.old.send.Player_Ban_Login, [0, "Instant win detected by distance."])
  962. this.transport.loseConnection()
  963. return
  964.  
  965. this.room.canChangeMap = False
  966. canGo = this.room.checkIfShamanCanGoIn() if this.isShaman else True
  967. if not canGo:
  968. this.sendSaveRemainingMiceMessage()
  969.  
  970. if this.isDead or not this.hasCheese and not this.isOpportunist:
  971. canGo = False
  972.  
  973. if this.room.isTutorial:
  974. this.sendPacket(Identifiers.send.Tutorial, chr(2))
  975. this.hasCheese = False
  976. reactor.callLater(10, lambda: this.enterRoom(this.server.recommendRoom(this.Langue)))
  977. this.sendRoundTime(10)
  978. return
  979.  
  980. if this.room.isEditeur:
  981. if not this.room.EMapValidated and this.room.EMapCode != 0:
  982. this.room.EMapValidated = True
  983. this.sendPacket(Identifiers.old.send.Map_Validated, [""])
  984.  
  985. if canGo:
  986. this.isDead = True
  987. this.hasCheese = False
  988. this.hasEnter = True
  989. this.isOpportunist = False
  990. this.room.numCompleted += 1
  991. place = this.room.numCompleted
  992. if this.room.isDoubleMap:
  993. if holeType == 1:
  994. this.room.FSnumCompleted += 1
  995. elif holeType == 2:
  996. this.room.SSnumCompleted += 1
  997. else:
  998. this.room.FSnumCompleted += 1
  999. this.room.SSnumCompleted += 1
  1000.  
  1001. timeTaken = int((time.time() - (this.playerStartTimeMillis if this.room.autoRespawn else this.room.gameStartTimeMillis)) * 100)
  1002. this.currentPlace = place
  1003. if place == 1:
  1004. this.playerScore += (4 if this.room.isRacing else 16) if not this.room.noAutoScore else 0
  1005. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn and not this.isGuest:
  1006. this.sendMessage('<BV>[M] <N>Congratulations to <BV>'+str(this.Username)+'<N> came first and received <BV>+3<N> coins.')
  1007. if not this.server.isNowEvent:
  1008. this.firstCount += 15
  1009. this.nowCoins += 15
  1010. else:
  1011. this.firstCount += 15
  1012. this.cheeseCount += 15
  1013. this.nowCoins += 15
  1014.  
  1015. if not this.tribeName == "":
  1016. this.tribePoints += 15
  1017.  
  1018. if not this.isGuest:
  1019. this.sendMessage("You won <V>" + str(6 if this.server.isNowEvent else 3) + "</V> coins!")
  1020.  
  1021. elif place == 2:
  1022. this.playerScore += (3 if this.room.isRacing else 14) if not this.room.noAutoScore else 0
  1023. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn and not this.isGuest:
  1024. this.sendMessage('<BV>[M] <N>Congratulations to <BV>'+str(this.Username)+'<N> came first and received <BV>+3<N> coins.')
  1025. if not this.server.isNowEvent:
  1026. this.firstCount += 10
  1027. this.nowCoins += 10
  1028. else:
  1029. this.firstCount += 10
  1030. this.cheeseCount += 10
  1031. this.nowCoins += 10
  1032.  
  1033. if not this.tribeName == "":
  1034. this.tribePoints += 10
  1035.  
  1036. if not this.isGuest:
  1037. this.sendMessage("You won <V>" + str(6 if this.server.isNowEvent else 3) + "</V> coins!")
  1038. elif place == 3:
  1039. this.playerScore += (2 if this.room.isRacing else 12) if not this.room.noAutoScore else 0
  1040. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.isShaman and not this.canShamanRespawn and not this.isGuest:
  1041. this.sendMessage('<BV>[M] <N>Congratulations to <BV>'+str(this.Username)+'<N> came first and received <BV>+3<N> coins.')
  1042. if not this.server.isNowEvent:
  1043. this.firstCount += 5
  1044. this.nowCoins += 5
  1045. else:
  1046. this.firstCount += 5
  1047. this.cheeseCount += 5
  1048. this.nowCoins += 5
  1049.  
  1050. if not this.tribeName == "":
  1051. this.tribePoints += 5
  1052.  
  1053. if not this.isGuest:
  1054. this.sendMessage("You won <V>" + str(6 if this.server.isNowEvent else 3) + "</V> coins!")
  1055. else:
  1056. this.playerScore += (1 if this.room.isRacing else 10) if not this.room.noAutoScore else 0
  1057.  
  1058. if this.room.isMulodrome:
  1059. if this.Username in this.room.redTeam:
  1060. this.room.redCount += 4 if place == 1 else 3 if place == 2 else 2 if place == 2 else 1
  1061.  
  1062. elif this.Username in this.room.blueTeam:
  1063. this.room.blueCount += 4 if place == 1 else 3 if place == 2 else 2 if place == 2 else 1
  1064.  
  1065. this.room.sendMulodromeRound()
  1066.  
  1067. if this.room.isDefilante:
  1068. if not this.room.noAutoScore: this.playerScore += this.defilantePoints
  1069. id = 2257
  1070. if not id in this.playerConsumables:
  1071. this.playerConsumables[id] = 1
  1072. else:
  1073. count = this.playerConsumables[id] + 1
  1074. this.playerConsumables[id] = count
  1075. this.sendAnimZeldaInventory(4, id, 1)
  1076.  
  1077. if this.room.isRacing:
  1078. id = 2254
  1079. this.racingRounds += 1
  1080. if this.racingRounds >= 5:
  1081. if not id in this.playerConsumables:
  1082. this.playerConsumables[id] = 1
  1083. else:
  1084. count = this.playerConsumables[id] + 1
  1085. this.playerConsumables[id] = count
  1086. this.sendAnimZeldaInventory(4, id, 1)
  1087. this.racingRounds = 0
  1088.  
  1089. if this.room.isBootcamp:
  1090. id = 2261
  1091. this.bootcampRounds += 1
  1092. if this.bootcampRounds == 5:
  1093. if not id in this.playerConsumables:
  1094. this.playerConsumables[id] = 1
  1095. else:
  1096. count = this.playerConsumables[id] + 1
  1097. this.playerConsumables[id] = count
  1098. this.sendAnimZeldaInventory(4, id, 1)
  1099.  
  1100. if this.room.getPlayerCountUnique() >= this.server.needToFirst and this.room.countStats and not this.room.isBootcamp and not this.isGuest:
  1101. if this.playerCode == this.room.currentShamanCode or this.playerCode == this.room.currentSecondShamanCode:
  1102. this.shamanCheeses += 1
  1103. this.sendAnimZelda(4, 2253)
  1104. this.sendNewConsumable(2253, 1)
  1105. if this.playerConsumables.has_key(2253):
  1106. this.playerConsumables[2253] += 1
  1107. else:
  1108. this.playerConsumables[2253] = 1
  1109. else:
  1110. this.cheeseCount += 1
  1111.  
  1112. count = 4 if place == 1 else 3 if place == 2 else 2 if place == 2 else 1
  1113. this.shopCheeses += count
  1114. this.shopFraises += count
  1115.  
  1116. this.sendGiveCurrency(0, 1)
  1117. this.skillModule.earnExp(False, 20)
  1118. if not this.isGuest:
  1119. if place == 1 and this.server.firstTitleList.has_key(this.firstCount):
  1120. title = this.server.firstTitleList[this.firstCount]
  1121. this.checkAndRebuildTitleList("first")
  1122. this.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  1123. this.sendCompleteTitleList()
  1124. this.sendTitleList()
  1125.  
  1126. if this.server.cheeseTitleList.has_key(this.cheeseCount):
  1127. title = this.server.cheeseTitleList[this.cheeseCount]
  1128. this.checkAndRebuildTitleList("cheese")
  1129. this.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  1130. this.sendCompleteTitleList()
  1131. this.sendTitleList()
  1132.  
  1133. elif this.room.getPlayerCountUnique() >= this.server.needToBootcamp and this.room.isBootcamp and not this.isGuest:
  1134. if not this.server.isNowEvent:
  1135. this.bootcampCount += 1
  1136. else:
  1137. this.bootcampCount += 3
  1138.  
  1139. if this.server.bootcampTitleList.has_key(this.bootcampCount):
  1140. title = this.server.bootcampTitleList[this.bootcampCount]
  1141. this.checkAndRebuildTitleList("bootcamp")
  1142. this.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  1143. this.sendCompleteTitleList()
  1144. this.sendTitleList()
  1145.  
  1146. this.room.giveShamanSave(this.room.currentSecondShamanName if holeType == 2 and this.room.isDoubleMap else this.room.currentShamanName, 0)
  1147. if this.room.currentShamanType != 0:
  1148. this.room.giveShamanSave(this.room.currentShamanName, this.room.currentShamanType)
  1149.  
  1150. if this.room.currentSecondShamanType != 0:
  1151. this.room.giveShamanSave(this.room.currentSecondShamanName, this.room.currentSecondShamanType)
  1152.  
  1153. this.sendPlayerWin(place, timeTaken)
  1154.  
  1155. if this.room.getPlayerCount() >= 2 and this.room.checkIfTooFewRemaining() and not this.room.isDoubleMap and this.room.currentShamanName != "" and this.isOpportunist:
  1156. this.playerWin(0)
  1157. else:
  1158. this.room.checkShouldChangeMap()
  1159.  
  1160. this.room.canChangeMap = True
  1161.  
  1162. def sendSaveRemainingMiceMessage(this):
  1163. this.sendPacket(Identifiers.old.send.Save_Remaining, [])
  1164.  
  1165. def sendGiveCurrency(this, type, count):
  1166. this.sendPacket(Identifiers.send.Give_Currency, ByteArray().writeByte(type).writeByte(count).toByteArray())
  1167.  
  1168. def sendPlayerWin(this, place, timeTaken):
  1169. 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())
  1170. this.hasCheese = False
  1171.  
  1172. def sendCompleteTitleList(this):
  1173. this.titleList = []
  1174. this.titleList.append(0.1)
  1175. this.titleList.extend(this.cheeseTitleList)
  1176. this.titleList.extend(this.firstTitleList)
  1177. this.titleList.extend(this.shamanTitleList)
  1178. this.titleList.extend(this.shopTitleList)
  1179. this.titleList.extend(this.bootcampTitleList)
  1180. this.titleList.extend(this.hardModeTitleList)
  1181. this.titleList.extend(this.divineModeTitleList)
  1182. this.titleList.extend(this.specialTitleList)
  1183.  
  1184. if this.privLevel >= 2:
  1185. this.titleList.append(1100.9)
  1186.  
  1187. if this.privLevel == 11:
  1188. 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])
  1189.  
  1190. if this.privLevel >= 5:
  1191. this.titleList.append(1103.9 if this.gender in [2, 0] else 1104.9)
  1192.  
  1193. if this.privLevel >= 6:
  1194. this.titleList.append(1105.9 if this.gender in [2, 0] else 1106.9)
  1195.  
  1196. if this.privLevel >= 7:
  1197. this.titleList.append(1107.9 if this.gender in [2, 0] else 1108.9)
  1198.  
  1199. if this.privLevel >= 8:
  1200. this.titleList.append(1109.9 if this.gender in [2, 0] else 1110.9)
  1201.  
  1202. if this.privLevel >= 9:
  1203. this.titleList.append(1111.9 if this.gender in [2, 0] else 1112.9)
  1204.  
  1205. if this.privLevel == 10:
  1206. 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])
  1207.  
  1208. def sendTitleList(this):
  1209. this.sendPacket(Identifiers.old.send.Titles_List, [this.titleList])
  1210.  
  1211. def sendUnlockedTitle(this, title, stars):
  1212. this.room.sendAll(Identifiers.old.send.Unlocked_Title, [this.playerCode, title, stars])
  1213.  
  1214. def sendMessage(this, message, tab=False):
  1215. this.sendPacket(Identifiers.send.Recv_Message, ByteArray().writeBool(tab).writeUTF(message).writeByte(0).writeUTF("").toByteArray())
  1216.  
  1217. def sendProfile(this, playerName):
  1218. player = this.server.players.get(playerName)
  1219.  
  1220. if player != None and not player.isGuest:
  1221. p = ByteArray().writeInt(player.playerID).writeUTF(player.Username if player.mouseName == "" else this.mouseName)
  1222. for stat in [player.shamanSaves, player.shamanCheeses, player.firstCount, player.cheeseCount, player.hardModeSaves, player.bootcampCount, player.divineModeSaves]:
  1223. p.writeInt(stat)
  1224.  
  1225. p.writeShort(player.TitleNumber)
  1226. titles = ByteArray()
  1227. for title in player.titleList:
  1228. titleInfo = str(title).split(".")
  1229. titles.writeShort(int(titleInfo[0])).writeByte(int(titleInfo[1]))
  1230.  
  1231. titlesResult = titles.toByteArray()
  1232.  
  1233. p.writeShort(len(player.titleList))
  1234. p.write(titlesResult)
  1235. p.writeUTF(player.playerLook)
  1236. p.writeUTF(player.tribeName)
  1237. p.writeInt(str(player.regDate)[:10])
  1238. p.writeInt(int(player.MouseColor, 16))
  1239. p.writeShort(player.shamanLevel)
  1240. p.writeByte(player.gender)
  1241. 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)
  1242. p.writeBool(True)
  1243. p.writeUTF(player.marriage)
  1244. p.writeUnsignedByte(len(player.shopBadges) * 2)
  1245.  
  1246. badges = map(int, player.shopBadges)
  1247. 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]:
  1248. if badge in badges:
  1249. p.writeUnsignedByte(badge).writeByte(0)
  1250. badges.remove(int(badge))
  1251.  
  1252. for badge in badges:
  1253. p.writeUnsignedByte(badge).writeByte(0)
  1254.  
  1255. 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]]
  1256. p.writeByte(len(stats))
  1257. for stat in stats:
  1258. p.writeByte(stat[0]).writeInt(stat[1]).writeInt(stat[2]).writeByte(stat[3])
  1259.  
  1260. p.writeByte(player.equipedShamanBadge).writeByte(len(player.shamanBadges))
  1261. for shamanBadge in player.shamanBadges:
  1262. p.writeByte(shamanBadge)
  1263.  
  1264. this.sendPacket(Identifiers.send.Profile, p.toByteArray())
  1265.  
  1266. def sendPlayerBan(this, hours, reason, silent):
  1267. this.sendPacket(Identifiers.old.send.Player_Ban, [3600000 * hours, reason])
  1268. if not silent and this.room != None:
  1269. for player in this.room.clients.values():
  1270. player.sendLangueMessage("", "<ROSE>$Message_Ban", this.Username, str(hours), reason)
  1271.  
  1272. this.server.disconnectIPAddress(this.ipAddress)
  1273.  
  1274. def sendPlayerEmote(this, emoteID, flag, others, lua):
  1275. p = ByteArray().writeInt(this.playerCode).writeByte(emoteID)
  1276. if not flag == "": p.writeUTF(flag)
  1277. result = p.writeBool(lua).toByteArray()
  1278.  
  1279. this.room.sendAllOthers(this, Identifiers.send.Player_Emote, result) if others else this.room.sendAll(Identifiers.send.Player_Emote, result)
  1280.  
  1281. def sendEmotion(this, emotion):
  1282. this.room.sendAllOthers(this, Identifiers.send.Emotion, ByteArray().writeInt(this.playerCode).writeByte(emotion).toByteArray())
  1283.  
  1284. def sendPlaceObject(this, objectID, code, px, py, angle, vx, vy, dur, sendAll):
  1285. p = ByteArray().writeInt(objectID).writeShort(code).writeShort(px).writeShort(py).writeShort(angle).writeByte(vx).writeByte(vy).writeBool(dur)
  1286. p.writeByte(0) if this.isGuest or sendAll else p.writeBytes(this.shopModule.getShamanItemCustom(code))
  1287.  
  1288. if not sendAll:
  1289. this.room.sendAllOthers(this, Identifiers.send.Spawn_Object, p.toByteArray())
  1290. this.room.objectID = objectID
  1291. else:
  1292. this.room.sendAll(Identifiers.send.Spawn_Object, p.toByteArray())
  1293.  
  1294. def sendAllModerationChat(this, type, message):
  1295. 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 "")
  1296. if "][" in playerName: playerName += this.Username
  1297. 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())
  1298.  
  1299. def sendStaffLogin(this, isDisconnect):
  1300. 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 "")
  1301. 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())
  1302.  
  1303. def sendTotem(this, totem, x, y, playerCode):
  1304. this.sendPacket(Identifiers.old.send.Totem, [str(playerCode) + "#" + str(x) + "#" + str(y) + totem])
  1305.  
  1306. def sendTotemItemCount(this, number):
  1307. if this.room.isTotemEditeur:
  1308. this.sendPacket(Identifiers.old.send.Totem_Item_Count, ByteArray().writeShort(number * 2).writeShort(0).toByteArray())
  1309.  
  1310. def initTotemEditeur(this):
  1311. if this.RTotem:
  1312. this.sendTotemItemCount(0)
  1313. this.RTotem = False
  1314. else:
  1315. if not this.STotem[1] == "":
  1316. this.Totem[0] = this.STotem[0]
  1317. this.Totem[1] = this.STotem[1]
  1318. this.sendTotemItemCount(int(this.STotem[0]))
  1319. this.sendTotem(this.STotem[1], 400, 202, this.playerCode)
  1320. else:
  1321. this.sendTotemItemCount(0)
  1322.  
  1323. def sendShamanType(this, mode, canDivine):
  1324. this.sendPacket(Identifiers.send.Shaman_Type, ByteArray().writeByte(mode).writeBool(canDivine).writeInt(int(this.ShamanColor, 16)).toByteArray())
  1325.  
  1326. def sendBanConsideration(this):
  1327. this.sendPacket(Identifiers.old.send.Ban_Consideration, ["0"])
  1328.  
  1329. def sendShamanPosition(this, direction):
  1330. this.room.sendAll(Identifiers.send.Shaman_Position, ByteArray().writeInt(this.playerCode).writeBool(direction).toByteArray())
  1331.  
  1332. def loadCafeMode(this):
  1333. can = this.privLevel >= 5 or (this.Langue.upper() == this.realLangue and this.privLevel != 0 and this.cheeseCount >= 100)
  1334. if not can:
  1335. this.sendLangueMessage("", "<ROSE>$PasAutoriseParlerSurServeur")
  1336.  
  1337. this.sendPacket(Identifiers.send.Open_Cafe, ByteArray().writeBool(can).toByteArray())
  1338. p = ByteArray()
  1339. this.Cursor.execute("select * from CafeTopics where Langue = ? order by Date desc limit 0, 20", [this.Langue])
  1340. r = this.Cursor.fetchall()
  1341. for rs in r:
  1342. p.writeInt(rs["TopicID"]).writeUTF(rs["Title"]).writeInt(this.server.getPlayerID(rs["Author"])).writeInt(rs["Posts"]).writeUTF(rs["LastPostName"]).writeInt(TFMUtils.getSecondsDiff(rs["Date"]))
  1343. this.sendPacket(Identifiers.send.Cafe_Topics_List, p.toByteArray())
  1344.  
  1345. def openCafeTopic(this, topicID):
  1346. p = ByteArray().writeBool(True).writeInt(topicID)
  1347. this.Cursor.execute("select * from CafePosts where TopicID = ? order by PostID asc", [topicID])
  1348. r = this.Cursor.fetchall()
  1349. for rs in r:
  1350. 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"])
  1351. this.sendPacket(Identifiers.send.Open_Cafe_Topic, p.toByteArray())
  1352.  
  1353. def createNewCafeTopic(this, title, message):
  1354. this.server.lastTopicID += 1
  1355. this.Cursor.execute("insert into CafeTopics values (?, ?, ?, '', 0, ?, ?)", [this.server.lastTopicID, title, this.Username, TFMUtils.getTime(), this.Langue])
  1356. this.server.updateConfig()
  1357. this.createNewCafePost(this.server.lastTopicID, message)
  1358. this.loadCafeMode()
  1359.  
  1360. def createNewCafePost(this, topicID, message):
  1361. commentsCount = 0
  1362. this.server.lastPostID += 1
  1363. this.Cursor.execute("insert into CafePosts values (?, ?, ?, ?, ?, 0, ?)", [this.server.lastPostID, topicID, this.Username, message, TFMUtils.getTime(), str(this.playerCode)])
  1364. this.Cursor.execute("update CafeTopics set Posts = Posts + 1, LastPostName = ?, Date = ? where TopicID = ?", [this.Username, TFMUtils.getTime(), topicID])
  1365. this.Cursor.execute("select count(*) as count from CafePosts where TopicID = ?", [topicID])
  1366. rs = this.Cursor.fetchone()
  1367. commentsCount = rs["count"]
  1368. this.openCafeTopic(topicID)
  1369. for client in this.server.players.values():
  1370. if client.isCafe:
  1371. client.sendPacket(Identifiers.send.Cafe_New_Post, ByteArray().writeInt(topicID).writeUTF(this.Username).writeInt(commentsCount).toByteArray())
  1372.  
  1373. def voteCafePost(this, topicID, postID, mode):
  1374. 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])
  1375.  
  1376. def sendLangueMessage(this, message1, message2, *args):
  1377. p = ByteArray().writeUTF(message1).writeUTF(message2).writeByte(len(args))
  1378. for arg in args:
  1379. p.writeUTF(arg)
  1380. this.sendPacket(Identifiers.send.Message_Langue, p.toByteArray())
  1381.  
  1382. def sendVampireMode(this, others):
  1383. this.isVampire = True
  1384. p = ByteArray().writeInt(this.playerCode)
  1385. if others:
  1386. this.room.sendAllOthers(this, Identifiers.send.Vampire_Mode, p.toByteArray())
  1387. else:
  1388. this.room.sendAll(Identifiers.send.Vampire_Mode, p.toByteArray())
  1389.  
  1390. def sendRemoveCheese(this):
  1391. this.room.sendAll(Identifiers.send.Remove_Cheese, ByteArray().writeInt(this.playerCode).toByteArray())
  1392.  
  1393. def sendLuaMessage(this, message):
  1394. this.sendPacket(Identifiers.send.Lua_Message, ByteArray().writeUTF(message).toByteArray())
  1395.  
  1396. def sendGameMode(this, mode):
  1397. mode = 1 if mode == 0 else mode
  1398. types = [1, 3, 8, 9, 11, 2, 10, 18, 16]
  1399. p = ByteArray().writeByte(len(types))
  1400. for roomType in types:
  1401. p.writeByte(roomType)
  1402.  
  1403. p.writeByte(mode)
  1404. modeInfo = this.server.getPlayersCountMode(mode, this.Langue)
  1405. if not modeInfo[0] == "":
  1406. roomsCount = 0
  1407. p.writeUnsignedByte(1).writeUnsignedByte(this.langueByte).writeUTF(str(modeInfo[0])).writeUTF(str(modeInfo[1])).writeUTF("mjj").writeUTF("1")
  1408. for checkRoom in this.server.rooms.values():
  1409. 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():
  1410. roomsCount +=1
  1411. p.writeUnsignedByte(0).writeUnsignedByte(this.langueByte).writeUTF(checkRoom.roomName).writeUnsignedShort(checkRoom.getPlayerCount()).writeUnsignedByte(checkRoom.maxPlayers).writeBool(checkRoom.isFuncorp)
  1412.  
  1413. if roomsCount == 0:
  1414. p.writeUnsignedByte(0).writeUnsignedByte(this.langueByte).writeUTF(("" if mode == 1 else str(modeInfo[0].split(" ")[1])) + "1").writeUnsignedShort(0).writeUnsignedByte(200).writeBool(False)
  1415.  
  1416. if mode == 18:
  1417. minigameList = ["#deathmatch", "#utility"]
  1418. moduleCount = {"#deathmatch": 0, "#utility": 0}
  1419. moduleMjj = {"#deathmatch": "#deathmatch", "#utility": "#utility0%s" % (this.Username)}
  1420. for checkRoom in this.server.rooms.values():
  1421. if checkRoom.isUtility:
  1422. moduleCount["#utility"] += checkRoom.getPlayerCount()
  1423. elif checkRoom.isDeathmatch:
  1424. moduleCount["#deathmatch"] += checkRoom.getPlayerCount()
  1425. for minigame in minigameList:
  1426. p.writeUnsignedByte(1).writeUnsignedByte(this.langueByte).writeUTF(str(minigame)).writeUTF(str(moduleCount[minigame])).writeUTF("mjj").writeUTF(str(moduleMjj[minigame]))
  1427. for checkRoom in this.server.rooms.values():
  1428. if checkRoom.isUtility or checkRoom.isDeathmatch:
  1429. p.writeUnsignedByte(0).writeUnsignedByte(this.langueByte).writeUTF(checkRoom.roomName).writeUnsignedShort(checkRoom.getPlayerCount()).writeUnsignedByte(checkRoom.maxPlayers).writeBool(checkRoom.isFuncorp)
  1430.  
  1431. this.sendPacket(Identifiers.send.Game_Mode, p.toByteArray())
  1432.  
  1433. def sendMusicVideo(this, sendAll):
  1434. music = this.room.musicVideos[0]
  1435. 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")))
  1436. if sendAll:
  1437. this.room.musicSkipVotes = 0
  1438. this.room.sendAll(Identifiers.send.Music_Video, p.toByteArray())
  1439. else:
  1440. this.sendPacket(Identifiers.send.Music_Video, p.toByteArray())
  1441.  
  1442. def checkMusicSkip(this):
  1443. if this.room.isMusic and this.room.isPlayingMusic:
  1444. count = this.room.getPlayersCount()
  1445. count = count if count % 2 == 0 else count + 1
  1446. if this.room.musicSkipVotes == count / 2:
  1447. this.room.musicVideos.remove(0)
  1448. this.sendMusicVideo(True)
  1449.  
  1450. def sendStaffMessage(this, message, othersLangues):
  1451. for player in this.server.players.values():
  1452. if othersLangues or player.Langue == this.Langue:
  1453. player.sendMessage(message, True)
  1454.  
  1455. def checkVip(this, vipTime):
  1456. days = TFMUtils.getDiffDays(vipTime)
  1457. if days >= 0:
  1458. this.privLevel = 1
  1459. if this.TitleNumber == 1100:
  1460. this.TitleNumber = 0
  1461.  
  1462. this.sendMessage("O seu VIP se estogou.")
  1463. this.Cursor.execute("update users set VipTime = 0 where Username = ?", [this.Username])
  1464. else:
  1465. this.sendMessage("Você ainda tem <V>"+str(days)+"</V> dias de VIP!")
  1466.  
  1467. def sendMenu(this):
  1468. if this.privLevel >= 1:
  1469. if this.showButtons:
  1470. text = "<a href='event:showButtons'><font color='#FA5858'>▲</font></a> <font color='#FFFFFF' size='10'>Menu</font>\n"
  1471. text += "\n<a href='event:shop:open'><img src='http://miceflash.top/images/menu/shop.png' align='right' hspace='5' vspace='3'></a>"
  1472. text += "\n<a href='event:spinTheWheel:open'><img src='http://miceflash.top/images/menu/roleta.png' align='right' hspace='5' vspace='3'></a>"
  1473. text += "\n<a href='event:vipInfo:open'><img src='http://miceflash.top/images/menu/vipInfo.png' align='right' hspace='5' vspace='3'></a>"
  1474. text += "\n<a href='event:consumablesShop:open'><img src='http://miceflash.top/images/menu/consumablesShop.png' align='right' hspace='5' vspace='3'></a>"
  1475. text += "\n<a href='event:staffList'><img src='http://miceflash.top/images/menu/staffList.png' align='right' hspace='5' vspace='3'></a>"
  1476. text += "\n<a href='event:help'><img src='http://miceflash.top/images/menu/help.png' align='right' hspace='5' vspace='3'></a>"
  1477. text += "\n<a href='event:changeColor'><img src='http://miceflash.top/images/menu/changeColor.png' align='right' hspace='5' vspace='3'></a>"
  1478. text += "\n<a href='event:ranking'><img src='http://miceflash.top/images/menu/ranking.png' align='right' hspace='5' vspace='3'></a>"
  1479. this.room.addTextArea(10000, str(text), this.Username, 743, 28, 52, 310, 0x97714C, 0x27373f, 50, False)
  1480. else:
  1481. 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)
  1482.  
  1483. def updateTribePoints(this):
  1484. this.Cursor.execute("update Tribe set Points = Points + ? where Code = ?", [this.tribePoints, this.tribeCode])
  1485. this.tribePoints = 0
  1486.  
  1487. def sendLogMessage(this, message):
  1488. 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())
  1489.  
  1490. def runLuaAdminScript(this, script):
  1491. try:
  1492. pythonScript = compile(str(script), "<string>", "exec")
  1493. exec pythonScript
  1494. startTime = int(time.time())
  1495. endTime = int(time.time())
  1496. totalTime = endTime - startTime
  1497. message = "<V>["+this.room.roomName+"]<BL> ["+this.Username+"] Lua script loaded in "+str(totalTime)+" ms (4000 max)"
  1498. this.sendLuaMessage(message)
  1499. except Exception as error:
  1500. this.server.sendStaffMessage(7, "<V>["+this.room.roomName+"]<BL> [Bot: "+this.Username+"][Exception]: "+str(error))
  1501.  
  1502. def runLuaScript(this, script):
  1503. try:
  1504. pythonScript = compile(str(script), "<string>", "exec")
  1505. exec pythonScript
  1506. startTime = int(time.time())
  1507. totalTime = int(time.time()) - startTime
  1508.  
  1509. if totalTime > 4000:
  1510. this.sendLuaMessage("<V>["+this.room.roomName+"]<BL> ["+this.Username+"] Lua script not loaded. ("+str(totalTime)+" ms - 4000 max)")
  1511. else:
  1512. this.sendLuaMessage("<V>["+this.room.roomName+"]<BL> ["+this.Username+"] Lua script loaded in "+str(totalTime)+" ms (4000 max)")
  1513. except Exception as error:
  1514. this.sendLuaMessage("<V>["+this.room.roomName+"]<BL> ["+this.Username+"][Exception]: "+str(error))
  1515.  
  1516. def sendAnimZelda(this, type, item):
  1517. if type == 7:
  1518. this.room.sendAll(Identifiers.send.Anim_Zelda, ByteArray().writeInt(this.playerCode).writeByte(type).writeUTF("$De6").writeByte(item).toByteArray())
  1519. else:
  1520. this.room.sendAll(Identifiers.send.Anim_Zelda, ByteArray().writeInt(this.playerCode).writeByte(type).writeInt(item).toByteArray())
  1521.  
  1522. def sendAnimZeldaInventory(this, id1, id2, count):
  1523. if id1 == 4:
  1524. this.sendPacket([100, 67], ByteArray().writeByte(0).writeShort(id2).writeShort(count).toByteArray())
  1525. #this.sendData("\x64C", this.put("bhh", 0, id2, count))
  1526. this.room.sendAll([8, 44], ByteArray().writeInt(this.playerCode).writeByte(id1).writeInt(id2).toByteArray())
  1527.  
  1528. def premioVillage(this, coisa):
  1529. if coisa[0] == 1:
  1530. medal = coisa[1]
  1531. if this.playerConsumables[coisa[4]] >= coisa[5]:
  1532. if not int(medal) in this.shopBadges:
  1533. this.shopModule.sendUnlockedBadge(medal)
  1534. this.shopBadges.append(str(medal))
  1535. this.playerConsumables[coisa[4]] -= coisa[5]
  1536. elif coisa[0] == 2:
  1537. symbol = str(coisa[1])
  1538. if not symbol in this.shamanBadges:
  1539. if this.shamanBadges[0] == '':
  1540. this.shamanBadges = [symbol]
  1541. else:
  1542. test = [symbol]
  1543. this.shamanBadges = this.shamanBadges + test
  1544. this.playerConsumables[coisa[4]] -= coisa[5]
  1545. this.sendAnimZeldaInventory(6, coisa[1], 1)
  1546. elif coisa[0] == 3:
  1547. titles = [str(coisa[1])+".1"]
  1548. #titles = ["387.1"]
  1549. title = random.choice(titles)
  1550. while title in this.titleList:
  1551. try:
  1552. titles.remove(title)
  1553. title = random.choice(titles)
  1554. except:
  1555. break
  1556. if not title in this.titleList:
  1557. stitle = title.split(".")
  1558. this.specialTitleList = this.specialTitleList + [title]
  1559. this.sendUnlockedTitle(stitle[0], stitle[1])
  1560.  
  1561. this.sendCompleteTitleList()
  1562. this.sendTitleList()
  1563. elif coisa[0] == 4:
  1564. if this.playerConsumables[coisa[4]] >= coisa[5]:
  1565. id = coisa[1]
  1566. if not id in this.playerConsumables:
  1567. this.playerConsumables[id] = coisa[2]
  1568. else:
  1569. count = this.playerConsumables[id] + coisa[2]
  1570. this.playerConsumables[id] = count
  1571. this.playerConsumables[coisa[4]] -= coisa[5]
  1572. this.sendAnimZeldaInventory(4, id, coisa[2])
  1573. this.BotsVillage(this.botVillage)
  1574.  
  1575. def BotsVillage(this, bot):
  1576. itens = list()
  1577. for item in this.itensBots[bot]:
  1578. if item[0] == 1 and str(item[1]) in this.shopBadges:
  1579. itens.append(item)
  1580. elif item[0] == 2 and str(item[1]) in this.shamanBadges:
  1581. itens.append(item)
  1582. elif item[0] == 3 and str(item[1])+".1" in this.titleList:
  1583. itens.append(item)
  1584. for item in itens:
  1585. this.itensBots[bot].remove(item)
  1586. p = ByteArray()
  1587. for items in this.itensBots[bot]:
  1588. count = items[5]
  1589. if items[4] in this.playerConsumables:
  1590. one = 0 if this.playerConsumables[items[4]] >= count else 1
  1591. else:
  1592. one = 1
  1593. #data += this.put("bbhhbhh", one, *items)
  1594. p.writeByte(one).writeByte(items[0]).writeShort(items[1]).writeShort(items[2]).writeByte(items[3]).writeShort(items[4]).writeShort(items[5])
  1595. this.sendPacket([26, 38], ByteArray().writeUTF(bot).writeByte(len(this.itensBots[bot])).toByteArray() + p.toByteArray())
  1596.  
  1597. def sendInventoryConsumables(this):
  1598. p = ByteArray().writeShort(len(this.playerConsumables))
  1599. for id, count in this.playerConsumables.items():
  1600. 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)
  1601. this.sendPacket(Identifiers.send.Inventory, p.toByteArray())
  1602.  
  1603. def updateInventoryConsumable(this, id, count):
  1604. this.sendPacket(Identifiers.send.Update_Inventory_Consumable, ByteArray().writeShort(id).writeUnsignedByte(250 if count > 250 else count).toByteArray())
  1605.  
  1606. def useInventoryConsumable(this, id):
  1607. if id == 29 or id == 30 or id == 2241:
  1608. this.sendPacket(Identifiers.send.Use_Inventory_Consumable, ByteArray().writeInt(this.playerCode).writeShort(id).toByteArray())
  1609. else:
  1610. this.room.sendAll(Identifiers.send.Use_Inventory_Consumable, ByteArray().writeInt(this.playerCode).writeShort(id).toByteArray())
  1611.  
  1612. def sendTradeResult(this, playerName, result):
  1613. this.sendPacket(Identifiers.send.Trade_Result, ByteArray().writeUTF(playerName).writeByte(result).toByteArray())
  1614.  
  1615. def sendTradeInvite(this, playerCode):
  1616. this.sendPacket(Identifiers.send.Trade_Invite, ByteArray().writeInt(playerCode).toByteArray())
  1617.  
  1618. def sendTradeStart(this, playerCode):
  1619. this.sendPacket(Identifiers.send.Trade_Start, ByteArray().writeInt(playerCode).toByteArray())
  1620.  
  1621. def tradeInvite(this, playerName):
  1622. player = this.room.clients.get(playerName)
  1623. 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:
  1624. if not player.isTrade:
  1625. if not player.room.name == this.room.name:
  1626. this.sendTradeResult(playerName, 5)
  1627. elif player.isTrade:
  1628. this.sendTradeResult(playerName, 0)
  1629. else:
  1630. this.sendLangueMessage("", "$Demande_Envoyée")
  1631. player.sendTradeInvite(this.playerCode)
  1632.  
  1633. this.tradeName = playerName
  1634. this.isTrade = True
  1635. else:
  1636. this.tradeName = playerName
  1637. this.isTrade = True
  1638. this.sendTradeStart(player.playerCode)
  1639. player.sendTradeStart(this.playerCode)
  1640.  
  1641. def cancelTrade(this, playerName):
  1642. player = this.room.clients.get(playerName)
  1643. if player != None:
  1644. this.tradeName = ""
  1645. this.isTrade = False
  1646. this.tradeConsumables = {}
  1647. this.tradeConfirm = False
  1648. player.tradeName = ""
  1649. player.isTrade = False
  1650. player.tradeConsumables = {}
  1651. player.tradeConfirm = False
  1652. player.sendTradeResult(this.Username, 2)
  1653.  
  1654. def tradeAddConsumable(this, id, isAdd):
  1655. player = this.room.clients.get(this.tradeName)
  1656. if player != None and player.isTrade and player.tradeName == this.Username:
  1657. if isAdd:
  1658. if this.tradeConsumables.has_key(id):
  1659. this.tradeConsumables[id] += 1
  1660. else:
  1661. this.tradeConsumables[id] = 1
  1662. else:
  1663. count = this.tradeConsumables[id] - 1
  1664. if count > 0:
  1665. this.tradeConsumables[id] = count
  1666. else:
  1667. del this.tradeConsumables[id]
  1668.  
  1669. player.sendPacket(Identifiers.send.Trade_Add_Consumable, ByteArray().writeBool(False).writeShort(id).writeBool(isAdd).writeByte(1).writeBool(False).toByteArray())
  1670. this.sendPacket(Identifiers.send.Trade_Add_Consumable, ByteArray().writeBool(True).writeShort(id).writeBool(isAdd).writeByte(1).writeBool(False).toByteArray())
  1671.  
  1672. def tradeResult(this, isAccept):
  1673. player = this.room.clients.get(this.tradeName)
  1674. if player != None and player.isTrade and player.tradeName == this.Username:
  1675. this.tradeConfirm = isAccept
  1676. player.sendPacket(Identifiers.send.Trade_Confirm, ByteArray().writeBool(False).writeBool(isAccept).toByteArray())
  1677. this.sendPacket(Identifiers.send.Trade_Confirm, ByteArray().writeBool(True).writeBool(isAccept).toByteArray())
  1678. if this.tradeConfirm and player.tradeConfirm:
  1679. for consumable in player.tradeConsumables.items():
  1680. if this.playerConsumables.has_key(consumable[0]):
  1681. this.playerConsumables[consumable[0]] += consumable[1]
  1682. else:
  1683. this.playerConsumables[consumable[0]] = consumable[1]
  1684.  
  1685. count = player.playerConsumables[consumable[0]] - consumable[1]
  1686. if count <= 0:
  1687. del player.playerConsumables[consumable[0]]
  1688. if consumable[0] in player.equipedConsumables:
  1689. player.equipedConsumables.remove(consumable[0])
  1690. else:
  1691. player.playerConsumables[consumable[0]] = consumable[1]
  1692.  
  1693. for consumable in this.tradeConsumables.items():
  1694. if this.playerConsumables.has_key(consumable[0]):
  1695. this.playerConsumables[consumable[0]] += consumable[1]
  1696. else:
  1697. this.playerConsumables[consumable[0]] = consumable[1]
  1698.  
  1699. count = this.playerConsumables[consumable[0]] - consumable[1]
  1700. if count <= 0:
  1701. del this.playerConsumables[consumable[0]]
  1702. if consumable[0] in player.equipedConsumables:
  1703. this.equipedConsumables.remove(consumable[0])
  1704. else:
  1705. this.playerConsumables[consumable[0]] = consumable[1]
  1706.  
  1707. player.tradeName = ""
  1708. player.isTrade = False
  1709. player.tradeConsumables = {}
  1710. player.tradeConfirm = False
  1711. player.sendPacket(Identifiers.send.Trade_Close)
  1712. player.sendInventoryConsumables()
  1713. this.tradeName = ""
  1714. this.isTrade = False
  1715. this.tradeConsumables = {}
  1716. this.tradeConfirm = False
  1717. this.sendPacket(Identifiers.send.Trade_Close)
  1718. this.sendInventoryConsumables()
  1719.  
  1720. def giveConsumable(this, id, amount=80, limit=80):
  1721. this.sendAnimZelda(4, id)
  1722. sum = (this.playerConsumables[id] if this.playerConsumables.has_key(id) else 0) + amount
  1723. if limit != -1 and sum > limit: sum = limit
  1724. if this.playerConsumables.has_key(id):
  1725. this.playerConsumables[id] = sum
  1726. else:
  1727. this.playerConsumables[id] = sum
  1728.  
  1729. this.updateInventoryConsumable(id, sum)
  1730.  
  1731. def sendNewConsumable(this, consumable, count):
  1732. this.sendPacket(Identifiers.send.New_Consumable, ByteArray().writeByte(0).writeShort(consumable).writeShort(count).toByteArray())
  1733.  
  1734. def checkLetters(this, playerLetters):
  1735. needUpdate = False
  1736. letters = playerLetters.split("/")
  1737. for letter in letters:
  1738. if not letter == "":
  1739. values = letter.split("|")
  1740. this.sendPacket(Identifiers.send.Letter, ByteArray().writeUTF(values[0]).writeUTF(values[1]).writeByte(int(values[2])).writeBytes(binascii.unhexlify(values[3])).toByteArray())
  1741. needUpdate = True
  1742.  
  1743. if needUpdate:
  1744. this.Cursor.execute("update users set Letters = '' where Username = ?", [this.Username])
  1745.  
  1746. def getFullItemID(this, category, itemID):
  1747. return itemID + 10000 + 1000 * category if (itemID >= 100) else itemID + 100 * category
  1748.  
  1749. def getSimpleItemID(this, category, itemID):
  1750. return itemID - 10000 - 1000 * category if (itemID >= 10000) else itemID - 100 * category
  1751.  
  1752. def getItemInfo(this, category, itemID):
  1753. shop = map(lambda x: map(int, x.split(",")), this.server.shopList)
  1754.  
  1755. return filter(lambda x: x[0] == category and x[1] == itemID, shop)[0] + ([20] if (category != 22) else [0])
  1756.  
  1757. class Server(protocol.ServerFactory):
  1758. protocol = Client
  1759. def __init__(this):
  1760.  
  1761. # Settings
  1762. this.DEBUG = bool(int(this.config("DEBUG")))
  1763. this.CKEY = str(this.config("CKEY"))
  1764. this.Version = str(this.config("Version"))
  1765. this.lastPlayerID = int(this.config("Last Player ID"))
  1766. this.lastMapEditeurCode = int(this.config("Last Map Editeur Code"))
  1767. this.needToFirst = int(this.config("Need To First"))
  1768. this.needToBootcamp = int(this.config("Need To Bootcamp"))
  1769. this.lastTribeID = int(this.config("Last Tribe ID"))
  1770. this.lastChatID = int(this.config("Last Chat ID"))
  1771. this.initialCheeses = int(this.config("Initial Cheeses"))
  1772. this.initialFraises = int(this.config("Initial Fraises"))
  1773. this.lastTopicID = int(this.config("Last Topic ID"))
  1774. this.lastPostID = int(this.config("Last Post ID"))
  1775. this.isNowEvent = bool(int(this.config("Now Event")))
  1776. this.adminAllow = this.config("admin Allow").split(", ")
  1777. this.shopList = Config.get("ConfigShop", "Shop List", 0).split(";")
  1778. this.shamanShopList = Config.get("ConfigShop", "Shaman Shop List", 0).split(";")
  1779. this.newVisuList = eval(Config.get("ConfigShop", "New Visu List", 0))
  1780.  
  1781. # Integer
  1782. this.lastPlayerCode = 0
  1783. this.lastGiftID = 0
  1784.  
  1785. # Nonetype
  1786. this.rebootTimer = None
  1787.  
  1788. # List
  1789. this.loginKeys = []
  1790. this.packetKeys = []
  1791. this.userMuteCache = []
  1792. this.tempIPBanList = []
  1793. this.userMuteCache = []
  1794. this.tempIPBanList = []
  1795. this.shopPromotions = []
  1796. this.ipPermaBanCache = []
  1797. this.userTempBanCache = []
  1798. this.userPermaBanCache = []
  1799.  
  1800. # Dict
  1801. this.reports = {"names": []}
  1802. this.rooms = {}
  1803. this.players = {}
  1804. this.shopListCheck = {}
  1805. this.shamanShopListCheck = {}
  1806. this.shopGifts = {}
  1807. this.chatMessages = {}
  1808. this.connectedCounts = {}
  1809. 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}
  1810. 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}
  1811. 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}
  1812. 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}
  1813. 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}
  1814. 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}
  1815. 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}
  1816. 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}
  1817. 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]
  1818. # Others
  1819. this.Cursor = Cursor
  1820. this.parseShop()
  1821. this.parseBanList()
  1822. this.parseShamanShop()
  1823. this.menu = this.parseJson("./include/menu.json")
  1824. this.blackList = this.parseJson("./include/blackList.json")
  1825. this.promotions = this.parseJson("./include/promotions.json")
  1826. this.parsePromotions()
  1827.  
  1828. def updateConfig(this):
  1829. this.configs("Last Player ID", str(this.lastPlayerID))
  1830. this.configs("Last Map Editeur Code", str(this.lastMapEditeurCode))
  1831. this.configs("Last Tribe ID", str(this.lastTribeID))
  1832. this.configs("Last Chat ID", str(this.lastChatID))
  1833. this.configs("Last Topic ID", str(this.lastTopicID))
  1834. this.configs("Last Post ID", str(this.lastPostID))
  1835.  
  1836. def parseShop(this):
  1837. for item in this.shopList:
  1838. values = item.split(",")
  1839. this.shopListCheck[values[0] + "|" + values[1]] = [int(values[5]), int(values[6])]
  1840.  
  1841. def parseShamanShop(this):
  1842. for item in this.shamanShopList:
  1843. values = item.split(",")
  1844. this.shamanShopListCheck[values[0]] = [int(values[3]), int(values[4])]
  1845.  
  1846. def sendOutput(this, message):
  1847. print "["+(str(time.strftime("%H:%M:%S")))+"] " + message
  1848.  
  1849. def config(this, setting):
  1850. return Config.get("Settings", setting, 0)
  1851.  
  1852. def configs(this, setting, value):
  1853. Config.set("Settings", setting, value)
  1854. with open("./include/Config.ini", "w") as f:
  1855. Config.write(f)
  1856.  
  1857. def parseJson(this, directory):
  1858. with open(directory, "r") as f:
  1859. return eval(f.read())
  1860.  
  1861. def updateBlackList(this):
  1862. with open("./include/blackList.json", "w") as f:
  1863. json.dump(str(this.blackList), f)
  1864.  
  1865. def sendServerReboot(this):
  1866. this.sendServerRestart(0, 0)
  1867. reactor.callLater(120, this.closeServer)
  1868.  
  1869. def sendServerRestart(this, no, sec):
  1870. if sec > 0 or no != 5:
  1871. 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)
  1872. if this.rebootTimer != None: this.rebootTimer.cancel()
  1873. 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))
  1874.  
  1875. def sendServerRestartSEC(this, seconds):
  1876. this.sendPanelRestartMessage(seconds)
  1877. this.sendWholeServer(Identifiers.send.Server_Restart, ByteArray().writeInt(seconds * 1000).toByteArray())
  1878.  
  1879. def sendPanelRestartMessage(this, seconds):
  1880. if seconds == 120:
  1881. this.sendOutput("[SERVER] The server will restart in 2 minutes.")
  1882. elif seconds < 120 and seconds > 1:
  1883. this.sendOutput("[SERVER] The server will restart in "+str(seconds)+" seconds.")
  1884. else:
  1885. this.sendOutput("[SERVER] The server will restart in 1 second.")
  1886.  
  1887. def closeServer(this):
  1888. this.updateConfig()
  1889. for client in this.players.values():
  1890. client.transport.loseConnection()
  1891. del this.players[client.Username]
  1892.  
  1893. os._exit(0)
  1894.  
  1895. def getConnectedPlayerCount(this):
  1896. return len(this.players)
  1897.  
  1898. def getRoomsCount(this):
  1899. return len(this.rooms)
  1900.  
  1901. def checkAlreadyExistingGuest(this, playerName):
  1902. found = False
  1903. result = ""
  1904.  
  1905. if not this.checkConnectedAccount(playerName):
  1906. found = True
  1907. result = playerName
  1908.  
  1909. while not found:
  1910. tempName = playerName + "_" + TFMUtils.getRandomChars(4)
  1911. if not this.checkConnectedAccount(tempName):
  1912. found = True
  1913. result = tempName
  1914. return result
  1915.  
  1916. def checkConnectedAccount(this, playerName):
  1917. return this.players.has_key(playerName)
  1918.  
  1919. def disconnectIPAddress(this, ip):
  1920. for client in this.players.values():
  1921. if client.ipAddress == ip:
  1922. client.transport.loseConnection()
  1923.  
  1924. def checkExistingUser(this, playerName):
  1925. this.Cursor.execute("select * from Users where Username = ?", [playerName])
  1926. if this.Cursor.fetchone():
  1927. return True
  1928. return False
  1929.  
  1930. def recommendRoom(this, langue):
  1931. found = False
  1932. x = 0
  1933. result = ""
  1934. while not found:
  1935. x += 1
  1936. if this.rooms.has_key(langue + "-" + str(x)):
  1937. if this.rooms[langue + "-" + str(x)].getPlayerCount() < 25:
  1938. found = True
  1939. result = str(x)
  1940. else:
  1941. found = True
  1942. result = str(x)
  1943. return result
  1944.  
  1945. def checkRoom(this, roomName, langue):
  1946. found = False
  1947. x = 0
  1948. result = roomName
  1949. if this.rooms.has_key(langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName):
  1950. room = this.rooms.get(langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName)
  1951. if room.getPlayerCount() < room.maxPlayers if room.maxPlayers != -1 else True:
  1952. found = True
  1953. else:
  1954. found = True
  1955.  
  1956. while not found:
  1957. x += 1
  1958. if this.rooms.has_key((langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName) + str(x)):
  1959. room = this.rooms.get((langue + "-" + roomName if not roomName.startswith("*") and roomName[0] != chr(3) else roomName) + str(x))
  1960. if room.getPlayerCount() < room.maxPlayers if room.maxPlayers != -1 else True:
  1961. found = True
  1962. result += str(x)
  1963. else:
  1964. found = True
  1965. result += str(x)
  1966. return result
  1967.  
  1968. def addClientToRoom(this, client, roomName):
  1969. if this.rooms.has_key(roomName):
  1970. this.rooms[roomName].addClient(client)
  1971. else:
  1972. room = Room(this, roomName)
  1973. this.rooms[roomName] = room
  1974. room.addClient(client)
  1975.  
  1976. def getIPPermaBan(this, ip):
  1977. return ip in this.ipPermaBanCache
  1978.  
  1979. def checkReport(this, array, playerName):
  1980. return playerName in array
  1981.  
  1982. def banPlayer(this, playerName, bantime, reason, modname, silent):
  1983. found = False
  1984.  
  1985. client = this.players.get(playerName)
  1986. if client != None:
  1987. found = True
  1988. if not modname == "Server":
  1989. client.banHours += bantime
  1990. ban = str(time.time())
  1991. bandate = ban[:len(ban) - 4]
  1992. this.Cursor.execute("insert into BanLog values (?, ?, ?, ?, ?, 'Online', ?, ?)", [playerName, modname, str(bantime), reason, bandate, client.roomName, client.ipAddress])
  1993. else:
  1994. this.sendStaffMessage(5, "<V>Server <BL>banned player <V>"+playerName+"<BL> for <V>1 <BL> hour. Reason: <V>Vote Populaire<BL>.")
  1995.  
  1996. this.Cursor.execute("update Users SET BanHours = ? WHERE Username = ?", [bantime, playerName])
  1997.  
  1998. if bantime >= 361 or client.banHours >= 361:
  1999. this.userPermaBanCache.append(playerName)
  2000. this.Cursor.execute("insert into UserPermaBan values (?, ?, ?)", [playerName, modname, reason])
  2001.  
  2002. if client.banHours >= 361:
  2003. this.ipPermaBanCache.append(client.ipAddress)
  2004. this.Cursor.execute("insert into IPPermaBan values (?, ?, ?)", [client.ipAddress, modname, reason])
  2005.  
  2006. if bantime >= 1 and bantime <= 360:
  2007. this.tempBanUser(playerName, bantime, reason)
  2008. this.tempBanIP(client.ipAddress, bantime)
  2009.  
  2010. if this.checkReport(this.reports["names"], playerName):
  2011. this.reports[playerName]["status"] = "banned"
  2012. this.reports[playerName]["status"] = "modname"
  2013. this.reports[playerName]["status"] = str(bantime)
  2014. this.reports[playerName]["banreason"] = "hack"
  2015.  
  2016. client.sendPlayerBan(bantime, reason, silent)
  2017.  
  2018. if not found and this.checkExistingUser(playerName) and not modname == "Server" and bantime >= 1:
  2019. found = True
  2020. totalBanTime = this.getTotalBanHours(playerName) + bantime
  2021. if (totalBanTime >= 361 and bantime <= 360) or bantime >= 361:
  2022. this.userPermaBanCache.append(playerName)
  2023. this.Cursor.execute("insert into UserPermaBan values (?, ?, ?)", [playerName, modname, reason])
  2024.  
  2025. if bantime >= 1 and bantime <= 360:
  2026. this.tempBanUser(playerName, bantime, reason)
  2027.  
  2028. this.Cursor.execute("update Users SET BanHours = ? WHERE Username = ?", [bantime, playerName])
  2029.  
  2030. ban = str(time.time())
  2031. bandate = ban[:len(ban) - 4]
  2032. this.Cursor.execute("insert into BanLog values (?, ?, ?, ?, ?, 'Offline', '', 'Offline')", [playerName, modname, str(bantime), reason, bandate])
  2033.  
  2034. return found
  2035.  
  2036. def checkTempBan(this, playerName):
  2037. this.Cursor.execute("select * from UserTempBan where Name = ?", [playerName])
  2038. if this.Cursor.fetchone():
  2039. return True
  2040. return False
  2041.  
  2042. def removeTempBan(this, playerName):
  2043. try:
  2044. this.userTempBanCache.remove(playerName)
  2045. this.Cursor.execute("delete from UserTempBan where Name = ?", [playerName])
  2046. except: pass
  2047.  
  2048. def tempBanUser(this, playerName, bantime, reason):
  2049. if this.checkTempBan(playerName):
  2050. this.removeTempBan(playerName)
  2051.  
  2052. this.userTempBanCache.append(playerName)
  2053. this.Cursor.execute("insert into UserTempBan values (?, ?, ?)", [playerName, str(TFMUtils.getTime() + (bantime * 60 * 60)), reason])
  2054.  
  2055. def getTempBanInfo(this, playerName):
  2056. this.Cursor.execute("select Reason, Time from UserTempBan where Name = ?", [playerName])
  2057. r = this.Cursor.fetchall()
  2058. for rs in r:
  2059. return [rs["Reason"], rs["Time"]]
  2060. return ["", 0]
  2061.  
  2062. def checkPermaBan(this, playerName):
  2063. this.Cursor.execute("select * from UserPermaBan where Name = ?", [playerName])
  2064. if this.Cursor.fetchone():
  2065. return True
  2066. return False
  2067.  
  2068. def removePermaBan(this, playerName):
  2069. try:
  2070. this.userPermaBanCache.remove(playerName)
  2071. this.Cursor.execute("delete from UserPermaBan where Name = ?", [playerName])
  2072. except: pass
  2073.  
  2074. def tempBanIP(this, ip, time):
  2075. if not ip in this.tempIPBanList:
  2076. this.tempIPBanList.append(ip)
  2077. reactor.callLater(time, lambda: this.tempIPBanList.remove(ip))
  2078.  
  2079. def getTotalBanHours(this, playerName):
  2080. this.Cursor.execute("select BanHours from Users where Username = ?", [playerName])
  2081. rs = this.Cursor.fetchone()
  2082. if rs:
  2083. return rs["BanHours"]
  2084. return 0
  2085.  
  2086. def parseBanList(this):
  2087. this.Cursor.execute("select ip from IPPermaBan")
  2088. rs = this.Cursor.fetchone()
  2089. if rs:
  2090. this.ipPermaBanCache.append(rs["ip"])
  2091.  
  2092. this.Cursor.execute("select Name from UserPermaBan")
  2093. rs = this.Cursor.fetchone()
  2094. if rs:
  2095. this.userPermaBanCache.append(rs["Name"])
  2096.  
  2097. this.Cursor.execute("select Name from UserTempBan")
  2098. rs = this.Cursor.fetchone()
  2099. if rs:
  2100. this.userTempBanCache.append(rs["Name"])
  2101.  
  2102. this.Cursor.execute("select Name from UserTempMute")
  2103. rs = this.Cursor.fetchone()
  2104. if rs:
  2105. this.userMuteCache.append(rs["Name"])
  2106.  
  2107. def voteBanPopulaire(this, playerName, ip):
  2108. client = this.players.get(playerName)
  2109. if client != None and client.privLevel == 1 and not ip in client.voteBan:
  2110. client.voteBan.append(ip)
  2111. if len(client.voteBan) == 10:
  2112. this.banPlayer(playerName, 1, "Vote Populaire", "Server", False)
  2113.  
  2114. def muteUser(this, playerName, mutetime, reason):
  2115. this.userMuteCache.append(playerName)
  2116. this.Cursor.execute("insert into UserTempMute values (?, ?, ?)", [playerName, str(TFMUtils.getTime() + (mutetime * 60 * 60)), reason])
  2117.  
  2118. def removeModMute(this, playerName):
  2119. try:
  2120. this.userMuteCache.remove(playerName)
  2121. this.Cursor.execute("delete from UserTempMute where Name = ?", [playerName])
  2122. except:pass
  2123.  
  2124. def getModMuteInfo(this, playerName):
  2125. this.Cursor.execute("select Time, Reason from UserTempMute where Name = ?", [playerName])
  2126. rs = this.Cursor.fetchone()
  2127. if rs:
  2128. return [rs["Time"], rs["Reason"]]
  2129. return [0, ""]
  2130.  
  2131. def mutePlayer(this, playerName, time, reason, modname):
  2132. client = this.players.get(playerName)
  2133. if client != None:
  2134. 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))
  2135. if playerName in this.userMuteCache:
  2136. this.removeModMute(playerName)
  2137.  
  2138. for player in client.room.clients.values():
  2139. if player.Username != playerName:
  2140. player.sendLangueMessage("", "<ROSE>$MuteInfo2", playerName, str(time), reason)
  2141.  
  2142. client.isMute = True
  2143. client.sendLangueMessage("", "<ROSE>$MuteInfo1", str(time), reason)
  2144. this.muteUser(playerName, time, reason)
  2145.  
  2146. def desmutePlayer(this, playerName, modname):
  2147. client = this.players.get(playerName)
  2148. if client != None:
  2149. this.sendStaffMessage(5, "<V>"+str(modname)+"<N> was unmuted <V>"+playerName+"<BL>.")
  2150. this.removeModMute(playerName)
  2151. client.isMute = False
  2152.  
  2153. def sendStaffChat(this, type, langue, identifiers, packet):
  2154. 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
  2155. for client in this.players.values():
  2156. if client.privLevel >= minLevel and client.Langue == langue or type == 1 or type == 4 or type == 5:
  2157. client.sendPacket(identifiers, packet)
  2158.  
  2159. def getTotemData(this, playerName):
  2160. if playerName.startswith("*"):
  2161. return []
  2162. else:
  2163. this.Cursor.execute("select ItemCount, Totem from Totem where Name = ?", [playerName])
  2164. rs = this.Cursor.fetchone()
  2165. if rs:
  2166. itemCount = rs["ItemCount"]
  2167. totem = rs["Totem"]
  2168. totem = totem.replace("%", chr(1))
  2169. return [str(itemCount), totem]
  2170. return []
  2171.  
  2172. def setTotemData(this, playerName, ItemCount, totem):
  2173. if playerName.startswith("*"):
  2174. pass
  2175. else:
  2176. totem = totem.replace(chr(1), "%")
  2177.  
  2178. if len(this.getTotemData(playerName)) != 0:
  2179. this.Cursor.execute("update Totem set ItemCount = ?, Totem = ? where Name = ?", [ItemCount, totem, playerName])
  2180. else:
  2181. this.Cursor.execute("insert into Totem values (?, ?, ?)", [playerName, ItemCount, totem])
  2182.  
  2183. def getShamanType(this, playerCode):
  2184. for player in this.players.values():
  2185. if player.playerCode == playerCode:
  2186. return player.shamanType
  2187.  
  2188. return 0
  2189.  
  2190. def getShamanLevel(this, playerCode):
  2191. for player in this.players.values():
  2192. if player.playerCode == playerCode:
  2193. return player.shamanLevel
  2194. return 0
  2195.  
  2196. def getShamanBadge(this, playerCode):
  2197. for player in this.players.values():
  2198. if player.playerCode == playerCode:
  2199. return player.skillModule.getShamanBadge()
  2200.  
  2201. return 0
  2202.  
  2203. def getPlayerAvatar(this, playerName):
  2204. this.Cursor.execute("select Avatar from Users where Username = ?", [playerName])
  2205. rs = this.Cursor.fetchone()
  2206. if rs:
  2207. return rs["Avatar"]
  2208. return 0
  2209.  
  2210. def getPlayerID(this, playerName):
  2211. if playerName.startswith("*"):
  2212. return 0
  2213.  
  2214. elif this.players.has_key(playerName):
  2215. return this.players[playerName].playerID
  2216. else:
  2217. this.Cursor.execute("select PlayerID from Users where Username = ?", [playerName])
  2218. rs = this.Cursor.fetchone()
  2219. if rs:
  2220. return rs["PlayerID"]
  2221. return 0
  2222.  
  2223. def getPlayerPrivlevel(this, playerName):
  2224. if playerName.startswith("*"):
  2225. return 0
  2226.  
  2227. elif this.players.has_key(playerName):
  2228. return this.players[playerName].privLevel
  2229. else:
  2230. this.Cursor.execute("select PrivLevel from Users where Username = ?", [playerName])
  2231. rs = this.Cursor.fetchone()
  2232. if rs:
  2233. return rs["PrivLevel"]
  2234. return 0
  2235.  
  2236. def getPlayerName(this, playerID):
  2237. this.Cursor.execute("select Username from Users where PlayerID = ?", [playerID])
  2238. rs = this.Cursor.fetchone()
  2239. if rs:
  2240. return rs["Username"]
  2241. return ""
  2242.  
  2243. def getPlayerRoomName(this, playerName):
  2244. if this.players.has_key(playerName):
  2245. return this.players[playerName].roomName
  2246. return ""
  2247.  
  2248. def getTribeInfo(this, tribeCode):
  2249. tribeRankings = {}
  2250. this.Cursor.execute("select * from Tribe where Code = ?", [tribeCode])
  2251. rs = this.Cursor.fetchone()
  2252. if rs:
  2253. for rank in rs["Rankings"].split(";"):
  2254. values = rank.split("|", 1)
  2255. tribeRankings[int(values[0])] = values[1]
  2256. return [rs["Name"], rs["Message"], rs["House"], tribeRankings, rs["Chat"]]
  2257. return ["", "", 0, tribeRankings, 0]
  2258.  
  2259. def getTribeHouse(this, tribeName):
  2260. this.Cursor.execute("select House from Tribe where Name = ?", [tribeName])
  2261. rs = this.Cursor.fetchone()
  2262. if rs:
  2263. return rs["House"]
  2264. return -1
  2265.  
  2266. def getPlayersCountMode(this, mode, langue):
  2267. 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 ""
  2268. playerCount = 0
  2269. for room in this.rooms.values():
  2270. 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()):
  2271. playerCount += room.getPlayerCount()
  2272. return [modeName, playerCount]
  2273.  
  2274. def parsePromotions(this):
  2275. needUpdate = False
  2276. i = 0
  2277. while i < len(this.promotions):
  2278. item = this.promotions[i]
  2279. if item[3] < 1000:
  2280. item[3] = TFMUtils.getTime() + item[3] * 86400 + 30
  2281. needUpdate = True
  2282.  
  2283. this.shopPromotions.append([item[0], item[1], item[2], item[3]])
  2284. i += 1
  2285.  
  2286. this.checkPromotionsEnd()
  2287.  
  2288. def checkPromotionsEnd(this):
  2289. needUpdate = False
  2290. for promotion in this.shopPromotions:
  2291. if TFMUtils.getHoursDiff(promotion[3]) <= 0:
  2292. this.shopPromotions.remove(promotion)
  2293. needUpdate = True
  2294. i = 0
  2295. while i < len(this.promotions):
  2296. if this.promotions[i][0] == promotion[0] and this.promotions[i][1] == promotion[1]:
  2297. this.promotions.remove(i)
  2298. i += 1
  2299.  
  2300. def sendWholeServer(this, identifiers, result):
  2301. for client in this.players.values():
  2302. client.sendPacket(identifiers, result)
  2303.  
  2304. def checkMessage(this, client, message):
  2305. list = this.blackList["list"]
  2306. i = 0
  2307. while i < len(list):
  2308. if re.search("[^a-zA-Z]*".join(list[i]), message.lower()):
  2309. this.sendStaffMessage(7, "[<V>" + client.roomName + "</V>][<T>" + client.Username + "</T>] sent a link in the message: [<J>" + str(message) + "</J>].")
  2310. return True
  2311. i += 1
  2312. return False
  2313.  
  2314. def setVip(this, playerName, days):
  2315. player = this.players.get(playerName)
  2316. if ((player != None and player.privLevel == 1) or this.getPlayerPrivlevel(playerName) == 1):
  2317. 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])
  2318. if player != None:
  2319. player.privLevel = 2
  2320.  
  2321. this.sendStaffMessage(7, "<V>"+playerName+"</V> became VIP for <V>"+str(days)+"</V> days.")
  2322. return True
  2323.  
  2324. return False
  2325.  
  2326. def getPlayerCode(this, playerName):
  2327. client = this.players.get(TFMUtils.parsePlayerName(playerName))
  2328. return client.playerCode if player != None else 0
  2329.  
  2330. def sendStaffMessage(this, minLevel, message):
  2331. for client in this.players.values():
  2332. if client.privLevel >= minLevel:
  2333. client.sendMessage(message)
  2334.  
  2335. class Room:
  2336. def __init__(this, server, name):
  2337.  
  2338. # String
  2339. this.currentSyncName = ""
  2340. this.currentShamanName = ""
  2341. this.currentSecondShamanName = ""
  2342. this.forceNextMap = "-1"
  2343. this.mapName = ""
  2344. this.mapXML = ""
  2345. this.EMapXML = ""
  2346. this.roomPassword = ""
  2347.  
  2348. # Integer
  2349. this.maxPlayers = 200
  2350. this.currentMap = 0
  2351. this.lastRoundCode = 0
  2352. this.mapCode = -1
  2353. this.mapYesVotes = 0
  2354. this.mapNoVotes = 0
  2355. this.mapPerma = -1
  2356. this.mapStatus = 0
  2357. this.currentSyncCode = -1
  2358. this.roundTime = 120
  2359. this.gameStartTime = 0
  2360. this.currentShamanCode = -1
  2361. this.currentSecondShamanCode = -1
  2362. this.currentShamanType = -1
  2363. this.currentSecondShamanType = -1
  2364. this.forceNextShaman = -1
  2365. this.numCompleted = 0
  2366. this.FSnumCompleted = 0
  2367. this.SSnumCompleted = 0
  2368. this.receivedNo = 0
  2369. this.receivedYes = 0
  2370. this.EMapLoaded = 0
  2371. this.EMapCode = 0
  2372. this.objectID = 0
  2373. this.tempTotemCount = -1
  2374. this.addTime = 0
  2375. this.cloudID = -1
  2376. this.companionBox = -1
  2377. this.mulodromeRoundCount = 0
  2378. this.redCount = 0
  2379. this.blueCount = 0
  2380. this.musicMapStatus = 0
  2381. this.roundsCount = -1
  2382. this.survivorMapStatus = 0
  2383. this.lastImageID = 0
  2384. this.changeMapAttemps = 0
  2385. this.musicSkipVotes = 0
  2386. this.musicTime = 0
  2387.  
  2388. this.gameStartTimeMillis = 0
  2389.  
  2390. # Bool
  2391. this.discoRoom = False
  2392. this.isClosed = False
  2393. this.isCurrentlyPlay = False
  2394. this.isDoubleMap = False
  2395. this.isNoShamanMap = False
  2396. this.isVotingMode = False
  2397. this.initVotingMode = True
  2398. this.isVotingBox = False
  2399. this.EMapValidated = False
  2400. this.countStats = True
  2401. this.never20secTimer = False
  2402. this.isVanilla = False
  2403. this.isEditeur = False
  2404. this.changed20secTimer = False
  2405. this.specificMap = False
  2406. this.noShaman = False
  2407. this.isTutorial = False
  2408. this.isTotemEditeur = False
  2409. this.autoRespawn = False
  2410. this.noAutoScore = False
  2411. this.catchTheCheeseMap = False
  2412. this.isTribeHouse = False
  2413. this.isTribeHouseMap = False
  2414. this.isMulodrome = False
  2415. this.isRacing = False
  2416. this.isMusic = False
  2417. this.isUtility = False
  2418. this.isDeathmatch = False
  2419. this.isPlayingMusic = False
  2420. this.isRacingP17 = False
  2421. this.isBootcamp = False
  2422. this.isBootcampP13 = False
  2423. this.isSurvivor = False
  2424. this.isSurvivorVamp = False
  2425. this.isDefilante = False
  2426. this.isNormRoom = False
  2427. this.isSnowing = False
  2428. this.canChangeMap = True
  2429. this.disableAfkKill = False
  2430. this.isFixedMap = False
  2431. this.noShamanSkills = False
  2432. this.is801Room = False
  2433. this.mapInverted = False
  2434. this.canChangeMusic = True
  2435. this.isFuncorp = False
  2436. this.isVillage = False
  2437.  
  2438. # Bool
  2439. this.changeMapTimer = None
  2440. this.closeRoomRoundJoinTimer = None
  2441. this.voteCloseTimer = None
  2442. this.killAfkTimer = None
  2443. this.autoRespawnTimer = None
  2444. this.endSnowTimer = None
  2445. this.startTimerLeft = None
  2446.  
  2447. # List Arguments
  2448. 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]
  2449. 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]
  2450. this.anchors = []
  2451. this.lastHandymouse = [-1, -1]
  2452. this.musicVideos = []
  2453.  
  2454. # List
  2455. this.redTeam = []
  2456. this.blueTeam = []
  2457. this.roomTimers = []
  2458. this.adminsRoom = []
  2459. this.playersBan = []
  2460.  
  2461. # Dict
  2462. this.clients = {}
  2463. this.currentShamanSkills = {}
  2464. this.currentSecondShamanSkills = {}
  2465. this.currentTimers = {}
  2466.  
  2467. # Others
  2468. this.name = name
  2469. this.server = server
  2470. this.Cursor = Cursor
  2471.  
  2472. if this.name.startswith("*"):
  2473. this.community = "xx"
  2474. this.roomName = this.name
  2475. else:
  2476. this.community = this.name.split("-")[0].lower()
  2477. this.roomName = this.name.split("-")[1]
  2478.  
  2479. if this.roomName.startswith(chr(3) + "[Editeur] "):
  2480. this.countStats = False
  2481. this.isEditeur = True
  2482. this.never20secTimer = True
  2483.  
  2484. elif this.roomName.startswith(chr(3) + "[Tutorial] "):
  2485. this.countStats = False
  2486. this.currentMap = 900
  2487. this.specificMap = True
  2488. this.noShaman = True
  2489. this.never20secTimer = True
  2490. this.isTutorial = True
  2491.  
  2492. elif this.roomName.startswith(chr(3) + "[Totem] "):
  2493. this.countStats = False
  2494. this.specificMap = True
  2495. this.currentMap = 444
  2496. this.isTotemEditeur = True
  2497. this.never20secTimer = True
  2498.  
  2499. elif this.roomName.startswith("*" + chr(3)):
  2500. this.countStats = False
  2501. this.isTribeHouse = True
  2502. this.autoRespawn = True
  2503. this.never20secTimer = True
  2504. this.noShaman = True
  2505.  
  2506. elif this.roomName.startswith("#utility"):
  2507. this.isUtility = True
  2508. this.roundTime = 0
  2509. this.never20secTimer = True
  2510. this.autoRespawn = True
  2511. this.countStats = False
  2512. this.noShaman = True
  2513. this.isFixedMap = True
  2514.  
  2515. elif this.roomName.startswith("music") or this.roomName.startswith("*music"):
  2516. this.isMusic = True
  2517.  
  2518. elif this.roomName.startswith("racing") or this.roomName.startswith("*racing"):
  2519. this.isRacing = True
  2520. this.noShaman = True
  2521. this.roundTime = 63
  2522.  
  2523. elif this.roomName.startswith("bootcamp") or this.roomName.startswith("*bootcamp"):
  2524. this.isBootcamp = True
  2525. this.countStats = False
  2526. this.roundTime = 360
  2527. this.never20secTimer = True
  2528. this.autoRespawn = True
  2529. this.noShaman = True
  2530.  
  2531. elif this.roomName.startswith("vanilla") or this.roomName.startswith("*vanilla"):
  2532. this.isVanilla = True
  2533.  
  2534. elif this.roomName.startswith("survivor") or this.roomName.startswith("*survivor"):
  2535. this.isSurvivor = True
  2536. this.roundTime = 90
  2537.  
  2538. elif this.roomName.startswith("defilante") or this.roomName.startswith("*defilante"):
  2539. this.isDefilante = True
  2540. this.noShaman = True
  2541. this.countStats = False
  2542. this.noAutoScore = True
  2543.  
  2544. elif this.roomName.startswith("village") or this.roomName.startswith("*village"):
  2545. this.isVillage = True
  2546. this.roundTime = 0
  2547. this.never20secTimer = True
  2548. this.autoRespawn = True
  2549. this.countStats = False
  2550. this.noShaman = True
  2551. this.isFixedMap = True
  2552.  
  2553. elif this.roomName.startswith("801") or this.roomName.startswith("*801"):
  2554. this.is801Room = True
  2555. this.roundTime = 0
  2556. this.never20secTimer = True
  2557. this.autoRespawn = True
  2558. this.countStats = False
  2559. this.noShaman = True
  2560. this.isFixedMap = True
  2561. else:
  2562. this.isNormRoom = True
  2563.  
  2564. this.mapChange()
  2565.  
  2566. def startTimer(this):
  2567. for client in this.clients.values():
  2568. client.sendMapStartTimerEnd()
  2569.  
  2570. def mapChange(this):
  2571. if this.changeMapTimer != None: this.changeMapTimer.cancel()
  2572.  
  2573. if not this.canChangeMap:
  2574. this.changeMapAttemps += 1
  2575. if this.changeMapAttemps < 5:
  2576. this.changeMapTimer = reactor.callLater(1, this.mapChange)
  2577. return
  2578.  
  2579. for timer in this.roomTimers:
  2580. timer.cancel()
  2581.  
  2582. this.roomTimers = []
  2583.  
  2584. for timer in [this.voteCloseTimer, this.killAfkTimer, this.autoRespawnTimer, this.startTimerLeft]:
  2585. if timer != None:
  2586. timer.cancel()
  2587.  
  2588. if this.initVotingMode:
  2589. if not this.isVotingBox and (this.mapPerma == 0 and this.mapCode != -1) and this.getPlayerCount() >= 2:
  2590. this.isVotingMode = True
  2591. this.isVotingBox = True
  2592. this.voteCloseTimer = reactor.callLater(8, this.closeVoting)
  2593. for client in this.clients.values():
  2594. client.sendPacket(Identifiers.old.send.Vote_Box, [this.mapName, this.mapYesVotes, this.mapNoVotes])
  2595. else:
  2596. this.votingMode = False
  2597. this.closeVoting()
  2598.  
  2599. elif this.isTribeHouse and this.isTribeHouseMap:
  2600. pass
  2601. else:
  2602. if this.isVotingMode:
  2603. TotalYes = this.mapYesVotes + this.receivedYes
  2604. TotalNo = this.mapNoVotes + this.receivedNo
  2605. isDel = False
  2606.  
  2607. if TotalYes + TotalNo >= 100:
  2608. TotalVotes = TotalYes + TotalNo
  2609. Rating = (1.0 * TotalYes / TotalNo) * 100
  2610. rate = str(Rating).split(".")
  2611. if int(rate[0]) < 50:
  2612. isDel = True
  2613. 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])
  2614. this.isVotingMode = False
  2615. this.receivedNo = 0
  2616. this.receivedYes = 0
  2617. for client in this.clients.values():
  2618. client.qualifiedVoted = False
  2619. client.isVoted = False
  2620.  
  2621. this.initVotingMode = True
  2622.  
  2623. this.lastRoundCode += 1
  2624. this.lastRoundCode %= 127
  2625.  
  2626. if this.isSurvivor:
  2627. for client in this.clients.values():
  2628. if not client.isDead and (not client.isVampire if this.isSurvivorVamp else not client.isShaman):
  2629. if not this.noAutoScore: client.playerScore += 10
  2630.  
  2631. if this.catchTheCheeseMap:
  2632. this.catchTheCheeseMap = False
  2633. else:
  2634. numCom = this.FSnumCompleted - 1 if this.isDoubleMap else this.numCompleted - 1
  2635. numCom2 = this.SSnumCompleted - 1 if this.isDoubleMap else 0
  2636. if numCom < 0: numCom = 0
  2637. if numCom2 < 0: numCom2 = 0
  2638.  
  2639. player = this.clients.get(this.currentShamanName)
  2640. if player != None:
  2641. this.sendAll(Identifiers.old.send.Shaman_Perfomance, [this.currentShamanName, numCom])
  2642. if not this.noAutoScore: player.playerScore = numCom
  2643. if numCom > 0:
  2644. player.skillModule.earnExp(True, numCom)
  2645.  
  2646. player2 = this.clients.get(this.currentSecondShamanName)
  2647. if player2 != None:
  2648. this.sendAll(Identifiers.old.send.Shaman_Perfomance, [this.currentSecondShamanName, numCom2])
  2649. if not this.noAutoScore: player2.playerScore = numCom2
  2650. if numCom2 > 0:
  2651. player2.skillModule.earnExp(True, numCom2)
  2652.  
  2653. if this.isSurvivor and this.getPlayerCount() >= this.server.needToFirst:
  2654. this.giveSurvivorStats()
  2655. elif this.isRacing and this.getPlayerCount() >= this.server.needToFirst:
  2656. this.giveRacingStats()
  2657.  
  2658. this.currentSyncCode = -1
  2659. this.currentSyncName = ""
  2660. this.currentShamanCode = -1
  2661. this.currentSecondShamanCode = -1
  2662. this.currentShamanName = ""
  2663. this.currentSecondShamanName = ""
  2664. this.currentShamanType = -1
  2665. this.currentSecondShamanType = -1
  2666. this.currentShamanSkills = {}
  2667. this.currentSecondShamanSkills = {}
  2668. this.changed20secTimer = False
  2669. this.isDoubleMap = False
  2670. this.isNoShamanMap = False
  2671. this.FSnumCompleted = 0
  2672. this.SSnumCompleted = 0
  2673. this.objectID = 0
  2674. this.tempTotemCount = -1
  2675. this.addTime = 0
  2676. this.cloudID = -1
  2677. this.companionBox = -1
  2678. this.lastHandymouse = [-1, -1]
  2679. this.isTribeHouseMap = False
  2680. this.canChangeMap = True
  2681. this.changeMapAttemps = 0
  2682.  
  2683. this.getSyncCode()
  2684.  
  2685. this.anchors = []
  2686.  
  2687. this.mapStatus += 1
  2688. this.mapStatus %= 13
  2689. this.musicMapStatus += 1
  2690. this.musicMapStatus %= 6
  2691. this.survivorMapStatus += 1
  2692. this.survivorMapStatus %= 11
  2693.  
  2694. this.isRacingP17 = not this.isRacingP17
  2695. this.isBootcampP13 = not this.isBootcampP13
  2696.  
  2697. this.numCompleted = 0
  2698. this.canChangeMusic = True
  2699.  
  2700. this.currentMap = this.selectMap()
  2701. this.checkVanillaXML()
  2702.  
  2703. if not this.noShamanSkills:
  2704. player = this.clients.get(this.currentShamanName)
  2705. if player != None:
  2706. if this.currentShamanName != None:
  2707. player.skillModule.getTimeSkill()
  2708.  
  2709. if this.currentSecondShamanName != None:
  2710. player.skillModule.getTimeSkill()
  2711.  
  2712. if this.currentMap in [range(44, 54), range(138, 144)] or this.mapPerma == 8 and this.getPlayerCount() >= 2:
  2713. this.isDoubleMap = True
  2714.  
  2715. if this.mapPerma == 7 or this.mapPerma == 42 or this.isSurvivorVamp:
  2716. this.isNoShamanMap = True
  2717.  
  2718. if this.currentMap in range(108, 114):
  2719. this.catchTheCheeseMap = True
  2720.  
  2721. this.gameStartTime = TFMUtils.getTime()
  2722. this.gameStartTimeMillis = time.time()
  2723. this.isCurrentlyPlay = False
  2724.  
  2725. for player in this.clients.values():
  2726. player.resetPlay()
  2727.  
  2728. for player in this.clients.values():
  2729. player.startPlay()
  2730. if player.isHidden:
  2731. player.sendPlayerDisconnect()
  2732.  
  2733. for player in this.clients.values():
  2734. if player.pet != 0:
  2735. if TFMUtils.getSecondsDiff(player.petEnd) >= 0:
  2736. player.pet = 0
  2737. player.petEnd = 0
  2738. else:
  2739. this.sendAll(Identifiers.send.Pet, ByteArray().writeInt(player.playerCode).writeUnsignedByte(player.pet).toByteArray())
  2740.  
  2741. if this.isSurvivorVamp:
  2742. reactor.callLater(5, this.sendVampireMode)
  2743.  
  2744. if this.isMulodrome:
  2745. this.mulodromeRoundCount += 1
  2746. this.sendMulodromeRound()
  2747.  
  2748. if this.mulodromeRoundCount <= 10:
  2749. for client in this.clients.values():
  2750. if client.Username in this.blueTeam:
  2751. this.setNameColor(client.Username, int("979EFF", 16))
  2752. else:
  2753. this.setNameColor(client.Username, int("FF9396", 16))
  2754. else:
  2755. this.sendAll(Identifiers.send.Mulodrome_End)
  2756.  
  2757. if this.isRacing or this.isDefilante:
  2758. this.roundsCount += 1
  2759. this.roundsCount %= 10
  2760. player = this.clients.get(this.getHighestScore())
  2761. this.sendAll(Identifiers.send.Rounds_Count, ByteArray().writeByte(this.roundsCount).writeInt(player.playerCode if player != None else 0).toByteArray())
  2762.  
  2763. this.startTimerLeft = reactor.callLater(3, this.startTimer)
  2764. this.closeRoomRoundJoinTimer = reactor.callLater(3, setattr, this, "isCurrentlyPlay", True)
  2765. if not this.isFixedMap and not this.isTribeHouse and not this.isTribeHouseMap:
  2766. this.changeMapTimer = reactor.callLater(this.roundTime + this.addTime, this.mapChange)
  2767.  
  2768. this.killAfkTimer = reactor.callLater(30, this.killAfk)
  2769. if this.autoRespawn or this.isTribeHouseMap:
  2770. this.autoRespawnTimer = reactor.callLater(2, this.respawnMice)
  2771.  
  2772. def getPlayerCount(this):
  2773. return len(filter(lambda player: not player.isHidden, this.clients.values()))
  2774.  
  2775. def getPlayerCountUnique(this):
  2776. ipList = []
  2777. for client in this.clients.values():
  2778. if not client.ipAddress in ipList:
  2779. ipList.append(client.ipAddress)
  2780. return len(ipList)
  2781.  
  2782. def getPlayerList(this):
  2783. result = []
  2784. for client in this.clients.values():
  2785. if not client.isHidden:
  2786. result.append(client.getPlayerData())
  2787. return result
  2788.  
  2789. def addClient(this, client):
  2790. this.clients[client.Username] = client
  2791.  
  2792. client.room = this
  2793. client.isDead = this.isCurrentlyPlay
  2794. this.sendAllOthers(client, Identifiers.old.send.Player_Respawn, [client.getPlayerData()])
  2795. client.startPlay()
  2796.  
  2797. def removeClient(this, client):
  2798. if client.Username in this.clients:
  2799. del this.clients[client.Username]
  2800. client.resetPlay()
  2801. client.playerScore = 0
  2802. client.sendPlayerDisconnect()
  2803.  
  2804. if this.isMulodrome:
  2805. if client.Username in this.redTeam: this.redTeam.remove(client.Username)
  2806. if client.Username in this.blueTeam: this.blueTeam.remove(client.Username)
  2807.  
  2808. if len(this.redTeam) == 0 and len(this.blueTeam) == 0:
  2809. this.mulodromeRoundCount = 10
  2810. this.sendMulodromeRound()
  2811.  
  2812. if len(this.clients) == 0:
  2813. for timer in [this.autoRespawnTimer, this.changeMapTimer, this.closeRoomRoundJoinTimer, this.endSnowTimer, this.killAfkTimer, this.voteCloseTimer]:
  2814. if timer != None:
  2815. timer.cancel()
  2816.  
  2817. this.isClosed = True
  2818. del this.server.rooms[this.name]
  2819. else:
  2820. if client.playerCode == this.currentSyncCode:
  2821. this.currentSyncCode = -1
  2822. this.currentSyncName = ""
  2823. this.getSyncCode()
  2824. for clientOnline in this.clients.values():
  2825. clientOnline.sendSync(this.currentSyncCode)
  2826. this.checkShouldChangeMap()
  2827.  
  2828. def checkShouldChangeMap(this):
  2829. if this.isBootcamp or this.autoRespawn or (this.isTribeHouse and this.isTribeHouseMap) or this.isFixedMap:
  2830. pass
  2831. else:
  2832. allDead = True
  2833. for client in this.clients.values():
  2834. if not client.isDead:
  2835. allDead = False
  2836.  
  2837. if allDead:
  2838. this.mapChange()
  2839.  
  2840. def sendAll(this, identifiers, packet=""):
  2841. for client in this.clients.values():
  2842. client.sendPacket(identifiers, packet)
  2843.  
  2844. def sendAllOthers(this, senderClient, identifiers, packet=""):
  2845. for client in this.clients.values():
  2846. if not client == senderClient:
  2847. client.sendPacket(identifiers, packet)
  2848.  
  2849. def sendAllChat(this, playerCode, playerName, message, LangueByte, isOnly):
  2850. p = ByteArray().writeInt(playerCode).writeUTF(playerName).writeByte(LangueByte).writeUTF(message)
  2851. if not isOnly:
  2852. for client in this.clients.values():
  2853. client.sendPacket(Identifiers.send.Chat_Message, p.toByteArray())
  2854. else:
  2855. client = this.clients.get(playerName)
  2856. if client != None:
  2857. client.sendPacket(Identifiers.send.Chat_Message, p.toByteArray())
  2858.  
  2859. def getSyncCode(this):
  2860. if this.getPlayerCount() > 0:
  2861. if this.currentSyncCode == -1:
  2862. players = this.clients
  2863. values = players.values()
  2864. client = random.choice(values)
  2865. this.currentSyncCode = client.playerCode
  2866. this.currentSyncName = client.Username
  2867. else:
  2868. if this.currentSyncCode == -1:
  2869. this.currentSyncCode = 0
  2870. this.currentSyncName = ""
  2871.  
  2872. return this.currentSyncCode
  2873.  
  2874. def selectMap(this):
  2875. if not this.forceNextMap == "-1":
  2876. force = this.forceNextMap
  2877. this.forceNextMap = "-1"
  2878. this.mapCode = -1
  2879.  
  2880. if force.isdigit():
  2881. return this.selectMapSpecificic(force, "Vanilla")
  2882. elif force.startswith("@"):
  2883. return this.selectMapSpecificic(force[1:], "Custom")
  2884. elif force.startswith("#"):
  2885. return this.selectMapSpecificic(force[1:], "Perm")
  2886. elif force.startswith("<"):
  2887. return this.selectMapSpecificic(force, "Xml")
  2888. else:
  2889. return 0
  2890.  
  2891. elif this.specificMap:
  2892. this.mapCode = -1
  2893. return this.currentMap
  2894. else:
  2895. if this.isEditeur:
  2896. return this.EMapCode
  2897.  
  2898. elif this.isTribeHouse:
  2899. tribeName = this.roomName[2:]
  2900. runMap = this.server.getTribeHouse(tribeName)
  2901.  
  2902. if runMap == 0:
  2903. this.mapCode = 0
  2904. this.mapName = "Tigrounette"
  2905. 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>"
  2906. this.mapYesVotes = 0
  2907. this.mapNoVotes = 0
  2908. this.mapPerma = 22
  2909. this.mapInverted = False
  2910. else:
  2911. run = this.selectMapSpecificic(runMap, "Custom")
  2912. if run != -1:
  2913. this.mapCode = 0
  2914. this.mapName = "Tigrounette"
  2915. 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>"
  2916. this.mapYesVotes = 0
  2917. this.mapNoVotes = 0
  2918. this.mapPerma = 22
  2919. this.mapInverted = False
  2920.  
  2921. elif this.is801Room or this.isVillage:
  2922. this.getMap801(801, "_Atelier 801")
  2923.  
  2924. elif this.isVanilla:
  2925. this.mapCode = -1
  2926. this.mapName = "Invalid";
  2927. this.mapXML = "<C><P /><Z><S /><D /><O /></Z></C>"
  2928. this.mapYesVotes = 0
  2929. this.mapNoVotes = 0
  2930. this.mapPerma = -1
  2931. this.mapInverted = False
  2932. map = random.choice(this.MapList)
  2933. while map == this.currentMap:
  2934. map = random.choice(this.MapList)
  2935. return map
  2936.  
  2937. else:
  2938. this.mapCode = -1
  2939. this.mapName = "Invalid";
  2940. this.mapXML = "<C><P /><Z><S /><D /><O /></Z></C>"
  2941. this.mapYesVotes = 0
  2942. this.mapNoVotes = 0
  2943. this.mapPerma = -1
  2944. this.mapInverted = False
  2945. return this.selectMapStatus(this.mapStatus)
  2946. return -1
  2947.  
  2948. def selectMapStatus(this, mapStatus):
  2949. customMaps = [0, -1, 4, 9, 5, 0, -1, 8, 6, 7]
  2950. mapList = []
  2951.  
  2952. if this.isVanilla:
  2953. map = random.choice(this.MapList)
  2954. while map == this.currentMap:
  2955. map = random.choice(this.MapList)
  2956. return map
  2957.  
  2958. elif this.isMusic:
  2959. if this.musicMapStatus == 5:
  2960. this.Cursor.execute("select Code from MapEditor where Perma = 19 ORDER BY RANDOM() LIMIT 1")
  2961. r = this.Cursor.fetchall()
  2962. for rs in r:
  2963. mapList.append(rs[0])
  2964.  
  2965. elif this.isUtility:
  2966. this.Cursor.execute("select Code from MapEditor where Perma = 45 ORDER BY RANDOM() LIMIT 1")
  2967. r = this.Cursor.fetchall()
  2968. for rs in r:
  2969. mapList.append(rs[0])
  2970.  
  2971. elif this.isRacing:
  2972. this.Cursor.execute("select Code from MapEditor where Perma = 17 ORDER BY RANDOM() LIMIT 1")
  2973. r = this.Cursor.fetchall()
  2974. for rs in r:
  2975. mapList.append(rs[0])
  2976.  
  2977. elif this.isBootcamp:
  2978. P3List = []
  2979. P13List = []
  2980.  
  2981. this.Cursor.execute("select Code, Perma from MapEditor where Perma = 3 or Perma = 13 ORDER BY RANDOM() LIMIT 1")
  2982. r = this.Cursor.fetchall()
  2983. for rs in r:
  2984. perma = rs[1]
  2985. if perma == 3:
  2986. P3List.append(rs[0])
  2987. else:
  2988. P13List.append(rs[0])
  2989.  
  2990. if this.isBootcampP13:
  2991. mapList = P3List if len(P13List) == 0 else P13List
  2992. else:
  2993. mapList = P13List if len(P3List) == 0 else P3List
  2994.  
  2995. elif this.isSurvivor:
  2996. this.isSurvivorVamp = this.survivorMapStatus == 10
  2997.  
  2998. this.Cursor.execute("select Code from MapEditor where Perma = ?", [11 if this.isSurvivorVamp else 10])
  2999. r = this.Cursor.fetchall()
  3000. for rs in r:
  3001. mapList.append(rs[0])
  3002.  
  3003. elif this.isDefilante:
  3004. this.Cursor.execute("select Code from MapEditor where Perma = 18 ORDER BY RANDOM() LIMIT 1")
  3005. r = this.Cursor.fetchall()
  3006. for rs in r:
  3007. mapList.append(rs[0])
  3008.  
  3009. elif mapStatus in customMaps:
  3010. multiple = False
  3011. selectCode = 0
  3012.  
  3013. if mapStatus == 1 or mapStatus == 9:
  3014. multiple = True
  3015. elif mapStatus == 2:
  3016. selectCode = 5
  3017. elif mapStatus == 3:
  3018. selectCode = 9
  3019. elif mapStatus == 5 or mapStatus == 11:
  3020. selectCode = 6
  3021. elif mapStatus == 6:
  3022. selectCode = 7
  3023. elif mapStatus == 7:
  3024. selectCode = 8
  3025. elif mapStatus == 10:
  3026. selectCode = 4
  3027.  
  3028. if multiple:
  3029. this.Cursor.execute("select Code from MapEditor where Perma = 0 ORDER BY RANDOM() LIMIT 1")
  3030. r = this.Cursor.fetchall()
  3031. for rs in r:
  3032. mapList.append(rs[0])
  3033.  
  3034. this.Cursor.execute("select Code from MapEditor where Perma = 1 ORDER BY RANDOM() LIMIT 1")
  3035. r = this.Cursor.fetchall()
  3036. for rs in r:
  3037. mapList.append(rs[0])
  3038. else:
  3039. this.Cursor.execute("select Code from MapEditor where Perma = ? ORDER BY RANDOM() LIMIT 1", [selectCode])
  3040. r = this.Cursor.fetchall()
  3041. for rs in r:
  3042. mapList.append(rs[0])
  3043. else:
  3044. map = random.choice(this.MapList)
  3045. while map == this.currentMap:
  3046. map = random.choice(this.MapList)
  3047. return map
  3048.  
  3049. if len(mapList) >= 1:
  3050. runMap = random.choice(mapList)
  3051. else:
  3052. runMap = 0
  3053.  
  3054. if len(mapList) >= 2:
  3055. while runMap == this.currentMap:
  3056. runMap = random.choice(mapList)
  3057.  
  3058. if runMap == 0:
  3059. map = random.choice(this.MapList)
  3060. while map == this.currentMap:
  3061. map = random.choice(this.MapList)
  3062. return map
  3063. else:
  3064. mapInfo = this.getMapInfo(runMap)
  3065. this.mapCode = runMap
  3066. this.mapName = str(mapInfo[0])
  3067. this.mapXML = str(mapInfo[1])
  3068. this.mapYesVotes = int(mapInfo[2])
  3069. this.mapNoVotes = int(mapInfo[3])
  3070. this.mapPerma = int(mapInfo[4])
  3071. this.mapInverted = random.randint(0, 100) > 85
  3072. return -1
  3073.  
  3074. def selectMapSpecificic(this, code, type):
  3075. if type == "Vanilla":
  3076. return int(code)
  3077.  
  3078. elif type == "Custom":
  3079. mapInfo = this.getMapInfo(int(code))
  3080. if mapInfo[0] == None:
  3081. return 0
  3082. else:
  3083. this.mapCode = int(code)
  3084. this.mapName = str(mapInfo[0])
  3085. this.mapXML = str(mapInfo[1])
  3086. this.mapYesVotes = int(mapInfo[2])
  3087. this.mapNoVotes = int(mapInfo[3])
  3088. this.mapPerma = int(mapInfo[4])
  3089. this.mapInverted = False
  3090. return -1
  3091.  
  3092. elif type == "Perm":
  3093. mapList = []
  3094. this.Cursor.execute("select Code from MapEditor where Perma = ? ORDER BY RANDOM() LIMIT 1", [int(str(code))])
  3095. r = this.Cursor.fetchall()
  3096. for rs in r:
  3097. mapList.append(rs["Code"])
  3098.  
  3099. if len(mapList) >= 1:
  3100. runMap = random.choice(mapList)
  3101. else:
  3102. runMap = 0
  3103.  
  3104. if len(mapList) >= 2:
  3105. while runMap == this.currentMap:
  3106. runMap = random.choice(mapList)
  3107.  
  3108. if runMap == 0:
  3109. map = random.choice(this.MapList)
  3110. while map == this.currentMap:
  3111. map = random.choice(this.MapList)
  3112. return map
  3113. else:
  3114. mapInfo = this.getMapInfo(runMap)
  3115. this.mapCode = runMap
  3116. this.mapName = str(mapInfo[0])
  3117. this.mapXML = str(mapInfo[1])
  3118. this.mapYesVotes = int(mapInfo[2])
  3119. this.mapNoVotes = int(mapInfo[3])
  3120. this.mapPerma = int(mapInfo[4])
  3121. this.mapInverted = False
  3122. return -1
  3123.  
  3124. elif type == "Xml":
  3125. this.mapCode = 0
  3126. this.mapName = "#Module"
  3127. this.mapXML = str(code)
  3128. this.mapYesVotes = 0
  3129. this.mapNoVotes = 0
  3130. this.mapPerma = 22
  3131. this.mapInverted = False
  3132. return -1
  3133.  
  3134. def getMapInfo(this, mapCode):
  3135. mapInfo = ["", "", 0, 0, 0]
  3136. this.Cursor.execute("select Name, XML, YesVotes, NoVotes, Perma from MapEditor where Code = ? ORDER BY RANDOM() LIMIT 1", [mapCode])
  3137. rs = this.Cursor.fetchone()
  3138. if rs:
  3139. mapInfo = rs["Name"], rs["XML"], rs["YesVotes"], rs["NoVotes"], rs["Perma"]
  3140.  
  3141. return mapInfo
  3142.  
  3143. def checkIfTooFewRemaining(this):
  3144. return len(filter(lambda player: not player.isDead, this.clients.values())) <= 2
  3145.  
  3146. def getAliveCount(this):
  3147. return len(filter(lambda player: not player.isDead, this.clients.values()))
  3148.  
  3149. def getDeathCountNoShaman(this):
  3150. return len(filter(lambda player: not player.isShaman and not player.isDead and not player.isNewPlayer, this.clients.values()))
  3151.  
  3152. def getHighestScore(this):
  3153. scores = []
  3154.  
  3155. for client in this.clients.values():
  3156. scores.append(client.playerScore)
  3157.  
  3158. try:
  3159. for client in this.clients.values():
  3160. if client.playerScore == max(scores):
  3161. return client.playerCode
  3162. except: pass
  3163. return 0
  3164.  
  3165. def getSecondHighestScore(this):
  3166. scores = []
  3167.  
  3168. for client in this.clients.values():
  3169. scores.append(client.playerScore)
  3170.  
  3171. scores.remove(max(scores))
  3172.  
  3173. try:
  3174. for client in this.clients.values():
  3175. if client.playerScore == max(scores):
  3176. return client.playerCode
  3177. except: pass
  3178. return 0
  3179.  
  3180. def getShamanCode(this):
  3181. if this.currentShamanCode == -1:
  3182. if this.currentMap in this.noShamanMaps or this.isNoShamanMap:
  3183. pass
  3184. elif this.noShaman or (this.survivorMapStatus == 7 and this.isSurvivor):
  3185. pass
  3186. else:
  3187. if this.forceNextShaman > 0:
  3188. this.currentShamanCode = this.forceNextShaman
  3189. this.forceNextShaman = 0
  3190. else:
  3191. this.currentShamanCode = this.getHighestScore()
  3192.  
  3193. if this.currentShamanCode == -1:
  3194. this.currentShamanName = ""
  3195. else:
  3196. for client in this.clients.values():
  3197. if client.playerCode == this.currentShamanCode:
  3198. this.currentShamanName = client.Username
  3199. this.currentShamanType = client.shamanType
  3200. this.currentShamanSkills = client.playerSkills
  3201. break
  3202. return this.currentShamanCode
  3203.  
  3204. def getDoubleShamanCode(this):
  3205. if this.currentShamanCode == -1 and this.currentSecondShamanCode == -1:
  3206. if this.forceNextShaman > 0:
  3207. this.currentShamanCode = this.forceNextShaman
  3208. this.forceNextShaman = 0
  3209. else:
  3210. this.currentShamanCode = this.getHighestScore()
  3211.  
  3212. if this.currentSecondShamanCode == -1:
  3213. this.currentSecondShamanCode = this.getSecondHighestScore()
  3214.  
  3215. if this.currentSecondShamanCode == this.currentShamanCode:
  3216. values = this.clients.values()
  3217. tempClient = random.choice(values)
  3218. this.currentSecondShamanCode = tempClient.playerCode
  3219.  
  3220. for client in this.clients.values():
  3221. if client.playerCode == this.currentShamanCode:
  3222. this.currentShamanName = client.Username
  3223. this.currentShamanType = client.shamanType
  3224. this.currentShamanSkills = client.playerSkills
  3225. break
  3226.  
  3227. if client.playerCode == this.currentSecondShamanCode:
  3228. this.currentSecondShamanName = client.Username
  3229. this.currentSecondShamanType = client.shamanType
  3230. this.currentSecondShamanSkills = client.playerSkills
  3231. break
  3232.  
  3233. return [this.currentShamanCode, this.currentSecondShamanCode]
  3234.  
  3235. def closeVoting(this):
  3236. this.initVotingMode = False
  3237. this.isVotingBox = False
  3238. if this.voteCloseTimer != None: this.voteCloseTimer.cancel()
  3239. this.mapChange()
  3240.  
  3241. def killAllNoDie(this):
  3242. for client in this.clients.values():
  3243. if not client.isDead:
  3244. client.isDead = True
  3245. this.checkShouldChangeMap()
  3246.  
  3247. def killAll(this):
  3248. for client in this.clients.values():
  3249. if not client.isDead:
  3250. client.sendPlayerDied()
  3251. client.isDead = True
  3252. this.checkShouldChangeMap()
  3253.  
  3254. def killShaman(this):
  3255. for client in this.clients.values():
  3256. if client.playerCode == this.currentShamanCode:
  3257. client.isDead = True
  3258. client.sendPlayerDied()
  3259. this.checkShouldChangeMap()
  3260.  
  3261. def killAfk(this):
  3262. if not this.isEditeur or not this.isTotemEditeur or not this.isBootcamp or not this.isTribeHouseMap or not this.disableAfkKill:
  3263. if ((TFMUtils.getTime() - this.gameStartTime) < 32 and (TFMUtils.getTime() - this.gameStartTime) > 28):
  3264. for client in this.clients.values():
  3265. if not client.isDead and client.isAfk:
  3266. client.isDead = True
  3267. if not this.noAutoScore: client.playerScore += 1
  3268. client.sendPlayerDied()
  3269. this.checkShouldChangeMap()
  3270.  
  3271. def checkIfDoubleShamansAreDead(this):
  3272. client1 = this.clients.get(this.currentShamanName)
  3273. client2 = this.clients.get(this.currentSecondShamanName)
  3274. return (False if client1 == None else client1.isDead) and (False if client2 == None else client2.isDead)
  3275.  
  3276. def checkIfShamanIsDead(this):
  3277. client = this.clients.get(this.currentShamanName)
  3278. return False if client == None else client.isDead
  3279.  
  3280. def checkIfShamanCanGoIn(this):
  3281. for client in this.clients.values():
  3282. if client.playerCode != this.currentShamanCode and client.playerCode != this.currentSecondShamanCode and not client.isDead:
  3283. return False
  3284. return True
  3285.  
  3286. def giveShamanSave(this, shamanName, type):
  3287. if not this.countStats:
  3288. return
  3289.  
  3290. client = this.clients.get(shamanName)
  3291. if client != None:
  3292. if type == 0:
  3293. client.shamanSaves += 1
  3294. elif type == 1:
  3295. client.hardModeSaves += 1
  3296. elif type == 2:
  3297. client.divineModeSaves += 1
  3298. if client.privLevel != 0:
  3299. counts = [client.shamanSaves, client.hardModeSaves, client.divineModeSaves]
  3300. titles = [this.server.shamanTitleList, this.server.hardModeTitleList, this.server.divineModeTitleList]
  3301. rebuilds = ["shaman", "hardmode", "divinemode"]
  3302. if titles[type].has_key(counts[type]):
  3303. title = titles[type][counts[type]]
  3304. client.checkAndRebuildTitleList(rebuilds[type])
  3305. client.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  3306. client.sendCompleteTitleList()
  3307. client.sendTitleList()
  3308.  
  3309. def respawnMice(this):
  3310. for client in this.clients.values():
  3311. if client.isDead:
  3312. client.isDead = False
  3313. client.playerStartTimeMillis = time.time()
  3314. this.sendAll(Identifiers.old.send.Player_Respawn, [client.getPlayerData(), 0 if this.isBootcamp and this.isUtility else 1])
  3315.  
  3316. if this.autoRespawn or this.isTribeHouseMap:
  3317. this.autoRespawnTimer = reactor.callLater(2, this.respawnMice)
  3318.  
  3319. def respawnSpecific(this, playerName, isResetPlay=False):
  3320. client = this.clients.get(playerName)
  3321. if client != None and client.isDead:
  3322. client.resetPlay(isResetPlay)
  3323. client.isAfk = False
  3324. client.playerStartTimeMillis = time.time()
  3325. this.sendAll(Identifiers.old.send.Player_Respawn, [client.getPlayerData(), 0 if this.isBootcamp else 1])
  3326.  
  3327. def sendMulodromeRound(this):
  3328. this.sendAll(Identifiers.send.Mulodrome_Result, ByteArray().writeByte(this.mulodromeRoundCount).writeShort(this.blueCount).writeShort(this.redCount).toByteArray())
  3329. if this.mulodromeRoundCount > 10:
  3330. this.sendAll(Identifiers.send.Mulodrome_End, "")
  3331. 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())
  3332. this.isMulodrome = False
  3333. this.mulodromeRoundCount = 0
  3334. this.redCount = 0
  3335. this.blueCount = 0
  3336. this.redTeam = []
  3337. this.blueTeam = []
  3338. this.isRacing = False
  3339. this.mapStatus = 1
  3340. this.never20secTimer = False
  3341. this.noShaman = False
  3342.  
  3343. def checkVanillaXML(this):
  3344. try:
  3345. with open("./include/vanilla/"+str(this.currentMap)+".xml", "r") as f:
  3346. XML = f.read()
  3347. f.close()
  3348.  
  3349. this.mapCode = int(this.currentMap)
  3350. this.mapName = "Transformice"
  3351. this.mapXML = str(XML)
  3352. this.mapYesVotes = 0
  3353. this.mapNoVotes = 0
  3354. this.mapPerma = 2
  3355. this.currentMap = -1
  3356. this.mapInverted = False
  3357. except: pass
  3358.  
  3359. def getMap801(this, code, name):
  3360. try:
  3361. with open("./include/vanilla/801.xml", "r") as f:
  3362. XML = f.read()
  3363. f.close()
  3364.  
  3365. this.mapCode = code
  3366. this.mapName = name
  3367. this.mapXML = str(XML)
  3368. this.mapYesVotes = 0
  3369. this.mapNoVotes = 0
  3370. this.mapPerma = 41
  3371. this.currentMap = -1
  3372. this.mapInverted = False
  3373. except: pass
  3374.  
  3375. def sendVampireMode(this):
  3376. client = this.clients.get(this.currentSyncName)
  3377. if client != None:
  3378. client.sendVampireMode(False)
  3379.  
  3380. def bindKeyBoard(this, playerName, key, down, yes):
  3381. client = this.clients.get(playerName)
  3382. if client != None:
  3383. client.sendPacket(Identifiers.send.Bind_Key_Board, ByteArray().writeShort(key).writeBool(down).writeBool(yes).toByteArray())
  3384.  
  3385. def addPhysicObject(this, id, x, y, bodyDef):
  3386. 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())
  3387.  
  3388. def chatMessage(this, message, playerName):
  3389. p = ByteArray().writeUTF(message)
  3390. if playerName == "":
  3391. this.sendAll(Identifiers.send.Message, p.toByteArray())
  3392. else:
  3393. client = this.clients.get(playerName)
  3394. if client != None:
  3395. client.sendPacket(Identifiers.send.Message, p.toByteArray())
  3396.  
  3397. def removeObject(this, objectId):
  3398. this.sendAll(Identifiers.send.Remove_Object, ByteArray().writeInt(objectId).writeBool(True).toByteArray())
  3399.  
  3400. def movePlayer(this, playerName, xPosition, yPosition, pOffSet, xSpeed, ySpeed, sOffSet):
  3401. client = this.clients.get(playerName)
  3402. if client != None:
  3403. client.sendPacket(Identifiers.send.Move_Player, ByteArray().writeShort(xPosition).writeShort(yPosition).writeBool(pOffSet).writeShort(xSpeed).writeShort(ySpeed).writeBool(sOffSet).toByteArray())
  3404.  
  3405. def setNameColor(this, playerName, color):
  3406. if this.clients.has_key(playerName):
  3407. this.sendAll(Identifiers.send.Set_Name_Color, ByteArray().writeInt(this.clients.get(playerName).playerCode).writeInt(color).toByteArray())
  3408.  
  3409. def bindMouse(this, playerName, yes):
  3410. client = this.clients.get(playerName)
  3411. if client != None:
  3412. client.sendPacket(Identifiers.send.Bind_Mouse, ByteArray().writeBool(yes).toByteArray())
  3413.  
  3414. def addPopup(this, id, type, text, targetPlayer, x, y, width, fixedPos):
  3415. p = ByteArray().writeInt(id).writeByte(type).writeUTF(text).writeShort(x).writeShort(y).writeShort(width).writeBool(fixedPos)
  3416. if targetPlayer == "":
  3417. this.sendAll(Identifiers.send.Add_Popup, p.toByteArray())
  3418. else:
  3419. player = this.clients.get(targetPlayer)
  3420. if player != None:
  3421. player.sendPacket(Identifiers.send.Add_Popup, p.toByteArray())
  3422.  
  3423. def addTextArea(this, id, text, targetPlayer, x, y, width, height, backgroundColor, borderColor, backgroundAlpha, fixedPos):
  3424. 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)
  3425. if targetPlayer == "":
  3426. this.sendAll(Identifiers.send.Add_Text_Area, p.toByteArray())
  3427. else:
  3428. client = this.clients.get(targetPlayer)
  3429. if client != None:
  3430. client.sendPacket(Identifiers.send.Add_Text_Area, p.toByteArray())
  3431.  
  3432. def removeTextArea(this, id, targetPlayer):
  3433. p = ByteArray().writeInt(id)
  3434. if targetPlayer == "":
  3435. this.sendAll(Identifiers.send.Remove_Text_Area, p.toByteArray())
  3436. else:
  3437. client = this.clients.get(targetPlayer)
  3438. if client != None:
  3439. client.sendPacket(Identifiers.send.Remove_Text_Area, p.toByteArray())
  3440.  
  3441. def updateTextArea(this, id, text, targetPlayer):
  3442. p = ByteArray().writeInt(id).writeUTF(text)
  3443. if targetPlayer == "":
  3444. this.sendAll(Identifiers.send.Update_Text_Area, p.toByteArray())
  3445. else:
  3446. client = this.clients.get(targetPlayer)
  3447. if client != None:
  3448. client.sendPacket(Identifiers.send.Update_Text_Area, p.toByteArray())
  3449.  
  3450. def showColorPicker(this, id, targetPlayer, defaultColor, title):
  3451. p = ByteArray().writeInt(id).writeInt(defaultColor).writeUTF(title)
  3452. if targetPlayer == "":
  3453. this.sendAll(Identifiers.send.Show_Color_Picker, p.toByteArray())
  3454. else:
  3455. client = this.clients.get(targetPlayer)
  3456. if client != None:
  3457. client.sendPacket(Identifiers.send.Show_Color_Picker, p.toByteArray())
  3458.  
  3459. def startSnowSchedule(this, power):
  3460. if this.isSnowing:
  3461. this.startSnow(0, power, False)
  3462.  
  3463. def startSnow(this, millis, power, enabled):
  3464. this.isSnowing = enabled
  3465. this.sendAll(Identifiers.send.Snow, ByteArray().writeBool(enabled).writeShort(power).toByteArray())
  3466. if enabled:
  3467. this.endSnowTimer = reactor.callLater(millis, lambda: this.startSnowSchedule(power))
  3468.  
  3469. def giveSurvivorStats(this):
  3470. for client in this.clients.values():
  3471. if not client.isNewPlayer:
  3472. client.survivorStats[0] += 1
  3473. if client.isShaman:
  3474. client.survivorStats[1] += 1
  3475. client.survivorStats[2] += this.getDeathCountNoShaman()
  3476. elif not client.isDead:
  3477. client.survivorStats[3] += 1
  3478.  
  3479. if client.survivorStats[0] >= 1000 and not str(120) in client.shopBadges:
  3480. client.shopModule.sendUnlockedBadge(str(120))
  3481. client.shopBadges.append(str(120))
  3482. client.shopModule.checkAndRebuildBadges()
  3483.  
  3484. if client.survivorStats[1] >= 800 and not str(121) in client.shopBadges:
  3485. client.shopModule.sendUnlockedBadge(str(121))
  3486. client.shopBadges.append(str(121))
  3487. client.shopModule.checkAndRebuildBadges()
  3488.  
  3489. if client.survivorStats[2] >= 20000 and not str(122) in client.shopBadges:
  3490. client.shopModule.sendUnlockedBadge(str(122))
  3491. client.shopBadges.append(str(122))
  3492. client.shopModule.checkAndRebuildBadges()
  3493.  
  3494. if client.survivorStats[3] >= 10000 and not str(123) in client.shopBadges:
  3495. client.shopModule.sendUnlockedBadge(str(123))
  3496. client.shopBadges.append(str(123))
  3497. client.shopModule.checkAndRebuildBadges()
  3498.  
  3499. def giveRacingStats(this):
  3500. for client in this.clients.values():
  3501. if not client.isNewPlayer:
  3502. client.racingStats[0] += 1
  3503. if client.hasCheese or client.hasEnter:
  3504. client.racingStats[1] += 1
  3505.  
  3506. if client.hasEnter:
  3507. if client.currentPlace <= 3:
  3508. client.racingStats[2] += 1
  3509.  
  3510. if client.currentPlace == 1:
  3511. client.racingStats[3] += 1
  3512.  
  3513. if client.racingStats[0] >= 1500 and not str(124) in client.shopBadges:
  3514. client.shopModule.sendUnlockedBadge(str(124))
  3515. client.shopBadges.append(str(124))
  3516. client.shopModule.checkAndRebuildBadges()
  3517.  
  3518. if client.racingStats[1] >= 10000 and not str(125) in client.shopBadges:
  3519. client.shopModule.sendUnlockedBadge(str(125))
  3520. client.shopBadges.append(str(125))
  3521. client.shopModule.checkAndRebuildBadges()
  3522.  
  3523. if client.racingStats[2] >= 10000 and not str(127) in client.shopBadges:
  3524. client.shopModule.sendUnlockedBadge(str(127))
  3525. client.shopBadges.append(str(127))
  3526. client.shopModule.checkAndRebuildBadges()
  3527.  
  3528. if client.racingStats[3] >= 10000 and not str(126) in client.shopBadges:
  3529. client.shopModule.sendUnlockedBadge(str(126))
  3530. client.shopBadges.append(str(126))
  3531. client.shopModule.checkAndRebuildBadges()
  3532.  
  3533. def send20SecRemainingTimer(this):
  3534. if not this.changed20secTimer:
  3535. if not this.never20secTimer and this.roundTime + (this.gameStartTime - TFMUtils.getTime()) > 21:
  3536. this.changed20secTimer = True
  3537. this.changeMapTimers(20)
  3538. for client in this.clients.values():
  3539. client.sendRoundTime(20)
  3540.  
  3541. def changeMapTimers(this, seconds):
  3542. if this.changeMapTimer != None: this.changeMapTimer.cancel()
  3543. this.changeMapTimer = reactor.callLater(seconds, this.mapChange)
  3544.  
  3545. def newConsumableTimer(this, code):
  3546. this.roomTimers.append(reactor.callLater(10, lambda: this.sendAll(Identifiers.send.Remove_Object, ByteArray().writeInt(code).writeBool(False).toByteArray())))
  3547.  
  3548. if __name__ == "__main__":
  3549. # Connection Settings
  3550. Config = ConfigParser.ConfigParser()
  3551. Config.read("./include/Config.ini")
  3552.  
  3553. # Connection Database
  3554. Database, Cursor = None, None
  3555. Database = sqlite3.connect("./database/Transformice.db", check_same_thread = False)
  3556. Database.text_factory = str
  3557. Database.isolation_level = None
  3558. Database.row_factory = sqlite3.Row
  3559. Cursor = Database.cursor()
  3560.  
  3561. # Connection Server
  3562. validPorts = []
  3563. TFM = Server()
  3564. for port in [443, 44440, 44444, 5555, 3724, 6112]:
  3565. try:
  3566. reactor.listenTCP(port, TFM)
  3567. validPorts.append(port)
  3568. except:
  3569. print "It was not possible to connect to the port: " + str(port)
  3570.  
  3571. if not validPorts == []:
  3572. print "Server running on ports: " + str(validPorts)
  3573. threading.Thread(target=reactor.run(), args=(False,)).start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement