UNPKG

5 kBJavaScriptView Raw
1var CSGO = require("../index"),
2 util = require("util"),
3 protos = require("../helpers/protos");
4
5CSGO.CSGOClient.prototype.matchmakingStatsRequest = function() {
6 if (!this._gcReady) {
7 if (this.debug) {
8 util.log("GC not ready, please listen for the 'ready' event.");
9 }
10 return null;
11 }
12
13 if (this.debug) {
14 util.log("Sending matchmaking stats request");
15 }
16
17 var payload = new protos.CMsgGCCStrike15_v2_MatchmakingClient2GCHello({});
18 this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_MatchmakingClient2GCHello, proto: {}},
19 payload.toBuffer());
20};
21
22CSGO.CSGOClient.prototype.requestCurrentLiveGames = function(callback) {
23 callback = callback || null;
24 if (!this._gcReady) {
25 if (this.debug) {
26 util.log("GC not ready");
27 }
28 return null;
29 }
30
31 if (this.debug) {
32 util.log("Sending live matches");
33 }
34
35 var payload = new protos.CMsgGCCStrike15_v2_MatchListRequestCurrentLiveGames();
36 this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_MatchListRequestCurrentLiveGames , proto: {}},
37 payload.toBuffer(), callback);
38};
39CSGO.CSGOClient.prototype.requestLiveGameForUser = function(accountid, callback) {
40 callback = callback || null;
41 if (!this._gcReady) {
42 if (this.debug) {
43 util.log("GC not ready");
44 }
45 return null;
46 }
47
48 if (this.debug) {
49 util.log("Sending live matches");
50 }
51
52 var payload = new protos.CMsgGCCStrike15_v2_MatchListRequestLiveGameForUser({
53 accountid: accountid
54 });
55 this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_MatchListRequestLiveGameForUser , proto: {}},
56 payload.toBuffer(), callback);
57};
58
59CSGO.CSGOClient.prototype.requestWatchInfoFriends = function(request, callback) {
60 callback = callback || null;
61 if (!this._gcReady) {
62 if (this.debug) {
63 util.log("GC not ready");
64 }
65 return null;
66 }
67
68 if (this.debug) {
69 util.log("Sending watch info request");
70 }
71
72 var payload = new protos.CMsgGCCStrike15_v2_ClientRequestWatchInfoFriends(request);
73 this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_ClientRequestWatchInfoFriends2, proto: {}},
74 payload.toBuffer(), callback);
75};
76
77CSGO.CSGOClient.prototype.requestGame = function(matchid, outcome, token, callback) {
78 callback = callback || null;
79 if (!this._gcReady) {
80 if (this.debug) {
81 util.log("GC not ready");
82 }
83 return null;
84 }
85
86 if (this.debug) {
87 util.log("Sending info match request with ID of " + matchid);
88 }
89
90 var payload = new protos.CMsgGCCStrike15_v2_MatchListRequestFullGameInfo({
91
92 });
93 if(matchid){
94 payload.matchid = matchid;
95 }
96 if(outcome){
97 payload.outcomeid = outcome;
98 }
99 if(token){
100 payload.token = token;
101 }
102 this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_MatchListRequestFullGameInfo, proto: {}},
103 payload.toBuffer(), callback);
104};
105
106CSGO.CSGOClient.prototype.requestRecentGames = function(arg1, arg2) {
107 if (!this._gcReady) {
108 if (this.debug) {
109 util.log("GC not ready");
110 }
111 return null;
112 }
113
114 var accid = this.ToAccountID(this._user._client.steamID);
115 var callback;
116 if (arguments.length >= 2) {
117 callback = arg2 || null;
118 util.log("Warning: The accountId parameter for requestRecentGames has been deprecated. The logged in bot accounts ID will be used.");
119 } else if (arguments.length == 1) {
120 if (typeof arg1 == 'function') {
121 callback = arg1 || null;
122 } else {
123 util.log("Warning: The accountId parameter for requestRecentGames has been deprecated. The logged in bot accounts ID will be used.");
124 }
125 }
126
127 if (this.debug) {
128 util.log("Sending recent match request with ID of " + accid);
129 }
130
131 var payload = new protos.CMsgGCCStrike15_v2_MatchListRequestRecentUserGames({
132 accountid: accid
133 });
134 this._gc.send({msg:CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_MatchListRequestRecentUserGames, proto: {}},
135 payload.toBuffer(), callback);
136 };
137
138var handlers = CSGO.CSGOClient.prototype._handlers;
139
140handlers[CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_MatchmakingGC2ClientHello] = function onMatchmakingStatsResponse(message) {
141 var matchmakingStatsResponse = protos.CMsgGCCStrike15_v2_MatchmakingGC2ClientHello.decode(message);
142
143 if (this.debug) {
144 util.log("Received matchmaking stats");
145 }
146 this.emit("matchmakingStatsData", matchmakingStatsResponse);
147};
148
149handlers[CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_MatchList] = function(message) {
150 var matchListResponse = protos.CMsgGCCStrike15_v2_MatchList.decode(message);
151
152 if (this.debug) {
153 util.log("Received match list");
154 }
155 this.emit("matchList", matchListResponse);
156};
157
158handlers[CSGO.ECSGOCMsg.k_EMsgGCCStrike15_v2_WatchInfoUsers] = function(message){
159 var response = protos.CMsgGCCStrike15_v2_WatchInfoUsers.decode(message);
160 if (this.debug) {
161 util.log('Recieved watch info');
162 }
163 this.emit('watchList', response);
164}