protected async UniTaskVoid HandleRequestUserLogin( RequestHandlerData requestHandler, RequestUserLoginMessage request, RequestProceedResultDelegate <ResponseUserLoginMessage> result) { long connectionId = requestHandler.ConnectionId; ResponseUserLoginMessage.Error error = ResponseUserLoginMessage.Error.None; ValidateUserLoginResp validateUserLoginResp = await DbServiceClient.ValidateUserLoginAsync(new ValidateUserLoginReq() { Username = request.username, Password = request.password }); string userId = validateUserLoginResp.UserId; string accessToken = string.Empty; if (string.IsNullOrEmpty(userId)) { error = ResponseUserLoginMessage.Error.InvalidUsernameOrPassword; userId = string.Empty; } else if (userPeersByUserId.ContainsKey(userId) || MapContainsUser(userId)) { error = ResponseUserLoginMessage.Error.AlreadyLogin; userId = string.Empty; } else { CentralUserPeerInfo userPeerInfo = new CentralUserPeerInfo(); userPeerInfo.connectionId = connectionId; userPeerInfo.userId = userId; userPeerInfo.accessToken = accessToken = Regex.Replace(System.Convert.ToBase64String(System.Guid.NewGuid().ToByteArray()), "[/+=]", ""); userPeersByUserId[userId] = userPeerInfo; userPeers[connectionId] = userPeerInfo; await DbServiceClient.UpdateAccessTokenAsync(new UpdateAccessTokenReq() { UserId = userId, AccessToken = accessToken }); } // Response result.Invoke( error == ResponseUserLoginMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error, new ResponseUserLoginMessage() { error = error, userId = userId, accessToken = accessToken, }); }
protected async UniTaskVoid HandleRequestUserLogin( RequestHandlerData requestHandler, RequestUserLoginMessage request, RequestProceedResultDelegate <ResponseUserLoginMessage> result) { #if UNITY_STANDALONE && !CLIENT_BUILD long connectionId = requestHandler.ConnectionId; UITextKeys message = UITextKeys.NONE; ValidateUserLoginResp validateUserLoginResp = await DbServiceClient.ValidateUserLoginAsync(new ValidateUserLoginReq() { Username = request.username, Password = request.password }); string userId = validateUserLoginResp.UserId; string accessToken = string.Empty; if (string.IsNullOrEmpty(userId)) { message = UITextKeys.UI_ERROR_INVALID_USERNAME_OR_PASSWORD; userId = string.Empty; } else if (userPeersByUserId.ContainsKey(userId) || MapContainsUser(userId)) { message = UITextKeys.UI_ERROR_ALREADY_LOGGED_IN; userId = string.Empty; } else { CentralUserPeerInfo userPeerInfo = new CentralUserPeerInfo(); userPeerInfo.connectionId = connectionId; userPeerInfo.userId = userId; userPeerInfo.accessToken = accessToken = Regex.Replace(System.Convert.ToBase64String(System.Guid.NewGuid().ToByteArray()), "[/+=]", ""); userPeersByUserId[userId] = userPeerInfo; userPeers[connectionId] = userPeerInfo; await DbServiceClient.UpdateAccessTokenAsync(new UpdateAccessTokenReq() { UserId = userId, AccessToken = accessToken }); } // Response result.Invoke( message == UITextKeys.NONE ? AckResponseCode.Success : AckResponseCode.Error, new ResponseUserLoginMessage() { message = message, userId = userId, accessToken = accessToken, }); #endif }
private async UniTaskVoid HandleRequestUserLoginRoutine(LiteNetLibMessageHandler messageHandler) { long connectionId = messageHandler.connectionId; RequestUserLoginMessage message = messageHandler.ReadMessage <RequestUserLoginMessage>(); ResponseUserLoginMessage.Error error = ResponseUserLoginMessage.Error.None; ValidateUserLoginResp validateUserLoginResp = await DbServiceClient.ValidateUserLoginAsync(new ValidateUserLoginReq() { Username = message.username, Password = message.password }); string userId = validateUserLoginResp.UserId; string accessToken = string.Empty; if (string.IsNullOrEmpty(userId)) { error = ResponseUserLoginMessage.Error.InvalidUsernameOrPassword; userId = string.Empty; } else if (userPeersByUserId.ContainsKey(userId) || MapContainsUser(userId)) { error = ResponseUserLoginMessage.Error.AlreadyLogin; userId = string.Empty; } else { CentralUserPeerInfo userPeerInfo = new CentralUserPeerInfo(); userPeerInfo.connectionId = connectionId; userPeerInfo.userId = userId; userPeerInfo.accessToken = accessToken = Regex.Replace(Convert.ToBase64String(Guid.NewGuid().ToByteArray()), "[/+=]", ""); userPeersByUserId[userId] = userPeerInfo; userPeers[connectionId] = userPeerInfo; await DbServiceClient.UpdateAccessTokenAsync(new UpdateAccessTokenReq() { UserId = userId, AccessToken = accessToken }); } ResponseUserLoginMessage responseMessage = new ResponseUserLoginMessage(); responseMessage.ackId = message.ackId; responseMessage.responseCode = error == ResponseUserLoginMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error; responseMessage.error = error; responseMessage.userId = userId; responseMessage.accessToken = accessToken; ServerSendResponse(connectionId, MMOMessageTypes.ResponseUserLogin, responseMessage); }