Exemplo n.º 1
0
 public override void run()
 {
     try
     {
         Account player = this._client._player;
         if (player == null || player.player_name.Length > 0 || (string.IsNullOrEmpty(this.name) || this.name.Length < ConfigGS.minNickSize) || this.name.Length > ConfigGS.maxNickSize)
         {
             this._client.SendPacket((SendPacket) new LOBBY_CREATE_NICK_NAME_PAK(2147487763U));
         }
         else
         {
             foreach (string str in NickFilter._filter)
             {
                 if (this.name.Contains(str))
                 {
                     this._client.SendPacket((SendPacket) new LOBBY_CREATE_NICK_NAME_PAK(2147487763U));
                     return;
                 }
             }
             if (!PlayerManager.isPlayerNameExist(this.name))
             {
                 if (AccountManager.updatePlayerName(this.name, player.player_id))
                 {
                     NickHistoryManager.CreateHistory(player.player_id, player.player_name, this.name, "First nick");
                     player.player_name = this.name;
                     List <ItemsModel> creationAwards = BasicInventoryXML.creationAwards;
                     if (creationAwards.Count > 0)
                     {
                         this._client.SendPacket((SendPacket) new INVENTORY_ITEM_CREATE_PAK(1, player, creationAwards));
                         this._client.SendPacket((SendPacket) new SERVER_MESSAGE_ITEM_RECEIVE_PAK(0U));
                     }
                     this._client.SendPacket((SendPacket) new LOBBY_CREATE_NICK_NAME_PAK(0U));
                     this._client.SendPacket((SendPacket) new BASE_QUEST_GET_INFO_PAK(player));
                 }
                 else
                 {
                     this._client.SendPacket((SendPacket) new LOBBY_CREATE_NICK_NAME_PAK(2147487763U));
                 }
             }
             else
             {
                 this._client.SendPacket((SendPacket) new LOBBY_CREATE_NICK_NAME_PAK(2147483923U));
             }
         }
     }
     catch (Exception ex)
     {
         Logger.warning("[LOBBY_CREATE_NICK_NAME_REC] " + ex.ToString());
     }
 }
Exemplo n.º 2
0
 public override void RunImplement()
 {
     try
     {
         Account player = client.SessionPlayer;
         if (player == null || player.nickname.Length > 0 || AccountManager.CheckNickLengthInvalid(nickname))
         {
             client.SendCompletePacket(PackageDataManager.LOBBY_CREATE_NICKNAME_ERROR_0x80001013_PAK);
             return;
         }
         if (StringFilter.CheckStringFilter(nickname) && !AccountManager.CheckNicknameExist(nickname).Result&& player.UpdateNick(nickname).Result)
         {
             player.nickname = nickname;
             if (!NickHistoryManager.CreateHistory(player.playerId, player.nickname, nickname, "First nick"))
             {
                 Logger.Analyze($" [LOBBY_CREATE_NICK_NAME_REQ] Não foi possivel salvar o histórico de nome. PlayerId: {player.playerId} Nickname: {nickname} Motivo: First nick.");
             }
             List <ItemsModel> awards = DefaultInventoryManager.awards;
             if (awards.Count > 0)
             {
                 client.SendPacket(new PROTOCOL_INVENTORY_ITEM_CREATE_ACK(1, player, awards));
                 client.SendCompletePacket(PackageDataManager.GAME_SERVER_MESSAGE_ITEM_RECEIVE_PAK);
             }
             client.SendCompletePacket(PackageDataManager.LOBBY_CREATE_NICKNAME_SUCCESS_PAK);
             client.SendPacket(new PROTOCOL_BASE_QUEST_GET_INFO_ACK(player));
             ApiManager.SendPacketToAllClients(new API_USER_INFO_ACK(player));
         }
         else
         {
             Logger.Analyze($" [LOBBY_CREATE_NICK_NAME_REQ] Não foi possivel atualizar o nome do jogador na database. PlayerId: {player.playerId} Nickname: {nickname} Motivo: First nick.");
             client.SendCompletePacket(PackageDataManager.LOBBY_CREATE_NICKNAME_ERROR_0x80000113_PAK);
         }
     }
     catch (Exception ex)
     {
         PacketLog(ex);
     }
 }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gera efeitos dos cupons na Database.
 /// </summary>
 /// <param name="cuponId">Id do cupom</param>
 /// <param name="cuponDays">Dias do cupom</param>
 /// <param name="player">Jogador</param>
 private void CreateCuponEffects(int cupomId, int cuponDays, Account player)
 {
     if (cupomId == 1201051000)
     {
         Clan clan = ClanManager.GetClan(player.clanId);
         if (clan.id > 0 && clan.ownerId == player.playerId)
         {
             if (!ClanManager.CheckNameLengthInvalid(txt) && StringFilter.CheckStringFilter(txt) && !ClanManager.IsClanNameExist(txt).Result&& clan.UpdateName(txt).Result)
             {
                 clan.name = txt;
                 List <Account> players = player.GetClanPlayers(-1);
                 using (CLAN_CHANGE_NAME_PAK packet = new CLAN_CHANGE_NAME_PAK(txt))
                 {
                     player.SendPacketForPlayers(packet, players);
                 }
             }
             else
             {
                 client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
                 return;
             }
         }
     }
     else if (cupomId == 1201052000)
     {
         Clan clan = ClanManager.GetClan(player.clanId);
         if (clan.id > 0 && clan.ownerId == player.playerId && !ClanManager.IsClanLogoExist(objetivo).Result&& clan.UpdateLogo(objetivo).Result)
         {
             clan.logo = objetivo;
             List <Account> players = player.GetClanPlayers(-1);
             using (CLAN_CHANGE_LOGO_PAK packet = new CLAN_CHANGE_LOGO_PAK(objetivo))
             {
                 player.SendPacketForPlayers(packet, players);
             }
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
     }
     else if (cupomId == 1201047000)
     {
         if (!AccountManager.CheckNickLengthInvalid(txt) && StringFilter.CheckStringFilter(txt) && !AccountManager.CheckNicknameExist(txt).Result&& player.UpdateNick(txt).Result)
         {
             player.nickname = txt;
             if (!NickHistoryManager.CreateHistory(player.playerId, player.nickname, txt, "Change nick"))
             {
                 Logger.Warning($" [GAME] [PROTOCOL_INVENTORY_ITEM_EFFECT_REQ] (CuponId: 1201047000) Não foi possivel salvar o histórico de nome. PlayerId: {player.playerId} Nickname: {txt} Motivo: Change nick.");
             }
             if (player.room != null)
             {
                 using (PROTOCOL_ROOM_GET_NICKNAME_ACK packet = new PROTOCOL_ROOM_GET_NICKNAME_ACK(player.slotId, player.nickname, player.nickcolor))
                 {
                     player.room.SendPacketToPlayers(packet);
                 }
             }
             client.SendPacket(new PROTOCOL_AUTH_CHANGE_NICKNAME_ACK(player.nickname));
             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);
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_2147483923_PAK);
             return;
         }
     }
     else if (cupomId == 1200006000)
     {
         if (player.ExecuteQuery($"UPDATE accounts SET nickcolor='{(int)objetivo}' WHERE id='{player.playerId}'"))
         {
             player.nickcolor = (byte)objetivo;
             client.SendPacket(new PROTOCOL_INVENTORY_ITEM_CREATE_ACK(1, player, new ItemsModel(cupomId, 3, "NameColor [Active]", 2, cuponDays, 0)));
             client.SendPacket(new BASE_2612_PAK(player));
             if (player.room != null)
             {
                 using (PROTOCOL_ROOM_GET_NICKNAME_ACK packet = new PROTOCOL_ROOM_GET_NICKNAME_ACK(player.slotId, player.nickname, player.nickcolor))
                 {
                     player.room.SendPacketToPlayers(packet);
                 }
             }
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
     }
     else if (cupomId == 1200009000)
     {
         if ((int)objetivo >= 51 || (int)objetivo < player.rankId - 10 || (int)objetivo > player.rankId + 10)
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
         else if (player.ExecuteQuery($"UPDATE player_bonus SET fakerank='{(int)objetivo}' WHERE player_id='{player.playerId}'"))
         {
             player.bonus.fakeRank = (int)objetivo;
             client.SendPacket(new PROTOCOL_BASE_USER_EFFECTS_ACK(info.Length, player.bonus));
             client.SendPacket(new PROTOCOL_INVENTORY_ITEM_CREATE_ACK(1, player, new ItemsModel(cupomId, 3, "Patente falsa [Active]", 2, cuponDays, 0)));
             if (player.room != null)
             {
                 player.room.UpdateSlotsInfo();
             }
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
     }
     else if (cupomId == 1200010000)
     {
         if (AccountManager.CheckNickLengthInvalid(txt))
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
         if (StringFilter.CheckStringFilter(txt) && !AccountManager.CheckNicknameExist(txt).Result&& player.UpdateFakeNick().Result&& player.UpdateNick(txt).Result)
         {
             player.bonus.fakeNick = player.nickname;
             player.nickname       = txt;
             if (!NickHistoryManager.CreateHistory(player.playerId, player.nickname, txt, "Change nick false"))
             {
                 Logger.Warning($" [GAME] [PROTOCOL_INVENTORY_ITEM_EFFECT_REQ] (CuponId: 1200010000) Não foi possivel salvar o histórico de nome. PlayerId: {player.playerId} Nickname: {txt} Motivo: Change nick false.");
             }
             client.SendPacket(new PROTOCOL_BASE_USER_EFFECTS_ACK(info.Length, player.bonus));
             client.SendPacket(new PROTOCOL_AUTH_CHANGE_NICKNAME_ACK(player.nickname));
             client.SendPacket(new PROTOCOL_INVENTORY_ITEM_CREATE_ACK(1, player, new ItemsModel(cupomId, 3, "FakeNick [Active]", 2, cuponDays, 0)));
             Room room = player.room;
             if (room != null)
             {
                 room.UpdateSlotsInfo();
             }
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_2147483923_PAK);
             return;
         }
     }
     else if (cupomId == 1200014000)
     {
         if (player.ExecuteQuery($"UPDATE player_bonus SET sightcolor='{(int)objetivo}' WHERE player_id='{player.playerId}'"))
         {
             player.bonus.sightColor = (short)objetivo;
             client.SendPacket(new PROTOCOL_BASE_USER_EFFECTS_ACK(info.Length, player.bonus));
             client.SendPacket(new PROTOCOL_INVENTORY_ITEM_CREATE_ACK(1, player, new ItemsModel(cupomId, 3, "Cor da mira [Active]", 2, cuponDays, 0)));
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
     }
     else if (cupomId == 1200005000)
     {
         Clan clan = ClanManager.GetClan(player.clanId);
         if (clan.id > 0 && clan.ownerId == player.playerId && player.ExecuteQuery($"UPDATE clan_data SET color='{(int)objetivo}' WHERE clan_id='{clan.id}'"))
         {
             clan.nameColor = (byte)objetivo;
             client.SendPacket(new CLAN_CHANGE_NAME_COLOR_PAK(clan.nameColor));
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
     }
     else if (cupomId == 1201085000)
     {
         if (player.room != null)
         {
             Account playerRoom = player.room.GetPlayerBySlot((int)objetivo);
             if (playerRoom != null)
             {
                 client.SendPacket(new PROTOCOL_ROOM_INSPECTPLAYER_ACK(playerRoom));
             }
             else
             {
                 client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
                 return;
             }
         }
         else
         {
             client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
             return;
         }
     }
     else
     {
         Logger.Error("[ITEM_EFFECT] Efeito do cupom não encontrado! Id: " + cupomId);
         client.SendCompletePacket(PackageDataManager.INVENTORY_ITEM_EQUIP_0x80000000_PAK);
         return;
     }
 }
Exemplo n.º 5
0
        private void CreateCuponEffects(int cupomId, uint cuponDays, Account p)
        {
            switch (cupomId)
            {
            case 1200005000:
                Clan clan1 = ClanManager.getClan(p.clanId);
                if (clan1._id > 0 && clan1.owner_id == this._client.player_id && ComDiv.updateDB("clan_data", "color", (object)(int)this.objetivo, "clan_id", (object)clan1._id))
                {
                    clan1._name_color = (int)this.objetivo;
                    this._client.SendPacket((SendPacket) new CLAN_CHANGE_NAME_COLOR_PAK((byte)clan1._name_color));
                    break;
                }
                this.erro = 2147483648U;
                break;

            case 1200006000:
                if (ComDiv.updateDB("accounts", "name_color", (object)(int)this.objetivo, "player_id", (object)p.player_id))
                {
                    p.name_color = (int)this.objetivo;
                    this._client.SendPacket((SendPacket) new INVENTORY_ITEM_CREATE_PAK(1, p, new ItemsModel(cupomId, 3, "NameColor [Active]", 2, cuponDays, 0L)));
                    this._client.SendPacket((SendPacket) new BASE_2612_PAK(p));
                    if (p._room == null)
                    {
                        break;
                    }
                    using (ROOM_GET_NICKNAME_PAK roomGetNicknamePak = new ROOM_GET_NICKNAME_PAK(p._slotId, p.player_name, p.name_color))
                    {
                        p._room.SendPacketToPlayers((SendPacket)roomGetNicknamePak);
                        break;
                    }
                }
                else
                {
                    this.erro = 2147483648U;
                    break;
                }

            case 1200009000:
                if ((int)this.objetivo >= 51 || (int)this.objetivo < p._rank - 10 || (int)this.objetivo > p._rank + 10)
                {
                    this.erro = 2147483648U;
                    break;
                }
                if (ComDiv.updateDB("player_bonus", "fakerank", (object)(int)this.objetivo, "player_id", (object)p.player_id))
                {
                    p._bonus.fakeRank = (int)this.objetivo;
                    this._client.SendPacket((SendPacket) new BASE_USER_EFFECTS_PAK(this.info.Length, p._bonus));
                    this._client.SendPacket((SendPacket) new INVENTORY_ITEM_CREATE_PAK(1, p, new ItemsModel(cupomId, 3, "Patente falsa [Active]", 2, cuponDays, 0L)));
                    if (p._room == null)
                    {
                        break;
                    }
                    p._room.updateSlotsInfo();
                    break;
                }
                this.erro = 2147483648U;
                break;

            case 1200010000:
                if (string.IsNullOrEmpty(this.txt) || this.txt.Length < ConfigGS.minNickSize || this.txt.Length > ConfigGS.maxNickSize)
                {
                    this.erro = 2147483648U;
                    break;
                }
                if (ComDiv.updateDB("player_bonus", "fakenick", (object)p.player_name, "player_id", (object)p.player_id) && ComDiv.updateDB("accounts", "player_name", (object)this.txt, "player_id", (object)p.player_id))
                {
                    p._bonus.fakeNick = p.player_name;
                    p.player_name     = this.txt;
                    this._client.SendPacket((SendPacket) new BASE_USER_EFFECTS_PAK(this.info.Length, p._bonus));
                    this._client.SendPacket((SendPacket) new AUTH_CHANGE_NICKNAME_PAK(p.player_name));
                    this._client.SendPacket((SendPacket) new INVENTORY_ITEM_CREATE_PAK(1, p, new ItemsModel(cupomId, 3, "FakeNick [Active]", 2, cuponDays, 0L)));
                    if (p._room == null)
                    {
                        break;
                    }
                    p._room.updateSlotsInfo();
                    break;
                }
                this.erro = 2147483648U;
                break;

            case 1200014000:
                if (ComDiv.updateDB("player_bonus", "sightcolor", (object)(int)this.objetivo, "player_id", (object)p.player_id))
                {
                    p._bonus.sightColor = (int)this.objetivo;
                    this._client.SendPacket((SendPacket) new BASE_USER_EFFECTS_PAK(this.info.Length, p._bonus));
                    this._client.SendPacket((SendPacket) new INVENTORY_ITEM_CREATE_PAK(1, p, new ItemsModel(cupomId, 3, "Cor da mira [Active]", 2, cuponDays, 0L)));
                    break;
                }
                this.erro = 2147483648U;
                break;

            case 1201047000:
                if (string.IsNullOrEmpty(this.txt) || this.txt.Length < ConfigGS.minNickSize || (this.txt.Length > ConfigGS.maxNickSize || p._inventory.getItem(1200010000) != null))
                {
                    this.erro = 2147483648U;
                    break;
                }
                if (!PlayerManager.isPlayerNameExist(this.txt))
                {
                    if (ComDiv.updateDB("accounts", "player_name", (object)this.txt, "player_id", (object)p.player_id))
                    {
                        NickHistoryManager.CreateHistory(p.player_id, p.player_name, this.txt, "Change nick");
                        p.player_name = this.txt;
                        if (p._room != null)
                        {
                            using (ROOM_GET_NICKNAME_PAK roomGetNicknamePak = new ROOM_GET_NICKNAME_PAK(p._slotId, p.player_name, p.name_color))
                                p._room.SendPacketToPlayers((SendPacket)roomGetNicknamePak);
                        }
                        this._client.SendPacket((SendPacket) new AUTH_CHANGE_NICKNAME_PAK(p.player_name));
                        if (p.clanId > 0)
                        {
                            using (CLAN_MEMBER_INFO_UPDATE_PAK memberInfoUpdatePak = new CLAN_MEMBER_INFO_UPDATE_PAK(p))
                                ClanManager.SendPacket((SendPacket)memberInfoUpdatePak, p.clanId, -1L, true, true);
                        }
                        AllUtils.syncPlayerToFriends(p, true);
                        break;
                    }
                    this.erro = 2147483648U;
                    break;
                }
                this.erro = 2147483923U;
                break;

            case 1201051000:
                if (string.IsNullOrEmpty(this.txt) || this.txt.Length > 16)
                {
                    this.erro = 2147483648U;
                    break;
                }
                Clan clan2 = ClanManager.getClan(p.clanId);
                if (clan2._id > 0 && clan2.owner_id == this._client.player_id)
                {
                    if (!ClanManager.isClanNameExist(this.txt) && ComDiv.updateDB("clan_data", "clan_name", (object)this.txt, "clan_id", (object)p.clanId))
                    {
                        clan2._name = this.txt;
                        using (CLAN_CHANGE_NAME_PAK clanChangeNamePak = new CLAN_CHANGE_NAME_PAK(this.txt))
                        {
                            ClanManager.SendPacket((SendPacket)clanChangeNamePak, p.clanId, -1L, true, true);
                            break;
                        }
                    }
                    else
                    {
                        this.erro = 2147483648U;
                        break;
                    }
                }
                else
                {
                    this.erro = 2147483648U;
                    break;
                }

            case 1201052000:
                Clan clan3 = ClanManager.getClan(p.clanId);
                if (clan3._id > 0 && clan3.owner_id == this._client.player_id && (!ClanManager.isClanLogoExist(this.objetivo) && PlayerManager.updateClanLogo(p.clanId, this.objetivo)))
                {
                    clan3._logo = this.objetivo;
                    using (CLAN_CHANGE_LOGO_PAK clanChangeLogoPak = new CLAN_CHANGE_LOGO_PAK(this.objetivo))
                    {
                        ClanManager.SendPacket((SendPacket)clanChangeLogoPak, p.clanId, -1L, true, true);
                        break;
                    }
                }
                else
                {
                    this.erro = 2147483648U;
                    break;
                }

            case 1201085000:
                if (p._room != null)
                {
                    Account playerBySlot = p._room.getPlayerBySlot((int)this.objetivo);
                    if (playerBySlot != null)
                    {
                        this._client.SendPacket((SendPacket) new ROOM_INSPECTPLAYER_PAK(playerBySlot));
                        break;
                    }
                    this.erro = 2147483648U;
                    break;
                }
                this.erro = 2147483648U;
                break;

            default:
                Logger.error("[ITEM_EFFECT] Efeito do cupom não encontrado! Id: " + (object)cupomId);
                this.erro = 2147483648U;
                break;
            }
        }