public static void HandleCharacterInfoRequest(ref LoginClient Client, PacketStream P)
        {
            ushort PacketLength = (ushort)P.ReadUShort();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            ushort UnencryptedLength = (ushort)P.ReadUShort();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            Logger.LogDebug("Received CharacterInfoRequest!");

            DateTime Timestamp = DateTime.Parse(P.ReadASCII());

            //Database.CheckCharacterTimestamp(Client.Username, Client, TimeStamp);

            Character[] Characters = new Character[] {};

            using (var db = DataAccess.Get())
            {
                Characters = db.Characters.GetForAccount(Client.AccountID).ToArray();
            }

            if (Characters != null)
            {
                PacketStream Packet       = new PacketStream(0x05, 0);
                MemoryStream PacketData   = new MemoryStream();
                BinaryWriter PacketWriter = new BinaryWriter(PacketData);

                /**
                 * Whats the point of checking a timestamp here? It saves a few bytes on a packet
                 * sent once per user session. Premature optimization.
                 */
                PacketWriter.Write((byte)Characters.Length);
                foreach (Character avatar in Characters)
                {
                    PacketWriter.Write(avatar.CharacterID);
                    PacketWriter.Write(avatar.GUID.ToString());
                    PacketWriter.Write(avatar.LastCached);
                    PacketWriter.Write(avatar.Name);
                    PacketWriter.Write(avatar.Sex);
                }

                Packet.Write(PacketData.ToArray(), 0, (int)PacketData.Length);
                PacketWriter.Close();
                Client.SendEncrypted(0x05, Packet.ToArray());
            }
            else //No characters existed for the account.
            {
                PacketStream Packet = new PacketStream(0x05, 0);
                Packet.WriteByte(0x00); //0 characters.

                Client.SendEncrypted(0x05, Packet.ToArray());
            }
        }
Exemplo n.º 2
0
        public static void HandleCityInfoRequest(PacketStream P, LoginClient Client)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            //This packet only contains a dummy byte, don't bother reading it.

            PacketStream Packet = new PacketStream(0x06, 0);

            MemoryStream PacketData   = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(PacketData);

            PacketWriter.Write((byte)NetworkFacade.CServerListener.CityServers.Count);

            foreach (CityServerClient City in NetworkFacade.CServerListener.CityServers)
            {
                PacketWriter.Write(City.ServerInfo.Name);
                PacketWriter.Write(City.ServerInfo.Description);
                PacketWriter.Write(City.ServerInfo.IP);
                PacketWriter.Write(City.ServerInfo.Port);
                PacketWriter.Write((byte)City.ServerInfo.Status);
                PacketWriter.Write(City.ServerInfo.Thumbnail);
                PacketWriter.Write(City.ServerInfo.UUID);

                PacketWriter.Flush();
            }

            Packet.Write(PacketData.ToArray(), 0, PacketData.ToArray().Length);
            PacketWriter.Close();

            Client.SendEncrypted(0x06, Packet.ToArray());
        }
        public static void HandleCityInfoRequest(ref LoginClient Client, PacketStream P)
        {
            ushort PacketLength = (ushort)P.ReadUShort();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            ushort UnencryptedLength = (ushort)P.ReadUShort();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            //This packet only contains a dummy byte, don't bother reading it.
            PacketStream Packet       = new PacketStream(0x06, 0);
            MemoryStream PacketData   = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(PacketData);

            PacketWriter.Write((byte)NetworkFacade.CServerListener.CityServers.Count);

            foreach (CityServerClient City in NetworkFacade.CServerListener.CityServers)
            {
                PacketWriter.Write((string)City.ServerInfo.Name);
                PacketWriter.Write((string)City.ServerInfo.Description);
                PacketWriter.Write((string)City.ServerInfo.IP);
                PacketWriter.Write((int)City.ServerInfo.Port);

                //Hack (?) to ensure status is written correctly.
                switch (City.ServerInfo.Status)
                {
                case CityInfoStatus.Ok:
                    PacketWriter.Write((byte)1);
                    break;

                case CityInfoStatus.Busy:
                    PacketWriter.Write((byte)2);
                    break;

                case CityInfoStatus.Full:
                    PacketWriter.Write((byte)3);
                    break;

                case CityInfoStatus.Reserved:
                    PacketWriter.Write((byte)4);
                    break;
                }

                PacketWriter.Write((ulong)City.ServerInfo.Thumbnail);
                PacketWriter.Write((string)City.ServerInfo.UUID);
                PacketWriter.Write((ulong)City.ServerInfo.Map);

                PacketWriter.Flush();
            }

            Packet.Write(PacketData.ToArray(), 0, PacketData.ToArray().Length);
            PacketWriter.Close();

            Client.SendEncrypted(0x06, Packet.ToArray());
        }
        public static void HandleCharacterInfoRequest(PacketStream P, LoginClient Client)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            Logger.LogDebug("Received CharacterInfoRequest!");

            byte Length = (byte)P.ReadByte();
            byte[] StrBuf = new byte[Length];
            P.Read(StrBuf, 0, Length - 1);
            DateTime Timestamp = DateTime.Parse(Encoding.ASCII.GetString(StrBuf));

            //Database.CheckCharacterTimestamp(Client.Username, Client, TimeStamp);

            Character[] Characters = Character.GetCharacters(Client.Username);

            if (Characters != null)
            {
                PacketStream Packet = new PacketStream(0x05, 0);

                MemoryStream PacketData = new MemoryStream();
                BinaryWriter PacketWriter = new BinaryWriter(PacketData);

                //The timestamp for all characters should be equal, so just check the first character.
                if (Timestamp < DateTime.Parse(Characters[0].LastCached) ||
                    Timestamp > DateTime.Parse(Characters[0].LastCached))
                {
                    //Write the characterdata into a temporary buffer.
                    if (Characters.Length == 1)
                    {
                        PacketWriter.Write(Characters[0].CharacterID);
                        PacketWriter.Write(Characters[0].GUID);
                        PacketWriter.Write(Characters[0].LastCached);
                        PacketWriter.Write(Characters[0].Name);
                        PacketWriter.Write(Characters[0].Sex);

                        PacketWriter.Flush();
                    }
                    else if (Characters.Length == 2)
                    {
                        PacketWriter.Write(Characters[0].CharacterID);
                        PacketWriter.Write(Characters[0].GUID);
                        PacketWriter.Write(Characters[0].LastCached);
                        PacketWriter.Write(Characters[0].Name);
                        PacketWriter.Write(Characters[0].Sex);

                        PacketWriter.Write(Characters[1].CharacterID);
                        PacketWriter.Write(Characters[1].GUID);
                        PacketWriter.Write(Characters[1].LastCached);
                        PacketWriter.Write(Characters[1].Name);
                        PacketWriter.Write(Characters[1].Sex);

                        PacketWriter.Flush();
                    }
                    else if (Characters.Length == 3)
                    {
                        PacketWriter.Write(Characters[0].CharacterID);
                        PacketWriter.Write(Characters[0].GUID);
                        PacketWriter.Write(Characters[0].LastCached);
                        PacketWriter.Write(Characters[0].Name);
                        PacketWriter.Write(Characters[0].Sex);

                        PacketWriter.Write(Characters[1].CharacterID);
                        PacketWriter.Write(Characters[1].GUID);
                        PacketWriter.Write(Characters[1].LastCached);
                        PacketWriter.Write(Characters[1].Name);
                        PacketWriter.Write(Characters[1].Sex);

                        PacketWriter.Write(Characters[2].CharacterID);
                        PacketWriter.Write(Characters[2].GUID);
                        PacketWriter.Write(Characters[2].LastCached);
                        PacketWriter.Write(Characters[2].Name);
                        PacketWriter.Write(Characters[2].Sex);

                        PacketWriter.Flush();
                    }

                    Packet.WriteByte((byte)Characters.Length);      //Total number of characters.
                    Packet.Write(PacketData.ToArray(), 0, (int)PacketData.Length);
                    PacketWriter.Close();

                    Client.SendEncrypted(0x05, Packet.ToArray());
                }
            }
            else //No characters existed for the account.
            {
                PacketStream Packet = new PacketStream(0x05, 0);
                Packet.WriteByte(0x00); //0 characters.

                Client.SendEncrypted(0x05, Packet.ToArray());
            }
        }
        public static void HandleCityInfoRequest(PacketStream P, LoginClient Client)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            //This packet only contains a dummy byte, don't bother reading it.

            PacketStream Packet = new PacketStream(0x06, 0);

            MemoryStream PacketData = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(PacketData);

            PacketWriter.Write((byte)NetworkFacade.CServerListener.CityServers.Count);

            foreach (CityServerClient City in NetworkFacade.CServerListener.CityServers)
            {
                PacketWriter.Write(City.ServerInfo.Name);
                PacketWriter.Write(City.ServerInfo.Description);
                PacketWriter.Write(City.ServerInfo.IP);
                PacketWriter.Write(City.ServerInfo.Port);
                PacketWriter.Write((byte)City.ServerInfo.Status);
                PacketWriter.Write(City.ServerInfo.Thumbnail);
                PacketWriter.Write(City.ServerInfo.UUID);

                PacketWriter.Flush();
            }

            Packet.Write(PacketData.ToArray(), 0, PacketData.ToArray().Length);
            PacketWriter.Close();

            Client.SendEncrypted(0x06, Packet.ToArray());
        }
Exemplo n.º 6
0
        public static void HandleCityInfoRequest(ref LoginClient Client, PacketStream P)
        {
            ushort PacketLength = (ushort)P.ReadUShort();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            ushort UnencryptedLength = (ushort)P.ReadUShort();
            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            //This packet only contains a dummy byte, don't bother reading it.
            PacketStream Packet = new PacketStream(0x06, 0);
            MemoryStream PacketData = new MemoryStream();
            BinaryWriter PacketWriter = new BinaryWriter(PacketData);
            PacketWriter.Write((byte)NetworkFacade.CServerListener.CityServers.Count);

            foreach (CityServerClient City in NetworkFacade.CServerListener.CityServers)
            {
                PacketWriter.Write((string)City.ServerInfo.Name);
                PacketWriter.Write((string)City.ServerInfo.Description);
                PacketWriter.Write((string)City.ServerInfo.IP);
                PacketWriter.Write((int)City.ServerInfo.Port);

                //Hack (?) to ensure status is written correctly.
                switch (City.ServerInfo.Status)
                {
                    case CityInfoStatus.Ok:
                        PacketWriter.Write((byte)1);
                        break;
                    case CityInfoStatus.Busy:
                        PacketWriter.Write((byte)2);
                        break;
                    case CityInfoStatus.Full:
                        PacketWriter.Write((byte)3);
                        break;
                    case CityInfoStatus.Reserved:
                        PacketWriter.Write((byte)4);
                        break;
                }

                PacketWriter.Write((ulong)City.ServerInfo.Thumbnail);
                PacketWriter.Write((string)City.ServerInfo.UUID);
                PacketWriter.Write((ulong)City.ServerInfo.Map);

                PacketWriter.Flush();
            }

            Packet.Write(PacketData.ToArray(), 0, PacketData.ToArray().Length);
            PacketWriter.Close();

            Client.SendEncrypted(0x06, Packet.ToArray());
        }
Exemplo n.º 7
0
        public static void HandleCharacterInfoRequest(ref LoginClient Client, PacketStream P)
        {
            ushort PacketLength = (ushort)P.ReadUShort();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            ushort UnencryptedLength = (ushort)P.ReadUShort();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            Logger.LogDebug("Received CharacterInfoRequest!");

            DateTime Timestamp = DateTime.Parse(P.ReadASCII());

            //Database.CheckCharacterTimestamp(Client.Username, Client, TimeStamp);

            Character[] Characters = new Character[]{};

            using (var db = DataAccess.Get())
            {
                Characters = db.Characters.GetForAccount(Client.AccountID).ToArray();
            }

            if (Characters != null)
            {
                PacketStream Packet = new PacketStream(0x05, 0);
                MemoryStream PacketData = new MemoryStream();
                BinaryWriter PacketWriter = new BinaryWriter(PacketData);

                /**
                 * Whats the point of checking a timestamp here? It saves a few bytes on a packet
                 * sent once per user session. Premature optimization.
                 */
                PacketWriter.Write((byte)Characters.Length);
                foreach(Character avatar in Characters){
                    PacketWriter.Write(avatar.CharacterID);
                    PacketWriter.Write(avatar.GUID.ToString());
                    PacketWriter.Write(avatar.LastCached);
                    PacketWriter.Write(avatar.Name);
                    PacketWriter.Write(avatar.Sex);
                }

                Packet.Write(PacketData.ToArray(), 0, (int)PacketData.Length);
                PacketWriter.Close();
                Client.SendEncrypted(0x05, Packet.ToArray());
            }
            else //No characters existed for the account.
            {
                PacketStream Packet = new PacketStream(0x05, 0);
                Packet.WriteByte(0x00); //0 characters.

                Client.SendEncrypted(0x05, Packet.ToArray());
            }
        }
Exemplo n.º 8
0
        public static void HandleCharacterInfoRequest(PacketStream P, LoginClient Client)
        {
            byte PacketLength = (byte)P.ReadByte();
            //Length of the unencrypted data, excluding the header (ID, length, unencrypted length).
            byte UnencryptedLength = (byte)P.ReadByte();

            P.DecryptPacket(Client.EncKey, Client.CryptoService, UnencryptedLength);

            Logger.LogDebug("Received CharacterInfoRequest!");

            byte Length = (byte)P.ReadByte();

            byte[] StrBuf = new byte[Length];
            P.Read(StrBuf, 0, Length - 1);
            DateTime Timestamp = DateTime.Parse(Encoding.ASCII.GetString(StrBuf));

            //Database.CheckCharacterTimestamp(Client.Username, Client, TimeStamp);

            Character[] Characters = Character.GetCharacters(Client.Username);

            if (Characters != null)
            {
                PacketStream Packet = new PacketStream(0x05, 0);

                MemoryStream PacketData   = new MemoryStream();
                BinaryWriter PacketWriter = new BinaryWriter(PacketData);

                //The timestamp for all characters should be equal, so just check the first character.
                if (Timestamp < DateTime.Parse(Characters[0].LastCached) ||
                    Timestamp > DateTime.Parse(Characters[0].LastCached))
                {
                    //Write the characterdata into a temporary buffer.
                    if (Characters.Length == 1)
                    {
                        PacketWriter.Write(Characters[0].CharacterID);
                        PacketWriter.Write(Characters[0].GUID);
                        PacketWriter.Write(Characters[0].LastCached);
                        PacketWriter.Write(Characters[0].Name);
                        PacketWriter.Write(Characters[0].Sex);

                        PacketWriter.Flush();
                    }
                    else if (Characters.Length == 2)
                    {
                        PacketWriter.Write(Characters[0].CharacterID);
                        PacketWriter.Write(Characters[0].GUID);
                        PacketWriter.Write(Characters[0].LastCached);
                        PacketWriter.Write(Characters[0].Name);
                        PacketWriter.Write(Characters[0].Sex);

                        PacketWriter.Write(Characters[1].CharacterID);
                        PacketWriter.Write(Characters[1].GUID);
                        PacketWriter.Write(Characters[1].LastCached);
                        PacketWriter.Write(Characters[1].Name);
                        PacketWriter.Write(Characters[1].Sex);

                        PacketWriter.Flush();
                    }
                    else if (Characters.Length == 3)
                    {
                        PacketWriter.Write(Characters[0].CharacterID);
                        PacketWriter.Write(Characters[0].GUID);
                        PacketWriter.Write(Characters[0].LastCached);
                        PacketWriter.Write(Characters[0].Name);
                        PacketWriter.Write(Characters[0].Sex);

                        PacketWriter.Write(Characters[1].CharacterID);
                        PacketWriter.Write(Characters[1].GUID);
                        PacketWriter.Write(Characters[1].LastCached);
                        PacketWriter.Write(Characters[1].Name);
                        PacketWriter.Write(Characters[1].Sex);

                        PacketWriter.Write(Characters[2].CharacterID);
                        PacketWriter.Write(Characters[2].GUID);
                        PacketWriter.Write(Characters[2].LastCached);
                        PacketWriter.Write(Characters[2].Name);
                        PacketWriter.Write(Characters[2].Sex);

                        PacketWriter.Flush();
                    }

                    Packet.WriteByte((byte)Characters.Length);      //Total number of characters.
                    Packet.Write(PacketData.ToArray(), 0, (int)PacketData.Length);
                    PacketWriter.Close();

                    Client.SendEncrypted(0x05, Packet.ToArray());
                }
            }
            else //No characters existed for the account.
            {
                PacketStream Packet = new PacketStream(0x05, 0);
                Packet.WriteByte(0x00); //0 characters.

                Client.SendEncrypted(0x05, Packet.ToArray());
            }
        }