public int Step1(string username, LobbyServiceResult service, LobbyCharacterResult character, long[] trace)
        {
            if (CheckVendor.NotValidUsername(username) ||
                CheckVendor.NotValidService(service) ||
                CheckVendor.NotValidCharacter(character) ||
                CheckVendor.NotValidTrace(trace))
            {
                return(03_0010);
            }

            _username = username;
            var recoveryGame = new RecoveryGame();

            recoveryGame.Username = username;

            recoveryGame.Service = service;

            recoveryGame.Character = character;

            recoveryGame.Trace = trace;

            recoveryGame.ReportTime = DateTime.Now;

            for (var i = 0; i < 3; i++)
            {
                var result = ApiCall.AccountRecoveryGame.Call(null, new MilvanethProtocol {
                    Context = null, Data = recoveryGame
                });

                if (!(result.Data is ServerResponse sr))
                {
                    return(02_0007);
                }

                if (!CheckVendor.NotValidResponse(sr))
                {
                    _serverResponse = sr;
                }

                if (sr.Message != 01_0003) // retry with pow
                {
                    return(sr.Message);
                }

                recoveryGame.ProofOfWork = ProofOfWorkVendor.CalculateProofOfWork(sr.AuthToken);
            }

            return(01_0002);
        }
Exemple #2
0
        public int Step1(string username, long[] trace)
        {
            var clientChallenge = new ClientChallenge();

            if (CheckVendor.NotValidUsername(username) || CheckVendor.NotValidTrace(trace))
            {
                return(03_0010);
            }

            clientChallenge.Trace = trace;

            _username = username;
            clientChallenge.Username = username;

            clientChallenge.ReportTime = DateTime.Now;

            for (var i = 0; i < 3; i++)
            {
                var result = ApiCall.AuthStart.Call(null, new MilvanethProtocol {
                    Context = null, Data = clientChallenge
                });

                if (!(result.Data is ServerChallenge sc))
                {
                    return(02_0007);
                }

                if (!CheckVendor.NotValidResponse(sc))
                {
                    _serverChallenge = sc;
                }

                if (sc.Message != 01_0003) // retry with pow
                {
                    return(sc.Message);
                }

                clientChallenge.SessionId = sc.SessionId;

                clientChallenge.ProofOfWork = ProofOfWorkVendor.CalculateProofOfWork(sc.ProofOfWork);
            }

            return(01_0002);
        }
Exemple #3
0
        public int Step1(LobbyServiceResult service, LobbyCharacterResult character, string username, string displayName, string email, byte[] password, long[] trace)
        {
            var registerForm = new RegisterForm();

            if (CheckVendor.NotValidService(service))
            {
                return(03_0000);
            }

            registerForm.Service = service;

            if (CheckVendor.NotValidCharacter(character))
            {
                return(03_0000);
            }

            registerForm.Character = character;

            if (CheckVendor.NotValidTrace(trace))
            {
                return(03_0008);
            }

            registerForm.Trace = trace;

            // 4-16个字符,可使用英文、数字和下划线,必须以字母开头
            if (CheckVendor.NotValidUsername(username))
            {
                return(03_0001);
            }

            registerForm.Username = username;

            // 2-12个字符,可使用中英文、数字和下划线
            if (CheckVendor.NotValidDisplayName(displayName))
            {
                return(03_0003);
            }

            registerForm.DisplayName = displayName;

            if (CheckVendor.NotValidEmail(email))
            {
                return(03_0005);
            }

            registerForm.Email = email;

            // 4个字符以上的中文或8个字符以上的数字和字母
            if (CheckVendor.NotValidPassword(password))
            {
                return(03_0007);
            }

            _username = username;
            _password = password;

            registerForm.Verifier = Srp6Vendor.Srp6Init(username, password, out var salt).ToByteArray();

            registerForm.Salt = salt;

            registerForm.GroupParam = Srp6Vendor.BitLength;

            registerForm.ReportTime = DateTime.Now;

            for (var i = 0; i < 3; i++)
            {
                var result = ApiCall.AccountCreate.Call(null, new MilvanethProtocol {
                    Context = null, Data = registerForm
                });

                if (!(result.Data is ServerChallenge sc))
                {
                    return(02_0007);
                }

                if (!CheckVendor.NotValidResponse(sc))
                {
                    _serverChallenge = sc;
                }

                if (sc.Message != 01_0003) // retry with pow
                {
                    return(sc.Message);
                }

                registerForm.SessionId = sc.SessionId;

                registerForm.ProofOfWork = ProofOfWorkVendor.CalculateProofOfWork(sc.ProofOfWork);
            }

            return(01_0002);
        }