Beispiel #1
0
        public AuthenticationResult Authenticate(IUnsafePacketReader credentialsReader, out IAccountSession session, out Account account)
        {
            session = null;
            account = null;

            var username = credentialsReader.ReadLengthString();
            if (username != "admin")
            {
                return AuthenticationResult.NotRegistered;
            }

            var password = credentialsReader.ReadLengthString();
            if (password != "admin")
            {
                return AuthenticationResult.IncorrectPassword;
            }

            session = new StubAccountSession();
            account = new Account()
                      {
                          AccountId = 1,
                          UserName = "******",
                          Password = "******",
                          Gender = Gender.Male,
                          GameMasterLevel = GameMasterLevel.GameMaster,
                          Status = AccountStatus.Active,
                          AccountPin = "0000",
                      };
            return AuthenticationResult.Success;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountSession"/> class.
        /// </summary>
        /// <param name="service">The <see cref="IAccountService"/> managing this session.</param>
        /// <param name="sessionId">The session identifier.</param>
        /// <param name="data">The loaded session data.</param>
        public AccountSession(IAccountService service, int sessionId, Account data)
        {
            this.SessionId = sessionId;
            this.AccountId = data.AccountId;
            this.AccountName = data.UserName;

            this.service = service;
        }
Beispiel #3
0
        private byte[] AuthResponse(AuthenticationResult result, Account account)
        {
            using (var builder = this.PacketFactory.CreatePacket("Authentication"))
            {
                builder.WriteInt32(result);

                builder.WriteInt16(0x0000);

                if (result == AuthenticationResult.Success)
                {
                    builder.WriteInt32(account.AccountId);

                    if (this.State == AuthClientState.SetGender)
                    {
                        builder.WriteByte(AuthOperationType.GenderSelect);
                    }
                    else if (this.State == AuthClientState.SetPin)
                    {
                        builder.WriteByte(AuthOperationType.PinSelect);
                    }
                    else
                    {
                        builder.WriteByte(account.Gender);
                    }

                    // Enables commands like /c, /ch, /m, /h (etc.), but disables trading
                    builder.WriteBoolean(account.IsGameMaster);

                    // Seems like 0x80 is a "MWLB" account - I doubt it... it disables attacking and allows GM fly
                    // 0x40, 0x20 (and probably 0x10, 0x8, 0x4, 0x2, and 0x1) don't appear to confer any particular benefits, restrictions, or functionality
                    // (Although I didn't test client GM commands or anything of the sort)
                    builder.WriteByte(account.IsGameMaster ? 0x80 : 0x00);

                    builder.WriteBoolean(account.IsGameMaster || account.IsGameMasterHelper);

                    builder.WriteLengthString(account.UserName);

                    builder.WriteByte(2);

                    // TODO: quiet ban support?
                    //builder.WriteByte(account.QuietBanReason);
                    builder.WriteByte(0);
                    //builder.WriteTimestamp(account.QuietBanTime);
                    builder.WriteInt64(0);

                    // TODO: Creation time
                    builder.WriteTimestamp(account.CreationTime);

                    builder.WriteInt32(0);
                }

                return builder.ToByteArray();
            }
        }
        /// <inheritdoc />
        public AuthenticationResult Authenticate(IUnsafePacketReader credentialsReader, out IAccountSession session, out Account account)
        {
            // Default value for failure scenarios:
            session = null;

            // TODO: user name validation, throw IllegalPacketException if not valid
            var userName = credentialsReader.ReadLengthString();
            // Attempt to load the account.
            account = this.accountProvider.LoadByUserName(userName);
            if (account == null)
            {
                // Fail with 'NotRegistered' if no account matches.
                return AuthenticationResult.NotRegistered;
            }

            // TODO: password validation, throw IllegalPacketException if not valid
            var password = credentialsReader.ReadLengthString();

            string hash = LoginCrypto.GetMd5HashString(password, true);
            if (!string.Equals(hash, account.Password, StringComparison.Ordinal))
            {
                // Fail with 'IncorrectPassword' if password hash is bad.
                return AuthenticationResult.IncorrectPassword;
            }

            // TODO: read other stuff from packet

            int sessionId;
            if (!this.accountService.TryRegisterSession(account.AccountId, out sessionId))
            {
                // Fail with 'AlreadyLoggedIn' if there is another session running on this account.
                return AuthenticationResult.AlreadyLoggedIn;
            }

            // Create the session.
            session = new AccountSession(this.accountService, sessionId, account);
            return AuthenticationResult.Success;
        }
 public void Save(Account account)
 {
 }