using System;
using System.Linq;

using FilterAPI.Networking;

using FilterManager.ManagerNetworking;

namespace FilterManager.ManagerHandlers
{
	internal class Manager3Handle
    {
        [ManagerPacketHandler(3, 15)]
        public static void HandleTransferKey(ManagerClient ClientSocket, Packet ClientPacket)
        {
            Byte[] Empty = new Byte[18];
            String TransferKey = String.Empty;

            if (((Empty = ClientPacket.PacketReader.ReadBytes(18)) != null) && ((TransferKey = ClientPacket.ReadString(64)) != String.Empty))
            {
                if (TransferKey.Length != 64) {
					ClientSocket.Dispose(); }
                else
                {
                    Int32 nUserNo = 0;

					if ((nUserNo = Program.GrabednUserNos.Where(Key => Key.Key == TransferKey).FirstOrDefault().Value) == 0) {
						ClientSocket.Dispose(); 
					}
                    else
                    {
                        ClientSocket.nUserNo = nUserNo;
                        ClientSocket.SendPacketServer(ClientPacket);
                    }
                }
            }
            else {
				ClientSocket.Dispose(); }
        }

        [ManagerPacketHandler(3, 24)]
        public static void HandleBackToCharacterSelect(ManagerClient ClientSocket, Packet ClientPacket)
        {
            Program.SQL.DeletetParties(ClientSocket.nCharNo);

            ClientSocket.nCharNo = -1;
            ClientSocket.sID = String.Empty;
            ClientSocket.PartyMaster = String.Empty;
            ClientSocket.PartyMembers.Clear();
            ClientSocket.SendPacketServer(ClientPacket);
        }
    }
}
