def read_data(data): ba = ByteArray(data) #大端模式标准对齐方式 ba.endian = "!" length = ba.readInt() print "length", length print "bytesAvailable", ba.bytesAvailable() #只用了1位字节存储 长度-128 - 127 #业务大类 actionName = ba.readByte() #具体业务类型 type = ba.readByte() print "actionName", actionName print "type", type str = ba.readUTFBytes(3) print str i = ba.readInt() print i
def equipClothe(this, packet): p = ByteArray(packet) clotheID = p.readByte() for clothe in this.client.clothes: values = clothe.split("/") if values[0] == "%02d" % (clotheID): this.client.playerLook = values[1] this.client.MouseColor = values[2] this.client.ShamanColor = values[3] break this.sendLookChange() this.sendShopList(False)
def saveClothe(this, packet): p = ByteArray(packet) clotheID = p.readByte() for clothe in this.client.clothes: values = clothe.split("/") if values[0] == "%02d" % (clotheID): values[1] = this.client.playerLook values[2] = this.client.MouseColor values[3] = this.client.ShamanColor this.client.clothes[this.client.clothes.index( clothe)] = "/".join(values) break this.sendShopList(False)
def dataReceived(this, data): packet = "" + data if packet.startswith("<policy-file-request/>"): this.transport.write( "<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>" ) this.transport.loseConnection() return elif packet.startswith("change_avatar_"): key = packet.replace("change_avatar_", "") if this.server.clientAvatarKeys.has_key(key): player = this.server.avatarKeys[key] this.transport.write(player.Username + " - " + player.playerID) else: this.transport.write("error") if packet == None or len(packet) < 2: return this.recvd += data while not this.recvd == "": dataLength = len(this.recvd) if dataLength > 1: p = ByteArray(this.recvd) sizeBytes = p.readByte() length = p.readUnsignedByte( ) if sizeBytes == 1 else p.readUnsignedShort( ) if sizeBytes == 2 else ( (p.readUnsignedByte() & 0xFF) << 16) | ( (p.readUnsignedByte() & 0xFF) << 8 ) | (p.readUnsignedByte() & 0xFF) if sizeBytes == 3 else 0 if length == 0: return length += 1 dataLength -= (sizeBytes + 1) if dataLength == length: this.parseString(this.recvd[sizeBytes + 1:]) this.recvd = "" elif dataLength < length: break else: this.parseString(this.recvd[sizeBytes + 1:][:length]) this.recvd = this.recvd[length + sizeBytes + 1:] else: break
def buyClothe(this, packet): p = ByteArray(packet) clotheID, withFraises = p.readByte(), p.readBool() this.client.clothes.append( "%02d/%s/%s/%s" % (clotheID, "1;0,0,0,0,0,0,0,0,0", "78583a", "fade55" if this.client.shamanSaves >= 1000 else "95d9d6")) if withFraises: this.client.shopFraises -= 5 if clotheID == 0 else 50 if clotheID == 1 else 100 else: this.client.shopFraises -= 40 if clotheID == 0 else 1000 if clotheID == 1 else 2000 if clotheID == 2 else 4000 this.sendShopList(False)
def parseSkillPacket(this, skill, packet): p = ByteArray(packet) if this.client.isShaman: if skill == "fly": fly = p.readBool() this.sendShamanFly(fly) elif skill == "projection": posX = p.readShort() posY = p.readShort() dir = p.readShort() this.sendProjectionSkill(posX, posY, dir) elif skill == "demoliton": objectID = p.readInt() this.sendDemolitionSkill(objectID) elif skill == "convert": objectID = p.readInt() this.sendConvertSkill(objectID) elif skill == "recycling": id = p.readShort() this.sendRecyclingSkill(id) elif skill == "antigravity": objectID = p.readInt() this.sendAntigravitySkill(objectID) elif skill == "restorative": objectID = p.readInt() id = p.readInt() this.sendRestorativeSkill(objectID, id) elif skill == "handymouse": handyMouseByte = p.readByte() objectID = p.readInt() if this.client.room.lastHandymouse[0] == -1: this.client.room.lastHandymouse = [objectID, handyMouseByte] else: this.sendHandymouseSkill(handyMouseByte, objectID) this.client.room.sendAllBin(Identifiers.send.Skill, chr(77) + chr(1)) this.client.room.lastHandymouse = [-1, -1] elif skill == "gravitational": id = p.readInt() this.sendGravitationalSkill(0, id)
def customItem(this, packet): p = ByteArray(packet) fullItem, length = p.readShort(), p.readByte() custom = length customs = list() i = 0 while i < length: customs.append(p.readInt()) i += 1 items = this.client.shopItems.split(",") for shopItem in items: sItem = shopItem.split("_")[0] if "_" in shopItem else shopItem if fullItem == int(sItem): newCustoms = map(lambda color: "%06X" % (0xffffff & color), customs) items[items.index( shopItem)] = sItem + "_" + "+".join(newCustoms) this.client.shopItems = ",".join(items) itemStr = str(fullItem) itemCat = (0 if fullItem / 10000 == 1 else fullItem / 10000) if len(itemStr) > 4 else fullItem / 100 item = int(itemStr[2 if len(itemStr) > 3 else 1:] ) if len(itemStr) >= 3 else fullItem equip = str(item) + this.getItemCustomization(fullItem, False) lookList = this.client.playerLook.split(";") lookItems = lookList[1].split(",") if "_" in lookItems[itemCat]: if lookItems[itemCat].split("_")[0] == itemStr: lookItems[itemCat] = equip elif lookItems[itemCat] == itemStr: lookItems[itemCat] = equip this.client.playerLook = lookList[0] + ";" + ",".join( lookItems) this.sendShopList(False) this.sendLookChange() break
def dataReceived(this, packet): data = "" + packet if packet.startswith("<policy-file-request/>"): this.transport.write( "<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>" ) this.transport.loseConnection() return if packet == None or len(packet) < 2: return this.recvd += packet while not this.recvd == "": dataLength = len(this.recvd) if dataLength > 1: p = ByteArray(this.recvd) sizeBytes = p.readByte() length = p.readUnsignedByte( ) if sizeBytes == 1 else p.readUnsignedShort( ) if sizeBytes == 2 else ( (p.readUnsignedByte() & 0xFF) << 16) | ( (p.readUnsignedByte() & 0xFF) << 8 ) | (p.readUnsignedByte() & 0xFF) if sizeBytes == 3 else 0 if length == 0: return length += 1 dataLength -= (sizeBytes + 1) if dataLength == length: this.parseString(this.recvd[sizeBytes + 1:]) this.recvd = "" elif dataLength < length: break else: this.parseString(this.recvd[sizeBytes + 1:][:length]) this.recvd = this.recvd[length + sizeBytes + 1:] else: break
def customShamanItem(this, packet): p = ByteArray(packet) fullItem, length = p.readShort(), p.readByte() customs = list() i = 0 while i < length: customs.append(p.readInt()) i += 1 items = this.client.shamanItems.split(",") for shopItem in items: sItem = shopItem.split("_")[0] if "_" in shopItem else shopItem if fullItem == int(sItem): newCustoms = map(lambda color: "%06X" % (0xffffff & color), customs) items[items.index( shopItem)] = sItem + "_" + "+".join(newCustoms) this.client.shamanItems = ",".join(items) item = str(fullItem) + this.getItemCustomization( fullItem, True) itemStr = str(fullItem) itemCat = int(itemStr[len(itemStr) - 2:]) index = itemCat if itemCat <= 4 else itemCat - 1 if itemCat <= 7 else 7 if itemCat == 10 else 8 if itemCat == 17 else 9 index -= 1 lookItems = this.client.shamanLook.split(",") if "_" in lookItems[index]: if lookItems[index].split("_")[0] == itemStr: lookItems[index] = item elif lookItems[index] == itemStr: lookItems[index] = item this.client.shamanLook = ",".join(lookItems) this.sendShopList(False) this.sendShamanLook() break
def giftResult(this, packet): p = ByteArray(packet) loc1, giftID, isOpen, message, loc2 = p.readShort(), p.readShort( ), p.readBool(), p.readUTF(), p.readByte() if isOpen: values = this.server.shopGifts[int(giftID)] player = this.server.players.get(str(values[0])) if player != None: player.sendMessageLangue("$DonItemRecu", this.client.Username) isShamanItem = bool(values[1]) fullItem = int(values[2]) if isShamanItem: itemStr = str(fullItem) itemCat = int(itemStr[len(itemStr) - 2:]) item = int(itemStr[:len(itemStr) - 2]) this.client.shamanItems += str( fullItem ) if this.client.shamanItems == "" else "," + str(fullItem) this.sendShopList(False) this.client.sendAnimZelda(1, fullItem) else: itemStr = str(fullItem) itemCat = (0 if fullItem / 10000 == 1 else fullItem / 10000) if len(itemStr) > 4 else fullItem / 100 item = int(itemStr[2 if len(itemStr) > 3 else 1:] ) if len(itemStr) >= 3 else fullItem this.client.shopItems += str( fullItem ) if this.client.shopItems == "" else "," + str(fullItem) this.client.sendAnimZelda(itemCat, item) this.checkUnlockShopTitle() this.checkUnlockShopBadge(fullItem) elif not message == "": values = this.server.shopGifts[int(giftID)] player = this.server.players.get(str(values[0])) if player != None: player.sendPacket( Identifiers.send.Shop_GIft_Message, ByteArray().writeShort(0).writeShort(giftID).writeUTF( this.client.Username).writeBool(bool( values[1])).writeShort(int( values[2])).writeUTF(message).writeUTF( this.client.playerLook).toByteArray(), True) else: this.Cursor.execute( "select LastReceivedMessages from Users where Username = ?", [str(values[0])]) rs = this.Cursor.fetchone() lastReceivedMessages = rs["LastReceivedMessages"] lastReceivedMessages = ( "" if lastReceivedMessages == "" else lastReceivedMessages + "/") + "[" + "|".join( map(str, [ this.client.Username, values[1], values[2], this.client.playerLook, message ])) + "]" this.Cursor.execute( "update Users set LastReceivedMessages = ? where Username = ?", [lastReceivedMessages, str(values[0])])