Пример #1
0
        public uint RequestUserRegister(string username, string password, AckMessageCallback callback)
        {
            RequestUserRegisterMessage message = new RequestUserRegisterMessage();

            message.username = username;
            message.password = password;
            return(Client.ClientSendAckPacket(DeliveryMethod.ReliableOrdered, MMOMessageTypes.RequestUserRegister, message, callback));
        }
Пример #2
0
        public uint RequestUserRegister(string username, string password, AckMessageCallback callback)
        {
            RequestUserRegisterMessage message = new RequestUserRegisterMessage();

            message.username = username;
            message.password = password;
            return(ClientSendRequest(MMOMessageTypes.RequestUserRegister, message, callback));
        }
Пример #3
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
        }
Пример #4
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,
            });
        }
Пример #5
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);
        }
Пример #6
0
        private IEnumerator 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;
            FindUsernameJob findUsernameJob = new FindUsernameJob(Database, username);

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

            if (findUsernameJob.result > 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
            {
                CreateUserLoginJob createUserLoginJob = new CreateUserLoginJob(Database, username, password);
                createUserLoginJob.Start();
                yield return(StartCoroutine(createUserLoginJob.WaitFor()));
            }
            ResponseUserRegisterMessage responseMessage = new ResponseUserRegisterMessage();

            responseMessage.ackId        = message.ackId;
            responseMessage.responseCode = error == ResponseUserRegisterMessage.Error.None ? AckResponseCode.Success : AckResponseCode.Error;
            responseMessage.error        = error;
            ServerSendPacket(connectionId, DeliveryMethod.ReliableOrdered, 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
        }