/// <summary>
        /// Fecha a conexão do cliente.
        /// </summary>
        /// <param name="destroyConn">Destruir conexão?</param>
        /// <param name="time">Tempo de espera para cancelar o recebimento de pacotes (milissegundos)</param>
        public void Close(bool destroyConnection, int time = 0)
        {
            if (closed)
            {
                return;
            }

            try
            {
                closed = true;
                LoginManager.RemoveSocket(this);
                Account player = _player;
                if (destroyConnection)
                {
                    if (player != null)
                    {
                        player.setOnlineStatus(false);
                        if (player._status.serverId == 0)
                        {
                            SEND_REFRESH_ACC.RefreshAccount(player, false);
                        }
                        player._status.ResetData(player.player_id);
                        player.SimpleClear();
                        player.updateCacheInfo();
                        _player = null;
                    }
                    _client.Close(time);
                    Thread.Sleep(time);
                    Dispose();
                }
                else if (player != null)
                {
                    player.SimpleClear();
                    player.updateCacheInfo();
                    _player = null;
                }
                Auth_SyncNet.UpdateAuthCount(0);
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[LoginClient.Close] Erro fatal!");
            }
        }
Beispiel #2
0
 public void Close(int time, bool destroyConnection)
 {
     if (this.closed)
     {
         return;
     }
     try
     {
         this.closed = true;
         LoginManager.RemoveSocket(this);
         Account player = this._player;
         if (destroyConnection)
         {
             if (player != null)
             {
                 player.setOnlineStatus(false);
                 if (player._status.serverId == (byte)0)
                 {
                     SEND_REFRESH_ACC.RefreshAccount(player, false);
                 }
                 player._status.ResetData(player.player_id);
                 player.SimpleClear();
                 player.updateCacheInfo();
                 this._player = (Account)null;
             }
             this._client.Close(time);
             Thread.Sleep(time);
             this.Dispose();
         }
         else if (player != null)
         {
             player.SimpleClear();
             player.updateCacheInfo();
             this._player = (Account)null;
         }
         Auth_SyncNet.UpdateGSCount(0);
     }
     catch (Exception ex)
     {
         Logger.warning("[LoginClient.Close] " + ex.ToString());
     }
 }
Beispiel #3
0
        public override void run()
        {
            try
            {
                /*
                 * switch (login)
                 * {
                 *  case "1":
                 *      // ID incorreta ou inexistente (Fecha Client)
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.LOGIN_EVENT_ERROR, login, 0));
                 *      break;
                 *  case "2":
                 *      // Este usuario esta conectado, tente conectar novamente mais tarde (Fecha)
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_ALREADY_LOGIN_WEB, login, 0));
                 *      break;
                 *  case "3":
                 *      // Usuario ou senha incorreta
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_USER_PASS_FAIL, login, 0));
                 *      break;
                 *  case "4":
                 *      // A conexão foi finalizada
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_LOGOUTING, login, 0));
                 *      break;
                 *  case "5":
                 *      // Tempo para tentativa de conexão com o servidor excedido, tente mais tarde
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_TIME_OUT_1, login, 0));
                 *      break;
                 *  case "6":
                 *      // Falha ao logar, tente conectar mais tarde
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_TIME_OUT_2, login, 0));
                 *      break;
                 *  case "7":
                 *      // Sua conta está bloqueada
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_ACCOUNT, login, 0));
                 *      break;
                 *  case "8":
                 *      // Devido ao excesso de usuarios no servidor, não foi possivel conectar
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_SERVER_USER_FULL, login, 0));
                 *      break;
                 *  case "9":
                 *      // Falha na conexão com o servidor, tente mais tarde
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_DB_BUFFER_FAIL, login, 0));
                 *      break;
                 *  case "10":
                 *      // ID ou senha incorretos
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_ID_PASS_INCORRECT, login, 0));
                 *      break;
                 *  case "11":
                 *      // ID ou senha incorretos
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_ID_PASS_INCORRECT2, login, 0));
                 *      break;
                 *  case "12":
                 *      // Falha na autenticação do email
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_EMAIL_AUTH_ERROR, login, 0));
                 *      break;
                 *  case "13":
                 *      // IP Bloqueado
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_IP, login, 0));
                 *      break;
                 *  case "14":
                 *      // STBL_IDX_EP_LOGIN_OK_EMAIL_ALERT_2
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_EMAIL_ALERT2, login, 0));
                 *      break;
                 *  case "15":
                 *      // STR_POPUP_MESSAGE_MIGRATION
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_MIGRATION, login, 0));
                 *      break;
                 *  case "16":
                 *      // ID incorreta ou inexistente (Fecha)
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_NON_STRING, login, 0));
                 *      break;
                 *  case "17":
                 *      // Login bloqueado devido a região
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_COUNTRY, login, 0));
                 *      break;
                 *  case "18":
                 *      // Usuario ou senha incorreta
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_INVALID_ACCOUNT, login, 0));
                 *      break;
                 *  case "19":
                 *      // VAZIO (Fecha)
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_PC_BLOCK, login, 0));
                 *      break;
                 *  case "20":
                 *      // Falha ao listar inventario, o jogo será fechado (Fecha)
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_INVENTORY_FAIL, login, 0));
                 *      break;
                 *  case "21":
                 *      // Sua conta está bloqueada
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_INNER, login, 0));
                 *      break;
                 *  case "22":
                 *      // Sua conta está bloqueada
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_OUTER, login, 0));
                 *      break;
                 *  case "23":
                 *      // Sua conta está bloqueada
                 *      _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_GAME, login, 0));
                 *      break;
                 *
                 * }
                 *
                 * return;
                 */



                string         Requisto_msg = "";
                EventErrorEnum erro         = 0;
                bool           block        = false;


                if (ConfigGA.LauncherKey != 0 && key != ConfigGA.LauncherKey)
                {
                    Requisto_msg = "Chave: " + key + " não compatível [" + login + "]";
                    block        = true;
                }
                else if (!ConfigGA.GameLocales.Contains(GameLocale))
                {
                    erro         = EventErrorEnum.Login_BLOCK_COUNTRY;
                    Requisto_msg = "País: " + GameLocale + " do cliente bloqueado [" + login + "]";
                }
                else if (GameVersion != ServerConfig.ClientVersion)
                {
                    Requisto_msg = "Versão: " + GameVersion + " não compatível [" + login + "]";
                }

                else if (ConfigGA.UserFileList != "0" && UserFileListMD5.ToLower() != ConfigGA.UserFileList.ToLower())
                {
                    Requisto_msg = "UserFileList: " + UserFileListMD5 + " não compatível [" + login + "]";
                }
                else if (ConfigGA.ValidIP &&
                         (
                             !LocalIP.checkInSubNet(IPAddress.Parse("192.168.0.0"), 16) &&
                             !LocalIP.checkInSubNet(IPAddress.Parse("10.0.0.0"), 8) &&
                             !LocalIP.checkInSubNet(IPAddress.Parse("172.16.0.0"), 12)
                         )
                         )
                {
                    erro         = EventErrorEnum.Login_BLOCK_IP;
                    Requisto_msg = "IP local inválido. {" + LocalIP + "} [" + login + "]";
                    block        = true;
                }
                else if (!DirectxMD5.IsValid(d3d9MD5.ToLower()))
                {
                    Requisto_msg = "d3d9MD5 nao listada: " + d3d9MD5 + " [" + login + "]";
                    block        = true;
                }



                if (!allowBot(login, password) && !ConfigGA.isTestMode)
                {
                    if (Requisto_msg != "")
                    {
                        Requisto_msg = "[" + PublicIP + "] " + Requisto_msg;

                        if (block)
                        {
                            Firewall.sendBlock(PublicIP, Requisto_msg, 2);
                        }

                        if (erro == 0 || ConfigGA.modeAtack)
                        {
                            _client.Close(true);
                        }
                        else
                        {
                            _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.LOGIN_EVENT_ERROR, login, 0));
                            _client.Close(false);
                        }

                        if (!ConfigGA.modeAtack)
                        {
                            SaveLog.LogLoginFaill(Requisto_msg);
                        }

                        Printf.info(Requisto_msg);

                        return;
                    }
                    if (passSize > ConfigGA.maxPassSize || passSize < ConfigGA.minPassSize)
                    {
                        _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_INVALID_ACCOUNT, login, 0));
                        SaveLog.LogLoginFaill("LOGIN - Tamanho de senha invalido " + passSize + " [" + login + "]");
                        return;
                    }
                    if (loginSize > ConfigGA.maxLoginSize || loginSize < ConfigGA.minLoginSize)
                    {
                        _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_INVALID_ACCOUNT, login, 0));
                        SaveLog.LogLoginFaill("LOGIN - Tamanho de login invalido " + loginSize + " [" + login + "]");
                        return;
                    }
                }

                // Verifica se o MAC ou IP tá bloqueado
                if (Banimento.GetBanStatus(MacAddress))
                {
                    Printf.info("Usuario: " + login + " tentou logar com MAC bloqueado");
                    SaveLog.LogLoginFaill("MAC " + MacAddress.ToString() + " banido [" + login + "]");
                    _client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_PC_BLOCK, login, 0));
                    _client.Close(false);
                    return;
                }

                _client._player = AccountManager.getInstance().getAccountDB(login, null, 0, 0);
                if (_client._player == null)
                {
                    _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_INVALID_ACCOUNT, login, 0L));
                    _client.Close(false);
                    return;
                }
                Account p = _client._player;
                if (p == null)
                {
                    _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_INVALID_ACCOUNT, login, 0));
                    SaveLog.LogLoginFaill("Conta retornada da DB é nula [" + login + "]");
                    _client.Close(false);
                    return;
                }
                if (!ConfigGA.isTestMode && !p.password.Equals(password))
                {
                    _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_ID_PASS_INCORRECT2, login, 0));
                    SaveLog.LogLoginFaill("Senha inválida [" + login + "]");
                    return;
                }
                if (p.access < 0)
                {
                    Printf.info("Usuario: " + login + " banido tentou logar");
                    SaveLog.LogLoginFaill("LOGIN - Banido permanente [" + login + "]");
                    _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_ACCOUNT, login, 0));
                    _client.Close(false);
                    return;
                }


                if (ConfigGA.onlyGM && !p.IsGM())
                {
                    SaveLog.LogLoginFaill("LOGIN - Login cancelado, apenas GM! [" + login + "]");
                    _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_TIME_OUT_2, login, 0));
                    _client.Close(false);
                    return;
                }

                Account pCache = AccountManager.getInstance().getAccount(p.player_id, true);
                if (p._isOnline) // Usuario já esta online
                {
                    _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_ALREADY_LOGIN_WEB, login, 0));
                    SaveLog.LogLoginFaill("LOGIN - Conta online [" + login + "]");
                    if (pCache != null && pCache._connection != null)
                    {
                        pCache.SendPacket(new AUTH_ACCOUNT_KICK_PAK(1));
                        pCache.SendPacket(new SERVER_MESSAGE_ERROR_PAK(2147487744));
                        pCache.Close(1000);
                    }
                    else
                    {
                        Auth_SyncNet.SendLoginKickInfo(p);
                    }
                    _client.Close(false);
                    return;
                }

                if (Banimento.checkBan(p.player_id))
                {
                    SaveLog.LogLoginFaill("LOGIN - Conta com ban ativo [" + login + "]");
                    _client.SendPacket(new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_ACCOUNT, login, 0));
                    _client.Close(false);
                    return;
                }


                //  Registrar ACESSO
                ComDiv.updateDB("contas", "player_id", p.player_id, new string[] { "lastip", "last_mac", "last_login" }, PublicIP, MacAddress, long.Parse(DateTime.Now.ToString("yyMMddHHmm")));

                // Faz login
                p.SetPlayerId(p.player_id, 31);
                p._clanPlayers = ClanManager.getClanPlayers(p.clan_id, p.player_id);
                _client.SendPacket(new BASE_LOGIN_PAK(0, login, p.player_id));
                _client.SendPacket(new AUTH_WEB_CASH_PAK(0));
                if (p.clan_id > 0)
                {
                    _client.SendPacket(new BASE_USER_CLAN_MEMBERS_PAK(p._clanPlayers));
                }
                p._status.SetData(4294967295, p.player_id);
                p._status.updateServer(0);
                p.setOnlineStatus(true);
                if (pCache != null)
                {
                    pCache._connection = _client;
                }
                SEND_REFRESH_ACC.RefreshAccount(p, true);

                if (ConfigGA.displayLogin)
                {
                    Printf.sucess("[" + login + "] Autenticou-se " + PublicIP);
                }

                SaveLog.info("[LOGIN] user:"******"; " + PublicIP + "; " + MacAddress);

                // Libera no firewall
                Firewall.sendAllow(PublicIP);
            }
            catch (Exception ex)
            {
                SaveLog.fatal(ex.ToString());
                Printf.b_danger("[BASE_LOGIN_REC.run] Erro fatal!");
            }
        }
Beispiel #4
0
 public override void run()
 {
     try
     {
         bool isD3D9Valid = DirectXML.IsValid(this.d3d9MD5);
         if (!isD3D9Valid)
         {
             Logger.warning("No listed: " + this.d3d9MD5);
         }
         ServerConfig config = LoginManager.Config;
         string       reason;
         if (!this.IsPacketDataValid(config, isD3D9Valid, out reason))
         {
             Logger.LogLogin(reason);
             this._client.SendPacket((SendPacket) new SERVER_MESSAGE_DISCONNECT_PAK(2147483904U, false));
             this._client.Close(1000, true);
         }
         else
         {
             this._client._player = AccountManager.getInstance().getAccountDB((object)this.login, (object)null, 0, 0);
             if (this._client._player == null && ConfigGA.AUTO_ACCOUNTS && !AccountManager.getInstance().CreateAccount(out this._client._player, this.login, this.passEnc, this._client.GetAddress()))
             {
                 Logger.LogLogin("Falha ao criar conta automaticamente [" + this.login + "]");
                 this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_USER_PASS_FAIL, this.login, 0L));
                 this._client.Close(1000, false);
             }
             else
             {
                 Account player = this._client._player;
                 if (player == null || !player.ComparePassword(this.passEnc))
                 {
                     string str = "";
                     if (player == null)
                     {
                         str = "Conta retornada da DB é nula";
                     }
                     else if (!player.ComparePassword(this.passEnc))
                     {
                         str = "Senha inválida";
                     }
                     Logger.LogLogin(str + " [" + this.login + "]");
                     this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_USER_PASS_FAIL, this.login, 0L));
                     this._client.Close(1000, false);
                 }
                 else if (player.access >= 0)
                 {
                     if (player.MacAddress != this.MacAddress)
                     {
                         ComDiv.updateDB("accounts", "last_mac", (object)this.MacAddress, "player_id", (object)player.player_id);
                     }
                     bool validMac;
                     bool validIp;
                     BanManager.GetBanStatus(this.MacAddress.ToString(), this.PublicIP, out validMac, out validIp);
                     if (validMac | validIp)
                     {
                         if (validMac)
                         {
                             Logger.LogLogin("MAC banido [" + this.login + "]");
                         }
                         else
                         {
                             Logger.LogLogin("IP banido [" + this.login + "]");
                         }
                         this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(validIp ? EventErrorEnum.Login_BLOCK_IP : EventErrorEnum.Login_BLOCK_ACCOUNT, this.login, 0L));
                         this._client.Close(1000, false);
                     }
                     else if (player.IsGM() && config.onlyGM || player.access >= 0 && !config.onlyGM)
                     {
                         Account account = AccountManager.getInstance().getAccount(player.player_id, true);
                         if (!player._isOnline)
                         {
                             if (BanManager.GetAccountBan(player.ban_obj_id).endDate > DateTime.Now)
                             {
                                 Logger.LogLogin("Conta com banimento ativo [" + this.login + "]");
                                 this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_ACCOUNT, this.login, 0L));
                                 this._client.Close(1000, false);
                             }
                             else
                             {
                                 player.SetPlayerId(player.player_id, 31);
                                 player._clanPlayers = ClanManager.getClanPlayers(player.clan_id, player.player_id);
                                 this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(0, this.login, player.player_id));
                                 this._client.SendPacket((SendPacket) new AUTH_WEB_CASH_PAK(0, 0, 0));
                                 if (player.clan_id > 0)
                                 {
                                     this._client.SendPacket((SendPacket) new BASE_USER_CLAN_MEMBERS_PAK(player._clanPlayers));
                                 }
                                 player._status.SetData(uint.MaxValue, player.player_id);
                                 player._status.updateServer((byte)0);
                                 player.setOnlineStatus(true);
                                 if (account != null)
                                 {
                                     account._connection = this._client;
                                 }
                                 SEND_REFRESH_ACC.RefreshAccount(player, true);
                             }
                         }
                         else
                         {
                             Logger.LogLogin("Conta online [" + this.login + "]");
                             this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_ALREADY_LOGIN_WEB, this.login, 0L));
                             if (account != null && account._connection != null)
                             {
                                 account.SendPacket((SendPacket) new AUTH_ACCOUNT_KICK_PAK(1));
                                 account.SendPacket((SendPacket) new SERVER_MESSAGE_ERROR_PAK(2147487744U));
                                 account.Close(1000);
                             }
                             else
                             {
                                 Auth_SyncNet.SendLoginKickInfo(player);
                             }
                             this._client.Close(1000, false);
                         }
                     }
                     else
                     {
                         Logger.LogLogin("Nível de acesso inválido [" + this.login + "]");
                         this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_TIME_OUT_2, this.login, 0L));
                         this._client.Close(1000, false);
                     }
                 }
                 else
                 {
                     Logger.LogLogin("Banido permanente [" + this.login + "]");
                     this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_BLOCK_ACCOUNT, this.login, 0L));
                     this._client.Close(1000, false);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Logger.warning("[BASE_LOGIN_REC] " + ex.ToString());
     }
 }