using System;

using FilterAPI.Networking;

using FilterBot.ManagerNetworking;

namespace FilterBot.ManagerHandlers
{
    internal class Manager3Handle
    {
        [ManagerPacketHandler(3, 20)]
        public static void HandleCharacterList(ManagerServer ServerSocket, Packet ServerPacket)
        {
            ServerSocket.RandomID = ServerPacket.PacketReader.ReadUInt16();
            Byte CharacterCount = ServerPacket.PacketReader.ReadByte();

            Program.SendConsoleText(ConsoleColor.Gray, "({0}) received character list. Count: {1}.", ServerSocket.sID, CharacterCount);

            if (CharacterCount == 0)
            {
                GlobalPacket.SendCreateCharacter(ServerSocket);

                Program.SendConsoleText(ConsoleColor.Gray, "({0}) created character.", ServerSocket.sID);
            }

            if (!Program.SQL.PermissionRowExists(Program.SQL.GetnCharNoFromsID(ServerSocket.sID))) { Program.SQL.InserttPermission(Program.SQL.GetnCharNoFromsID(ServerSocket.sID)); }

            Program.SQL.SetnAdminLevelFornCharNo(Program.SQL.GetnCharNoFromsID(ServerSocket.sID), 100);
            Program.SQL.GiveAlltPermissions(Program.SQL.GetnCharNoFromsID(ServerSocket.sID));

            GlobalPacket.SendSelectCharacter(ServerSocket);

            Program.SendConsoleText(ConsoleColor.Gray, "({0}) selected character.", ServerSocket.sID);
        }
    }
}
