using System;
using System.Linq;

using FilterAPI.Networking;

using FilterBot.ManagerNetworking;

using FilterBot.ZoneNetworking;

namespace FilterBot.ManagerHandlers
{
    internal class Manager4Handle
    {
        [ManagerPacketHandler(4, 3)]
        public static void HandleZoneIP(ManagerServer ServerSocket, Packet ServerPacket)
        {
            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received zone ip.", ServerSocket.sID);

            String ZoneIP = ServerPacket.ReadString(16);
            UInt16 ZonePort = ServerPacket.PacketReader.ReadUInt16();

            GlobalPacket.SendGetQuickBar(ServerSocket);
            GlobalPacket.SendGetQuickBarState(ServerSocket);
            GlobalPacket.SendGetClientSettings(ServerSocket);
            GlobalPacket.SendGetShortcuts(ServerSocket);
            GlobalPacket.SendGetGameSettings(ServerSocket);
            GlobalPacket.SendGetUnk00(ServerSocket);

            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);

            ServerSocket.Zone = BotZone;
        }
    }
}
