Advertisement
Guest User

Untitled

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