コード例 #1
0
        private GameOperationResponse HandleLoginUser(int sessionId, LoginUser operation)
        {
            try
            {
                var userData = this.application.UserDatabase.Query <UserData>("UserData/ByUsername")
                               //.Customize(x => x.WaitForNonStaleResultsAsOfNow())
                               .Select(user => new { user.Username, user.Salt, user.Password })
                               .FirstOrDefault(user => user.Username.Equals(operation.Username, StringComparison.CurrentCultureIgnoreCase));
                if (userData == null)
                {
                    return(operation.GetErrorResponse((short)ResultCode.IncorrectUsernameOrPassword));
                }

                var passwordHash = SaltedHash.Create(userData.Salt, userData.Password);
                if (passwordHash.Verify(operation.Password) == false)
                {
                    return(operation.GetErrorResponse((short)ResultCode.IncorrectUsernameOrPassword));
                }

                // requesting master to authorize client
                this.peer.SendOperationRequest(new OperationRequest((byte)ServerOperationCode.AckClientUserLogin,
                                                                    new AckClientUserLogin
                {
                    SessionId = sessionId,
                    Username  = userData.Username
                }),
                                               new SendParameters());
                return(null);
            }
            catch (Exception e)
            {
                _logger.Error(e);
                return(operation.GetErrorResponse((short)ResultCode.Fail));
            }
        }
コード例 #2
0
        protected virtual GameOperationResponse HandleOperationLogin(GameOperationRequest operationRequest, MessageParameters parameters)
        {
            var operation = new LoginUser(peer.Protocol, operationRequest);

            if (!operation.IsValid)
            {
                return(operation.GetErrorResponse((short)ResultCode.InvalidOperationParameter, operation.GetErrorMessage()));
            }

            ThreadPool.QueueUserWorkItem(
                o => this.ExecUserOperation(() => this.HandleLoginUser(operationRequest.ClientId, operation), operationRequest.ClientId, parameters));

            return(null);
        }