Advertisement
Guest User

Untitled

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