using System;
using System.Linq;
using System.Threading;

using FilterAPI.Networking;

using FilterManager.ManagerNetworking;

namespace FilterManager.ManagerHandlers
{
    internal class Manager4Handle
    {
        [ManagerPacketHandler(4, 1)]
        public static void HandleCharacterSelect(ManagerClient ClientSocket, Packet ClientPacket)
        {
            Byte SlotNo = 255;

            if ((SlotNo = ClientPacket.PacketReader.ReadByte()) != 255)
            {
                if (SlotNo > 4) {
					ClientSocket.Dispose(); }
                else
                {
                    String sID = Program.SQL.GetsIDFromnUserIDAndnSlotNo(ClientSocket.nUserNo, SlotNo);

                    ClientSocket.nCharNo = Program.SQL.GetnCharNoFromsID(sID);
                    ClientSocket.sID = sID;
                    ClientSocket.SendPacketServer(ClientPacket);
                }
            }
            else {
				ClientSocket.Dispose(); }
        }

        [ManagerPacketHandler(4, 3)]
        public static void HandleZoneIP(ManagerClient ClientSocket, Packet ServerPacket)
        {
            String IPAddress = ServerPacket.ReadString(16);
            UInt16 Port = ServerPacket.PacketReader.ReadUInt16();

            using (var ServerPacketRewrite = new Packet(4, 3))
            {
                ServerPacketRewrite.WriteString(Program.Auth.ConfigValues["ManagerTransferIP"], 16);
                ServerPacketRewrite.PacketWriter.Write(Port);

                ClientSocket.SendPacketClient(ServerPacketRewrite);
            }
        }
    }
}
