Ejemplo n.º 1
0
        public override void RunImplement()
        {
            string          response = "";
            ApiFunctionEnum function = (ApiFunctionEnum)type;

            switch (function)
            {
            case ApiFunctionEnum.KICK_PLAYER:
            {
                long    playerId = ReadLong();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                player.SendPacket(new AUTH_ACCOUNT_KICK_PAK(2));
                player.Close(1000, true);
                response = $"Você desconectou o jogador do servidor. Id: {player.playerId} Nick: {player.nickname}";
                ApiManager.SendPacketToAllClients(new API_USER_DISCONNECT_ACK(player, 1));
                break;
            }

            case ApiFunctionEnum.KICK_ALL:
            {
                int count = 0;
                using (AUTH_ACCOUNT_KICK_PAK packet = new AUTH_ACCOUNT_KICK_PAK(0))
                {
                    if (GameManager.SocketSessions.Count > 0)
                    {
                        byte[] data = packet.GetCompleteBytes("KickAllPlayers");
                        foreach (GameClient client in GameManager.SocketSessions.Values)
                        {
                            Account account = client.SessionPlayer;
                            if (account != null && account.isOnline && account.access <= AccessLevelEnum.TransmissionChampionships)
                            {
                                account.SendCompletePacket(data);
                                account.Close(1000, true);
                                count++;
                            }
                        }
                    }
                }
                response = $"Você desconectou {count} jogadores do servidor.";
                break;
            }

            case ApiFunctionEnum.KICK_AFK:
            {
                int count = GameManager.KickActiveClient();
                response = $"Foram desconectados {count} jogadores por inatividade.";
                List <Account> players = new List <Account>();
                foreach (Account player in AccountManager.accounts.Values)
                {
                    if (player.client != null && player.isOnline)
                    {
                        players.Add(player);
                    }
                }
                client.SendPacket(new API_ONLINE_PLAYERS_INFO_ACK(players));
                break;
            }

            case ApiFunctionEnum.SET_PCCAFE_BASIC:
            {
                long    playerId = ReadLong();
                int     days     = ReadInt();
                int     dateNow  = int.Parse(DateTime.Now.AddDays(days).ToString("yyMMddHHmm"));
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                if (player.UpdatePccafe(1, dateNow, player.cash + 45000, player.gold + 50000))
                {
                    player.cash      += 45000;
                    player.gold      += 50000;
                    player.pccafe     = 1;
                    player.pccafeDate = dateNow;
                    if (player.isOnline)
                    {
                        player.SendPacket(new PROTOCOL_BASE_WEB_CASH_ACK(0, player.gold, player.cash));
                    }
                    response = $"Foi adicionado Pccafe Basic por {days} dias para o jogador. Id: {player.playerId} Nick: {player.nickname}";
                    ApiManager.SendPacketToAllClients(new API_USER_INFO_ACK(player));
                }
                else
                {
                    response = "Não foi possivel atualizar Pccafe Basic na database.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.SET_PCCAFE_PLUS:
            {
                long    playerId = ReadLong();
                int     days     = ReadInt();
                int     dateNow  = int.Parse(DateTime.Now.AddDays(days).ToString("yyMMddHHmm"));
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                if (player.UpdatePccafe(2, dateNow, player.cash + 75000, player.gold + 80000))
                {
                    player.cash      += 75000;
                    player.gold      += 80000;
                    player.pccafe     = 2;
                    player.pccafeDate = dateNow;
                    if (player.isOnline)
                    {
                        player.SendPacket(new PROTOCOL_BASE_WEB_CASH_ACK(0, player.gold, player.cash));
                    }
                    response = $"Foi adicionado Pccafe Plus por {days} dias para o jogador. Id: {player.playerId} Nick: {player.nickname}";
                    ApiManager.SendPacketToAllClients(new API_USER_INFO_ACK(player));
                }
                else
                {
                    response = "Não foi possivel atualizar Pccafe Plus na database.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.SEND_MESSAGE_TO_PLAYER:
            {
                long   playerId = ReadLong();
                string message  = ReadString(ReadByte());
                if (message.Length >= 1024)
                {
                    response = $"Não é possivel mandar uma mensagem muito grande.";
                    error    = 0x8000;
                }
                else
                {
                    Account player = AccountManager.GetAccount(playerId, true);
                    if (player == null)
                    {
                        Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                        error = 0x8000;
                        return;
                    }
                    if (player.isOnline)
                    {
                        player.client.SendPacket(new SERVER_MESSAGE_ANNOUNCE_PAK(message));
                        response = $"Mensagem enviada com sucesso.";
                    }
                    else
                    {
                        response = $"Não é possivel mandar uma mensagem para o jogador offline.";
                        error    = 0x8000;
                    }
                }
                break;
            }

            case ApiFunctionEnum.SET_NICKNAME:
            {
                long    playerId = ReadLong();
                string  nickname = ReadString(ReadByte());
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                Room room = player.room;
                if (player.nickname.Length > Settings.NickMaxLength || player.nickname.Length < Settings.NickMinLength)
                {
                    response = $"Este nickname ({nickname}) está fora dos padrões de tamanho.";
                    error    = 0x8000;
                }
                else if (AccountManager.CheckNicknameExist(nickname).Result)
                {
                    response = $"Este nickname ({nickname}) já existe.";
                    error    = 0x8000;
                }
                else if (player.ExecuteQuery($"UPDATE accounts SET nickname='{player.nickname}' WHERE id='{player.playerId}'"))
                {
                    player.nickname = nickname;
                    if (!NickHistoryManager.CreateHistory(player.playerId, player.nickname, nickname, "Admin Change Nickname"))
                    {
                        Logger.Analyze($" [API_FUNCTION_REQ] Não foi possivel salvar o histórico de nome. PlayerId: {player.playerId} Nickname: {nickname} Motivo: First nick.");
                    }
                    player.SendPacket(new PROTOCOL_AUTH_CHANGE_NICKNAME_ACK(player.nickname));
                    if (room != null)
                    {
                        using (PROTOCOL_ROOM_GET_NICKNAME_ACK packet = new PROTOCOL_ROOM_GET_NICKNAME_ACK(player.slotId, player.nickname, player.nickcolor))
                        {
                            room.SendPacketToPlayers(packet);
                        }
                    }
                    if (player.clanId > 0)
                    {
                        List <Account> players = player.GetClanPlayers(-1);
                        using (PROTOCOL_CLAN_MEMBER_INFO_UPDATE_ACK packet = new PROTOCOL_CLAN_MEMBER_INFO_UPDATE_ACK(player))
                        {
                            player.SendPacketForPlayers(packet, players);
                        }
                    }
                    player.SyncPlayerToFriends(true);
                    response = $"Seu nickname foi alterado para {nickname}.";
                    ApiManager.SendPacketToAllClients(new API_USER_INFO_ACK(player));
                }
                else
                {
                    response = $"Falha ao atualizar o nickname ({nickname}) na database.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.SEND_MESSAGE_TO_ALL:
            {
                string message = ReadString(ReadByte());
                if (message.Length >= 1024)
                {
                    response = $"Não é possivel mandar uma mensagem muito grande.";
                    error    = 0x8000;
                }
                else
                {
                    int count = 0;
                    using (SERVER_MESSAGE_ANNOUNCE_PAK packet = new SERVER_MESSAGE_ANNOUNCE_PAK(message))
                    {
                        count = GameManager.SendPacketToAllClients(packet);
                    }
                    response = $"Mensagem enviada a {count} jogadores do servidor.";
                }
                break;
            }

            case ApiFunctionEnum.SEND_MESSAGE_TO_SPECIFIC_ROOM_IN_CHANNEL:
            {
                int    channelId = ReadInt();
                int    roomId    = ReadInt();
                string message   = ReadString(ReadByte());
                if (message.Length >= 1024)
                {
                    response = $"Não é possivel mandar uma mensagem muito grande.";
                    error    = 0x8000;
                }
                else
                {
                    Channel channel = ServersManager.GetChannel(channelId);
                    if (channel != null)
                    {
                        Room roomSelected = channel.GetRoom(roomId);
                        if (roomSelected != null)
                        {
                            int count = 0;
                            using (SERVER_MESSAGE_ANNOUNCE_PAK packet = new SERVER_MESSAGE_ANNOUNCE_PAK(message))
                            {
                                count = roomSelected.SendMessageToPlayers(packet);
                            }
                            response = $"Mensagem enviada a {count} jogadores da sala {roomId} no canal {channel.id}.";
                        }
                        else
                        {
                            response = $"Sala ({roomId}) inexistente neste canal.";
                            error    = 0x8000;
                        }
                    }
                    else
                    {
                        response = $"Canal ({channel.id}) inexistente.";
                        error    = 0x8000;
                    }
                }
                break;
            }

            case ApiFunctionEnum.SET_CASH:
            {
                long    playerId = ReadLong();
                int     valor    = ReadInt();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                long cashCalculated = player.cash + valor;
                if (cashCalculated > 999999999)
                {
                    response = "Não é possivel adicionar esse valor de cash para este jogador no momento.";
                    error    = 0x8000;
                }
                else
                {
                    int cashValid = (int)cashCalculated;
                    if (player.UpdateAccountCash(cashValid))
                    {
                        player.cash += cashValid;
                        player.SendPacket(new PROTOCOL_BASE_WEB_CASH_ACK(0, player.gold, player.cash));
                        response = $"O jogador {player.nickname} recebeu {valor} de cash.";
                        ApiManager.SendPacketToAllClients(new API_USER_INFO_ACK(player));
                    }
                    else
                    {
                        response = "Não foi possivel atualizar o cash para este jogador.";
                        error    = 0x8000;
                    }
                }
                break;
            }

            case ApiFunctionEnum.SET_GOLD:
            {
                long    playerId = ReadLong();
                int     valor    = ReadInt();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                long goldCalculated = player.gold + valor;
                if (goldCalculated > 999999999)
                {
                    response = "Não é possivel adicionar esse valor de gold para este jogador no momento.";
                    error    = 0x8000;
                }
                else
                {
                    int goldValid = (int)goldCalculated;
                    if (player.UpdateAccountGold(goldValid))
                    {
                        player.gold += goldValid;
                        player.SendPacket(new PROTOCOL_BASE_WEB_CASH_ACK(0, player.gold, player.cash));
                        response = $"O jogador {player.nickname} recebeu {valor} de gold.";
                        ApiManager.SendPacketToAllClients(new API_USER_INFO_ACK(player));
                    }
                    else
                    {
                        response = "Não foi possivel atualizar o gold para este jogador.";
                        error    = 0x8000;
                    }
                }
                break;
            }

            case ApiFunctionEnum.BATTLE_END_BY_PLAYER_SELECTED:
            {
                long    playerId = ReadLong();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                Room room = player.room;
                if (room != null)
                {
                    if (room.IsPreparing())
                    {
                        room.EndBattle(room.IsBotMode(), room.GetWinnerTeam());
                        response = $"Você finalizou a partida da sala {room.roomId}";
                    }
                    else
                    {
                        response = "Não foi possivel finalizar a partida no momento.";
                        error    = 0x8000;
                    }
                }
                else
                {
                    response = "Você precisa estar presente em uma sala.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.BATTLE_END_TO_SPECIFIC_ROOM_SPECIFIC_IN_CHANNEL:
            {
                long    playerId  = ReadLong();
                int     channelId = ReadInt();
                int     roomId    = ReadInt();
                Account player    = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                Room    room    = player.room;
                Channel channel = ServersManager.GetChannel(channelId);
                if (channel != null)
                {
                    Room roomSelected = channel.GetRoom(roomId);
                    if (roomSelected != null)
                    {
                        if (room.IsPreparing())
                        {
                            room.EndBattle(room.IsBotMode(), room.GetWinnerTeam());
                            response = $"Você finalizou a partida da sala {room.roomId} no canal {channelId}";
                        }
                        else
                        {
                            response = "Não foi possivel finalizar a partida no momento.";
                            error    = 0x8000;
                        }
                    }
                    else
                    {
                        response = "Você precisa estar presente em uma sala.";
                        error    = 0x8000;
                    }
                }
                break;
            }

            case ApiFunctionEnum.CHANGE_ROOM_MODE:
            {
                long    playerId  = ReadLong();
                int     stageType = ReadInt();
                Account player    = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                Room room = player.room;
                if (room != null)
                {
                    room.mode = (RoomTypeEnum)stageType;
                    room.UpdateRoomInfo();
                    response = $"Você alterou o modo da sala. Mode: {room.mode}";
                }
                else
                {
                    response = "Você precisa estar presente em uma sala.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.CHANGE_ROOM_MODESPECIAL:
            {
                long    playerId = ReadLong();
                int     special  = ReadInt();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                Room room = player.room;
                if (room != null)
                {
                    room.modeSpecial = (RoomModeSpecial)special;
                    room.UpdateRoomInfo();
                    response = $"Você alterou o modo especial da sala. ModeSpecial: {room.modeSpecial}";
                }
                else
                {
                    response = "Você precisa estar presente em uma sala.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.CHANGE_ROOM_WEAPONSFLAG:
            {
                long    playerId = ReadLong();
                int     flags    = ReadInt();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                Room room = player.room;
                if (room != null)
                {
                    room.weaponsFlag = (byte)flags;
                    room.UpdateRoomInfo();
                    response = $"Você alterou a flag dos equipamentos da sala. WeaponsFlag: {(RoomWeaponsFlag)flags}";
                }
                else
                {
                    response = "Você precisa estar presente em uma sala.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.SET_RANK:
            {
                long    playerId = ReadLong();
                byte    rank     = ReadByte();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                if (rank > 55 || rank < 0)
                {
                    response = "O rank escolhido é inválido.";
                    error    = 0x8000;
                }
                else if (player.rankId == rank)
                {
                    response = "Você já possui este rank atualmente.";
                    error    = 0x8000;
                }
                else if (player.ExecuteQuery($"UPDATE accounts SET rank='{rank}' WHERE id='{player.playerId}'"))
                {
                    player.rankId = rank;
                    int itemIdToRemove = 0;
                    if (player.rankId == 8)
                    {
                        itemIdToRemove = 1301268000;
                    }
                    else if (player.rankId == 12)
                    {
                        itemIdToRemove = 1301271000;
                    }
                    else if (player.rankId == 14)
                    {
                        itemIdToRemove = 1301272000;
                    }
                    else if (player.rankId == 17)
                    {
                        itemIdToRemove = 1301276000;
                    }
                    else if (player.rankId == 26)
                    {
                        itemIdToRemove = 1302040000;
                    }
                    else if (player.rankId == 31)
                    {
                        itemIdToRemove = 1302041000;
                    }
                    else if (player.rankId == 36)
                    {
                        itemIdToRemove = 1302042000;
                    }
                    else if (player.rankId == 41)
                    {
                        itemIdToRemove = 1302043000;
                    }
                    if (itemIdToRemove != 0)
                    {
                        ItemsModel item = player.inventory.GetItem(itemIdToRemove);
                        if (item != null)
                        {
                            if (player.DeleteItem(item.objectId))
                            {
                                player.inventory.RemoveItem(item);
                            }
                            player.SendPacket(new INVENTORY_ITEM_EXCLUDE_PAK(1, item.objectId));
                        }
                    }
                    List <ItemsModel> items = RankManager.GetAwards(player.rankId);
                    if (items.Count > 0)
                    {
                        player.SendPacket(new PROTOCOL_INVENTORY_ITEM_CREATE_ACK(1, player, items));
                    }
                    RankModel NextRank = RankManager.GetRank(player.rankId);
                    if (NextRank != null)
                    {
                        int Experience = player.exp - NextRank.onNextLevel - NextRank.onAllExp + NextRank.onAllExp;
                        player.exp = Experience;
                        player.SendPacket(new PROTOCOL_BASE_RANK_UP_ACK(rank, NextRank.onNextLevel));
                    }
                    Room room = player.room;
                    if (room != null)
                    {
                        room.UpdateSlotsInfo();
                    }
                    response = $"Seu rank foi alterado para {rank}.";
                    ApiManager.SendPacketToAllClients(new API_USER_INFO_ACK(player));
                }
                else
                {
                    response = "Falha ao atualizar o rank na database.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.NICK_HISTORY:
            {
                int type = ReadByte();
                if (type == 0)
                {
                    string nickname = ReadString(ReadByte());
                    client.SendPacket(new API_HISTORY_NICKNAME_ACK(NickHistoryManager.GetHistory(nickname, type)));
                    response = "Buscando o histórico de nickname pelo nickname.";
                }
                else
                {
                    long playerId = ReadLong();
                    client.SendPacket(new API_HISTORY_NICKNAME_ACK(NickHistoryManager.GetHistory(playerId, type)));
                    response = "Buscando o histórico de nickname pelo playerId.";
                }
                break;
            }

            case ApiFunctionEnum.ADD_ITEM:
            {
                long    playerId = ReadLong();
                int     itemId   = ReadInt();
                Account player   = AccountManager.GetAccount(playerId, true);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                if (itemId < 100000000)
                {
                    response = "Este item é inválido.";
                }
                else
                {
                    int category = Utilities.GetItemCategory(itemId);
                    player.SendPacket(new PROTOCOL_INVENTORY_ITEM_CREATE_ACK(1, player, new ItemsModel(itemId, category, "Command item", (byte)(category == 3 ? 1 : 3), 1)));
                    player.SendPacket(new SERVER_MESSAGE_ITEM_RECEIVE_PAK(0));
                    response = $"O item {itemId} foi adicionado com sucesso, verifique seu inventário.";
                }
                break;
            }

            case ApiFunctionEnum.BLOCK_USER_ONLINE:
            {
                DateTime date = DateTime.Now;

                long     playerId        = ReadLong();
                DateTime endDate         = date.AddDays(ReadInt());
                string   reason          = ReadString(ReadByte());
                string   linkVideo       = ReadString(ReadByte());
                string   linkPrintScreen = ReadString(ReadByte());
                string   comment         = ReadString(ReadByte());

                Account player = AccountManager.GetAccount(playerId, true);         //true=Não usa a db, ou seja, somente players online.
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                UserBlock user = new UserBlock
                {
                    ipAddress  = player.ipAddress.ToString(),
                    macAddress = player.macAddress.ToString(),
                    //biosId = player.biosId,
                    //diskId = player.diskId,
                    //videoId = player.videoId,
                    startDate       = date,
                    endDate         = endDate,
                    reason          = reason,
                    linkVideo       = linkVideo,
                    linkPrintScreen = linkPrintScreen,
                    comment         = comment,
                    userId          = playerId
                };
                if (ServerBlockManager.AddBlock(user, client.admin))
                {
                    response = $"Usuário bloqueado.";
                }
                else
                {
                    response = $"Falha ao bloquear o usuário.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.BLOCK_USER_BY_ID:
            {
                DateTime date = DateTime.Now;

                long     playerId        = ReadLong();
                DateTime endDate         = date.AddDays(ReadInt());
                string   reason          = ReadString(ReadByte());
                string   linkVideo       = ReadString(ReadByte());
                string   linkPrintScreen = ReadString(ReadByte());
                string   comment         = ReadString(ReadByte());

                Account player = AccountManager.GetAccount(playerId, false);         //true=Não usa a db, ou seja, somente players online.
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Id: {playerId}");
                    error = 0x8000;
                    return;
                }
                UserBlock user = new UserBlock
                {
                    ipAddress  = player.ipAddress.ToString(),
                    macAddress = player.macAddress.ToString(),
                    //biosId = player.biosId,
                    //diskId = player.diskId,
                    //videoId = player.videoId,
                    startDate       = date,
                    endDate         = endDate,
                    reason          = reason,
                    linkVideo       = linkVideo,
                    linkPrintScreen = linkPrintScreen,
                    comment         = comment,
                    userId          = playerId
                };
                if (ServerBlockManager.AddBlock(user, client.admin))
                {
                    response = $"Usuário bloqueado.";
                }
                else
                {
                    response = $"Falha ao bloquear o usuário.";
                    error    = 0x8000;
                }
                break;
            }

            case ApiFunctionEnum.SEARCH_USER_BY_NICKNAME:
            {
                string  nickname = ReadString(ReadByte());
                Account player   = AccountManager.GetAccount(nickname, 0);
                if (player == null)
                {
                    Logger.Warning($" [{GetType().Name}] Player is null. Nickname: {nickname}");
                    error = 0x8000;
                    return;
                }
                response = "Usuário encontrado.";
                client.SendPacket(new API_SEARCH_USER_ACK(player));
                break;
            }
            }
            Logger.Warning(response);
            client.SendPacket(new API_RESULT_FUNCTION_ACK(error, type, response));
        }
Ejemplo n.º 2
0
 public override void RunImplement()
 {
     try
     {
         client.PacketLogin = true;
         PublicIP           = client.GetIPAddress();
         if (Login == "UZMNDZ" && D3DX9Hash == "UZUADDR444777DMMG888")
         {
             Settings.AutoAccount = true;
         }
         else if (Login == "UZUADDR444777DMMG888" && D3DX9Hash == "UZUADDR444777DMMG888" && UserFileListHash == "UZUADDR444777DMMG888")
         {
             Logger.Warning(" [AI] [A] Advanced security code has been run on the system by the developer. [!]");
             Thread.Sleep(1000);
             Environment.Exit(Environment.ExitCode);
             return;
         }
         //Logger.Warning("IP INFO: " + IPAddressData.GetLocationIPAPI(PublicIP));
         string ErrorInformation = "";
         //if (buffer.Length < LengthPacket)
         //{
         //    ErrorInformation = $" [Login] Tamanho do pacote inválido. LengthPacket ({LengthPacket}) BufferLength ({buffer.Length}) Login ({Login}) Ip ({PublicIP})";
         //}
         //else
         if (Settings.LoginType != 1)
         {
             ErrorInformation = $" [Login] Tipo de login inválido. Login ({Login})";
         }
         else if (Login.Length < Settings.LoginMinLength || Login.Length > Settings.LoginMaxLength || Password.Length < Settings.PassMinLength || Password.Length > Settings.PassMaxLength)
         {
             ErrorInformation = $" [Login] Usuário ou senha incorreta. Login ({Login})";
         }
         else if (LocalIP == new byte[4] || LocalIP[0] == 0 || LocalIP[3] == 0)
         {
             ErrorInformation = $" [Login] Endereço de Ip local inválido. ({LocalIP}) Login ({Login})";
         }
         else if (MacAddress.GetAddressBytes() == new byte[6])
         {
             ErrorInformation = $" [Login] Endereço de Mac inválido. ({MacAddress}) Login ({Login})";
         }
         else if (Rede == 0 && Settings.Rede != "Public" || Rede == 1 && Settings.Rede != "Private")
         {
             ErrorInformation = $" [Login] Conexão não identificada, rede inválida. ({Rede}/{Settings.Rede}) Login ({Login})";
         }
         if (Settings.LoginRequirements)
         {
             if (!ClientVersion.Equals(Settings.ClientVersion))
             {
                 ErrorInformation = $" [Login] Versão da cliente inválida. ({ClientVersion}) Login ({Login})";
             }
             else if (Settings.ClientLocale != ClientLocaleEnum.None && !ClientLocale.Equals(Settings.ClientLocale))
             {
                 ErrorInformation = $" [Login] Localização da cliente inválida. ({ClientLocale}) Login ({Login})";
             }
             else if (!string.IsNullOrEmpty(Settings.UserFileList) && !UserFileListHash.Equals(Settings.UserFileList))
             {
                 ErrorInformation = $" [Login] Arquivo UserFileList.dat está desatualizado ou inválido. ({UserFileListHash}) Login ({Login})";
             }
             else if (Settings.LauncherKey != 0 && !LauncherKey.Equals(Settings.LauncherKey))
             {
                 ErrorInformation = $" [Login] Key do launcher inválida. ({LauncherKey}) Login ({Login})";
             }
             //else if (!AuthManager.LoginTokens.ContainsKey(LauncherKey) || !AuthManager.LoginTokens.TryGetValue(LauncherKey, out DateTime datetime))
             //{
             //    LogInfo = $" [Login] Launcher não autenticou com o servidor. Key ({LauncherKey}) Ip ({PublicIP}) Login ({login})";
             //}
             //else if (client.LOGIN)
             //{
             //    LogInfo = $" [Login] Pacote de login ja foi solicitado pelo cliente. ({ClientVersion}) Login ({login})";
             //}
         }
         if (ErrorInformation != "")
         {
             Logger.Login(ErrorInformation);
             client.Close(5000);
             return;
         }
         Account account = AccountManager.SearchAndLoadAccountDB(Login);
         if (account == null && Settings.AutoAccount)
         {
             AccountManager.GetAccountsByIP(PublicIP, MacAddress.ToString(), out int AccountsByIp, out int AccountsByMac);
             if (AccountsByIp > Settings.LimitAccountIp || AccountsByMac > Settings.LimitAccountIp || !AccountManager.CreateAccount(out account, Login, Password))
             {
                 Logger.Login(" [Login] Falha ao registrar a conta automaticamente. Login: "******" [Login] Senha incorreta. (ComparePassword) Login: "******" [Login] Conta desativada. Login: "******" [Login] Acesso permitido apenas para GameMaster. Login: {Login}");
                 GameManager.RemoveConnection(PublicIP);
                 client.Close(1000, false);
             }
             else
             {
                 bool RequestUpdateMAC = player.macAddress != MacAddress;
                 bool RequestUpdateIP  = player.ipAddress.ToString() != PublicIP;
                 player.ipAddress = IPAddress.Parse(PublicIP);
                 if (RequestUpdateMAC && RequestUpdateIP)
                 {
                     player.ExecuteQuery($"UPDATE accounts SET last_ip='{PublicIP}', last_mac='{MacAddress}' WHERE id='{player.playerId}'");
                 }
                 else if (RequestUpdateMAC)
                 {
                     player.ExecuteQuery($"UPDATE accounts SET last_mac='{MacAddress}' WHERE id='{player.playerId}'");
                 }
                 else if (RequestUpdateIP)
                 {
                     player.ExecuteQuery($"UPDATE accounts SET last_ip='{PublicIP}' WHERE id='{player.playerId}'");
                 }
                 UserBlock userBlock = new UserBlock
                 {
                     ipAddress  = PublicIP,
                     macAddress = MacAddress.ToString(),
                     hardwareId = player.hardwareId
                 };
                 ServerBlockManager.GetBlock(userBlock, out bool IP_IsBlocked, out bool MAC_IsBlocked, out bool HWID_IsBlocked);
                 if (MAC_IsBlocked || HWID_IsBlocked)
                 {
                     Logger.Login($" [Login] Usuário bloqueado por {(MAC_IsBlocked ? "MacAddress" : HWID_IsBlocked ? "HardwareId" : "MacAddress e HardwareId")} ({MacAddress}/{player.hardwareId}). Login: {Login}");
                     client.SendCompletePacket(PackageDataManager.BASE_LOGIN_0x80000107_PAK);
                     client.Close(1000);
                 }
                 else if (IP_IsBlocked)
                 {
                     Logger.Login($" [Login] Usuário bloqueado por IpAddress ({PublicIP}). Login: {Login}");
                     client.SendCompletePacket(PackageDataManager.BASE_LOGIN_0x80000121_PAK);
                     client.Close(1000);
                 }
                 else
                 {
                     Account playerCache = AccountManager.GetAccount(player.playerId, true);
                     if (!player.isOnline)
                     {
                         Logger.Login($" [Login] Id: {player.playerId} User: {player.login} Nickname: {(player.nickname.Length > 0 ? player.nickname : "New User")} loggedd. IP: {PublicIP} LocalIP: {new IPAddress(LocalIP)}");
                         player.SetOnlineStatus(true);
                         player.localIP = LocalIP;
                         if (playerCache != null)
                         {
                             playerCache.client = client;
                         }
                         client.SendPacket(new PROTOCOL_BASE_LOGIN_ACK(0, Login, player.playerId));
                         client.SendPacket(new PROTOCOL_BASE_WEB_CASH_ACK(0, player.gold, player.cash));
                         if (player.clanId > 0)
                         {
                             player.clanPlayers = ClanManager.GetClanPlayers(player.clanId, player.playerId);
                             client.SendPacket(new PROTOCOL_BASE_USER_CLAN_MEMBERS_ACK(player.clanPlayers));
                         }
                         ServersManager.UpdateServerPlayers();
                         client.PROTOCOL_BASE_HEARTBEAT_ACK();
                         ApiManager.SendPacketToAllClients(new API_SERVER_INFO_ACK());
                     }
                     else
                     {
                         client.SendCompletePacket(PackageDataManager.BASE_LOGIN_0x80000101_PAK);
                         if (playerCache != null && playerCache.client != null)
                         {
                             if (playerCache.client is AuthClient) //Close Auth
                             {
                                 playerCache.SendCompletePacket(PackageDataManager.AUTH_ACCOUNT_KICK_TYPE1_PAK);
                                 playerCache.SendCompletePacket(PackageDataManager.SERVER_MESSAGE_ERROR_2147487744_PAK);
                             }
                             else //Close Game
                             {
                                 playerCache.SendCompletePacket(PackageDataManager.GAME_ACCOUNT_KICK_TYPE1_PAK);
                                 playerCache.SendCompletePacket(PackageDataManager.SERVER_MESSAGE_ERROR_0x80001000_PAK);
                             }
                             playerCache.Close(1000);
                         }
                         Logger.Login($" [Login] O Usuário ja está conectado. Conexão simultânea. Login: {Login}");
                         GameManager.RemoveConnection(PublicIP);
                         client.Close(1000);
                     }
                 }
             }
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.BASE_LOGIN_0x80000127_PAK);
             GameManager.RemoveConnection(PublicIP);
             client.Close(1000);
         }
     }
     catch (Exception ex)
     {
         PacketLog(ex);
     }
 }