Example #1
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();
        }