Exemplo n.º 1
0
        public void VerifyLogin(string packet)
        {
            // TODO: implement check for maintenances
            string[] packetsplit = packet.Split(' ');
            UserDTO  user        = new UserDTO {
                Name = packetsplit[2], Password = ConfigurationManager.AppSettings["UseOldCrypto"] == "true" ? EncryptionBase.Sha512(LoginEncryption.GetPassword(packetsplit[3])).ToUpper() : packetsplit[3]
            };
            AccountDTO loadedAccount = DAOFactory.AccountDAO.LoadByName(user.Name);

            if (loadedAccount != null && loadedAccount.Password.ToUpper().Equals(user.Password))
            {
                DAOFactory.AccountDAO.WriteGeneralLog(loadedAccount.AccountId, _session.IpAddress, null, "Connection", "LoginServer");

                //check if the account is connected
                if (!ServerCommunicationClient.Instance.HubProxy.Invoke <bool>("AccountIsConnected", loadedAccount.Name).Result)
                {
                    AuthorityType type    = loadedAccount.Authority;
                    PenaltyLogDTO penalty = DAOFactory.PenaltyLogDAO.LoadByAccount(loadedAccount.AccountId).FirstOrDefault(s => s.DateEnd > DateTime.Now && s.Penalty == PenaltyType.Banned);
                    if (penalty != null)
                    {
                        _session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("BANNED"), penalty.Reason, penalty.DateEnd.ToString("yyyy-MM-dd-HH:mm"))}");
                    }
                    else
                    {
                        switch (type)
                        {
                        case AuthorityType.Unconfirmed:
                        {
                            _session.SendPacket($"fail {Language.Instance.GetMessageFromKey("NOTVALIDATE")}");
                        }
                        break;

                        default:
                        {
                            int newSessionId = SessionFactory.Instance.GenerateSessionId();
                            DAOFactory.AccountDAO.UpdateLastSessionAndIp(user.Name, newSessionId, _session.IpAddress);
                            Logger.Log.DebugFormat(Language.Instance.GetMessageFromKey("CONNECTION"), user.Name, newSessionId);

                            // inform communication service about new player from login server
                            try
                            {
                                ServerCommunicationClient.Instance.HubProxy.Invoke("RegisterAccountLogin", user.Name, newSessionId);
                            }
                            catch (Exception ex)
                            {
                                Logger.Log.Error("General Error SessionId: " + newSessionId, ex);
                            }
                            _session.SendPacket(BuildServersPacket(user.Name, newSessionId));
                        }
                        break;
                        }
                    }
                }
                else
                {
                    _session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("ALREADY_CONNECTED"))}");
                }
            }
            else
            {
                _session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("IDERROR"))}");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// login packet
        /// </summary>
        /// <param name="loginPacket"></param>
        public void VerifyLogin(LoginPacket loginPacket)
        {
            if (loginPacket == null)
            {
                return;
            }

            UserDTO user = new UserDTO
            {
                Name     = loginPacket.Name,
                Password = ConfigurationManager.AppSettings["UseOldCrypto"] == "true" ? EncryptionBase.Sha512(LoginEncryption.GetPassword(loginPacket.Password)).ToUpper() : loginPacket.Password
            };
            AccountDTO loadedAccount = DAOFactory.AccountDAO.LoadByName(user.Name);

            if (loadedAccount != null && loadedAccount.Password.ToUpper().Equals(user.Password))
            {
                DAOFactory.AccountDAO.WriteGeneralLog(loadedAccount.AccountId, _session.IpAddress, null, GeneralLogType.Connection, "LoginServer");

                //check if the account is connected
                if (!CommunicationServiceClient.Instance.IsAccountConnected(loadedAccount.AccountId))
                {
                    AuthorityType type    = loadedAccount.Authority;
                    PenaltyLogDTO penalty = DAOFactory.PenaltyLogDAO.LoadByAccount(loadedAccount.AccountId).FirstOrDefault(s => s.DateEnd > DateTime.Now && s.Penalty == PenaltyType.Banned);
                    if (penalty != null)
                    {
                        _session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("BANNED"), penalty.Reason, penalty.DateEnd.ToString("yyyy-MM-dd-HH:mm"))}");
                    }
                    else
                    {
                        switch (type)
                        {
                        case AuthorityType.Unconfirmed:
                        {
                            _session.SendPacket($"fail {Language.Instance.GetMessageFromKey("NOTVALIDATE")}");
                        }
                        break;

                        case AuthorityType.Banned:
                        {
                            _session.SendPacket($"fail {Language.Instance.GetMessageFromKey("IDERROR")}");
                        }
                        break;

                        case AuthorityType.Closed:
                        {
                            _session.SendPacket($"fail {Language.Instance.GetMessageFromKey("IDERROR")}");
                        }
                        break;

                        default:
                        {
                            int newSessionId = SessionFactory.Instance.GenerateSessionId();
                            Logger.Log.DebugFormat(Language.Instance.GetMessageFromKey("CONNECTION"), user.Name, newSessionId);

                            // inform communication service about new player from login server
                            try
                            {
                                CommunicationServiceClient.Instance.RegisterAccountLogin(loadedAccount.AccountId, newSessionId);
                            }
                            catch (Exception ex)
                            {
                                Logger.Log.Error("General Error SessionId: " + newSessionId, ex);
                            }
                            _session.SendPacket(BuildServersPacket(loadedAccount.AccountId, newSessionId));
                        }
                        break;
                        }
                    }
                }
                else
                {
                    _session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("ALREADY_CONNECTED"))}");
                }
            }
            else
            {
                _session.SendPacket($"fail {string.Format(Language.Instance.GetMessageFromKey("IDERROR"))}");
            }
        }
        /// <summary>
        /// login packet
        /// </summary>
        /// <param name="loginPacket"></param>
        public void VerifyLogin(LoginPacket loginPacket)
        {
            if (loginPacket == null)
            {
                return;
            }

            UserDTO user = new UserDTO
            {
                Name     = loginPacket.Name,
                Password = ConfigurationManager.AppSettings["UseOldCrypto"] == "true" ? EncryptionBase.Sha512(LoginEncryption.GetPassword(loginPacket.Password)).ToUpper() : loginPacket.Password
            };
            AccountDTO loadedAccount = DaoFactory.AccountDao.LoadByName(user.Name);

            if (loadedAccount != null && loadedAccount.Password.ToUpper().Equals(user.Password))
            {
                DaoFactory.AccountDao.WriteGeneralLog(loadedAccount.AccountId, _session.IpAddress, null, GeneralLogType.Connection, "LoginServer");

                //check if the account is connected
                if (!CommunicationServiceClient.Instance.IsAccountConnected(loadedAccount.AccountId))
                {
                    AuthorityType type    = loadedAccount.Authority;
                    PenaltyLogDTO penalty = DaoFactory.PenaltyLogDao.LoadByAccount(loadedAccount.AccountId).FirstOrDefault(s => s.DateEnd > DateTime.Now && s.Penalty == PenaltyType.Banned);
                    if (penalty != null)
                    {
                        _session.SendPacket($"failc 7");
                    }
                    else
                    {
                        switch (type)
                        {
                        // TODO TO ENUM
                        case AuthorityType.Unconfirmed:
                        {
                            _session.SendPacket($"failc {(byte)LoginFailType.CantConnect}");
                        }
                        break;

                        case AuthorityType.Banned:
                        {
                            _session.SendPacket($"failc {(byte)LoginFailType.Banned}");
                        }
                        break;

                        case AuthorityType.Closed:
                        {
                            _session.SendPacket($"failc {(byte)LoginFailType.CantConnect}");
                        }
                        break;

                        default:
                        {
                            int newSessionId = SessionFactory.Instance.GenerateSessionId();
                            Logger.Log.DebugFormat(Language.Instance.GetMessageFromKey("CONNECTION"), user.Name, newSessionId);

                            if (CommunicationServiceClient.Instance.GetMaintenanceState() && _session.Account.Authority <= AuthorityType.GameMaster)
                            {
                                _session.SendPacket("failc 2");
                                return;
                            }
                            try
                            {
                                CommunicationServiceClient.Instance.RegisterAccountLogin(loadedAccount.AccountId, newSessionId, loadedAccount.Name);
                            }
                            catch (Exception ex)
                            {
                                Logger.Log.Error("General Error SessionId: " + newSessionId, ex);
                            }
                            _session.SendPacket(BuildServersPacket(loadedAccount.AccountId, newSessionId));
                        }
                        break;
                        }
                    }
                }
                else
                {
                    _session.SendPacket($"failc {(byte)LoginFailType.AlreadyConnected}");
                }
            }
            else
            {
                _session.SendPacket($"failc {(byte)LoginFailType.AccountOrPasswordWrong}");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// login packet
        /// </summary>
        /// <param name="loginPacket"></param>
        public void VerifyLogin(LoginPacket loginPacket)
        {
            if (loginPacket == null)
            {
                return;
            }

            UserDTO user = new UserDTO
            {
                Name     = loginPacket.Name,
                Password = ConfigurationManager.AppSettings["UseOldCrypto"] == "true" ? EncryptionBase.Sha512(LoginEncryption.GetPassword(loginPacket.Password)).ToUpper() : loginPacket.Password
            };
            AccountDTO loadedAccount = DAOFactory.AccountDAO.FirstOrDefault(s => s.Name == user.Name);

            if (loadedAccount != null && loadedAccount.Password.ToUpper().Equals(user.Password))
            {
                // TODO LOG LOGIN

                //check if the account is connected
                if (!CommunicationServiceClient.Instance.IsAccountConnected(loadedAccount.AccountId))
                {
                    AuthorityType type    = loadedAccount.Authority;
                    PenaltyLogDTO penalty = DAOFactory.PenaltyLogDAO.FirstOrDefault(s => s.AccountId.Equals(loadedAccount.AccountId) && s.DateEnd > DateTime.Now && s.Penalty == PenaltyType.Banned);
                    if (penalty != null)
                    {
                        _session.SendPacket($"failc 7");
                    }
                    else
                    {
                        switch (type)
                        {
                        // TODO TO ENUM
                        case AuthorityType.Unconfirmed:
                        {
                            _session.SendPacket($"failc {(byte)LoginFailType.CantConnect}");
                        }
                        break;

                        case AuthorityType.Banned:
                        {
                            _session.SendPacket($"failc {(byte)LoginFailType.Banned}");
                        }
                        break;

                        case AuthorityType.Closed:
                        {
                            _session.SendPacket($"failc {(byte)LoginFailType.CantConnect}");
                        }
                        break;

                        default:
                        {
                            int newSessionId = SessionFactory.Instance.GenerateSessionId();
                            Logger.Log.DebugFormat(Language.Instance.GetMessageFromKey("CONNECTION"), user.Name, newSessionId);

                            // TODO MAINTENANCE MODE (MASTER SERVER)
                            // IF MAINTENANCE
                            // _session.SendPacket($"failc 2");
                            // inform communication service about new player from login server
                            try
                            {
                                CommunicationServiceClient.Instance.RegisterAccountLogin(loadedAccount.AccountId, newSessionId, loadedAccount.Name);
                            }
                            catch (Exception ex)
                            {
                                Logger.Log.Error("General Error SessionId: " + newSessionId, ex);
                            }
                            _session.SendPacket(BuildServersPacket(loadedAccount.AccountId, newSessionId));
                        }
                        break;
                        }
                    }
                }
                else
                {
                    _session.SendPacket($"failc {(byte)LoginFailType.AlreadyConnected}");
                }
            }
            else
            {
                _session.SendPacket($"failc {(byte)LoginFailType.AccountOrPasswordWrong}");
            }
        }