Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.59 KB | None | 0 0
  1. #coding: utf-8
  2. import binascii
  3.  
  4. from ByteArray import ByteArray
  5. from Identifiers import Identifiers
  6.  
  7. class ParseShop:
  8. def __init__(this, player, server):
  9. this.client = player
  10. this.server = player.server
  11. this.Cursor = player.Cursor
  12.  
  13. def getShopLength(this):
  14. return 0 if this.client.shopItems == "" else len(this.client.shopItems.split(","))
  15.  
  16. def checkUnlockShopTitle(this):
  17. if this.server.shopTitleList.has_key(this.getShopLength()):
  18. title = this.server.shopTitleList[this.getShopLength()]
  19. this.client.checkAndRebuildTitleList("shop")
  20. this.client.sendUnlockedTitle(int(title - (title % 1)), int(round((title % 1) * 10)))
  21. this.client.sendCompleteTitleList()
  22. this.client.sendTitleList()
  23.  
  24. def checkAndRebuildBadges(this):
  25. rebuild = False
  26. for badge in this.server.shopBadges.items():
  27. if not badge[0] in this.client.shopBadges and this.checkInShop(badge[0]):
  28. this.client.shopBadges.append(str(badge[1]))
  29. rebuild = True
  30.  
  31. if rebuild:
  32. badges = map(int, this.client.shopBadges)
  33. this.client.shopBadges = []
  34. for badge in badges:
  35. if not badge in this.client.shopBadges:
  36. this.client.shopBadges.append(badge)
  37.  
  38. def checkUnlockShopBadge(this, itemID):
  39. if not this.client.isGuest:
  40. if this.server.shopBadges.has_key(itemID):
  41. unlockedBadge = this.server.shopBadges[itemID]
  42. this.sendUnlockedBadge(unlockedBadge)
  43. this.checkAndRebuildBadges()
  44.  
  45. def checkInShop(this, checkItem):
  46. if not this.client.shopItems == "":
  47. for shopItem in this.client.shopItems.split(","):
  48. if checkItem == int(shopItem.split("_")[0] if "_" in shopItem else shopItem):
  49. return True
  50. else:
  51. return False
  52.  
  53. def checkInShamanShop(this, checkItem):
  54. if not this.client.shamanItems == "":
  55. for shamanItems in this.client.shamanItems.split(","):
  56. if checkItem == int(shamanItems.split("_")[0] if "_" in shamanItems else shamanItems):
  57. return True
  58. else:
  59. return False
  60.  
  61. def checkInPlayerShop(this, type, playerName, checkItem):
  62. this.Cursor.execute("select %s from Users where Username = ?" %(type), [playerName])
  63. for rs in this.Cursor.fetchall():
  64. items = rs[type]
  65. if not items == "":
  66. for shopItem in items.split(","):
  67. if checkItem == int(shopItem.split("_")[0] if "_" in shopItem else shopItem):
  68. return True
  69. else:
  70. return False
  71.  
  72. def getItemCustomization(this, checkItem, isShamanShop):
  73. items = this.client.shamanItems if isShamanShop else this.client.shopItems
  74. if not items == "":
  75. for shopItem in items.split(","):
  76. itemSplited = shopItem.split("_")
  77. custom = itemSplited[1] if len(itemSplited) >= 2 else ""
  78. if int(itemSplited[0]) == checkItem:
  79. return "" if custom == "" else ("_" + custom)
  80. else:
  81. return ""
  82.  
  83. def getShamanItemCustom(this, code):
  84. item = this.client.shamanItems.split(",")
  85. if "_" in item:
  86. itemSplited = item.split("_")
  87. custom = (itemSplited[1] if len(itemSplited) >= 2 else "").split("+")
  88. if int(itemSplited[0]) == code:
  89. packet = ByteArray().writeByte(len(custom))
  90. x = 0
  91. while x < len(custom):
  92. packet.writeInt(int(custom[x], 16))
  93. x += 1
  94. return packet.toByteArray()
  95. return chr(0)
  96.  
  97. def getShopItemPrice(this, fullItem):
  98. itemCat = (0 if fullItem / 10000 == 1 else fullItem / 10000) if fullItem > 9999 else fullItem / 100
  99. item = fullItem % 1000 if fullItem > 9999 else fullItem % 100 if fullItem > 999 else fullItem % (100 * itemCat) if fullItem > 99 else fullItem
  100. return this.getItemPromotion(itemCat, item, this.server.shopListCheck[str(itemCat) + "|" + str(item)][1])
  101.  
  102. def getShamanShopItemPrice(this, fullItem):
  103. return this.server.shamanShopListCheck[str(fullItem)][1]
  104.  
  105. def getItemPromotion(this, itemCat, item, price):
  106. for promotion in this.server.shopPromotions:
  107. if promotion[0] == itemCat and promotion[1] == item:
  108. return int((1 if promotion[2] == 0 else promotion[2]) / 100.0 * price)
  109. return price
  110.  
  111.  
  112. def sendShopList(this):
  113. this.sendShopList(True)
  114.  
  115. def sendShopList(this, sendItems=True):
  116. shopItems = [] if this.client.shopItems == "" else this.client.shopItems.split(",")
  117.  
  118. packet = ByteArray().writeInt(this.client.shopCheeses).writeInt(this.client.shopFraises).writeUTF(this.client.playerLook).writeInt(len(shopItems))
  119. for item in shopItems:
  120. if "_" in item:
  121. itemSplited = item.split("_")
  122. realItem = itemSplited[0]
  123. custom = itemSplited[1] if len(itemSplited) >= 2 else ""
  124. realCustom = [] if custom == "" else custom.split("+")
  125. packet.writeByte(len(realCustom)+1).writeInt(int(realItem))
  126. x = 0
  127. while x < len(realCustom):
  128. packet.writeInt(int(realCustom[x], 16))
  129. x += 1
  130. else:
  131. packet.writeByte(0).writeInt(int(item))
  132.  
  133. shop = this.server.shopList if sendItems else []
  134. packet.writeInt(len(shop))
  135. for item in shop:
  136. value = item.split(",")
  137. packet.writeShort(value[0]).writeShort(value[1]).writeByte(value[2]).writeByte(value[3]).writeByte(value[4]).writeInt(value[5]).writeInt(value[6]).writeShort(0)
  138.  
  139. visuais = this.server.newVisuList
  140. packet.writeByte(len(visuais))
  141. i = len(visuais)
  142. visu = []
  143. for visual in visuais.items():
  144. visu.append(visual[1])
  145. if visual[1] in visu:
  146. visu.remove(visual[1])
  147. packet.writeShort(visual[0])
  148. a = visual[1]
  149. packet.writeUTF(''.join(a))
  150. packet.writeByte(0 if visual[0] in [1] else 0 if visual[0] in [2] else 0 if visual[0] in [3] else 2)
  151. i -= 1
  152.  
  153. packet.writeShort(len(this.client.clothes))
  154.  
  155. for clothes in this.client.clothes:
  156. clotheSplited = clothes.split("/")
  157. packet.writeUTF(clotheSplited[1] + ";" + clotheSplited[2] + ";" + clotheSplited[3])
  158.  
  159. shamanItems = [] if this.client.shamanItems == "" else this.client.shamanItems.split(",")
  160. packet.writeShort(len(shamanItems))
  161. for item in shamanItems:
  162. if "_" in item:
  163. itemSplited = item.split("_")
  164. realItem = itemSplited[0]
  165. custom = itemSplited[1] if (len(itemSplited) >= 2) else ""
  166. realCustom = [] if custom == "" else custom.split("+")
  167. packet.writeShort(int(realItem)).writeBoolean(item in this.client.shamanLook.split(",")).writeByte(len(realCustom) + 1)
  168. x = 0
  169. while x < len(realCustom):
  170. packet.writeInt(int(realCustom[x], 16))
  171. x += 1
  172. else:
  173. packet.writeShort(int(item)).writeBoolean(item in this.client.shamanLook.split(",")).writeByte(0)
  174.  
  175. shamanShop = this.server.shamanShopList if sendItems else []
  176. packet.writeShort(len(shamanShop))
  177. for item in shamanShop:
  178. value = item.split(",")
  179. packet.writeInt(value[0]).writeByte(value[1]).writeByte(value[2]).writeByte(value[3]).writeInt(value[4]).writeShort(value[5])
  180. this.client.sendPacket(Identifiers.send.Shop_List, packet.toByteArray())
  181.  
  182. def sendShamanItems(this):
  183. shamanItems = [] if this.client.shamanItems == "" else this.client.shamanItems.split(",")
  184.  
  185. packet = ByteArray().writeShort(len(shamanItems))
  186. for item in shamanItems:
  187. if "_" in item:
  188. custom = item.split("_")[1] if len(item.split("_")) >= 2 else ""
  189. realCustom = [] if custom == "" else custom.split("+")
  190. packet.writeShort(int(item.split("_")[0])).writeBoolean(item in this.client.shamanLook.split(",")).writeByte(len(realCustom) + 1)
  191. x = 0
  192. while x < len(realCustom):
  193. packet.writeInt(int(realCustom[x], 16))
  194. x += 1
  195. else:
  196. packet.writeShort(int(item)).writeBoolean(item in this.client.shamanLook.split(",")).writeByte(0)
  197. this.client.sendPacket(Identifiers.send.Shaman_Items, packet.toByteArray())
  198.  
  199. def sendLookChange(this):
  200. kostum, giysiler = this.client.playerLook.split(";")
  201. giysiler = giysiler.split(',')
  202. giysiler.append('0')
  203. packet = ByteArray().writeByte(int(kostum))
  204.  
  205. for item in giysiler:
  206. if "_" in item:
  207. custom = item.split("_")[1] if len(item.split("_")) >= 2 else ""
  208. realCustom = [] if custom == "" else custom.split("+")
  209. packet.writeInt(int(item.split("_")[0])).writeByte(len(realCustom))
  210.  
  211. x = 0
  212. while x < len(realCustom):
  213. packet.writeInt(int(realCustom[x], 16))
  214. x += 1
  215. else:
  216. packet.writeInt(int(item)).writeByte(0)
  217.  
  218. try:
  219. packet.writeInt(int(this.client.mouseColor, 16))
  220. except:
  221. packet.writeInt(int("78583A", 16))
  222. this.client.sendPacket(Identifiers.send.Look_Change, packet.toByteArray())
  223. def sendShamanLook(this):
  224. items = ByteArray()
  225.  
  226. count = 0
  227. for item in this.client.shamanLook.split(","):
  228. realItem = int(item.split("_")[0]) if "_" in item else int(item)
  229. if realItem != 0:
  230. items.writeShort(realItem)
  231. count += 1
  232. this.client.sendPacket(Identifiers.send.Shaman_Look, ByteArray().writeShort(count).writeBytes(items.toByteArray()).toByteArray())
  233.  
  234. def sendItemBuy(this, fullItem, withFraises, pret):
  235. this.client.sendPacket(Identifiers.send.Item_Buy, ByteArray().writeInt(fullItem).writeBoolean(withFraises).writeShort(pret).toByteArray())
  236.  
  237. def sendUnlockedBadge(this, badge):
  238. this.client.room.sendAll(Identifiers.send.Unlocked_Badge, ByteArray().writeInt(this.client.playerCode).writeShort(badge).toByteArray())
  239.  
  240. def sendGiftResult(this, type, playerName):
  241. this.client.sendPacket(Identifiers.send.Gift_Result, ByteArray().writeByte(type).writeUTF(playerName).writeByte(0).writeShort(0).toByteArray())
  242.  
  243. def equipClothe(this, packet):
  244. clotheID = packet.readByte()
  245. for clothe in this.client.clothes:
  246. values = clothe.split("/")
  247. if values[0] == "%02d" %(clotheID):
  248. this.client.playerLook = values[1]
  249. this.client.mouseColor = values[2]
  250. this.client.shamanColor = values[3]
  251. break
  252. save = this.client.playerLook.split(";")
  253. this.client.checkElection(int(save[0]))
  254. this.sendLookChange()
  255. this.sendShopList(False)
  256.  
  257. def saveClothe(this, packet):
  258. clotheID = packet.readByte()
  259. for clothe in this.client.clothes:
  260. values = clothe.split("/")
  261. if values[0] == "%02d" %(clotheID):
  262. values[1] = this.client.playerLook
  263. values[2] = this.client.mouseColor
  264. values[3] = this.client.shamanColor
  265. this.client.clothes[this.client.clothes.index(clothe)] = "/".join(values)
  266. break
  267.  
  268. this.sendShopList(False)
  269.  
  270. def sendShopInfo(this):
  271. this.client.sendPacket(Identifiers.send.Shop_Info, ByteArray().writeInt(this.client.shopCheeses).writeInt(this.client.shopFraises).toByteArray())
  272.  
  273. def equipItem(this, packet):
  274. fullItem = packet.readInt()
  275. itemCat = (0 if fullItem / 10000 == 1 else fullItem / 10000) if fullItem > 9999 else fullItem / 100
  276. item = fullItem % 1000 if fullItem > 9999 else fullItem % 100 if fullItem > 999 else fullItem % (100 * itemCat) if fullItem > 99 else fullItem
  277. lookList = this.client.playerLook.split(";")
  278. lookItems = lookList[1].split(",")
  279. lookCheckList = lookItems[:]
  280. i = 0
  281. while i < len(lookCheckList):
  282. lookCheckList[i] = lookCheckList[i].split("_")[0] if "_" in lookCheckList[i] else lookCheckList[i]
  283. i += 1
  284.  
  285. if itemCat <= 10:
  286. lookItems[itemCat] = "0" if lookCheckList[itemCat] == str(item) else str(item) + this.getItemCustomization(fullItem, False)
  287. elif itemCat == 21:
  288. lookList[0] = "1"
  289. color = "bd9067" if item == 0 else "593618" if item == 1 else "8c887f" if item == 2 else "dfd8ce" if item == 3 else "4e443a" if item == 4 else "e3c07e" if item == 5 else "272220" if item == 6 else "78583a"
  290. this.client.mouseColor = "78583a" if this.client.mouseColor == color else color
  291. else:
  292. lookList[0] = "1" if lookList[0] == str(item) else str(item)
  293. this.client.mouseColor = "78583a"
  294. this.client.checkElection(int(lookList[0]))
  295.  
  296. this.client.playerLook = lookList[0] + ";" + ",".join(map(str, lookItems))
  297. this.sendLookChange()
  298.  
  299. def buyItem(this, packet):
  300. fullItem, withFraises, pret = packet.readInt(), packet.readBoolean(), packet.readShort()
  301. #this.client.sendMessage("<ROSE>Pret:<CH> " +str(pret), True)
  302. print "id: " + str(fullItem) + " \nbranza: " + str(withFraises) + " \npret: " + str(pret)
  303. itemCat = (0 if fullItem / 10000 == 1 else fullItem / 10000) if fullItem > 9999 else fullItem / 100
  304. item = fullItem % 1000 if fullItem > 9999 else fullItem % 100 if fullItem > 999 else fullItem % (100 * itemCat) if fullItem > 99 else fullItem
  305. this.client.shopItems += str(fullItem) if this.client.shopItems == "" else "," + str(fullItem)
  306. #price = this.getItemPromotion(itemCat, item, this.server.shopListCheck[str(itemCat) + "|" + str(item)][1 if withFraises else 0])
  307. if withFraises:
  308. this.client.shopFraises -= pret
  309. else:
  310. this.client.shopCheeses -= pret
  311.  
  312. this.sendItemBuy(fullItem,withFraises,pret)
  313. this.sendShopList(False)
  314. this.client.sendAnimZelda(0, fullItem)
  315. this.checkUnlockShopTitle()
  316. this.checkUnlockShopBadge(fullItem)
  317.  
  318. def customItemBuy(this, packet):
  319. fullItem, withFraises = packet.readShort(), packet.readBoolean()
  320.  
  321. items = this.client.shopItems.split(",")
  322. for shopItem in items:
  323. item = shopItem.split("_")[0] if "_" in shopItem else shopItem
  324. if fullItem == int(item):
  325. items[items.index(shopItem)] = shopItem + "_"
  326. break
  327.  
  328. this.client.shopItems = ",".join(items)
  329. if withFraises:
  330. this.client.shopFraises -= 20
  331. else:
  332. this.client.shopCheeses -= 2000
  333.  
  334. if len(this.client.custom) == 1:
  335. if not fullItem in this.client.custom:
  336. this.client.custom.append(fullItem)
  337. else:
  338. if not str(fullItem) in this.client.custom:
  339. this.client.custom.append(str(fullItem))
  340.  
  341. this.sendShopList(False)
  342.  
  343. def customItem(this, packet):
  344. fullItem, length = packet.readShort(), packet.readByte()
  345. custom = length
  346. customs = list()
  347.  
  348. i = 0
  349. while i < length:
  350. customs.append(packet.readInt())
  351. i += 1
  352.  
  353. items = this.client.shopItems.split(",")
  354. for shopItem in items:
  355. sItem = shopItem.split("_")[0] if "_" in shopItem else shopItem
  356. if fullItem == int(sItem):
  357. newCustoms = map(lambda color: "%06X" %(0xffffff & color), customs)
  358.  
  359. items[items.index(shopItem)] = sItem + "_" + "+".join(newCustoms)
  360. this.client.shopItems = ",".join(items)
  361.  
  362. itemCat = (0 if fullItem / 10000 == 1 else fullItem / 10000) if fullItem > 9999 else fullItem / 100
  363. item = fullItem % 1000 if fullItem > 9999 else fullItem % 100 if fullItem > 999 else fullItem % (100 * itemCat) if fullItem > 99 else fullItem
  364. equip = str(item) + this.getItemCustomization(fullItem, False)
  365. lookList = this.client.playerLook.split(";")
  366. lookItems = lookList[1].split(",")
  367.  
  368. if "_" in lookItems[itemCat]:
  369. if lookItems[itemCat].split("_")[0] == str(item):
  370. lookItems[itemCat] = equip
  371.  
  372. elif lookItems[itemCat] == str(item):
  373. lookItems[itemCat] = equip
  374. this.client.playerLook = lookList[0] + ";" + ",".join(lookItems)
  375. this.sendShopList(False)
  376. this.sendLookChange()
  377. break
  378.  
  379. def buyShamanItem(this, packet):
  380. fullItem, withFraises = packet.readShort(), packet.readBoolean()
  381. price = this.server.shamanShopListCheck[str(fullItem)][1 if withFraises else 0]
  382. this.client.shamanItems += str(fullItem) if this.client.shamanItems == "" else "," + str(fullItem)
  383.  
  384. if withFraises:
  385. this.client.shopFraises -= price
  386. else:
  387. this.client.shopCheeses -= price
  388.  
  389. this.sendShopList(False)
  390. this.client.sendAnimZelda(1, fullItem)
  391.  
  392. def equipShamanItem(this, packet):
  393. fullItem = packet.readInt()
  394. item = str(fullItem) + this.getItemCustomization(fullItem, True)
  395. itemStr = str(fullItem)
  396. itemCat = int(itemStr[:len(itemStr)-2])
  397. index = itemCat if itemCat <= 4 else itemCat - 1 if itemCat <= 7 else 7 if itemCat == 10 else 8 if itemCat == 17 else 9
  398. index -= 1
  399. lookItems = this.client.shamanLook.split(",")
  400.  
  401. if "_" in lookItems[index]:
  402. if lookItems[index].split("_")[0] == itemStr:
  403. lookItems[index] = "0"
  404. else:
  405. lookItems[index] = item
  406.  
  407. elif lookItems[index] == itemStr:
  408. lookItems[index] = "0"
  409. else:
  410. lookItems[index] = item
  411.  
  412. this.client.shamanLook = ",".join(lookItems)
  413. this.sendShamanLook()
  414.  
  415. def customShamanItemBuy(this, packet):
  416. fullItem, withFraises = packet.readShort(), packet.readBoolean()
  417.  
  418. items = this.client.shamanItems.split(",")
  419. for shopItem in items:
  420. item = shopItem.split("_")[0] if "_" in shopItem else shopItem
  421. if fullItem == int(item):
  422. items[items.index(shopItem)] = shopItem + "_"
  423. break
  424.  
  425. this.client.shamanItems = ",".join(items)
  426. if withFraises:
  427. this.client.shopFraises -= 150
  428. else:
  429. this.client.shopCheeses -= 4000
  430.  
  431. this.sendShopList(False)
  432.  
  433. def customShamanItem(this, packet):
  434. fullItem, length = packet.readShort(), packet.readByte()
  435. customs = []
  436. i = 0
  437. while i < length:
  438. customs.append(packet.readInt())
  439. i += 1
  440.  
  441. items = this.client.shamanItems.split(",")
  442. for shopItem in items:
  443. sItem = shopItem.split("_")[0] if "_" in shopItem else shopItem
  444. if fullItem == int(sItem):
  445. newCustoms = map(lambda color: "%06X" %(0xFFFFFF & color), customs)
  446.  
  447. items[items.index(shopItem)] = sItem + "_" + "+".join(newCustoms)
  448. this.client.shamanItems = ",".join(items)
  449.  
  450. item = str(fullItem) + this.getItemCustomization(fullItem, True)
  451. itemStr = str(fullItem)
  452. itemCat = int(itemStr[len(itemStr)-2:])
  453. index = itemCat if itemCat <= 4 else itemCat - 1 if itemCat <= 7 else 7 if itemCat == 10 else 8 if itemCat == 17 else 9
  454. index -= 1
  455. lookItems = this.client.shamanLook.split(",")
  456.  
  457. if "_" in lookItems[index]:
  458. if lookItems[index].split("_")[0] == itemStr:
  459. lookItems[index] = item
  460.  
  461. elif lookItems[index] == itemStr:
  462. lookItems[index] = item
  463.  
  464. this.client.shamanLook = ",".join(lookItems)
  465. this.sendShopList()
  466. this.sendShamanLook()
  467. break
  468.  
  469. def buyClothe(this, packet):
  470. clotheID, withFraises = packet.readByte(), packet.readBoolean()
  471. this.client.clothes.append("%02d/1;0,0,0,0,0,0,0,0,0/78583a/%s" %(clotheID, "fade55" if this.client.shamanSaves >= 1000 else "95d9d6"))
  472. if withFraises:
  473. this.client.shopFraises -= 5 if clotheID == 0 else 50 if clotheID == 1 else 100
  474. else:
  475. this.client.shopFraises -= 40 if clotheID == 0 else 1000 if clotheID == 1 else 2000 if clotheID == 2 else 4000
  476.  
  477. this.sendShopList(False)
  478.  
  479. def sendGift(this, packet):
  480. playerName, isShamanItem, fullItem, message = packet.readUTF(), packet.readBoolean(), packet.readShort(), packet.readUTF()
  481. if not this.server.checkExistingUser(playerName):
  482. this.sendGiftResult(1, playerName)
  483. else:
  484. player = this.server.players.get(playerName)
  485. if player != None:
  486. if (player.parseShop.checkInShamanShop(fullItem) if isShamanItem else player.parseShop.checkInShop(fullItem)):
  487. this.sendGiftResult(2, playerName)
  488. else:
  489. this.server.lastGiftID += 1
  490. player.sendPacket(Identifiers.send.Shop_Gift, ByteArray().writeInt(this.server.lastGiftID).writeUTF(this.client.playerName).writeUTF(this.client.playerLook).writeBoolean(isShamanItem).writeShort(fullItem).writeUTF(message).writeBoolean(False).toByteArray())
  491. this.sendGiftResult(0, playerName)
  492. this.server.shopGifts[this.server.lastGiftID] = [this.client.playerName, isShamanItem, fullItem]
  493. this.client.shopFraises -= this.getShamanShopItemPrice(fullItem) if isShamanItem else this.getShopItemPrice(fullItem)
  494. this.sendShopList()
  495. else:
  496. gifts = ""
  497. if (this.checkInPlayerShop("ShamanItems" if isShamanItem else "ShopItems", playerName, fullItem)):
  498. this.sendGiftResult(2, playerName)
  499. else:
  500. this.Cursor.execute("select Gifts from Users where Username = ?", [playerName])
  501. rs = this.Cursor.fetchone()
  502. gifts = rs["Gifts"]
  503.  
  504. gifts += ("" if gifts == "" else "/") + binascii.hexlify("|".join(map(str, [this.client.playerName, this.client.playerLook, isShamanItem, fullItem, message])))
  505. this.Cursor.execute("update Users set Gifts = ? where Username = ?", [gifts, playerName])
  506. this.sendGiftResult(0, playerName)
  507.  
  508. def giftResult(this, packet):
  509. giftID, isOpen, message, isMessage = packet.readInt(), packet.readBoolean(), packet.readUTF(), packet.readBoolean()
  510. if isOpen:
  511. values = this.server.shopGifts[int(giftID)]
  512. player = this.server.players.get(str(values[0]))
  513. if player != None:
  514. player.sendLangueMessage("", "$DonItemRecu", this.client.playerName)
  515.  
  516. isShamanItem = bool(values[1])
  517. fullItem = int(values[2])
  518. if isShamanItem:
  519. this.client.shamanItems += str(fullItem) if this.client.shamanItems == "" else ",%s" %(fullItem)
  520. this.sendShopList(False)
  521. this.client.sendAnimZelda(1, fullItem)
  522. else:
  523. this.client.shopItems += str(fullItem) if this.client.shopItems == "" else ",%s" %(fullItem)
  524. this.client.sendAnimZelda(0, fullItem)
  525. this.checkUnlockShopTitle()
  526. this.checkUnlockShopBadge(fullItem)
  527.  
  528. elif not message == "":
  529. values = this.server.shopGifts[int(giftID)]
  530. player = this.server.players.get(str(values[0]))
  531. if player != None:
  532. player.sendPacket(Identifiers.send.Shop_Gift, ByteArray().writeInt(giftID).writeUTF(this.client.playerName).writeUTF(this.client.playerLook).writeBoolean(bool(values[1])).writeShort(int(values[2])).writeUTF(message).writeBoolean(True).toByteArray())
  533. else:
  534. messages = ""
  535. this.Cursor.execute("select Messages from Users where Username = ?", [str(values[0])])
  536. rs = this.Cursor.fetchone()
  537. messages = rs["Messages"]
  538.  
  539. messages += ("" if messages == "" else "/") + binascii.hexlify("|".join(map(str, [this.client.playerName, this.client.playerLook, values[1], values[2], message])))
  540. this.Cursor.execute("update Users set Messages = ? where Username = ?", [messages, str(values[0])])
  541.  
  542. def checkGiftsAndMessages(this, lastReceivedGifts, lastReceivedMessages):
  543. needUpdate = False
  544. gifts = lastReceivedGifts.split("/")
  545. for gift in gifts:
  546. if not gift == "":
  547. values = binascii.unhexlify(gift).split("|", 4)
  548. this.server.lastGiftID += 1
  549. this.client.sendPacket(Identifiers.send.Shop_Gift, ByteArray().writeInt(this.server.lastGiftID).writeUTF(values[0]).writeUTF(values[1]).writeBoolean(bool(values[2])).writeShort(int(values[3])).writeUTF(values[4] if len(values) > 4 else "").writeBoolean(False).toByteArray())
  550. this.server.shopGifts[this.server.lastGiftID] = [values[0], bool(values[2]), int(values[3])]
  551. needUpdate = True
  552.  
  553. messages = lastReceivedMessages.split("/")
  554. for message in messages:
  555. if not message == "":
  556. values = binascii.unhexlify(message).split("|", 4)
  557. this.client.sendPacket(Identifiers.send.Shop_GIft, ByteArray().writeShort(0).writeShort(0).writeUTF(values[0]).writeBoolean(bool(values[1])).writeShort(int(values[2])).writeUTF(values[4]).writeUTF(values[3]).writeBoolean(True).toByteArray())
  558. needUpdate = True
  559.  
  560. if needUpdate:
  561. this.Cursor.execute("update Users set Gifts = '', Messages = '' where Username = ?", [this.client.playerName])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement