Exemple #1
0
        protected async UniTaskVoid HandleRequestUserRegister(
            RequestHandlerData requestHandler,
            RequestUserRegisterMessage request,
            RequestProceedResultDelegate <ResponseUserRegisterMessage> result)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            UITextKeys       message          = UITextKeys.NONE;
            string           username         = request.username;
            string           password         = request.password;
            FindUsernameResp findUsernameResp = await DbServiceClient.FindUsernameAsync(new FindUsernameReq()
            {
                Username = username
            });

            if (findUsernameResp.FoundAmount > 0)
            {
                message = UITextKeys.UI_ERROR_USERNAME_EXISTED;
            }
            else if (string.IsNullOrEmpty(username) || username.Length < minUsernameLength)
            {
                message = UITextKeys.UI_ERROR_USERNAME_TOO_SHORT;
            }
            else if (username.Length > maxUsernameLength)
            {
                message = UITextKeys.UI_ERROR_USERNAME_TOO_LONG;
            }
            else if (string.IsNullOrEmpty(password) || password.Length < minPasswordLength)
            {
                message = UITextKeys.UI_ERROR_PASSWORD_TOO_SHORT;
            }
            else
            {
                await DbServiceClient.CreateUserLoginAsync(new CreateUserLoginReq()
                {
                    Username = username,
                    Password = password
                });
            }
            // Response
            result.Invoke(
                message == UITextKeys.NONE ? AckResponseCode.Success : AckResponseCode.Error,
                new ResponseUserRegisterMessage()
            {
                message = message,
            });
#endif
        }
Exemple #2
0
        protected async UniTaskVoid HandleRequestUserRegister(
            RequestHandlerData requestHandler,
            RequestUserRegisterMessage request,
            RequestProceedResultDelegate <ResponseUserRegisterMessage> result)
        {
            ResponseUserRegisterMessage.Error error = ResponseUserRegisterMessage.Error.None;
            string           username         = request.username;
            string           password         = request.password;
            FindUsernameResp findUsernameResp = await DbServiceClient.FindUsernameAsync(new FindUsernameReq()
            {
                Username = username
            });

            if (findUsernameResp.FoundAmount > 0)
            {
                error = ResponseUserRegisterMessage.Error.UsernameAlreadyExisted;
            }
            else if (string.IsNullOrEmpty(username) || username.Length < minUsernameLength)
            {
                error = ResponseUserRegisterMessage.Error.TooShortUsername;
            }
            else if (username.Length > maxUsernameLength)
            {
                error = ResponseUserRegisterMessage.Error.TooLongUsername;
            }
            else if (string.IsNullOrEmpty(password) || password.Length < minPasswordLength)
            {
                error = ResponseUserRegisterMessage.Error.TooShortPassword;
            }
            else
            {
                await DbServiceClient.CreateUserLoginAsync(new CreateUserLoginReq()
                {
                    Username = username,
                    Password = password
                });
            }
            // Response
            result.Invoke(
                error == ResponseUserRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error,
                new ResponseUserRegisterMessage()
            {
                error = error,
            });
        }
Exemple #3
0
        private async UniTaskVoid HandleRequestUserRegisterRoutine(LiteNetLibMessageHandler messageHandler)
        {
            long connectionId = messageHandler.connectionId;
            RequestUserRegisterMessage message = messageHandler.ReadMessage <RequestUserRegisterMessage>();

            ResponseUserRegisterMessage.Error error = ResponseUserRegisterMessage.Error.None;
            string           username         = message.username;
            string           password         = message.password;
            FindUsernameResp findUsernameResp = await DbServiceClient.FindUsernameAsync(new FindUsernameReq()
            {
                Username = username
            });

            if (findUsernameResp.FoundAmount > 0)
            {
                error = ResponseUserRegisterMessage.Error.UsernameAlreadyExisted;
            }
            else if (string.IsNullOrEmpty(username) || username.Length < minUsernameLength)
            {
                error = ResponseUserRegisterMessage.Error.TooShortUsername;
            }
            else if (username.Length > maxUsernameLength)
            {
                error = ResponseUserRegisterMessage.Error.TooLongUsername;
            }
            else if (string.IsNullOrEmpty(password) || password.Length < minPasswordLength)
            {
                error = ResponseUserRegisterMessage.Error.TooShortPassword;
            }
            else
            {
                await DbServiceClient.CreateUserLoginAsync(new CreateUserLoginReq()
                {
                    Username = username,
                    Password = password
                });
            }
            ResponseUserRegisterMessage responseMessage = new ResponseUserRegisterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseUserRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendResponse(connectionId, MMOMessageTypes.ResponseUserRegister, responseMessage);
        }
        protected async UniTaskVoid HandleRequestUserRegister(
            RequestHandlerData requestHandler,
            RequestUserRegisterMessage request,
            RequestProceedResultDelegate <ResponseUserRegisterMessage> result)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            if (disableDefaultLogin)
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_SERVICE_NOT_AVAILABLE
                });
                return;
            }
            string username = request.username.Trim();
            string password = request.password.Trim();
            string email    = request.email.Trim();
            if (!NameValidating.ValidateUsername(username))
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_INVALID_USERNAME
                });
                return;
            }
            if (requireEmail)
            {
                if (string.IsNullOrEmpty(email) || !Email.IsValid(email))
                {
                    result.InvokeError(new ResponseUserRegisterMessage()
                    {
                        message = UITextKeys.UI_ERROR_INVALID_EMAIL,
                    });
                    return;
                }
                AsyncResponseData <FindEmailResp> findEmailResp = await DbServiceClient.FindEmailAsync(new FindEmailReq()
                {
                    Email = email
                });

                if (!findEmailResp.IsSuccess)
                {
                    result.InvokeError(new ResponseUserRegisterMessage()
                    {
                        message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR,
                    });
                    return;
                }
                if (findEmailResp.Response.FoundAmount > 0)
                {
                    result.InvokeError(new ResponseUserRegisterMessage()
                    {
                        message = UITextKeys.UI_ERROR_EMAIL_ALREADY_IN_USE,
                    });
                    return;
                }
            }
            AsyncResponseData <FindUsernameResp> findUsernameResp = await DbServiceClient.FindUsernameAsync(new FindUsernameReq()
            {
                Username = username
            });

            if (!findUsernameResp.IsSuccess)
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR,
                });
                return;
            }
            if (findUsernameResp.Response.FoundAmount > 0)
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_USERNAME_EXISTED,
                });
                return;
            }
            if (string.IsNullOrEmpty(username) || username.Length < minUsernameLength)
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_USERNAME_TOO_SHORT,
                });
                return;
            }
            if (username.Length > maxUsernameLength)
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_USERNAME_TOO_LONG,
                });
                return;
            }
            if (string.IsNullOrEmpty(password) || password.Length < minPasswordLength)
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_PASSWORD_TOO_SHORT,
                });
                return;
            }
            AsyncResponseData <EmptyMessage> createResp = await DbServiceClient.CreateUserLoginAsync(new CreateUserLoginReq()
            {
                Username = username,
                Password = password,
                Email    = email,
            });

            if (!createResp.IsSuccess)
            {
                result.InvokeError(new ResponseUserRegisterMessage()
                {
                    message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR,
                });
                return;
            }
            // Response
            result.InvokeSuccess(new ResponseUserRegisterMessage());
#endif
        }