Beispiel #1
0
        public static void HandleAuthResponse(ref PacketReader packet, ref WorldClass session)
        {
            BitUnpack BitUnpack = new BitUnpack(packet);

            packet.Skip(54);

            int addonSize = packet.ReadInt32();

            packet.Skip(addonSize);

            uint   nameLength  = BitUnpack.GetNameLength <uint>(12);
            string accountName = packet.ReadString(nameLength);

            SQLResult result = DB.Realms.Select("SELECT * FROM accounts WHERE name = '{0}'", accountName);

            if (result.Count == 0)
            {
                session.clientSocket.Close();
            }
            else
            {
                session.Account = new Account()
                {
                    Id         = result.Read <int>(0, "id"),
                    Name       = result.Read <String>(0, "name"),
                    Password   = result.Read <String>(0, "password"),
                    SessionKey = result.Read <String>(0, "sessionkey"),
                    Expansion  = result.Read <byte>(0, "expansion"),
                    GMLevel    = result.Read <byte>(0, "gmlevel"),
                    IP         = result.Read <String>(0, "ip"),
                    Language   = result.Read <String>(0, "language")
                }
            };

            string K = session.Account.SessionKey;

            byte[] kBytes = new byte[K.Length / 2];

            for (int i = 0; i < K.Length; i += 2)
            {
                kBytes[i / 2] = Convert.ToByte(K.Substring(i, 2), 16);
            }

            session.Crypt.Initialize(kBytes);

            uint      realmId          = WorldConfig.RealmId;
            SQLResult realmClassResult = DB.Realms.Select("SELECT class, expansion FROM realm_classes WHERE realmId = '{0}'", realmId);
            SQLResult realmRaceResult  = DB.Realms.Select("SELECT race, expansion FROM realm_races WHERE realmId = '{0}'", realmId);

            bool HasAccountData = true;
            bool IsInQueue      = false;

            PacketWriter authResponse = new PacketWriter(JAMCMessage.AuthResponse);
            BitPack      BitPack      = new BitPack(authResponse);

            BitPack.Write(1);                                      // HasAccountData

            if (HasAccountData)
            {
                BitPack.Write(realmClassResult.Count, 25);         // Activation count for classes
                BitPack.Write(0);                                  // Unknown, 5.0.4
                BitPack.Write(0);                                  // Unknown, 5.1.0
                BitPack.Write(0, 22);                              // Activate character template windows/button

                //if (HasCharacterTemplate)
                //Write bits for char templates...

                BitPack.Write(realmRaceResult.Count, 25);          // Activation count for races
                BitPack.Write(IsInQueue);                          // IsInQueue
            }

            if (IsInQueue)
            {
                BitPack.Write(0);                                  // Unknown
                BitPack.Flush();

                authResponse.WriteUInt32(0);                       // QueuePosition
            }
            else
            {
                BitPack.Flush();
            }

            if (HasAccountData)
            {
                //if (HasCharacterTemplate)
                //Write data for char templates...

                for (int r = 0; r < realmRaceResult.Count; r++)
                {
                    authResponse.WriteUInt8(realmRaceResult.Read <byte>(r, "expansion"));
                    authResponse.WriteUInt8(realmRaceResult.Read <byte>(r, "race"));
                }

                authResponse.WriteUInt32(0);
                authResponse.WriteUInt32(0);
                authResponse.WriteUInt8(0);
                authResponse.WriteUInt8(session.Account.Expansion);
                authResponse.WriteUInt8(session.Account.Expansion);

                for (int c = 0; c < realmClassResult.Count; c++)
                {
                    authResponse.WriteUInt8(realmClassResult.Read <byte>(c, "class"));
                    authResponse.WriteUInt8(realmClassResult.Read <byte>(c, "expansion"));
                }

                authResponse.WriteUInt32(0);
            }

            authResponse.WriteUInt8((byte)AuthCodes.AUTH_OK);

            session.Send(authResponse);

            MiscHandler.HandleUpdateClientCacheVersion(ref session);
            TutorialHandler.HandleTutorialFlags(ref session);
        }
    }