Example #1
0
        private void ParseServerLoginMessage()
        {
#if DEBUG_PROXY
            Trace.WriteLine("[DEBUG] Proxy [ParseServerLoginMessage]");
#endif
            serverInMessage.ReadPosition = 2;

            if (Adler.Generate(serverInMessage) != serverInMessage.ReadChecksum())
            {
                throw new Exception("Wrong checksum.");
            }

            Xtea.Decrypt(serverInMessage, xteaKey);
            serverInMessage.Size         = serverInMessage.ReadInternalHead() + 8;
            serverInMessage.ReadPosition = 8;

            clientOutMessage.Reset();
            Array.Copy(serverInMessage.Buffer, clientOutMessage.Buffer, serverInMessage.Size);
            clientOutMessage.Size = serverInMessage.Size;

            while (serverInMessage.ReadPosition < serverInMessage.Size)
            {
                byte cmd = serverInMessage.ReadByte();

                switch (cmd)
                {
                case 0x0A:                         //Error message
                    var msg = serverInMessage.ReadString();
                    break;

                case 0x0B:                         //For your information
                    serverInMessage.ReadString();
                    break;

                case 0x14:                         //MOTD
                    serverInMessage.ReadString();
                    break;

                case 0x1E:                         //Patching exe/dat/spr messages
                case 0x1F:
                case 0x20:
                    //DisconnectClient(0x0A, "A new client is avalible, please download it first!");
                    break;

                case 0x28:                         //Select other login server
                    //selectedLoginServer = random.Next(0, loginServers.Length - 1);
                    break;

                case 0x64:     //character list
                    if (client.Version.Number <= ClientVersion.Version1011.Number)
                    {
                        int nChar = (int)serverInMessage.ReadByte();
                        charList = new CharacterLoginInfo[nChar];

                        for (int i = 0; i < nChar; i++)
                        {
                            charList[i].CharName  = serverInMessage.ReadString();
                            charList[i].WorldName = serverInMessage.ReadString();
                            clientOutMessage.WriteAt(new byte[] { 127, 0, 0, 1 }, serverInMessage.ReadPosition);
                            charList[i].WorldIP = serverInMessage.ReadUInt();
                            clientOutMessage.WriteAt(BitConverter.GetBytes((ushort)worldClientPort), serverInMessage.ReadPosition);
                            charList[i].WorldPort = serverInMessage.ReadUShort();

                            if (client.Version.Number >= ClientVersion.Version981.Number)
                            {
                                serverInMessage.ReadByte();     //isPreviewWorld
                            }
                        }

                        if (client.Version.Number >= ClientVersion.Version1011.Number)
                        {
                            serverInMessage.ReadUShort();     //PremiumTime
                        }
                    }
                    else if (client.Version.Number >= ClientVersion.Version1012.Number)
                    {
                        clientOutMessage.WritePosition = serverInMessage.ReadPosition;

                        byte nWorlds = serverInMessage.ReadByte();
                        clientOutMessage.WriteByte(nWorlds);
                        WorldLoginInfo[] worldList = new WorldLoginInfo[nWorlds];
                        for (byte i = 0; i < nWorlds; i++)
                        {
                            worldList[i].ID = serverInMessage.ReadByte();
                            clientOutMessage.WriteByte(worldList[i].ID);
                            worldList[i].Name = serverInMessage.ReadString();
                            clientOutMessage.WriteString(worldList[i].Name);
                            worldList[i].Hostname = serverInMessage.ReadString();
                            clientOutMessage.WriteString("127.0.0.1");
                            worldList[i].Port = serverInMessage.ReadUShort();
                            clientOutMessage.WriteUShort((ushort)worldClientPort);
                            worldList[i].IsPreviewWorld = serverInMessage.ReadBool();
                            clientOutMessage.WriteByte(Convert.ToByte(worldList[i].IsPreviewWorld));
                        }

                        byte nChars = serverInMessage.ReadByte();
                        clientOutMessage.WriteByte(nChars);
                        charList = new CharacterLoginInfo[nChars];
                        for (byte j = 0; j < nChars; j++)
                        {
                            byte WorldID = serverInMessage.ReadByte();
                            clientOutMessage.WriteByte(WorldID);
                            charList[j].CharName = serverInMessage.ReadString();
                            clientOutMessage.WriteString(charList[j].CharName);
                            charList[j].WorldName     = worldList[WorldID].Name;
                            charList[j].WorldIP       = BitConverter.ToUInt32(Dns.GetHostAddresses(worldList[WorldID].Hostname)[0].GetAddressBytes(), 0);
                            charList[j].WorldPort     = worldList[WorldID].Port;
                            charList[j].WorldIPString = worldList[WorldID].Hostname;
                        }

                        ushort PremiumTime = serverInMessage.ReadUShort();
                        clientOutMessage.WriteUShort(PremiumTime);

                        clientOutMessage.Size = clientOutMessage.WritePosition;
                    }
                    break;

                default:
                    break;
                }
            }

            clientOutMessage.WriteInternalHead();
            Xtea.Encrypt(clientOutMessage, xteaKey);
            Adler.Generate(clientOutMessage, true);
            clientOutMessage.WriteHead();

            SendToClient(clientOutMessage);
        }
Example #2
0
        private void ParseServerLoginMessage()
        {
#if DEBUG_PROXY
            Trace.WriteLine("[DEBUG] Proxy [ParseServerLoginMessage]");
#endif
            serverInMessage.ReadPosition = 2;

            if (Adler.Generate(serverInMessage) != serverInMessage.ReadChecksum())
            {
                throw new Exception("Wrong checksum.");
            }

            Xtea.Decrypt(serverInMessage, xteaKey);
            serverInMessage.Size         = serverInMessage.ReadInternalHead() + 8;
            serverInMessage.ReadPosition = 8;

            clientOutMessage.Reset();
            Array.Copy(serverInMessage.Buffer, clientOutMessage.Buffer, serverInMessage.Size);
            clientOutMessage.Size = serverInMessage.Size;

            while (serverInMessage.ReadPosition < serverInMessage.Size)
            {
                byte cmd = serverInMessage.ReadByte();

                switch (cmd)
                {
                case 0x0A:                         //Error message
                    var msg = serverInMessage.ReadString();
                    break;

                case 0x0B:                         //For your information
                    serverInMessage.ReadString();
                    break;

                case 0x0C:     //token succes
                case 0x0D:     //token error
                    serverInMessage.ReadByte();
                    break;

                case 0x11:     //update
                    serverInMessage.ReadString();
                    break;

                case 0x14:                         //MOTD
                    serverInMessage.ReadString();
                    break;

                case 0x1E:                         //Patching exe/dat/spr messages
                case 0x1F:
                case 0x20:
                    //DisconnectClient(0x0A, "A new client is avalible, please download it first!");
                    break;

                case 0x28:                         //session key
                    serverInMessage.ReadString();
                    break;

                case 0x64:     //character list
                    if (client.Version.Number <= ClientVersion.Version1011.Number)
                    {
                        int nChar = (int)serverInMessage.ReadByte();
                        charList = new CharacterLoginInfo[nChar];

                        for (int i = 0; i < nChar; i++)
                        {
                            charList[i].CharName  = serverInMessage.ReadString();
                            charList[i].WorldName = serverInMessage.ReadString();
                            clientOutMessage.WriteAt(new byte[] { 127, 0, 0, 1 }, serverInMessage.ReadPosition);
                            charList[i].WorldIP = serverInMessage.ReadUInt();
                            clientOutMessage.WriteAt(BitConverter.GetBytes((ushort)worldClientPort), serverInMessage.ReadPosition);
                            charList[i].WorldPort = serverInMessage.ReadUShort();

                            if (client.Version.Number >= ClientVersion.Version981.Number)
                            {
                                serverInMessage.ReadByte();     //isPreviewWorld
                            }
                        }

                        if (client.Version.Number >= ClientVersion.Version1011.Number)
                        {
                            serverInMessage.ReadUShort();     //PremiumTime
                        }
                    }
                    else if (client.Version.Number >= ClientVersion.Version1012.Number)
                    {
                        clientOutMessage.WritePosition = serverInMessage.ReadPosition;

                        byte nWorlds = serverInMessage.ReadByte();
                        clientOutMessage.WriteByte(nWorlds);
                        WorldLoginInfo[] worldList = new WorldLoginInfo[nWorlds];
                        for (byte i = 0; i < nWorlds; i++)
                        {
                            worldList[i].ID = serverInMessage.ReadByte();
                            clientOutMessage.WriteByte(worldList[i].ID);
                            worldList[i].Name = serverInMessage.ReadString();
                            clientOutMessage.WriteString(worldList[i].Name);
                            worldList[i].Hostname = serverInMessage.ReadString();
                            clientOutMessage.WriteString("127.0.0.1");
                            worldList[i].Port = serverInMessage.ReadUShort();
                            clientOutMessage.WriteUShort((ushort)worldClientPort);
                            worldList[i].IsPreviewWorld = serverInMessage.ReadBool();
                            clientOutMessage.WriteByte(Convert.ToByte(worldList[i].IsPreviewWorld));
                        }

                        byte nChars = serverInMessage.ReadByte();
                        clientOutMessage.WriteByte(nChars);
                        charList = new CharacterLoginInfo[nChars];
                        for (byte j = 0; j < nChars; j++)
                        {
                            byte WorldID = serverInMessage.ReadByte();
                            clientOutMessage.WriteByte(WorldID);
                            charList[j].CharName = serverInMessage.ReadString();
                            clientOutMessage.WriteString(charList[j].CharName);
                            charList[j].WorldName     = worldList[WorldID].Name;
                            charList[j].WorldIP       = BitConverter.ToUInt32(Dns.GetHostAddresses(worldList[WorldID].Hostname)[0].GetAddressBytes(), 0);
                            charList[j].WorldPort     = worldList[WorldID].Port;
                            charList[j].WorldIPString = worldList[WorldID].Hostname;
                        }

                        /**
                         * Not very accurately named variables, but I'll settle for some pseudocode in case of futher implementations
                         *
                         * if version < 10.80:
                         *      ushort PremiumTime
                         * else if version < 10.82
                         *      bool isPremium
                         *      uint PremiumTime (In seconds from epoch - don't quote me on this :D)
                         * else if version >= 10.82
                         *      byte AccountStatus (0 = normal, 1 = frozen, 2 = suspended)
                         *      bool isPremium
                         *      uint PremiumTime
                         */

                        ushort PremiumTime = serverInMessage.ReadUShort();
                        clientOutMessage.WriteUShort(PremiumTime);

                        if (client.Version.Number >= ClientVersion.Version1090.Number) // From 10.80 - but haven't added 10.80 support.
                        {
                            uint PremiumSeconds = serverInMessage.ReadUInt();          // Not sure about this name.
                            clientOutMessage.WriteUInt(PremiumSeconds);
                        }

                        clientOutMessage.Size = clientOutMessage.WritePosition;
                    }
                    break;

                default:
                    break;
                }
            }

            clientOutMessage.WriteInternalHead();
            Xtea.Encrypt(clientOutMessage, xteaKey);
            Adler.Generate(clientOutMessage, true);
            clientOutMessage.WriteHead();

            SendToClient(clientOutMessage);
        }
Example #3
0
        internal void SendServerMarketCreate(OfferKind kind, ushort itemid, ushort amount, uint pieceprice, bool isanonymous)
        {
            if (!client.LoggedIn)
                return;

            var message = new OutMessage();
            message.WriteByte(0xF5);
            message.WriteByte((byte)kind);
            message.WriteUShort(itemid);
            message.WriteUShort(amount);
            message.WriteUInt(pieceprice);
            message.WriteByte(Convert.ToByte(isanonymous));

            client.Proxy.SendToServer(message);
        }
Example #4
0
        internal void SendServerMarketAccept(uint timestamp, ushort counter, ushort amount)
        {
            if (!client.LoggedIn)
                return;

            var message = new OutMessage();
            message.WriteByte(0xF5);
            message.WriteUInt(timestamp);
            message.WriteUShort(counter);
            message.WriteUShort(amount);

            client.Proxy.SendToServer(message);
        }
Example #5
0
        internal void SendServerMarketBrowse(ushort itemid)
        {
            if (!client.LoggedIn)
                return;

            var message = new OutMessage();
            message.WriteByte(0xF5);
            message.WriteUShort(itemid);

            client.Proxy.SendToServer(message);
        }