public Character(InPacket packet) { GUID = packet.ReadUInt64(); Name = packet.ReadCString(); Race = (Race)packet.ReadByte(); Class = (Class)packet.ReadByte(); Gender = (Gender)packet.ReadByte(); Bytes = packet.ReadBytes(5); Level = packet.ReadByte(); ZoneId = packet.ReadUInt32(); MapId = packet.ReadUInt32(); X = packet.ReadSingle(); Y = packet.ReadSingle(); Z = packet.ReadSingle(); GuildId = packet.ReadUInt32(); Flags = packet.ReadUInt32(); packet.ReadUInt32(); // customize (rename, etc) packet.ReadByte(); // first login PetInfoId = packet.ReadUInt32(); PetLevel = packet.ReadUInt32(); PetFamilyId = packet.ReadUInt32(); // read items for (int i = 0; i < Items.Length - 1; ++i) Items[i] = new Item(packet); // read bags for (int i = 0; i < 4; ++i) { packet.ReadUInt32(); packet.ReadByte(); packet.ReadUInt32(); } }
void HandleCharEnum(InPacket packet) { byte count = packet.ReadByte(); if (count == 0) { Game.UI.LogLine("No characters found!"); } else { Character[] characters = new Character[count]; for (byte i = 0; i < count; ++i) characters[i] = new Character(packet); Game.UI.PresentCharacterList(characters); } }
void HandleServerAuthChallenge(InPacket packet) { uint one = packet.ReadUInt32(); uint seed = packet.ReadUInt32(); BigInteger seed1 = packet.ReadBytes(16).ToBigInteger(); BigInteger seed2 = packet.ReadBytes(16).ToBigInteger(); var rand = System.Security.Cryptography.RandomNumberGenerator.Create(); byte[] bytes = new byte[4]; rand.GetBytes(bytes); BigInteger ourSeed = bytes.ToBigInteger(); uint zero = 0; byte[] authResponse = HashAlgorithm.SHA1.Hash ( Encoding.ASCII.GetBytes(Game.Username.ToUpper()), BitConverter.GetBytes(zero), BitConverter.GetBytes((uint)ourSeed), BitConverter.GetBytes(seed), Game.Key.ToCleanByteArray() ); OutPacket response = new OutPacket(WorldCommand.ClientAuthSession); response.Write((uint)12340); // client build response.Write(zero); response.Write(Game.Username.ToUpper().ToCString()); response.Write(zero); response.Write((uint)ourSeed); response.Write(zero); response.Write(zero); response.Write(zero); response.Write((ulong)zero); response.Write(authResponse); response.Write(zero); // length of addon data Send(response); // TODO: don't fully initialize here, auth may fail // instead, initialize in HandleServerAuthResponse when auth succeeds // will require special logic in network code to correctly decrypt/parse packet header AuthenticationCrypto.Initialize(Game.Key.ToCleanByteArray()); }
protected void HandleNameQueryResponse(InPacket packet) { var pguid = packet.ReadPackedGuid(); var end = packet.ReadBoolean(); if (end) //! True if not found, false if found return; var name = packet.ReadCString(); if (!Game.World.PlayerNameLookup.ContainsKey(pguid)) { //! Add name definition per GUID Game.World.PlayerNameLookup.Add(pguid, name); //! See if any queued messages for this GUID are stored Queue<ChatMessage> messageQueue = null; if (Game.World.QueuedChatMessages.TryGetValue(pguid, out messageQueue)) { ChatMessage m; while (messageQueue.GetEnumerator().MoveNext()) { //! Print with proper name and remove from queue m = messageQueue.Dequeue(); m.Sender.Sender = name; Game.UI.PresentChatMessage(m); } } } /* var realmName = packet.ReadCString(); var race = (Race)packet.ReadByte(); var gender = (Gender)packet.ReadByte(); var cClass = (Class)packet.ReadByte(); var decline = packet.ReadBoolean(); if (!decline) return; for (var i = 0; i < 5; i++) var declinedName = packet.ReadCString(); */ }
void HandleServerAuthResponse(InPacket packet) { CommandDetail detail = (CommandDetail)packet.ReadByte(); uint billingTimeRemaining = packet.ReadUInt32(); byte billingFlags = packet.ReadByte(); uint billingTimeRested = packet.ReadUInt32(); byte expansion = packet.ReadByte(); if (detail == CommandDetail.AuthSuccess) { OutPacket request = new OutPacket(WorldCommand.ClientEnumerateCharacters); Send(request); } else { Game.UI.LogLine(string.Format("Authentication succeeded, but received response {0}", detail)); Game.UI.Exit(); } }
void HandleChatPlayerNotFound(InPacket packet) { Game.UI.LogLine(String.Format("Player {0} not found!", packet.ReadCString())); }
public void HandleMonsterMovementPacket(InPacket packet) { ResetData(); updateType = ObjectUpdateType.UPDATETYPE_MOVEMENT; guid = packet.ReadPackedGuid(); byte unk = packet.ReadByte(); WorldObject worldObject = game.Objects[guid]; worldObject.Set(packet.ReadVector3()); }
public void HandleUpdatePacket(InPacket packet) { blockCount = packet.ReadUInt32(); for (int blockIndex = 0; blockIndex < blockCount; blockIndex++) { ResetData(); updateType = (ObjectUpdateType)packet.ReadByte(); switch (updateType) { case ObjectUpdateType.UPDATETYPE_VALUES: guid = packet.ReadPackedGuid(); ReadValuesUpdateData(packet); break; case ObjectUpdateType.UPDATETYPE_MOVEMENT: guid = packet.ReadPackedGuid(); ReadMovementUpdateData(packet); break; case ObjectUpdateType.UPDATETYPE_CREATE_OBJECT: case ObjectUpdateType.UPDATETYPE_CREATE_OBJECT2: guid = packet.ReadPackedGuid(); objectType = (TypeID)packet.ReadByte(); ReadMovementUpdateData(packet); ReadValuesUpdateData(packet); break; case ObjectUpdateType.UPDATETYPE_OUT_OF_RANGE_OBJECTS: var guidCount = packet.ReadUInt32(); for (var guidIndex = 0; guidIndex < guidCount; guidIndex++) outOfRangeGuids.Add(packet.ReadPackedGuid()); break; case ObjectUpdateType.UPDATETYPE_NEAR_OBJECTS: break; } HandleUpdateData(); } }
protected void HandleCompressedUpdateObject(InPacket packet) { updateObjectHandler.HandleUpdatePacket(packet.Inflate()); }
protected void HandleLogoutComplete(InPacket packet) { Connected = false; LoggedIn = false; Running = false; loggedOutEvent.SetResult(true); }
protected void HandleCharCreate(InPacket packet) { var response = (CommandDetail)packet.ReadByte(); if (response == CommandDetail.CHAR_CREATE_SUCCESS) SendPacket(new OutPacket(WorldCommand.CMSG_CHAR_ENUM)); else NoCharactersFound(); }
protected void HandleTransferPending(InPacket packet) { Player.ResetPosition(); var newMap = packet.ReadUInt32(); }
protected void HandleLoginVerifyWorld(InPacket packet) { Player.MapID = (int)packet.ReadUInt32(); Player.X = packet.ReadSingle(); Player.Y = packet.ReadSingle(); Player.Z = packet.ReadSingle(); Player.O = packet.ReadSingle(); }
protected void HandleTradeStatus(InPacket packet) { if (Behavior.Begger) { TradeStatus status = (TradeStatus)packet.ReadUInt32(); switch (status) { case TradeStatus.BeginTrade: TraderGUID = packet.ReadUInt64(); // Stop moving CancelActionsByFlag(ActionFlag.Movement); // Accept trade OutPacket beginTrade = new OutPacket(WorldCommand.CMSG_BEGIN_TRADE); SendPacket(beginTrade); break; case TradeStatus.Canceled: EnableActionsByFlag(ActionFlag.Movement); TraderGUID = 0; break; case TradeStatus.Accept: OutPacket acceptTrade = new OutPacket(WorldCommand.CMSG_ACCEPT_TRADE); SendPacket(acceptTrade); break; case TradeStatus.Tradecomplete: DoSayChat("Thank you!"); EnableActionsByFlag(ActionFlag.Movement); HandleTriggerInput(TriggerActionType.TradeCompleted, TraderGUID); TraderGUID = 0; break; } } }
private void QueuePacket(InPacket packet) { packetsQueue.Enqueue(packet); }
protected void HandleMessageChat(InPacket packet) { var type = (ChatMessageType)packet.ReadByte(); var lang = (Language)packet.ReadInt32(); var guid = packet.ReadUInt64(); var unkInt = packet.ReadInt32(); switch (type) { case ChatMessageType.Say: case ChatMessageType.Yell: case ChatMessageType.Party: case ChatMessageType.PartyLeader: case ChatMessageType.Raid: case ChatMessageType.RaidLeader: case ChatMessageType.RaidWarning: case ChatMessageType.Guild: case ChatMessageType.Officer: case ChatMessageType.Emote: case ChatMessageType.TextEmote: case ChatMessageType.Whisper: case ChatMessageType.WhisperInform: case ChatMessageType.System: case ChatMessageType.Channel: case ChatMessageType.Battleground: case ChatMessageType.BattlegroundNeutral: case ChatMessageType.BattlegroundAlliance: case ChatMessageType.BattlegroundHorde: case ChatMessageType.BattlegroundLeader: case ChatMessageType.Achievement: case ChatMessageType.GuildAchievement: { ChatChannel channel = new ChatChannel(); channel.Type = type; if (type == ChatMessageType.Channel) { channel.ChannelName = packet.ReadCString(); } var sender = packet.ReadUInt64(); ChatMessage message = new ChatMessage(); var textLen = packet.ReadInt32(); message.Message = packet.ReadCString(); message.Language = lang; message.ChatTag = (ChatTag)packet.ReadByte(); message.Sender = channel; //! If we know the name of the sender GUID, use it //! For system messages sender GUID is 0, don't need to do anything fancy string senderName = null; if (type == ChatMessageType.System || Game.World.PlayerNameLookup.TryGetValue(sender, out senderName)) { message.Sender.Sender = senderName; Game.UI.PresentChatMessage(message); return; } //! If not we place the message in the queue, //! .. either existent Queue <ChatMessage> messageQueue = null; if (Game.World.QueuedChatMessages.TryGetValue(sender, out messageQueue)) { messageQueue.Enqueue(message); } //! or non existent else { messageQueue = new Queue <ChatMessage>(); messageQueue.Enqueue(message); Game.World.QueuedChatMessages.Add(sender, messageQueue); } //! Furthermore we send CMSG_NAME_QUERY to the server to retrieve the name of the sender OutPacket response = new OutPacket(NetworkOperationCode.CMSG_NAME_QUERY); response.Write(sender); Game.SendPacket(response); //! Enqueued chat will be printed when we receive SMSG_NAME_QUERY_RESPONSE break; } default: return; } }
protected void HandleChatPlayerNotFound(InPacket packet) { Game.UI.LogLine(String.Format("Player {0} not found!", packet.ReadCString())); }
protected void HandleNewWorld(InPacket packet) { Player.MapID = (int)packet.ReadUInt32(); Player.X = packet.ReadSingle(); Player.Y = packet.ReadSingle(); Player.Z = packet.ReadSingle(); Player.O = packet.ReadSingle(); OutPacket result = new OutPacket(WorldCommand.MSG_MOVE_WORLDPORT_ACK); SendPacket(result); }
void ReadMovementInfo(InPacket packet) { movementInfo = new MovementInfo(packet); }
protected void HandleMoveTeleportAck(InPacket packet) { var packGuid = packet.ReadPackedGuid(); packet.ReadUInt32(); var movementFlags = packet.ReadUInt32(); var extraMovementFlags = packet.ReadUInt16(); var time = packet.ReadUInt32(); Player.X = packet.ReadSingle(); Player.Y = packet.ReadSingle(); Player.Z = packet.ReadSingle(); Player.O = packet.ReadSingle(); CancelActionsByFlag(ActionFlag.Movement); OutPacket result = new OutPacket(WorldCommand.MSG_MOVE_TELEPORT_ACK); result.WritePacketGuid(Player.GUID); result.Write((UInt32)0); result.Write(time); SendPacket(result); }
private void ReadValuesUpdateData(InPacket packet) { byte blockCount = packet.ReadByte(); int[] updateMask = new int[blockCount]; for (var i = 0; i < blockCount; i++) updateMask[i] = packet.ReadInt32(); var mask = new BitArray(updateMask); for (var i = 0; i < mask.Count; ++i) { if (!mask[i]) continue; updateFields[i] = packet.ReadUInt32(); } }
protected void HandleLogoutResponse(InPacket packet) { bool logoutOk = packet.ReadUInt32() == 0; bool instant = packet.ReadByte() != 0; if(instant || !logoutOk) { Connected = false; LoggedIn = false; Running = false; } }
protected void HandleDestroyObject(InPacket packet) { ulong guid = packet.ReadUInt64(); WorldObject worldObject; if (Objects.TryGetValue(guid, out worldObject)) { worldObject.ResetPosition(); Objects.Remove(guid); } }
protected void HandleUpdateObject(InPacket packet) { updateObjectHandler.HandleUpdatePacket(packet); }
protected void HandleAllAchievementData(InPacket packet) { CompletedAchievements.Clear(); AchievementCriterias.Clear(); for (;;) { uint achievementId = packet.ReadUInt32(); if (achievementId == 0xFFFFFFFF) break; packet.ReadPackedTime(); CompletedAchievements.Add(achievementId); } for (;;) { uint criteriaId = packet.ReadUInt32(); if (criteriaId == 0xFFFFFFFF) break; ulong criteriaCounter = packet.ReadPackedGuid(); packet.ReadPackedGuid(); packet.ReadInt32(); packet.ReadPackedTime(); packet.ReadInt32(); packet.ReadInt32(); AchievementCriterias[criteriaId] = criteriaCounter; } }
protected void HandleMove(InPacket packet) { updateObjectHandler.HandleMovementPacket(packet); }
protected void HandleCriteriaUpdate(InPacket packet) { uint criteriaId = packet.ReadUInt32(); ulong criteriaCounter = packet.ReadPackedGuid(); AchievementCriterias[criteriaId] = criteriaCounter; }
public void HandleMovementPacket(InPacket packet) { ResetData(); updateType = ObjectUpdateType.UPDATETYPE_MOVEMENT; guid = packet.ReadPackedGuid(); ReadMovementInfo(packet); HandleUpdateData(); }
protected void HandlePartyList(InPacket packet) { GroupType groupType = (GroupType)packet.ReadByte(); packet.ReadByte(); packet.ReadByte(); packet.ReadByte(); if (groupType.HasFlag(GroupType.GROUPTYPE_LFG)) { packet.ReadByte(); packet.ReadUInt32(); } packet.ReadUInt64(); packet.ReadUInt32(); uint membersCount = packet.ReadUInt32(); GroupMembersGuids.Clear(); for (uint index = 0; index < membersCount; index++) { packet.ReadCString(); UInt64 memberGuid = packet.ReadUInt64(); GroupMembersGuids.Add(memberGuid); packet.ReadByte(); packet.ReadByte(); packet.ReadByte(); packet.ReadByte(); } GroupLeaderGuid = packet.ReadUInt64(); }
void ReadMovementUpdateData(InPacket packet) { flags = (ObjectUpdateFlags)packet.ReadUInt16(); if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_LIVING)) { ReadMovementInfo(packet); movementSpeeds = new Dictionary<UnitMoveType,float>(); movementSpeeds[UnitMoveType.MOVE_WALK] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_RUN] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_RUN_BACK] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_SWIM] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_SWIM_BACK] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_FLIGHT] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_FLIGHT_BACK] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_TURN_RATE] = packet.ReadSingle(); movementSpeeds[UnitMoveType.MOVE_PITCH_RATE] = packet.ReadSingle(); if (movementInfo.Flags.HasFlag(MovementFlags.MOVEMENTFLAG_SPLINE_ENABLED)) { splineFlags = (SplineFlags)packet.ReadUInt32(); if (splineFlags.HasFlag(SplineFlags.Final_Angle)) splineFacingAngle = packet.ReadSingle(); else if (splineFlags.HasFlag(SplineFlags.Final_Target)) splineFacingTargetGuid = packet.ReadUInt64(); else if (splineFlags.HasFlag(SplineFlags.Final_Point)) splineFacingPointX = packet.ReadVector3(); splineTimePassed = packet.ReadInt32(); splineDuration = packet.ReadInt32(); splineId = packet.ReadUInt32(); packet.ReadSingle(); packet.ReadSingle(); splineVerticalAcceleration = packet.ReadSingle(); splineEffectStartTime = packet.ReadInt32(); uint splineCount = packet.ReadUInt32(); for (uint index = 0; index < splineCount; index++) splinePoints.Add(packet.ReadVector3()); splineEvaluationMode = (SplineEvaluationMode)packet.ReadByte(); splineEndPoint = packet.ReadVector3(); } } else if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_POSITION)) { transportGuid = packet.ReadPackedGuid(); position = packet.ReadVector3(); transportOffset = packet.ReadVector3(); o = packet.ReadSingle(); corpseOrientation = packet.ReadSingle(); } else if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_STATIONARY_POSITION)) { position = packet.ReadVector3(); o = packet.ReadSingle(); } if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_UNKNOWN)) packet.ReadUInt32(); if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_LOWGUID)) lowGuid = packet.ReadUInt32(); if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_HAS_TARGET)) targetGuid = packet.ReadPackedGuid(); if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_TRANSPORT)) transportTimer = packet.ReadUInt32(); if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_VEHICLE)) { vehicledID = packet.ReadUInt32(); vehicleOrientation = packet.ReadSingle(); } if (flags.HasFlag(ObjectUpdateFlags.UPDATEFLAG_ROTATION)) goRotation = packet.ReadInt64(); }
protected void HandlePartyDisband(InPacket packet) { GroupLeaderGuid = 0; GroupMembersGuids.Clear(); }
void HandleMessageChat(InPacket packet) { var type = (ChatMessageType)packet.ReadByte(); var lang = (Language)packet.ReadInt32(); var guid = packet.ReadUInt64(); var unkInt = packet.ReadInt32(); switch (type) { case ChatMessageType.Say: case ChatMessageType.Yell: case ChatMessageType.Party: case ChatMessageType.PartyLeader: case ChatMessageType.Raid: case ChatMessageType.RaidLeader: case ChatMessageType.RaidWarning: case ChatMessageType.Guild: case ChatMessageType.Officer: case ChatMessageType.Emote: case ChatMessageType.TextEmote: case ChatMessageType.Whisper: case ChatMessageType.WhisperInform: case ChatMessageType.System: case ChatMessageType.Channel: case ChatMessageType.Battleground: case ChatMessageType.BattlegroundNeutral: case ChatMessageType.BattlegroundAlliance: case ChatMessageType.BattlegroundHorde: case ChatMessageType.BattlegroundLeader: case ChatMessageType.Achievement: case ChatMessageType.GuildAchievement: { ChatChannel channel = new ChatChannel(); channel.Type = type; if (type == ChatMessageType.Channel) channel.ChannelName = packet.ReadCString(); var sender = packet.ReadUInt64(); ChatMessage message = new ChatMessage(); var textLen = packet.ReadInt32(); message.Message = packet.ReadCString(); message.Language = lang; message.ChatTag = (ChatTag)packet.ReadByte(); message.Sender = channel; //! If we know the name of the sender GUID, use it //! For system messages sender GUID is 0, don't need to do anything fancy string senderName = null; if (type == ChatMessageType.System || Game.World.PlayerNameLookup.TryGetValue(sender, out senderName)) { message.Sender.Sender = senderName; Game.UI.PresentChatMessage(message); return; } //! If not we place the message in the queue, //! .. either existent Queue<ChatMessage> messageQueue = null; if (Game.World.QueuedChatMessages.TryGetValue(sender, out messageQueue)) messageQueue.Enqueue(message); //! or non existent else { messageQueue = new Queue<ChatMessage>(); messageQueue.Enqueue(message); Game.World.QueuedChatMessages.Add(sender, messageQueue); } //! Furthermore we send CMSG_NAME_QUERY to the server to retrieve the name of the sender OutPacket response = new OutPacket(WorldCommand.CMSG_NAME_QUERY); response.Write(sender); Game.SendPacket(response); //! Enqueued chat will be printed when we receive SMSG_NAME_QUERY_RESPONSE break; } default: return; } }
public MovementInfo(InPacket packet) { Flags = (MovementFlags)packet.ReadUInt32(); Flags2 = (MovementFlags2)packet.ReadUInt16(); Time = packet.ReadUInt32(); Position = packet.ReadVector3(); O = packet.ReadSingle(); if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_ONTRANSPORT)) { TransportGuid = packet.ReadPackedGuid(); TransportPosition = packet.ReadVector3(); TransportO = packet.ReadSingle(); TransportTime = packet.ReadUInt32(); TransportSeat = packet.ReadByte(); if (Flags2.HasFlag(MovementFlags2.MOVEMENTFLAG2_INTERPOLATED_MOVEMENT)) TransportTime2 = packet.ReadUInt32(); } if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_SWIMMING) || Flags.HasFlag(MovementFlags.MOVEMENTFLAG_FLYING) || Flags2.HasFlag(MovementFlags2.MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING)) Pitch = packet.ReadSingle(); FallTime = packet.ReadUInt32(); if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_FALLING)) { JumpZSpeed = packet.ReadSingle(); JumpSinAngle = packet.ReadSingle(); JumpCosAngle = packet.ReadSingle(); JumpXYSpeed = packet.ReadSingle(); } if (Flags.HasFlag(MovementFlags.MOVEMENTFLAG_SPLINE_ELEVATION)) SplineElevation = packet.ReadSingle(); }