Esempio n. 1
0
	def decode(self, string):
		self.b.addInfos(string)

		while(self.b.getSize() > self.b.getCursor()):
			try:
				self.deserialize()
			except MessageToShort:

				# Don't wait too long
				if(self.b.discardReadAndSaveUnread() >= 3):
					self.b.reset()
				break
			except UnknowMessage as exp:
				printRed("Unknow packet type: {}\n".format(exp))
				printRed("info restantes: {}\n".format(
					self.b.getSize() - self.b.getCursor()
				))

				self.b.reset()
				break
			except StopException:

				self.b.reset()
				break
			except:
				print "Exception in user code:"
				print '-'*60
				traceback.print_exc(file=sys.stdout)
				print '-'*60

				self.b.reset()
				break
Esempio n. 2
0
	def deserialize(self):
		var1 = self.b.readUnsignedShort()
		msgId = var1>>2
		sizeLen = var1 & 0x03
	
		msgSize = 0
		if(sizeLen == 0):
			msgSize = 0
		elif(sizeLen == 1):
			msgSize = self.b.readUnsignedByte()
		elif(sizeLen == 2):
			msgSize = self.b.readUnsignedShort()
		else:
			printRed("wrong size {}\n".format(sizeLen))
			raise StopException()

		if(msgSize > self.b.getSize()):
			#printGreen("size: {}, cursor: {}\n".format(b.getSize(), b.getCursor()))
			if(sizeLen == 1):
				self.b.moveCursor(-3)
			elif(sizeLen == 2):
				self.b.moveCursor(-4)

			#printGreen("size: {}, cursor: {}\n".format(b.getSize(), b.getCursor()))
			printRed("message too short (id: {}) {} > {}\n".format(
				msgId, msgSize, self.b.getSize()
			))
			raise MessageToShort()

		if(msgId == MapComplementaryInformationsDataMessage.getProtocolId()):
			printBlue("[new map]\n")

			self.infos = MapComplementaryInformationsDataMessage()
			self.infos.deserialize(self.b)
		elif(msgId == BasicNoOperationMessage.getProtocolId()):
			self.basicBNOM = BasicNoOperationMessage()
			self.basicBNOM.deserialize(self.b)
		elif(msgId == BasicLatencyStatsRequestMessage.getProtocolId()):
			self.basicLSRM = BasicLatencyStatsRequestMessage()
			self.basicLSRM.deserialize(self.b)
		elif(msgId == NotificationListMessage.getProtocolId()):
			self.notiLM = NotificationListMessage()
			self.notiLM.deserialize(self.b)
		elif(msgId == CharacterSelectedSuccessMessage.getProtocolId()):
			self.characterSSM = CharacterSelectedSuccessMessage()
			self.characterSSM.deserialize(self.b)
		elif(msgId == InventoryContentAndPresetMessage.getProtocolId()):
			self.inventoryCAPM = InventoryContentAndPresetMessage()
			self.inventoryCAPM.deserialize(self.b)

			objs = self.inventoryCAPM.objects
			for obj in objs:
				if(obj.objectGID == 10418):
					for effect in obj.effects:
						monster = self.monsters.getObj(effect.diceConst)
						if(monster._race == 78):
							printBlue("{}\n".format(self.i18n_fr.getText(monster._nameId)))
		else:
			raise UnknowMessage(msgId)
Esempio n. 3
0
	def deserialize(self, b):
		Item.deserialize(self, b)

		self.position = b.readUnsignedByte()
		self.objectGID = b.readShort()
		self.powerRate = b.readShort()
		self.overMax = b.readBoolean()

		self.effects = list()
		nbEffect = b.readUnsignedShort()
		printGreen("nbEffect: {}, position: {}, GID: {}, Rate {}, overMax: {}, ".format(nbEffect, self.position, self.objectGID, self.powerRate, self.overMax))
		for i in range(0, nbEffect):
			effectType = b.readUnsignedShort()

			effect = 0
			if(effectType == ObjectEffect.getProtocolId()):
				printRed(", Effect")
				effect = ObjectEffect()
			elif(effectType == ObjectEffectInteger.getProtocolId()):
				printRed(", EffectInt")
				effect = ObjectEffectInteger()
			elif(effectType == ObjectEffectCreature.getProtocolId()):
				printRed(", EffectCrea")
				effect = ObjectEffectCreature()
			elif(effectType == ObjectEffectDate.getProtocolId()):
				printRed(", EffectDate")
				effect = ObjectEffectDate()
			elif(effectType == ObjectEffectDice.getProtocolId()):
				printRed(", EffectDice")
				effect = ObjectEffectDice()
			elif(effectType == ObjectEffectDuration.getProtocolId()):
				printRed(", EffectDuration")
				effect = ObjectEffectDuration()
			elif(effectType == ObjectEffectString.getProtocolId()):
				printRed(", EffectStr")
				effect = ObjectEffectString()
			elif(effectType == ObjectEffectLadder.getProtocolId()):
				printRed(", EffectLadder")
				effect = ObjectEffectLadder()
			elif(effectType == ObjectEffectMinMax.getProtocolId()):
				printRed(", EffectMinMax")
				effect = ObjectEffectMinMax()
			else:
				raise UnknowEffectType(effectType)

			effect.deserialize(b)
			self.effects.append(effect)

		self.objectUID = b.readInt()
		self.quantity = b.readInt()
		printGreen("UID: {}, quantity: {}\n".format(self.objectUID, self.quantity))