Beispiel #1
0
        protected void HandleResponseUserLogin(LiteNetLibMessageHandler messageHandler)
        {
            TransportHandler         transportHandler = messageHandler.transportHandler;
            ResponseUserLoginMessage message          = messageHandler.ReadMessage <ResponseUserLoginMessage>();

            transportHandler.ReadResponse(message.ackId, message.responseCode, message);
        }
Beispiel #2
0
        private IEnumerator HandleRequestFacebookLoginRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestFacebookLoginMessage message = messageHandler.ReadMessage <RequestFacebookLoginMessage>();

            ResponseUserLoginMessage.Error error = ResponseUserLoginMessage.Error.None;
            string userId      = string.Empty;
            string accessToken = string.Empty;
            // Validate by facebook api
            string    url       = "https://graph.facebook.com/" + message.id + "?access_token=" + message.accessToken + "&fields=id,name,email";
            WebClient webClient = new WebClient();
            string    json      = webClient.DownloadString(url);

            json = json.Replace(@"\u0040", "@");
            Dictionary <string, object> dict = Json.Deserialize(json) as Dictionary <string, object>;

            if (dict.ContainsKey("id") && dict.ContainsKey("email"))
            {
                string           email = (string)dict["email"];
                FacebookLoginJob job   = new FacebookLoginJob(Database, message.id, email);
                job.Start();
                yield return(StartCoroutine(job.WaitFor()));

                userId = job.result;
            }
            // Response clients
            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;
                UpdateAccessTokenJob updateAccessTokenJob = new UpdateAccessTokenJob(Database, userId, accessToken);
                updateAccessTokenJob.Start();
                yield return(StartCoroutine(updateAccessTokenJob.WaitFor()));
            }
            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;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseUserLogin, responseMessage);
        }
Beispiel #3
0
        public void OnLogin(ResponseHandlerData responseHandler, AckResponseCode responseCode, INetSerializable response)
        {
            LoggingIn = false;
            string storingUsername = string.Empty;
            string storingPassword = string.Empty;

            if (responseCode == AckResponseCode.Timeout)
            {
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), LanguageManager.GetText(UITextKeys.UI_ERROR_CONNECTION_TIMEOUT.ToString()));
                if (onLoginFail != null)
                {
                    onLoginFail.Invoke();
                }
                return;
            }
            ResponseUserLoginMessage castedResponse = response as ResponseUserLoginMessage;

            switch (responseCode)
            {
            case AckResponseCode.Error:
                string errorMessage = string.Empty;
                switch (castedResponse.error)
                {
                case ResponseUserLoginMessage.Error.AlreadyLogin:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_ALREADY_LOGGED_IN.ToString());
                    break;

                case ResponseUserLoginMessage.Error.InvalidUsernameOrPassword:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_INVALID_USERNAME_OR_PASSWORD.ToString());
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), errorMessage);
                if (onLoginFail != null)
                {
                    onLoginFail.Invoke();
                }
                break;

            default:
                if (toggleAutoLogin != null && toggleAutoLogin.isOn)
                {
                    // Store password
                    PlayerPrefs.SetString(keyPassword, storingPassword);
                    PlayerPrefs.Save();
                }
                if (onLoginSuccess != null)
                {
                    onLoginSuccess.Invoke();
                }
                break;
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        private IEnumerator HandleRequestUserLoginRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestUserLoginMessage message = messageHandler.ReadMessage <RequestUserLoginMessage>();

            ResponseUserLoginMessage.Error error       = ResponseUserLoginMessage.Error.None;
            ValidateUserLoginJob           validateJob = new ValidateUserLoginJob(Database, message.username, message.password);

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

            string userId      = validateJob.result;
            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;
                UpdateAccessTokenJob updateAccessTokenJob = new UpdateAccessTokenJob(Database, userId, accessToken);
                updateAccessTokenJob.Start();
                yield return(StartCoroutine(updateAccessTokenJob.WaitFor()));
            }
            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;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, MMOMessageTypes.ResponseUserLogin, responseMessage);
        }
Beispiel #6
0
        private void OnRequestUserLogin(AckResponseCode responseCode, BaseAckMessage messageData, AckMessageCallback callback)
        {
            if (callback != null)
            {
                callback.Invoke(responseCode, messageData);
            }

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

            UserId            = string.Empty;
            AccessToken       = string.Empty;
            SelectCharacterId = string.Empty;
            if (responseCode == AckResponseCode.Success)
            {
                ResponseUserLoginMessage castedResponse = response as ResponseUserLoginMessage;
                UserId            = castedResponse.userId;
                AccessToken       = castedResponse.accessToken;
                SelectCharacterId = string.Empty;
            }
        }
        public void OnLogin(AckResponseCode responseCode, BaseAckMessage message)
        {
            ResponseUserLoginMessage castedMessage = (ResponseUserLoginMessage)message;

            switch (responseCode)
            {
            case AckResponseCode.Error:
                string errorMessage = string.Empty;
                switch (castedMessage.error)
                {
                case ResponseUserLoginMessage.Error.AlreadyLogin:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_ALREADY_LOGGED_IN.ToString());
                    break;

                case ResponseUserLoginMessage.Error.InvalidUsernameOrPassword:
                    errorMessage = LanguageManager.GetText(UITextKeys.UI_ERROR_INVALID_USERNAME_OR_PASSWORD.ToString());
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), errorMessage);
                if (onLoginFail != null)
                {
                    onLoginFail.Invoke();
                }
                break;

            case AckResponseCode.Timeout:
                UISceneGlobal.Singleton.ShowMessageDialog(LanguageManager.GetText(UITextKeys.UI_LABEL_ERROR.ToString()), LanguageManager.GetText(UITextKeys.UI_ERROR_CONNECTION_TIMEOUT.ToString()));
                if (onLoginFail != null)
                {
                    onLoginFail.Invoke();
                }
                break;

            default:
                if (onLoginSuccess != null)
                {
                    onLoginSuccess.Invoke();
                }
                break;
            }
        }
Beispiel #9
0
        public void OnLogin(AckResponseCode responseCode, BaseAckMessage message)
        {
            ResponseUserLoginMessage castedMessage = (ResponseUserLoginMessage)message;

            switch (responseCode)
            {
            case AckResponseCode.Error:
                string errorMessage = string.Empty;
                switch (castedMessage.error)
                {
                case ResponseUserLoginMessage.Error.AlreadyLogin:
                    errorMessage = "User already logged in";
                    break;

                case ResponseUserLoginMessage.Error.InvalidUsernameOrPassword:
                    errorMessage = "Invalid username or password";
                    break;
                }
                UISceneGlobal.Singleton.ShowMessageDialog("Cannot Login", errorMessage);
                if (onLoginFail != null)
                {
                    onLoginFail.Invoke();
                }
                break;

            case AckResponseCode.Timeout:
                UISceneGlobal.Singleton.ShowMessageDialog("Cannot Login", "Connection timeout");
                if (onLoginFail != null)
                {
                    onLoginFail.Invoke();
                }
                break;

            default:
                if (onLoginSuccess != null)
                {
                    onLoginSuccess.Invoke();
                }
                break;
            }
        }
Beispiel #10
0
 public void OnLogin(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseUserLoginMessage response)
 {
     if (responseCode.ShowUnhandledResponseMessageDialog(response.message))
     {
         if (onLoginFail != null)
         {
             onLoginFail.Invoke();
         }
         return;
     }
     if (onLoginSuccess != null)
     {
         onLoginSuccess.Invoke();
     }
 }
Beispiel #11
0
        public void OnLogin(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseUserLoginMessage response)
        {
            LoggingIn = false;
            string storingUsername = string.Empty;
            string storingPassword = string.Empty;

            if (responseCode.ShowUnhandledResponseMessageDialog(response.message))
            {
                if (onLoginFail != null)
                {
                    onLoginFail.Invoke();
                }
                return;
            }
            if (toggleAutoLogin != null && toggleAutoLogin.isOn)
            {
                // Store password
                PlayerPrefs.SetString(keyUsername, storingUsername);
                PlayerPrefs.SetString(keyPassword, storingPassword);
                PlayerPrefs.Save();
            }
            if (onLoginSuccess != null)
            {
                onLoginSuccess.Invoke();
            }
        }
        private async UniTaskVoid OnRequestUserLogin(ResponseHandlerData responseHandler, AckResponseCode responseCode, ResponseUserLoginMessage response, ResponseDelegate <ResponseUserLoginMessage> callback)
        {
            await UniTask.Yield();

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

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