Esempio n. 1
0
        internal async Task UpdateClan(CMsgClientClanState clan)
        {
            IClan before;
            IClan after;

            await _slim.WaitAsync();

            try
            {
                before = _clans[clan.steamid_clan];

                if (before is UnknownClan)
                {
                    after = Clan.Create(Client, before.Relationship, clan);
                }
                else
                {
                    after = (before as Clan).WithState(clan);
                }

                _clans[after.Id] = after;
            }
            finally
            {
                _slim.Release();
            }

            await InvokeClanUpdated(before, after).ConfigureAwait(false);

            await Task.WhenAll(clan.announcements.Concat(clan.events).Select(e => new Event(e.gid, e.event_time, e.headline, e.game_id, e.just_posted)).Select(e => InvokeClanEventStarted(after, e))).ConfigureAwait(false);
        }
Esempio n. 2
0
        internal async Task UpdateFriend(CMsgClientPersonaState persona)
        {
            var users = new List <(IUser Before, IUser After)>();
            var clans = new List <(IClan Before, IClan After)>();

            ISelfUser currentBefore = null;
            ISelfUser currentAfter  = null;

            await _slim.WaitAsync();

            try
            {
                var flag = (ClientPersonaStateFlag)persona.status_flags;

                foreach (var friend in persona.friends)
                {
                    SteamId friendId = friend.friendid;

                    if (friendId == Client.SteamId) // that's us!
                    {
                        currentBefore = _currentUser;

                        if (currentBefore is OfflineSelfUser)
                        {
                            currentAfter = SelfUser.Create(Client, friend, flag);
                        }
                        else
                        {
                            currentAfter = (currentBefore as SelfUser).WithState(friend, flag);
                        }
                    }
                    else if (friendId.IsClan)
                    {
                        IClan before;
                        IClan after;

                        before = _clans[friend.friendid];

                        if (before is UnknownUser)
                        {
                            after = Clan.Create(Client, before.Relationship, friend, flag);
                        }
                        else
                        {
                            after = (before as Clan).WithPersonaState(friend, flag);
                        }

                        _clans[after.Id] = after;

                        clans.Add((before, after));
                    }
                    else
                    {
                        IUser before;
                        IUser after;

                        before = _users[friend.friendid];

                        if (before is UnknownUser)
                        {
                            after = User.Create(Client, before.Relationship, friend, flag);
                        }
                        else
                        {
                            after = (before as User).WithState(friend, flag);
                        }

                        _users[after.Id] = after;

                        users.Add((before, after));
                    }
                }
            }
            finally
            {
                _slim.Release();
            }

            if (currentBefore != null || currentAfter != null)
            {
                _currentUser = currentAfter;
                await InvokeCurrentUserUpdated(currentBefore, currentAfter).ConfigureAwait(false);
            }

            await Task.WhenAll(users.Select(t => InvokeUserUpdated(t.Before, t.After)).Concat(clans.Select(t => InvokeClanUpdated(t.Before, t.After)))).ConfigureAwait(false);
        }