Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Implement Rich Presence handling #12

Merged
merged 1 commit into from
Oct 27, 2015
Merged

Implement Rich Presence handling #12

merged 1 commit into from
Oct 27, 2015

Conversation

sbx320
Copy link
Contributor

@sbx320 sbx320 commented Oct 16, 2015

This fixes #10 by introducing a RichPresenceUpdate callback.

I've avoided parsing the KeyValue inside the callback for performance reasons, since there's no point in parsing rich presence information when not required by the user. This has the downside that the callback will trigger on all RP updates including other games e.g. Team Fortress 2.

Example Usage for printing out all RP updates:

    Action<KeyValue, int> kvDeepPrint = null;

    // Recursively print a KeyValue structure
    kvDeepPrint = ((kv, depth) =>
    {
        Console.Write(new String('\t', depth));
        Console.ForegroundColor = ConsoleColor.Cyan;
        Console.Write(kv.Name);
        Console.Write("\t");
        Console.ResetColor();
        Console.WriteLine(kv.Value);

        foreach (var child in kv.Children)
            kvDeepPrint(child, depth + 1);
    });

    manager.Subscribe<DotaGCHandler.RichPresenceUpdate>(c =>
    {
        foreach (var richPresence in c.result.rich_presence)
        {
            using (MemoryStream stream = new MemoryStream(richPresence.rich_presence_kv))
            {
                KeyValue rp = new KeyValue();
                if (!rp.TryReadAsBinary(stream))
                    continue;

                Console.WriteLine("Rich Presence for " + richPresence.steamid_user);
                kvDeepPrint(rp, 0);
            }
        }
    });

@paralin
Copy link
Owner

paralin commented Oct 16, 2015

Nice work. Thanks for the effort as always. Will test later and merge.

I'm thinking of implementing a rich presence subsystem for the library. Maybe you could create rich presence monitors that would subscribe to a specific users events and parse them out into easy to use state objects and events. I'll look into writing that tomorrow.

paralin added a commit that referenced this pull request Oct 27, 2015
Implement Rich Presence handling
@paralin paralin merged commit 280f98a into paralin:master Oct 27, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event for ended matches of friends
2 participants