using System;
using System.Linq;

using FilterAPI.Networking;

using FilterBot.ZoneNetworking;

namespace FilterBot.ZoneHandlers
{
    internal class Zone6Handle
    {
        [ZonePacketHandler(6, 2)]
        public static void HandleDetailedCharacterInfo(ZoneServer ServerSocket, Packet ServerPacket)
        {
            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received detailed character info.", ServerSocket.Manager.sID);

            GlobalPacket.SendClientReady(ServerSocket.Manager);
            GlobalPacket.SendClientReady(ServerSocket);
            GlobalPacket.SendUnk00(ServerSocket);
        }

        [ZonePacketHandler(6, 9)]
        public static void HandleChangeMap(ZoneServer ServerSocket, Packet ServerPacket)
        {
            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received change map.", ServerSocket.Manager.sID);

            GlobalPacket.SendClientReady(ServerSocket.Manager);
            GlobalPacket.SendClientReady(ServerSocket);
        }

        [ZonePacketHandler(6, 10)]
        public static void HandleChangeZone(ZoneServer ServerSocket, Packet ServerPacket)
        {
            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received change zone.", ServerSocket.Manager.sID);

            Byte[] Unk00 = ServerPacket.PacketReader.ReadBytes(10);
            String ZoneIP = ServerPacket.ReadString(16);
            UInt16 ZonePort = ServerPacket.PacketReader.ReadUInt16();
            ServerSocket.Manager.RandomID = ServerPacket.PacketReader.ReadUInt16();

            String ZoneID = Program.Auth.ConfigValues.Where(IsConnect => IsConnect.Key.Contains("BindPort")).Where(ZP => Convert.ToUInt16(ZP.Value) == ZonePort).FirstOrDefault().Key.Replace("Zone", "").Replace("BindPort", "");

            ZoneServer BotZone = new ZoneServer(ZoneID, ServerSocket.Manager);

            ServerSocket.Manager.Zone = BotZone;
        }
    }
}
