using System;

using FilterAPI.Networking;

using FilterBot.LoginNetworking;

using FilterBot.ManagerNetworking;

using FilterBot.ZoneNetworking;

namespace FilterBot
{
    internal class GlobalPacket
    {
        public static void SendVersion(LoginServer ServerSocket)
        {
            using (var ClientPacket = new Packet(3, 1))
            {
                ClientPacket.PacketWriter.Write(Convert.ToInt16(Program.Auth.ConfigValues["LoginYear"]));
                ClientPacket.PacketWriter.Write(Convert.ToInt16(Program.Auth.ConfigValues["LoginVersion"]));
                ClientPacket.PacketWriter.Write((Byte)0);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendToken(LoginServer ServerSocket)
        {
            using (var ClientPacket = new Packet(3, 32))
            {
                ClientPacket.WriteString(ServerSocket.sToken, 65);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendHash(LoginServer ServerSocket)
        {
            using (var ClientPacket = new Packet(3, 4))
            {
                ClientPacket.PacketWriter.Write((Byte)29);
                ClientPacket.WriteString("33B543B0CA6E7C41E5D1D0651307", 29);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendSelectWorld(LoginServer ServerSocket, Byte WorldID)
        {
            using (var ClientPacket = new Packet(3, 11))
            {
                ClientPacket.PacketWriter.Write((Byte)WorldID);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendPong(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(2, 5)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendTransferKey(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(3, 15))
            {
                ClientPacket.WriteString("", 18);
                ClientPacket.WriteString(ServerSocket.TransferKey, 64);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendCreateCharacter(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(5, 1))
            {
                ClientPacket.PacketWriter.Write((Byte)0);
                ClientPacket.WriteString(ServerSocket.sID, 16);
                ClientPacket.PacketWriter.Write((Byte)25);
                ClientPacket.PacketWriter.Write((Byte)2);
                ClientPacket.PacketWriter.Write((Byte)2);
                ClientPacket.PacketWriter.Write((Byte)0);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendSelectCharacter(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(4, 1))
            {
                ClientPacket.PacketWriter.Write((Byte)0);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendGetQuickBar(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(28, 2)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendGetQuickBarState(ManagerServer ServerSocket)
        {
            using(var ClientPacket = new Packet(28, 4)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendGetClientSettings(ManagerServer ServerSocket)
        {
            using(var ClientPacket = new Packet(28, 12)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendGetShortcuts(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(28, 14)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendGetGameSettings(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(28, 10)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendGetUnk00(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(31, 6)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendSaveQuickBar(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(28, 16))
            {
                ClientPacket.PacketWriter.Write(ServerSocket.QuickBar);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendClientReady(ManagerServer ServerSocket)
        {
            using (var ClientPacket = new Packet(22, 27)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendRejectParty(ManagerServer ServerSocket, String sID)
        {
            using (var ClientPacket = new Packet(14, 5))
            {
                ClientPacket.WriteString(sID, 16);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendPartyInvite(ManagerServer ServerSocket, String sID)
        {
            using (var ClientPacket = new Packet(14, 2))
            {
                ClientPacket.WriteString(sID, 16);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendPartyBan(ManagerServer ServerSocket, String sID)
        {
            using (var ClientPacket = new Packet(14, 20))
            {
                ClientPacket.WriteString(sID, 16);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendWhisperMessageClient(ManagerServer ServerSocket, String sID, String Message, params Object[] Args)
        {
            String FormattedMessage = String.Format(Message, Args);

            using (var ClientPacket = new Packet(8, 12))
            {
                ClientPacket.WriteString(sID, 16);
                ClientPacket.PacketWriter.Write(FormattedMessage);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendPong(ZoneServer ServerSocket)
        {
            using (var ClientPacket = new Packet(2, 5)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendSHNHashes(ZoneServer ServerSocket)
        {
            using (var ClientPacket = new Packet(6, 1))
            {
                ClientPacket.PacketWriter.Write(ServerSocket.Manager.RandomID);
                ClientPacket.WriteString(ServerSocket.Manager.sID, 16);
                ClientPacket.WriteString("81eb45358e8d01b254454a2c4467a1f4756f0a7413009392e591afc19ca88fcae308d8559d894e5c714e0e39746dbb6b3caf424de02c3c0f25fc6ae6a41e6fcbb98e5fb4624bffa192e09b5604e6351503a904594d798d5f2c57b0fde4ab405b7ac0acfdad3b51cc164ffc076780904210bdf3fed84a26524e878c21ae3d2be5323ae3e8deba4b1acc3fd3273956efa97dbc7b6b28a4a2f8a7dfdb4333ba35c35a3b72a2d1d2b6490e7b2e103007000aa7cbb59d19de434f0c8ef4f526b051b5e059712ca4f307b98ba10d8649f4b3af6a16e6fa03cc72a9655ba55011533d16c242db68b20e1eafecb7067885d18952c903b25641c70b43ad1c19ce6819609849fe3c13f63bd254e5e940abb51c4b0415b3fe6762a4f7a017ed1e06b10e7efd848653de05d70e38d1e0aa42ac97df85fa1e177dc604a0b3e68bd8b21d49a80d3196ddba87a10d8c22c0fde25be99e79abd6ea726da00614a56f33ea5e63cc97ce2415b92e7773ecf7e63610adcb903e4298df6f8c96ba2a154ba35695c25e0c54540d7003c3866fdc9418732f4c73ef97f50e5d8ad48cf665b847ee10a6d98a", 832);

                ServerSocket.SendPacket(ClientPacket);
            }
        }

        public static void SendClientReady(ZoneServer ServerSocket)
        {
            using (var ClientPacket = new Packet(6, 3)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendUnk00(ZoneServer ServerSocket)
        {
           using (var ClientPacket = new Packet(8, 11)) { ServerSocket.SendPacket(ClientPacket); }
        }

        public static void SendNormalMessageClient(ZoneServer ServerSocket, String Message, params Object[] Args)
        {
            String FormattedMessage = String.Format(Message, Args);

            using (var ClientPacket = new Packet(8, 1))
            {
                ClientPacket.PacketWriter.Write(FormattedMessage);

                ServerSocket.SendPacket(ClientPacket);
            }
        }
    }
}
