Exemplo n.º 1
0
        private static void SendCharacterList(LobbySession session)
        {
            session.NewEvent(new DatabaseGenericEvent <List <CharacterInfo> >(DatabaseManager.DataCentre.GetCharacters(session.ServiceAccount.Id), characters =>
            {
                session.Characters = characters;

                ServerCharacterList characterList = new ServerCharacterList
                {
                    VeteranRank               = 0,
                    DaysTillNextVeteranRank   = 0u,
                    DaysSubscribed            = 0u,
                    SubscriptionDaysRemaining = 0u,
                    RealmCharacterLimit       = session.ServiceAccount.RealmCharacterLimit,
                    AccountCharacterLimit     = session.ServiceAccount.AccountCharacterLimit,
                    Expansion = session.ServiceAccount.Expansion,
                    Offset    = 1
                };

                if (session.Characters.Count == 0)
                {
                    session.Send(characterList);
                    return;
                }

                for (int i = 0; i < session.Characters.Count; i++)
                {
                    // client expects no more than 2 characters per chunk
                    if (i % ServerCharacterList.MaxCharactersPerPacket == 0)
                    {
                        // flush previous chunk
                        if (i != 0)
                        {
                            session.Send(characterList);
                            session.FlushPacketQueue();
                            characterList.Characters.Clear();
                        }

                        // weird...
                        characterList.Offset = (byte)(session.Characters.Count - i <= ServerCharacterList.MaxCharactersPerPacket ? i * 2 + 1 : i * 2);
                    }

                    RealmInfo realmInfo = AssetManager.GetRealmInfo(session.Characters[i].RealmId);
                    if (realmInfo == null)
                    {
                        continue;
                    }

                    characterList.Characters.Add(((byte)i, realmInfo.Name, session.Characters[i]));

                    // flush final chunk
                    if (i == session.Characters.Count - 1)
                    {
                        session.Send(characterList);
                        session.FlushPacketQueue();
                    }
                }
Exemplo n.º 2
0
 public static void HandleClientHello(LobbySession session, ClientHello hello)
 {
     session.CalculateNetworkKey(hello.Time, hello.Seed);
     session.SessionHash = XxHash.CalculateHash(Guid.NewGuid().ToByteArray());
     session.Send(new ServerHello
     {
         SessionHash = session.SessionHash
     });
 }
Exemplo n.º 3
0
        private static void SendRealmList(LobbySession session)
        {
            ReadOnlyCollection <RealmInfo> realmInfo = AssetManager.RealmInfoStore;

            ServerRealmList realmList = new ServerRealmList {
                Sequence = session.Sequence
            };

            for (ushort i = 0; i < realmInfo.Count; i++)
            {
                // client expects no more than 6 realms per chunk
                if (i % ServerRealmList.MaxRealmsPerPacket == 0)
                {
                    // flush previous chunk
                    if (i != 0)
                    {
                        session.Send(realmList);
                        realmList.Realms.Clear();
                    }

                    realmList.Offset = i;
                    realmList.Final  = (ushort)(realmInfo.Count - i < ServerRealmList.MaxRealmsPerPacket ? 1 : 0);
                }

                RealmInfo realm = realmInfo[i];
                realmList.Realms.Add(new ServerRealmList.RealmInfo
                {
                    Id       = realm.Id,
                    Position = i,
                    Name     = realm.Name,
                    Flags    = realm.Flags
                });

                // flush final chunk
                if (i == realmInfo.Count - 1)
                {
                    session.Send(realmList);
                }
            }
        }
Exemplo n.º 4
0
        public static void HandleClientLobbyRequest(LobbySession session, ClientLobbyRequest sessionRequest)
        {
            session.Sequence = sessionRequest.Sequence;

            string[] versionExplode = sessionRequest.Version.Split('+');
            // module data, version...
            if (versionExplode.Length < 1)
            {
                return;
            }

            foreach (string moduleVersion in versionExplode[0].Split(','))
            {
                string[] moduleExplode = moduleVersion.Split('/');
                if (moduleExplode.Length != 3)
                {
                    continue;
                }

                #if DEBUG
                Console.WriteLine($"Module - File: {moduleExplode[0]}, Version: {moduleExplode[1]}, Digest: {moduleExplode[2]}");
                #endif

                if (!AssetManager.IsValidVersion(moduleExplode[0], moduleExplode[1], moduleExplode[2]))
                {
                    session.SendError(1012, 13101);
                    return;
                }
            }

            session.AuthToken = new Token(sessionRequest.Token);

            #if DEBUG
            Console.WriteLine($"Token: {sessionRequest.Token}");
            #endif

            session.NewEvent(new DatabaseGenericEvent <uint>(DatabaseManager.Authentication.GetAccount(session.AuthToken.SessionId), accountId =>
            {
                if (accountId == 0u)
                {
                    session.SendError(1000, 13100);
                    return;
                }

                session.NewEvent(new DatabaseGenericEvent <List <ServiceAccountInfo> >(DatabaseManager.Authentication.GetServiceAccounts(accountId), serviceAccounts =>
                {
                    if (serviceAccounts.Count == 0)
                    {
                        // TODO: probably not the correct error to display when no service accounts are present
                        session.SendError(1000, 13209);
                        return;
                    }

                    session.ServiceAccounts = serviceAccounts;
                    session.Send(new ServerServiceAccountList
                    {
                        Sequence        = session.Sequence,
                        ServiceAccounts = session.ServiceAccounts
                    });
                }));
            }));
        }