Exemple #1
0
        public void DoOfficerChat()
        {
            Log("Officer Message: ");
            var message = Game.UI.ReadLine();

            var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

            response.Write((uint)ChatMessageType.Officer);
            var race = Game.World.SelectedCharacter.Race;
            var language = race.IsHorde() ? Language.Orcish : Language.Common;
            response.Write((uint)language);
            response.Write(message.ToCString());
            Game.SendPacket(response);
        }
Exemple #2
0
        protected 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());
        }
Exemple #3
0
        public void DoWhisperReply()
        {
            if (Game.World.LastWhisperers.Count == 0)
                return;

            var target = Game.World.LastWhisperers.Peek();
            LogLine("Hit <TAB> to cycle trough last whisperers, hit <ENTER> to select current recipient, hit <ESCAPE> to return.", LogLevel.Detail);
            LogLine(String.Format("To: {0}", target));
            while (true)
            {
                ConsoleKeyInfo key = Game.UI.ReadKey();
                switch (key.Key)
                {
                    case ConsoleKey.Enter:
                        goto cont;
                    case ConsoleKey.Tab:
                        //! To do: maybe a more efficient way for this:
                        var previous = Game.World.LastWhisperers.Dequeue();
                        Game.World.LastWhisperers.Enqueue(previous);
                        target = Game.World.LastWhisperers.Peek();
                        if (target != previous)
                            LogLine(String.Format("To: {0}", target));
                        continue;
                    case ConsoleKey.Escape:
                        return;
                    default:
                        continue;
                }
            }

            cont:
            Log("Message: ");
            var message = Game.UI.ReadLine();

            var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

            response.Write((uint)ChatMessageType.Whisper);
            var race = Game.World.SelectedCharacter.Race;
            var language = race.IsHorde() ? Language.Orcish : Language.Common;
            response.Write((uint)language);
            response.Write(target.ToCString());
            response.Write(message.ToCString());
            Game.SendPacket(response);

            //! Print on WhisperInform message
        }
        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());
        }
Exemple #5
0
        public void Send(OutPacket packet)
        {
            LastOutOpcode = packet.Header.Command;
            byte[] data = packet.Finalize(authenticationCrypto);

            try
            {
                connection.Client.Send(data, 0, data.Length, SocketFlags.None);
            }
            catch (ObjectDisposedException ex)
            {
            }
            catch (EndOfStreamException ex)
            {
            }

            Interlocked.Add(ref transferred, data.Length);
            Interlocked.Add(ref sent, data.Length);
        }
Exemple #6
0
        protected 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.AUTH_OK)
            {
                OutPacket request = new OutPacket(WorldCommand.CMSG_CHAR_ENUM);
                Send(request);
            }
            else
            {
                Game.UI.LogLine(string.Format("Authentication succeeded, but received response {0}", detail));
                Game.UI.Exit();
            }
        }
Exemple #7
0
        protected 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.CMSG_CHAR_ENUM);
                Send(request);
            }
            else
            {
                Game.UI.LogLine(string.Format("Authentication succeeded, but received response {0}", detail));
                Game.UI.Exit();
            }
        }
Exemple #8
0
        protected 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.AUTH_OK)
            {
                OutPacket request = new OutPacket(WorldCommand.CMSG_CHAR_ENUM);
                Send(request);
                AuthFrame.ShowCharacterUI = true;
                Exchange.AuthMessage      = "Retrieving character list...";
            }
            else
            {
                Exchange.AuthMessage = "Authentication succeeded, but received response " + detail;
            }
        }
Exemple #9
0
        public void Send(OutPacket packet)
        {
            lastOutPacket = packet;
            byte[] data = packet.Finalize(authenticationCrypto);

            try
            {
                connection.Client.BeginSend(data, 0, data.Length, SocketFlags.None, null, null);
            }
            catch (ObjectDisposedException ex)
            {
                Game.UI.LogException(ex);
            }
            catch (EndOfStreamException ex)
            {
                Game.UI.LogException(ex);
            }

            Interlocked.Add(ref transferred, data.Length);
            Interlocked.Add(ref sent, data.Length);
        }
Exemple #10
0
        public void DoWhisper()
        {
            LogLine("Enter name of player to whisper, or enter 'Q' to go back.", LogLevel.Detail);
            Log("To: ");
            var target = Game.UI.ReadLine();
            if (target == "Q")
                return;

            Log("Message: ");
            var message = Game.UI.ReadLine();

            var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

            response.Write((uint)ChatMessageType.Whisper);
            var race = Game.World.SelectedCharacter.Race;
            var language = race.IsHorde() ? Language.Orcish : Language.Common;
            response.Write((uint)language);
            response.Write(target.ToCString());
            response.Write(message.ToCString());
            Game.SendPacket(response);

            //! Print on WhisperInform message
        }
Exemple #11
0
        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.Log(string.Format("Authentication succeeded, but received response {0}", detail));
                Game.UI.Exit();
            }
        }
Exemple #12
0
 public ClientHeader(WorldCommand command, OutPacket packet)
 {
     this.Command = command;
     Packet = packet;
 }
Exemple #13
0
        protected void HandleMessageChat(InPacket packet)
        {
            var    chatType   = (ChatMessageType)packet.ReadByte();
            var    language   = (Language)packet.ReadInt32();
            UInt64 senderGuid = packet.ReadUInt64();
            var    unkInt     = packet.ReadUInt32();

            UInt32 senderNameLen   = 0;
            string senderName      = null;
            UInt64 receiverGuid    = 0;
            UInt32 receiverNameLen = 0;
            string receiverName    = null;
            string channelName     = null;

            switch (chatType)
            {
            case ChatMessageType.MonsterSay:
            case ChatMessageType.MonsterParty:
            case ChatMessageType.MonsterYell:
            case ChatMessageType.MonsterWhisper:
            case ChatMessageType.MonsterEmote:
            case ChatMessageType.RaidBossEmote:
            case ChatMessageType.RaidBossWhisper:
            case ChatMessageType.BattleNet:
                senderNameLen = packet.ReadUInt32();
                senderName    = packet.ReadCString();
                receiverGuid  = packet.ReadUInt64();
                if (receiverGuid != 0 && !receiverGuid.IsPlayer() && !receiverGuid.IsPet())
                {
                    receiverNameLen = packet.ReadUInt32();
                    receiverName    = packet.ReadCString();
                }
                break;

            case ChatMessageType.WhisperForeign:
                senderNameLen = packet.ReadUInt32();
                senderName    = packet.ReadCString();
                receiverGuid  = packet.ReadUInt64();
                break;

            case ChatMessageType.BattlegroundNeutral:
            case ChatMessageType.BattlegroundAlliance:
            case ChatMessageType.BattlegroundHorde:
                receiverGuid = packet.ReadUInt64();
                if (receiverGuid != 0 && !receiverGuid.IsPlayer())
                {
                    receiverNameLen = packet.ReadUInt32();
                    receiverName    = packet.ReadCString();
                }
                break;

            case ChatMessageType.Achievement:
            case ChatMessageType.GuildAchievement:
                receiverGuid = packet.ReadUInt64();
                break;

            default:
                if (packet.Header.Command == WorldCommand.SMSG_GM_MESSAGECHAT)
                {
                    senderNameLen = packet.ReadUInt32();
                    senderName    = packet.ReadCString();
                }

                if (chatType == ChatMessageType.Channel)
                {
                    channelName = packet.ReadCString();
                }

                receiverGuid = packet.ReadUInt64();
                break;
            }

            UInt32 messageLen = packet.ReadUInt32();
            string message    = packet.ReadCString();
            var    chatTag    = (ChatTag)packet.ReadByte();

            if (chatType == ChatMessageType.Achievement || chatType == ChatMessageType.GuildAchievement)
            {
                var achievementId = packet.ReadUInt32();
            }

            ChatChannel channel = new ChatChannel();

            channel.Type = chatType;

            if (chatType == ChatMessageType.Channel)
            {
                channel.ChannelName = channelName;
            }

            ChatMessage chatMessage = new ChatMessage();

            chatMessage.Message  = message;
            chatMessage.Language = language;
            chatMessage.ChatTag  = chatTag;
            chatMessage.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
            if (senderGuid == 0 || !string.IsNullOrEmpty(senderName) ||
                Game.World.PlayerNameLookup.TryGetValue(senderGuid, out senderName))
            {
                chatMessage.Sender.Sender = senderName;
                Game.UI.PresentChatMessage(chatMessage);
                return;
            }

            //! If not we place the message in the queue,
            //! .. either existent
            Queue <ChatMessage> messageQueue = null;

            if (Game.World.QueuedChatMessages.TryGetValue(senderGuid, out messageQueue))
            {
                messageQueue.Enqueue(chatMessage);
            }
            //! or non existent
            else
            {
                messageQueue = new Queue <ChatMessage>();
                messageQueue.Enqueue(chatMessage);
                Game.World.QueuedChatMessages.Add(senderGuid, 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(senderGuid);
            Game.SendPacket(response);

            //! Enqueued chat will be printed when we receive SMSG_NAME_QUERY_RESPONSE
        }
Exemple #14
0
 public ClientHeader(NetworkOperationCode command, OutPacket packet)
 {
     this.Command = command;
     Packet       = packet;
 }
Exemple #15
0
        public void Update()
        {
            if (Game.World.SelectedCharacter == null)
                return;

            TimeSpan diff = DateTime.UtcNow - _lastKeepAliveTime;
            if (diff.TotalSeconds > 10)
            {
                _lastKeepAliveTime = DateTime.UtcNow;
                OutPacket response = new OutPacket(WorldCommand.CMSG_NAME_QUERY);
                response.Write(Game.World.SelectedCharacter.GUID);
                Game.SendPacket(response);
            }
        }
Exemple #16
0
 public void SendPacket(OutPacket packet)
 {
     if (socket is WorldSocket)
     {
         ((WorldSocket)socket).Send(packet);
         HandleTriggerInput(TriggerActionType.Opcode, packet);
     }
 }
Exemple #17
0
        public void Send(OutPacket packet)
        {
            LastOutOpcode = packet.Header.Command;
            byte[] data = packet.Finalize(authenticationCrypto);

            try
            {
                connection.Client.Send(data, 0, data.Length, SocketFlags.None);
            }
            catch(ObjectDisposedException ex)
            {
                Game.UI.LogException(ex);
            }
            catch(EndOfStreamException ex)
            {
                Game.UI.LogException(ex);
            }

            Interlocked.Add(ref transferred, data.Length);
            Interlocked.Add(ref sent, data.Length);
        }
Exemple #18
0
        public void PresentCharacterList(Character[] characterList)
        {
            LogLine("\n\tName\tLevel Class Race");

            int index = 0;
            foreach (Character character in characterList)
                LogLine
                (
                    string.Format("{4}\t{0}\t{1} {2} {3}",
                    character.Name,
                    character.Level,
                    character.Race,
                    character.Class,
                    index++)
                );

            if (characterList.Length < 10)
                LogLine(string.Format("{0}\tCreate a new character. (NOT YET IMPLEMENTED)", index));

            int length = characterList.Length == 10 ? 10 : (characterList.Length + 1);
            index = -1;
            while (index > length || index < 0)
            {
                Log("Choose a character:  ");
                if (!int.TryParse(Console.ReadLine(), out index))
                    LogLine();
            }

            if (index < characterList.Length)
            {
                Game.World.SelectedCharacter = characterList[index];
                // TODO: enter world

                LogLine(string.Format("Entering pseudo-world with character {0}", Game.World.SelectedCharacter.Name));

                OutPacket packet = new OutPacket(WorldCommand.CMSG_PLAYER_LOGIN);
                packet.Write(Game.World.SelectedCharacter.GUID);
                Game.SendPacket(packet);
            }
            else
            {
                // TODO: character creation
            }
        }
Exemple #19
0
 public ClientHeader(WorldCommand command, OutPacket packet)
 {
     this.Command = command;
     Packet       = packet;
 }
Exemple #20
0
        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;
            }
        }
Exemple #21
0
 void HandleWardenDataResponse(InPacket packet)
 {
     // flawed out packet, needs to be filled with sha1 checksum and warden data
     OutPacket response = new OutPacket(WorldCommand.CMSG_WARDEN_DATA);
     Game.SendPacket(response);
 }
        public void Send(OutPacket packet)
        {
            byte[] data = packet.Finalize();

            // TODO: switch to asynchronous send
            lock (SendLock)
                connection.Client.Send(data);

            Interlocked.Add(ref transferred, data.Length);
            Interlocked.Add(ref sent, data.Length);

            //Game.UI.LogLine(string.Format("Sent packet {0}", packet.Header.Command));
        }
Exemple #23
0
            private void HandleUpdateData()
            {
                if (guid == game.Player.GUID)
                {
                    foreach (var pair in updateFields)
                        game.Player[pair.Key] = pair.Value;
                }
                else
                {
                    switch (updateType)
                    {
                        case ObjectUpdateType.UPDATETYPE_VALUES:
                            {
                                WorldObject worldObject = game.Objects[guid];
                                foreach (var pair in updateFields)
                                    worldObject[pair.Key] = pair.Value;
                                break;
                            }
                        case ObjectUpdateType.UPDATETYPE_MOVEMENT:
                            {
                                if (movementInfo != null)
                                {
                                    WorldObject worldObject = game.Objects[guid];
                                    worldObject.Set(movementInfo.Position);
                                    worldObject.O = movementInfo.O;
                                }
                                break;
                            }
                        case ObjectUpdateType.UPDATETYPE_CREATE_OBJECT:
                        case ObjectUpdateType.UPDATETYPE_CREATE_OBJECT2:
                            {
                                WorldObject worldObject = new WorldObject();
                                worldObject.GUID = guid;
                                if (movementInfo != null)
                                {
                                    worldObject.Set(movementInfo.Position);
                                    worldObject.O = movementInfo.O;
                                }
                                worldObject.MapID = game.Player.MapID;
                                foreach (var pair in updateFields)
                                    worldObject[pair.Key] = pair.Value;

#if DEBUG
                                if (game.Objects.ContainsKey(guid))
                                    game.Log($"{updateType} called with guid 0x{guid:X} already added", LogLevel.Error);
#endif
                                game.Objects[guid] = worldObject;

                                if (worldObject.IsType(HighGuid.Player))
                                {
                                    OutPacket nameQuery = new OutPacket(WorldCommand.CMSG_NAME_QUERY);
                                    nameQuery.Write(guid);
                                    game.SendPacket(nameQuery);
                                }
                                break;
                            }
                        default:
                            break;
                    }
                }

                foreach (var outOfRangeGuid in outOfRangeGuids)
                {
                    WorldObject worldObject;
                    if (game.Objects.TryGetValue(outOfRangeGuid, out worldObject))
                    {
                        worldObject.ResetPosition();
                        game.Objects.Remove(outOfRangeGuid);
                    }
                }
            }
Exemple #24
0
        public void CreateCharacter(Race race, Class classWow)
        {
            Log("Creating new character");
            OutPacket createCharacterPacket = new OutPacket(WorldCommand.CMSG_CHAR_CREATE);
            StringBuilder charName = new StringBuilder("Bot");
            foreach (char c in Username.Substring(3).Take(9))
	        {
                charName.Append((char)(97 + int.Parse(c.ToString())));
	        }

            // Ensure Name rules are applied
            char previousChar = '\0';
            for (int i = 0; i < charName.Length; i++ )
            {
                if (charName[i] == previousChar)
                    charName[i]++;
                previousChar = charName[i];
            }

            createCharacterPacket.Write(charName.ToString().ToCString());
            createCharacterPacket.Write((byte)race);
            createCharacterPacket.Write((byte)classWow);
            createCharacterPacket.Write((byte)Gender.Male);
            byte skin = 6; createCharacterPacket.Write(skin);
            byte face = 5; createCharacterPacket.Write(face);
            byte hairStyle = 0; createCharacterPacket.Write(hairStyle);
            byte hairColor = 1; createCharacterPacket.Write(hairColor);
            byte facialHair = 5; createCharacterPacket.Write(facialHair);
            byte outfitId = 0; createCharacterPacket.Write(outfitId);

            SendPacket(createCharacterPacket);
        }
Exemple #25
0
        public void UpdateCommands()
        {
            if (Game.World.SelectedCharacter == null)
                return;

            string s = Console.ReadLine();
            if (String.IsNullOrEmpty(s))
                return;

            string message = s;
            if (s.StartsWith("/")) // client command
            {
                int idx = s.IndexOf(" "); // first space, get the end of the '/' command
                if (idx != -1)
                {
                    _chatHeader = s.Substring(0, idx);
                    message = s.Substring(idx + 1); // after the space
                }
            }

            if (_chatHeader.StartsWith("/s")) // "/say"
            {
                var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

                response.Write((uint)ChatMessageType.Say);
                var race = Game.World.SelectedCharacter.Race;
                var language = race.IsHorde() ? Language.Orcish : Language.Common;
                response.Write((uint)language);
                response.Write(message.ToCString());
                Game.SendPacket(response);
            }
            else if (_chatHeader.StartsWith("/y")) // "/yell"
            {
                var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

                response.Write((uint)ChatMessageType.Yell);
                var race = Game.World.SelectedCharacter.Race;
                var language = race.IsHorde() ? Language.Orcish : Language.Common;
                response.Write((uint)language);
                response.Write(message.ToCString());
                Game.SendPacket(response);
            }
            else if (_chatHeader.StartsWith("/g")) // "/guild"
            {
                var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

                response.Write((uint)ChatMessageType.Guild);
                var race = Game.World.SelectedCharacter.Race;
                var language = race.IsHorde() ? Language.Orcish : Language.Common;
                response.Write((uint)language);
                response.Write(message.ToCString());
                Game.SendPacket(response);
            }
            else if (_chatHeader.StartsWith("/w")) // "/whisper <target>"
            {
                var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

                if (s.StartsWith("/w")) // if it's the /w command being used, get the target, it must be in the string
                {
                    int idx = message.IndexOf(" ");
                    if (idx != -1)
                    {
                        _chatTarget = message.Substring(0, idx);
                        message = message.Substring(idx);
                    }
                }
                // else, we're using last _chatHeader, and thus last _chatTarget

                response.Write((uint)ChatMessageType.Whisper);
                var race = Game.World.SelectedCharacter.Race;
                var language = race.IsHorde() ? Language.Orcish : Language.Common;
                response.Write((uint)language);
                response.Write(_chatTarget.ToCString());
                response.Write(message.ToCString());
                Game.SendPacket(response);
            }
            else if (_chatHeader.StartsWith("/join")) // "/join <channel>"
            {
                var response = new OutPacket(WorldCommand.CMSG_JOIN_CHANNEL);

                uint channelId = 0;
                // byte is uint8
                byte unk1 = 0;
                byte unk2 = 0;
                int idx = message.IndexOf(" ");
                if (idx == -1)
                    return;

                string channel = message.Substring(0, idx);
                string password = "";

                response.Write((uint)channelId);
                response.Write((byte)unk1);
                response.Write((byte)unk2);
                response.Write(channel.ToCString());
                response.Write(password.ToCString());
                Game.SendPacket(response);
            }
            else if (_chatHeader.StartsWith("/leave")) // "/leave <channel>"
            {
                uint unk = 0;
                int idx = message.IndexOf(" ");
                if (idx == -1)
                    return;

                string channel = message.Substring(0, idx);

                var response = new OutPacket(WorldCommand.CMSG_LEAVE_CHANNEL);
                response.Write((uint)unk);
                response.Write(channel.ToCString());
                Game.SendPacket(response);
            }
        }
Exemple #26
0
 public void DoTextEmote(TextEmote emote)
 {
     var packet = new OutPacket(WorldCommand.CMSG_TEXT_EMOTE);
     packet.Write((uint)emote);
     packet.Write((uint)0);
     packet.Write((ulong)0);
     SendPacket(packet);
 }
Exemple #27
0
        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);
        }
Exemple #28
0
 public override async Task Exit()
 {
     ClearTriggers();
     ClearAIs();
     if (LoggedIn)
     {
         OutPacket logout = new OutPacket(WorldCommand.CMSG_LOGOUT_REQUEST);
         SendPacket(logout);
         await loggedOutEvent.Task;
     }
     else
     {
         Connected = false;
         LoggedIn = false;
         Running = false;
     }
 }
        public void PresentCharacterList(Character[] characterList)
        {
            LogLine("\n\tName\tLevel Class Race");

            int index = 0;
            foreach (Character character in characterList)
                LogLine
                (
                    string.Format("{4}\t{0}\t{1} {2} {3}",
                    character.Name,
                    character.Level,
                    character.Race,
                    character.Class,
                    index++)
                );

            if (characterList.Length < 10)
                LogLine(string.Format("{0}\tCreate a new character. (NOT YET IMPLEMENTED)", index));

            int length = characterList.Length == 10 ? 10 : (characterList.Length + 1);

            index = Settings.Default.CharID;

            while (index > length || index < 0)
            {
                Log("Choose a character:  ");
                if (!int.TryParse(Console.ReadLine(), out index))
                    LogLine();
            }

            if (index < characterList.Length)
            {
                Game.World.SelectedCharacter = characterList[index];
                // TODO: enter world

                if (Settings.Default.LagServer == 0)
                {
                    LogLine(string.Format("Entering pseudo-world with character {0}", Game.World.SelectedCharacter.Name));

                    OutPacket packet = new OutPacket(WorldCommand.CMSG_PLAYER_LOGIN);
                    packet.Write(Game.World.SelectedCharacter.GUID);
                    Game.SendPacket(packet);
                }
                else
                {
                    LogLine(string.Format("Entering lag mode with character {0}", Game.World.SelectedCharacter.Name));

                    for (ulong i = 0; i < Settings.Default.LagServer; ++i)
                    {
                        OutPacket packet1 = new OutPacket(WorldCommand.CMSG_CHAR_CUSTOMIZE);
                        packet1.Write(Game.World.SelectedCharacter.GUID);
                        packet1.Write(Game.World.SelectedCharacter.Name);
                        packet1.Write(0);
                        packet1.Write(0);
                        packet1.Write(0);
                        packet1.Write(0);
                        packet1.Write(0);
                        packet1.Write(0);
                        Game.SendPacket(packet1);

                        //Thread.Sleep(1000);

                        OutPacket keelpack = new OutPacket(WorldCommand.ClientEnumerateCharacters);
                        Game.SendPacket(keelpack);

                        //Thread.Sleep(1000);
                    }
                }
            }
            else
            {
                // TODO: character creation
            }
        }
Exemple #30
0
 public override void PresentCharacterList(Character[] characterList)
 {
     World.SelectedCharacter = characterList[Character];
     OutPacket packet = new OutPacket(WorldCommand.CMSG_PLAYER_LOGIN);
     packet.Write(World.SelectedCharacter.GUID);
     SendPacket(packet);
     LoggedIn = true;
     Player.GUID = World.SelectedCharacter.GUID;
 }
Exemple #31
0
        public void Send(OutPacket packet)
        {
            byte[] data = packet.Finalize();

            // TODO: switch to asynchronous send
            lock (SendLock)
                connection.Client.Send(data);

            Interlocked.Add(ref transferred, data.Length);
            Interlocked.Add(ref sent, data.Length);
        }
Exemple #32
0
        public void DoWhisperChat(string message, string player)
        {
            var response = new OutPacket(WorldCommand.CMSG_MESSAGECHAT);

            response.Write((uint)ChatMessageType.Whisper);
            var race = World.SelectedCharacter.Race;
            var language = race.IsHorde() ? Language.Orcish : Language.Common;
            response.Write((uint)language);
            response.Write(player.ToCString());
            response.Write(message.ToCString());
            SendPacket(response);
        }
Exemple #33
0
 public void Resurrect()
 {
     OutPacket repop = new OutPacket(WorldCommand.CMSG_REPOP_REQUEST);
     repop.Write((byte)0);
     SendPacket(repop);
 }
Exemple #34
0
 public void SetFacing(float orientation)
 {
     if (!Player.GetPosition().IsValid)
         return;
     var packet = new OutPacket(WorldCommand.MSG_MOVE_SET_FACING);
     packet.WritePacketGuid(Player.GUID);
     packet.Write((UInt32)0); //flags
     packet.Write((UInt16)0); //flags2
     packet.Write((UInt32)0); //time
     Player.O = orientation;
     packet.Write(Player.X);
     packet.Write(Player.Y);
     packet.Write(Player.Z);
     packet.Write(Player.O);
     packet.Write((UInt32)0); //fall time
     SendPacket(packet);
 }
Exemple #35
0
        public BotGame(string hostname, int port, string username, string password, int realmId, int character, BotBehaviorSettings behavior)
            : base(hostname, port, username, password, realmId, character)
        {
            this.Behavior = behavior;

            #region AutoResurrect
            if (Behavior.AutoResurrect)
            {
                // Resurrect if bot reaches 0 hp
                AddTrigger(new Trigger(new[]
                {
                    new UpdateFieldTriggerAction((int)UnitField.UNIT_FIELD_HEALTH, 0)
                }, () =>
                   {
                       CancelActionsByFlag(ActionFlag.Movement);
                       Resurrect();
                   }));

                // Resurrect sequence
                AddTrigger(new Trigger(new TriggerAction[]
                {
                    new UpdateFieldTriggerAction((int)PlayerField.PLAYER_FLAGS, (uint)PlayerFlags.PLAYER_FLAGS_GHOST, () =>
                        {
                            OutPacket corpseQuery = new OutPacket(WorldCommand.MSG_CORPSE_QUERY);
                            SendPacket(corpseQuery);
                        }),
                    new OpcodeTriggerAction(WorldCommand.MSG_CORPSE_QUERY, packet =>
                    {
                        var inPacket = packet as InPacket;
                        if (inPacket == null)
                            return false;

                        bool found = inPacket.ReadByte() != 0;
                        if (found)
                        {
                            var mapId = inPacket.ReadInt32();

                            var corpsePosition = new Position(inPacket.ReadSingle(),
                                                              inPacket.ReadSingle(),
                                                              inPacket.ReadSingle(),
                                                              0.0f,
                                                              inPacket.ReadInt32());
                            Player.CorpsePosition = corpsePosition.GetPosition();

                            if (mapId == corpsePosition.MapID)
                            {
                                MoveTo(corpsePosition);
                                return true;
                            }
                        }

                        return false;
                    }),
                    new CustomTriggerAction(TriggerActionType.DestinationReached, (inputs) =>
                    {
                        if (Player.IsGhost && (Player.CorpsePosition - Player).Length <= 39f)
                        {
                            if (DateTime.Now > CorpseReclaim)
                                return true;
                            else
                                ScheduleAction(() => HandleTriggerInput(TriggerActionType.DestinationReached, inputs), CorpseReclaim.AddSeconds(1));
                        }

                        return false;
                    },() =>
                      {
                          OutPacket reclaimCorpse = new OutPacket(WorldCommand.CMSG_RECLAIM_CORPSE);
                          reclaimCorpse.Write(Player.GUID);
                          SendPacket(reclaimCorpse);
                      })
                }, null));
            }
            #endregion
        }
Exemple #36
0
        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);
        }
Exemple #37
0
        protected void HandleResurrectRequest(InPacket packet)
        {
            var resurrectorGuid = packet.ReadUInt64();
            OutPacket response = new OutPacket(WorldCommand.CMSG_RESURRECT_RESPONSE);
            response.Write(resurrectorGuid);
            if (Behavior.AutoAcceptResurrectRequests)
            {
                response.Write((byte)1);
                SendPacket(response);

                OutPacket result = new OutPacket(WorldCommand.MSG_MOVE_TELEPORT_ACK);
                result.WritePacketGuid(Player.GUID);
                result.Write((UInt32)0);
                result.Write(DateTime.Now.Millisecond);
                SendPacket(result);
            }
            else
            {
                response.Write((byte)0);
                SendPacket(response);
            }
        }
Exemple #38
0
        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;
            }
        }
Exemple #39
0
 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;
         }
     }
 }