コード例 #1
0
        private void VerifyLogin(byte[] initialBuffer)
        {
            LoginPacket lp = (LoginPacket)ReadPacket(new LoginPacket(), initialBuffer);
            AccountDAO  l  = new AccountDAO(Server.ServerInstance.Database);

            if (l.VerifyLogin(lp.Username, lp.Password))
            {
                Tuple <bool, bool> banStatus = l.BanStatus(lp.Username);
                if (banStatus.Item1)
                {
                    SendPacket(banStatus.Item2
                                   ? new LoginFailPacket(PermaBannedMessage)
                                   : new LoginFailPacket(TempBannedMessage));
                    return;
                }

                if (AuthQueue.Add(lp.Username, _sessionId))
                {
                    SendPacket(new LoginOkPacket(_sessionId));
                }
                else
                {
                    SendPacket(new LoginFailPacket(AlreadyLoggedInMessage));
                }
            }
            else
            {
                SendPacket(new LoginFailPacket(WrongPasswordMessage));
            }
            Disconnect("Completed");
        }
コード例 #2
0
        private void ProcessSessionRequestPacket(IPacket packet)
        {
            SessionRequestPacket p = (SessionRequestPacket)packet;

            if (AuthQueue.CheckAuth(p.Username, p.SessionID))
            {
                SendPacket(new SessionResponsePacket(p.Username, SessionResponse.Ok));
            }
            else if (AuthQueue.IsAlreadyLoggedIn(p.Username))
            {
                SendPacket(new SessionResponsePacket(p.Username, SessionResponse.AlreadyLoggedIn));
            }
            else
            {
                SendPacket(new SessionResponsePacket(p.Username, SessionResponse.Wrong));
            }
        }
コード例 #3
0
        private void ProcessSessionActionPacket(IPacket packet)
        {
            SessionActionPacket sap = (SessionActionPacket)packet;

            if (sap.Action == SessionAction.Login)
            {
                AuthQueue.LogIn(sap.Username);
            }
            else if (sap.Action == SessionAction.Logout)
            {
                AuthQueue.LogOut(sap.Username);
            }
            else if (sap.Action == SessionAction.Disconnect)
            {
                AuthQueue.Remove(sap.Username);
            }
        }
コード例 #4
0
        public static void AuthSessionRequest(RealmClient client, RealmPacketIn packet)
        {
            packet.SkipBytes(8);
            string                   accName      = packet.ReadString();
            uint                     clientSeed   = packet.ReadUInt32();
            BigInteger               clientDigest = packet.ReadBigInteger(20);
            AuthenticationInfo       authInfo;
            SecureRemotePassword     srp;
            AuthenticationErrorCodes errorCode = AuthenticationErrorCodes.AuthFailed;

            client.Account = new Account(client, accName);

            if (!client.Account.Initialize())
            {
                errorCode = AuthenticationErrorCodes.UnknownAccount;

                goto sendErrorReply;
            }

            if (client.Server.RequestAuthenticationInfo(accName, out authInfo))
            {
                srp = new SecureRemotePassword(accName, authInfo.Verifier, new BigInteger(authInfo.Salt, 32));

                client.Account.SessionKey = authInfo.SessionKey;
                client.SystemInfo         = SystemInformation.Deserialize(authInfo.SystemInformation);
            }
            else
            {
                goto sendErrorReply;
            }

            BigInteger clientVerifier = srp.Hash(srp.Username, new byte[4], clientSeed, client.Server.AuthSeed,
                                                 client.Account.SessionKey);

            client.IsEncrypted = true;             // all packets from here on are encrypted, including the AuthSessionReplys

            if (clientVerifier == clientDigest)
            {
                AddonHandler.ReadAddOns(client, packet);

                client.Server.LoginAccount(client.Account.Username);

                if (AuthQueue.QueuedClients > 0 ||
                    client.Server.NumberOfClients > client.Server.Config.ServerCapacity)
                {
                    AuthQueue.EnqueueClient(client);

                    return;
                }

                SendAuthSessionSuccess(client);

                return;
            }
            else
            {
                goto sendErrorReply;
            }

sendErrorReply:
            SendAuthSessionErrorReply(client, errorCode);

            client.Disconnect();
        }
コード例 #5
0
        /// <summary>
        /// Called from within the IO-Context
        /// </summary>
        /// <param name="client"></param>
        /// <param name="accountName"></param>
        internal static void InitializeAccount(IRealmClient client, string accountName)
        {
            if (!client.IsConnected)
            {
                return;
            }

            if (RealmServer.Instance.IsAccountLoggedIn(accountName))
            {
                log.Info("Client ({0}) tried to use online Account: {1}.", client, accountName);
                LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_ALREADY_ONLINE);
            }
            else if (!RealmServer.Instance.AuthClient.IsConnected)
            {
                LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_DB_BUSY);
            }
            else if (ValidateAuthentication(client, accountName))
            {
                // else request it from the AuthServer
                var addr = client.ClientAddress;
                if (addr == null)
                {
                    return;
                }

                var accountInfo = RealmServer.Instance.RequestAccountInfo(accountName, addr.GetAddressBytes());

                if (accountInfo == null)
                {
                    // Account not found
                    RealmServer.Instance.Error(client, Resources.FailedToRetrieveAccount, accountName);

                    LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_UNKNOWN_ACCOUNT);
                    return;
                }

                // create new Account with newly fetched account-info
                var account = new RealmAccount(accountName, accountInfo);

                //if (!account.IsActive)
                //{
                //    // Account is inactive (banned)
                //    LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_BANNED);
                //    return;
                //}

                if (RealmServerConfiguration.Status != RealmStatus.Open && !account.Role.IsStaff)
                {
                    // RealmServer is locked and only staff members may join
                    LoginHandler.SendAuthSessionErrorReply(client, LoginErrorCode.AUTH_LOCKED_ENFORCED);
                    return;
                }

                RealmServer.Instance.RegisterAccount(account);
                account.LoadCharacters();
                account.LoadAccountData();

                account.Client = client;
                client.Account = account;

                log.Info("Account \"{0}\" logged in from {1}.", accountName, client.ClientAddress);

                if (RealmServer.Instance.ClientCount > RealmServerConfiguration.MaxClientCount &&
                    !account.Role.MaySkipAuthQueue)
                {
                    AuthQueue.EnqueueClient(client);
                }
                else
                {
                    LoginHandler.InviteToRealm(client);
                }
            }
        }