private GameOperationResponse HandleCreateNewUser(int sessionId, CreateUser operation) { try { var username = operation.Username.ToUpper(); var existingUserData = this.application.UserDatabase.Query <UserData>("UserData/ByUsername") //.Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Select(user => new { user.Username }) .FirstOrDefault(user => user.Username.Equals(operation.Username, StringComparison.CurrentCultureIgnoreCase)); if (existingUserData != null) { return(operation.GetErrorResponse((short)ResultCode.UsernameAlreadyExists)); } ResultCode resultCode; if (LoginHelper.IsValidUsername(username, out resultCode) == false) { return(operation.GetErrorResponse((short)resultCode)); } if (LoginHelper.IsValidPassword(operation.Password, out resultCode) == false) { return(operation.GetErrorResponse((short)resultCode)); } var passwordHash = SaltedHash.Create(operation.Password); var newUserInfo = new UserData { Id = UserData.GenerateId(username), Username = username, Salt = passwordHash.Salt, Password = passwordHash.Hash, IsBanned = false, CreatedOn = DateTime.Now, LastLogin = null, }; this.application.UserDatabase.Store(newUserInfo); return(operation.GetErrorResponse((short)ResultCode.Ok)); } catch (Exception e) { _logger.Error(e); return(operation.GetErrorResponse((short)ResultCode.Fail)); } }
protected virtual GameOperationResponse HandleOperationCreateNewUser(GameOperationRequest operationRequest, MessageParameters parameters) { var operation = new CreateUser(peer.Protocol, operationRequest); if (!operation.IsValid) { return(operation.GetErrorResponse((short)ResultCode.InvalidOperationParameter, operation.GetErrorMessage())); } ThreadPool.QueueUserWorkItem( o => this.ExecUserOperation(() => this.HandleCreateNewUser(operationRequest.ClientId, operation), operationRequest.ClientId, parameters)); return(null); }