Skip to content

Commit ee2a902

Browse files
committed
Added requestGame method
1 parent 1f5961f commit ee2a902

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const ByteBuffer = require('bytebuffer');
22
const EventEmitter = require('events').EventEmitter;
3+
const {ShareCode} = require('globaloffensive-sharecode');
34
const SteamID = require('steamid');
45
const Util = require('util');
56

@@ -150,6 +151,30 @@ GlobalOffensive.prototype._send = function(type, protobuf, body) {
150151
return true;
151152
};
152153

154+
GlobalOffensive.prototype.requestGame = function(shareCodeOrDetails) {
155+
if (typeof shareCodeOrDetails == 'string') {
156+
shareCodeOrDetails = (new ShareCode(shareCodeOrDetails)).decode();
157+
}
158+
159+
if (typeof shareCodeOrDetails != 'object' || !shareCodeOrDetails) {
160+
throw new Error('shareCodeOrDetails must be a sharecode or an object with properties matchId, outcomeId, token');
161+
}
162+
163+
let requiredProps = ['matchId', 'outcomeId', 'token'];
164+
requiredProps.sort();
165+
let extantProps = Object.keys(shareCodeOrDetails);
166+
extantProps.sort();
167+
if (extantProps.join() != requiredProps.join()) {
168+
throw new Error('shareCodeOrDetails must be a sharecode or an object with properties matchId, outcomeId, token');
169+
}
170+
171+
this._send(Language.MatchListRequestFullGameInfo, Protos.CMsgGCCStrike15_v2_MatchListRequestFullGameInfo, {
172+
matchid: shareCodeOrDetails.matchId,
173+
outcomeid: shareCodeOrDetails.outcomeId,
174+
token: shareCodeOrDetails.token
175+
});
176+
};
177+
153178
GlobalOffensive.prototype.requestLiveGames = function() {
154179
this._send(Language.MatchListRequestCurrentLiveGames, Protos.CMsgGCCStrike15_v2_MatchListRequestCurrentLiveGames, {});
155180
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"dependencies": {
2727
"bytebuffer": "^5.0.1",
28+
"globaloffensive-sharecode": "^1.1.1",
2829
"long": "^3.2.0",
2930
"protobufjs": "^6.8.8",
3031
"steamid": "^1.1.0"

0 commit comments

Comments
 (0)