예제 #1
0
        protected void HandleResponseValidateAccessToken(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler transportHandler          = messageHandler.transportHandler;
            ResponseValidateAccessTokenMessage message = messageHandler.ReadMessage <ResponseValidateAccessTokenMessage>();

            transportHandler.ReadResponse(message.ackId, message.responseCode, message);
        }
예제 #2
0
        private async UniTaskVoid HandleRequestValidateAccessTokenRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestValidateAccessTokenMessage message = messageHandler.ReadMessage <RequestValidateAccessTokenMessage>();

            ResponseValidateAccessTokenMessage.Error error = ResponseValidateAccessTokenMessage.Error.None;
            string userId      = message.userId;
            string accessToken = message.accessToken;
            ValidateAccessTokenResp validateAccessTokenResp = await DbServiceClient.ValidateAccessTokenAsync(new ValidateAccessTokenReq()
            {
                UserId      = userId,
                AccessToken = accessToken
            });

            if (!validateAccessTokenResp.IsPass)
            {
                error       = ResponseValidateAccessTokenMessage.Error.InvalidAccessToken;
                userId      = string.Empty;
                accessToken = string.Empty;
            }
            else
            {
                CentralUserPeerInfo userPeerInfo;
                if (userPeersByUserId.TryGetValue(userId, out userPeerInfo))
                {
                    userPeersByUserId.Remove(userPeerInfo.userId);
                    userPeers.Remove(userPeerInfo.connectionId);
                }
                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      = userPeerInfo.userId,
                    AccessToken = accessToken
                });
            }
            ResponseValidateAccessTokenMessage responseMessage = new ResponseValidateAccessTokenMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseValidateAccessTokenMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            responseMessage.userId       = userId;
            responseMessage.accessToken  = accessToken;
            ServerSendResponse(connectionId, MMOMessageTypes.ResponseValidateAccessToken, responseMessage);
        }
예제 #3
0
        private void OnRequestValidateAccessToken(AckResponseCode responseCode, BaseAckMessage messageData, AckMessageCallback callback)
        {
            if (callback != null)
            {
                callback.Invoke(responseCode, messageData);
            }

            UserId      = string.Empty;
            AccessToken = string.Empty;
            if (messageData.responseCode == AckResponseCode.Success)
            {
                ResponseValidateAccessTokenMessage castedMessage = messageData as ResponseValidateAccessTokenMessage;
                UserId      = castedMessage.userId;
                AccessToken = castedMessage.accessToken;
            }
        }
        private void OnRequestValidateAccessToken(ResponseHandlerData responseHandler, AckResponseCode responseCode, INetSerializable response, ResponseDelegate callback)
        {
            if (callback != null)
            {
                callback.Invoke(responseHandler, responseCode, response);
            }

            UserId      = string.Empty;
            AccessToken = string.Empty;
            if (responseCode == AckResponseCode.Success)
            {
                ResponseValidateAccessTokenMessage castedResponse = response as ResponseValidateAccessTokenMessage;
                UserId      = castedResponse.userId;
                AccessToken = castedResponse.accessToken;
            }
        }
예제 #5
0
        private IEnumerator HandleRequestValidateAccessTokenRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestValidateAccessTokenMessage message = messageHandler.ReadMessage <RequestValidateAccessTokenMessage>();

            ResponseValidateAccessTokenMessage.Error error = ResponseValidateAccessTokenMessage.Error.None;
            string userId      = message.userId;
            string accessToken = message.accessToken;
            ValidateAccessTokenJob validateAccessTokenJob = new ValidateAccessTokenJob(Database, userId, accessToken);

            validateAccessTokenJob.Start();
            yield return(StartCoroutine(validateAccessTokenJob.WaitFor()));

            if (!validateAccessTokenJob.result)
            {
                error       = ResponseValidateAccessTokenMessage.Error.InvalidAccessToken;
                userId      = string.Empty;
                accessToken = string.Empty;
            }
            else
            {
                CentralUserPeerInfo userPeerInfo;
                if (userPeersByUserId.TryGetValue(userId, out userPeerInfo))
                {
                    userPeersByUserId.Remove(userPeerInfo.userId);
                    userPeers.Remove(userPeerInfo.connectionId);
                }
                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;
                UpdateAccessTokenJob updateAccessTokenJob = new UpdateAccessTokenJob(Database, userId, accessToken);
                updateAccessTokenJob.Start();
                yield return(StartCoroutine(updateAccessTokenJob.WaitFor()));
            }
            ResponseValidateAccessTokenMessage responseMessage = new ResponseValidateAccessTokenMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseValidateAccessTokenMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            responseMessage.userId       = userId;
            responseMessage.accessToken  = accessToken;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseValidateAccessToken, responseMessage);
        }
예제 #6
0
 private void OnValidateAccessToken(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseValidateAccessTokenMessage response)
 {
     if (responseCode == AckResponseCode.Success)
     {
         if (onValidateAccessTokenSuccess != null)
         {
             onValidateAccessTokenSuccess.Invoke();
         }
     }
 }
        private async UniTaskVoid OnRequestValidateAccessToken(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseValidateAccessTokenMessage response, ResponseDelegate <ResponseValidateAccessTokenMessage> callback)
        {
            await UniTask.Yield();

            if (callback != null)
            {
                callback.Invoke(responseHandler, responseCode, response);
            }

            GameInstance.UserId    = string.Empty;
            GameInstance.UserToken = string.Empty;
            if (responseCode == AckResponseCode.Success)
            {
                GameInstance.UserId    = response.userId;
                GameInstance.UserToken = response.accessToken;
            }
        }