using System;

using FilterAPI.Networking;

using FilterBot.LoginNetworking;

using FilterBot.ManagerNetworking;

namespace FilterBot.LoginHandlers
{
    internal class Login3Handle
    {
        [LoginPacketHandler(3, 3)]
        public static void HandleVersionOK(LoginServer ServerSocket, Packet ServerPacket)
        {
            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received version ok.", ServerSocket.sID);

            GlobalPacket.SendToken(ServerSocket);
            GlobalPacket.SendHash(ServerSocket);
        }

        [LoginPacketHandler(3, 10)]
        public static void HandleWorldList(LoginServer ServerSocket, Packet ServerPacket)
        {
            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received world list.", ServerSocket.sID);

            Byte WorldCount = ServerPacket.PacketReader.ReadByte();
            Byte WorldID = ServerPacket.PacketReader.ReadByte();

            GlobalPacket.SendSelectWorld(ServerSocket, WorldID);
        }

        [LoginPacketHandler(3, 12)]
        public static void HandleTransferKey(LoginServer ServerSocket, Packet ServerPacket)
        {
            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received transfer key.", ServerSocket.sID);

            Byte WorldStatus = ServerPacket.PacketReader.ReadByte();
            String WorldIP = ServerPacket.ReadString(16);
            UInt16 WorldPort = ServerPacket.PacketReader.ReadUInt16();
            String TransferKey = ServerPacket.ReadString(64);

            ManagerServer BotManager = new ManagerServer(ServerSocket.nUserNo, ServerSocket.sID, TransferKey);

            if (Program.BotManagers.ContainsKey(ServerSocket.sID)) { Program.BotManagers.Remove(ServerSocket.sID); }

            Program.BotManagers.Add(ServerSocket.sID, BotManager);

            ServerSocket.Dispose();
        }
    }
}
