private Thing internalGetThing(NetworkMessage incMsg, NetworkMessage outMsg) { //get thing type ushort thingId = incMsg.GetUInt16(); outMsg.AddUInt16(thingId); if (thingId == 0x0061 || thingId == 0x0062) { //creatures Creature creature = null; if (thingId == 0x0062) { //creature is known uint creatureID = incMsg.GetUInt32(); outMsg.AddUInt32(creatureID); creature = Creatures.GetInstance().GetCreature(creatureID); } else if (thingId == 0x0061) { //creature is not known //perhaps we have to remove a known creature uint removeID = incMsg.GetUInt32(); outMsg.AddUInt32(removeID); Creatures.GetInstance().RemoveCreature(removeID); //add a new creature uint creatureID = incMsg.GetUInt32(); outMsg.AddUInt32(creatureID); creature = Creatures.GetInstance().AddCreature(creatureID); if (creature == null) return null; creature.SetName(incMsg.GetString()); outMsg.AddString(creature.GetName()); } if (creature == null) return null; //read creature properties creature.SetHealth(incMsg.GetByte()); outMsg.AddByte(creature.GetHealth()); if (creature.GetHealth() > 100) return null; byte direction = incMsg.GetByte(); outMsg.AddByte(direction); if (direction > 3) return null; creature.SetTurnDirection((Direction)direction); creature.SetOutfit(incMsg.GetOutfit()); outMsg.AddOutfit(creature.GetOutfit()); //check if we can read 6 bytes if (!incMsg.CanRead(6)) return null; creature.SetLightLevel(incMsg.GetByte()); outMsg.AddByte(creature.GetLightLevel()); creature.SetLightColor(incMsg.GetByte()); outMsg.AddByte(creature.GetLightColor()); creature.SetSpeed(incMsg.GetUInt16()); outMsg.AddUInt16(creature.GetSpeed()); creature.SetSkull(incMsg.GetByte()); outMsg.AddByte(creature.GetSkull()); creature.SetShield(incMsg.GetByte()); outMsg.AddByte(creature.GetShield()); if (thingId == 0x0061) { // emblem is sent only in packet type 0x61 creature.SetEmblem(incMsg.GetByte()); outMsg.AddByte(creature.GetEmblem()); } byte impassable = incMsg.GetByte(); creature.SetImpassable(impassable == 0x01); outMsg.AddByte(impassable); return creature; } else if (thingId == 0x0063) { //creature turn uint creatureID = incMsg.GetUInt32(); outMsg.AddUInt32(creatureID); Creature creature = Creatures.GetInstance().GetCreature(creatureID); if (creature == null) return null; //check if we can read 1 byte byte direction = incMsg.GetByte(); outMsg.AddByte(direction); if (direction > 3) return null; creature.SetTurnDirection((Direction)direction); return creature; } else { //item return internalGetItem(incMsg, outMsg, thingId); } }
private bool parseCreatureOutfit(NetworkMessage incMsg, NetworkMessage outMsg) { uint creatureId = incMsg.GetUInt32(); outMsg.AddUInt32(creatureId); Creature creature = Creatures.GetInstance().GetCreature(creatureId); if (creature != null) { creature.SetOutfit(incMsg.GetOutfit()); outMsg.AddOutfit(creature.GetOutfit()); } else { outMsg.AddOutfit(incMsg.GetOutfit()); } return true; }
private bool parseOutfitWindow(NetworkMessage incMsg, NetworkMessage outMsg) { Outfit outfit = incMsg.GetOutfit(); outMsg.AddOutfit(outfit); byte nOutfits = incMsg.GetByte(); if (nOutfits == 0 || nOutfits > 25) { Logger.Log("Outfit window - n = 0 || n > 25", LogType.ERROR); return false; } for (uint i = 0; i < nOutfits; ++i) { ushort outfitID = incMsg.GetUInt16(); outMsg.AddUInt16(outfitID); if (Objects.GetInstance().GetOutfitType(outfitID) == null) { Logger.Log("Outfit window - outfit list error", LogType.ERROR); return false; } String name = incMsg.GetString(); outMsg.AddString(name); byte addons = incMsg.GetByte(); outMsg.AddByte(addons); } return true; }