Advertisement
Guest User

Untitled

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