Example #1
0
        public bool Execute(PlayerDetails playerDetails)
        {
            bool   executed = false;
            bool   error    = false;
            string msg      = "";

            try
            {
                if (_cmdElements.Length < 2 || _cmdElements.Length > 3)
                {
                    msg = "Wrong login command!";
                    return(false);
                }

                string login = _cmdElements[1];
                string pass  = (_cmdElements.Length == 3 ? _cmdElements[2] : "");

                if (_playerHandler.CheckIfLoginInUse(login))
                {
                    msg = "An account is already in use!";
                    return(false);
                }

                if (!_accountData.AccountValidation(login, pass, Models.Database.DbAccountsData.PasswordType.Decrypted))
                {
                    msg = "Wrong login or password!";
                    return(false);
                }

                playerDetails.Login             = login;
                playerDetails.LoginAttemptCount = 0;
                msg      = $"Player [{playerDetails.Login}] has logged in, TCP client ID [{playerDetails.TcpClientId}].";
                executed = true;
            }
            catch (Exception exception)
            {
                error = true;
                msg   = $"Login execution error: {exception.Message}";
            }
            finally
            {
                _logger.UpdateLog(msg);
                SendLoginCommand(playerDetails, executed, (executed ? "" : (error ? "An error occured on the server!" : msg)));
            }

            return(executed);
        }