1 | var CSGO = require("../index"),
|
2 | util = require("util"),
|
3 | protos = require("../helpers/protos");
|
4 |
|
5 | CSGO.CSGOClient.prototype.richPresenceRequest = function(steamids, callback){
|
6 | this._gc._client.send({
|
7 | msg: CSGO.EMsg.ClientRichPresenceRequest,
|
8 | proto: {
|
9 | routing_appid: 730
|
10 | }
|
11 | },
|
12 | new protos.schema.CMsgClientRichPresenceRequest({
|
13 | steamid_request: steamids
|
14 | }).toBuffer(), callback);
|
15 | };
|
16 |
|
17 | CSGO.CSGOClient.prototype.richPresenceUpload = function(rp, steamids, callback){
|
18 | var payload = new protos.schema.CMsgClientRichPresenceUpload();
|
19 | payload.rich_presence_kv = require("../helpers/VDF").encode(rp);
|
20 | if(this.debug){
|
21 | util.log("Rich presence Payload:")
|
22 | console.log(payload.rich_presence_kv);
|
23 | }
|
24 | if(steamids){
|
25 | payload.steamid_broadcast = steamids;
|
26 | }
|
27 | this._gc._client.send({
|
28 | msg: CSGO.EMsg.ClientRichPresenceUpload,
|
29 | proto: {
|
30 | routing_appid: 730
|
31 | }
|
32 | },
|
33 | payload.toBuffer(), callback);
|
34 | };
|
35 |
|
36 | var handlers = CSGO.CSGOClient.prototype._handlers;
|
37 |
|
38 | handlers[CSGO.EMsg.ClientRichPresenceInfo] = function(data) {
|
39 | var vdf = require('../helpers/VDF');
|
40 | var response_kv = protos.schema.CMsgClientRichPresenceInfo.decode(data);
|
41 | var output = {};
|
42 | for(var index in response_kv.rich_presence){
|
43 | if(response_kv.rich_presence.hasOwnProperty(index)){
|
44 | var rp = vdf.decode(response_kv.rich_presence[index].rich_presence_kv.toBuffer());
|
45 | if(rp.hasOwnProperty('RP')) {
|
46 | rp = rp.RP;
|
47 | }
|
48 | output[response_kv.rich_presence[index].steamid_user] = rp;
|
49 | }
|
50 | }
|
51 | this.emit('richPresenceInfo', output);
|
52 | };
|