Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

Commit 20562c1

Browse files
authored
Merge pull request #591 from Arcana/dev
Various fixes and improvements
2 parents 1d9e01c + 1628b95 commit 20562c1

25 files changed

+1854
-494
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: node_js
22
node_js:
3-
- "8.9.1"
4-
- "9.2.0"
3+
- "10.1.0"
4+
- "8.11.1"

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Changelog 6.1.0
2+
## General
3+
* Removed some trailing util.log commands
4+
* Protobuf updates
5+
* Attempt to fix mocha not exiting
6+
* Added profile request fuction that allows fetching profile page
7+
18
# Changelog 6.0.0
29
## General
310
Fixed some chat channel bugs

README.md

+54-24
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Dota 2 module
8080
* [.requestChatChannels()](#module_Dota2.Dota2Client+requestChatChannels)
8181
* [.requestPlayerMatchHistory(account_id, [options], [callback])](#module_Dota2.Dota2Client+requestPlayerMatchHistory)
8282
* [.requestProfileCard(account_id, [callback])](#module_Dota2.Dota2Client+requestProfileCard)
83+
* [.requestProfile(account_id, [callback])](#module_Dota2.Dota2Client+requestProfile)
8384
* [.requestHallOfFame(week, [callback])](#module_Dota2.Dota2Client+requestHallOfFame)
8485
* [.requestPlayerInfo(account_ids)](#module_Dota2.Dota2Client+requestPlayerInfo)
8586
* [.requestTrophyList(account_id, [callback])](#module_Dota2.Dota2Client+requestTrophyList)
@@ -149,6 +150,7 @@ Dota 2 module
149150
* ["chatChannelsData" (channels)](#module_Dota2.Dota2Client+event_chatChannelsData)
150151
* ["playerMatchHistoryData" (requestId, matchHistoryResponse)](#module_Dota2.Dota2Client+event_playerMatchHistoryData)
151152
* ["profileCardData" (account_id, profileCardResponse)](#module_Dota2.Dota2Client+event_profileCardData)
153+
* ["profileData" (profileResponse)](#module_Dota2.Dota2Client+event_profileData)
152154
* ["hallOfFameData" (week, featured_players, featured_farmer, hallOfFameResponse)](#module_Dota2.Dota2Client+event_hallOfFameData)
153155
* ["playerInfoData" (playerInfoData)](#module_Dota2.Dota2Client+event_playerInfoData)
154156
* ["trophyListData" (trophyListResponse)](#module_Dota2.Dota2Client+event_trophyListData)
@@ -218,6 +220,7 @@ Dota 2 module
218220
* [.requestChatChannels()](#module_Dota2.Dota2Client+requestChatChannels)
219221
* [.requestPlayerMatchHistory(account_id, [options], [callback])](#module_Dota2.Dota2Client+requestPlayerMatchHistory)
220222
* [.requestProfileCard(account_id, [callback])](#module_Dota2.Dota2Client+requestProfileCard)
223+
* [.requestProfile(account_id, [callback])](#module_Dota2.Dota2Client+requestProfile)
221224
* [.requestHallOfFame(week, [callback])](#module_Dota2.Dota2Client+requestHallOfFame)
222225
* [.requestPlayerInfo(account_ids)](#module_Dota2.Dota2Client+requestPlayerInfo)
223226
* [.requestTrophyList(account_id, [callback])](#module_Dota2.Dota2Client+requestTrophyList)
@@ -287,6 +290,7 @@ Dota 2 module
287290
* ["chatChannelsData" (channels)](#module_Dota2.Dota2Client+event_chatChannelsData)
288291
* ["playerMatchHistoryData" (requestId, matchHistoryResponse)](#module_Dota2.Dota2Client+event_playerMatchHistoryData)
289292
* ["profileCardData" (account_id, profileCardResponse)](#module_Dota2.Dota2Client+event_profileCardData)
293+
* ["profileData" (profileResponse)](#module_Dota2.Dota2Client+event_profileData)
290294
* ["hallOfFameData" (week, featured_players, featured_farmer, hallOfFameResponse)](#module_Dota2.Dota2Client+event_hallOfFameData)
291295
* ["playerInfoData" (playerInfoData)](#module_Dota2.Dota2Client+event_playerInfoData)
292296
* ["trophyListData" (trophyListResponse)](#module_Dota2.Dota2Client+event_trophyListData)
@@ -364,29 +368,29 @@ The lobby the bot is currently in. Falsy if the bot isn't in a lobby.
364368
| --- | --- | --- | --- |
365369
| game_name | <code>string</code> | | Name of the lobby |
366370
| pass_key | <code>string</code> | | Lobby password |
367-
| server_region | [<code>ServerRegion</code>](#module_Dota2.ServerRegion) | <code>module:Dota2.ServerRegion.UNSPECIFIED</code> | Server region where the lobby will be created |
368-
| game_mode | <code>DOTA_GameMode</code> | <code>DOTA_GameMode.DOTA_GAMEMODE_AP</code> | Game mode |
369-
| game_version | <code>DOTAGameVersion</code> | <code>DOTAGameVersion.GAME_VERSION_STABLE</code> | Version of the game |
370-
| cm_pick | <code>DOTA_CM_PICK</code> | <code>DOTA_CM_PICK.DOTA_CM_RANDOM</code> | Who gets first pick |
371-
| allow_cheats | <code>boolean</code> | <code>false</code> | Whether or not to allow cheats |
372-
| fill_with_bots | <code>boolean</code> | <code>false</code> | Whether or not to fill empty slots with bots |
373-
| bot_difficulty_radiant | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for radiant bots, if fill_with_bots is true. |
374-
| bot_difficulty_dire | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for dire bots, if fill_with_bots is true. |
375-
| bot_radiant | <code>number</code> | | Presumably the ID of the custom AI to be applied to radiant bots. |
376-
| bot_dire | <code>number</code> | | Presumably the ID of the custom AI to be applied to dire bots. |
377-
| allow_spectating | <code>boolean</code> | <code>true</code> | Whether or not to allow spectating |
378-
| series_type | <code>SeriesType</code> | <code>NONE</code> | Whether or not the game is part of a series (Bo3, Bo5). |
379-
| radiant_series_wins | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
380-
| dire_series_wins | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
381-
| previous_match_override | <code>number</code> | | In a series, the match ID of the previous game. If not supplied, the GC will try to find it automatically based on the teams and the players. |
382-
| allchat | <code>boolean</code> | <code>false</code> | Whether or not it's allowed to all-chat |
383-
| dota_tv_delay | <code>LobbyDotaTVDelay</code> | <code>LobbyDotaTV_120</code> | How much time the game should be delayed for DotaTV. |
384-
| leagueid | <code>number</code> | | The league this lobby is being created for. The bot should be a league admin for this to work. |
385-
| custom_game_mode | <code>string</code> | | Name of the custom game |
386-
| custom_map_name | <code>string</code> | | Which map the custom game should be played on |
387-
| custom_difficulty | <code>number</code> | | Difficulty of the custom game |
388-
| custom_game_id | [<code>Long</code>](#external_Long) | | 64bit ID of the custom game mode |
389-
| pause_setting | <code>LobbyDotaPauseSetting</code> | <code>0</code> | Pause setting: 0 - unlimited, 1 - limited, 2 - disabled |
371+
| [server_region] | [<code>ServerRegion</code>](#module_Dota2.ServerRegion) | <code>module:Dota2.ServerRegion.UNSPECIFIED</code> | Server region where the lobby will be created |
372+
| [game_mode] | <code>DOTA_GameMode</code> | <code>DOTA_GameMode.DOTA_GAMEMODE_AP</code> | Game mode |
373+
| [game_version] | <code>DOTAGameVersion</code> | <code>DOTAGameVersion.GAME_VERSION_STABLE</code> | Version of the game |
374+
| [cm_pick] | <code>DOTA_CM_PICK</code> | <code>DOTA_CM_PICK.DOTA_CM_RANDOM</code> | Who gets first pick |
375+
| [allow_cheats] | <code>boolean</code> | <code>false</code> | Whether or not to allow cheats |
376+
| [fill_with_bots] | <code>boolean</code> | <code>false</code> | Whether or not to fill empty slots with bots |
377+
| [bot_difficulty_radiant] | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for radiant bots, if fill_with_bots is true. |
378+
| [bot_difficulty_dire] | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for dire bots, if fill_with_bots is true. |
379+
| [bot_radiant] | <code>number</code> | | Presumably the ID of the custom AI to be applied to radiant bots. |
380+
| [bot_dire] | <code>number</code> | | Presumably the ID of the custom AI to be applied to dire bots. |
381+
| [allow_spectating] | <code>boolean</code> | <code>true</code> | Whether or not to allow spectating |
382+
| [series_type] | <code>SeriesType</code> | <code>NONE</code> | Whether or not the game is part of a series (Bo3, Bo5). |
383+
| [radiant_series_wins] | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
384+
| [dire_series_wins] | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
385+
| [previous_match_override] | <code>number</code> | | In a series, the match ID of the previous game. If not supplied, the GC will try to find it automatically based on the teams and the players. |
386+
| [allchat] | <code>boolean</code> | <code>false</code> | Whether or not it's allowed to all-chat |
387+
| [dota_tv_delay] | <code>LobbyDotaTVDelay</code> | <code>LobbyDotaTV_120</code> | How much time the game should be delayed for DotaTV. |
388+
| [leagueid] | <code>number</code> | | The league this lobby is being created for. The bot should be a league admin for this to work. |
389+
| [custom_game_mode] | <code>string</code> | | Name of the custom game |
390+
| [custom_map_name] | <code>string</code> | | Which map the custom game should be played on |
391+
| [custom_difficulty] | <code>number</code> | | Difficulty of the custom game |
392+
| [custom_game_id] | [<code>Long</code>](#external_Long) | | 64bit ID of the custom game mode |
393+
| [pause_setting] | <code>LobbyDotaPauseSetting</code> | <code>0</code> | Pause setting: 0 - unlimited, 1 - limited, 2 - disabled |
390394

391395
<a name="module_Dota2.Dota2Client+LobbyInvite"></a>
392396

@@ -549,6 +553,22 @@ Requires the GC to be [ready](#module_Dota2.Dota2Client+event_ready).
549553
| account_id | <code>number</code> | Dota 2 account ID of the player whose profile card the bot should fetch |
550554
| [callback] | [<code>requestCallback</code>](#module_Dota2..requestCallback) | Called with `err, CMsgDOTAProfileCard` |
551555

556+
<a name="module_Dota2.Dota2Client+requestProfile"></a>
557+
558+
#### dota2Client.requestProfile(account_id, [callback])
559+
Sends a message to the Game Coordinator requesting `account_id`'s profile page.
560+
This method is heavily rate limited. When abused, the GC just stops responding.
561+
Even the regular client runs into this limit when you check too many profiles.
562+
Provide a callback or listen for [profileData](#module_Dota2.Dota2Client+event_profileData) event for Game Coordinator's response.
563+
Requires the GC to be [ready](#module_Dota2.Dota2Client+event_ready).
564+
565+
**Kind**: instance method of [<code>Dota2Client</code>](#module_Dota2.Dota2Client)
566+
567+
| Param | Type | Description |
568+
| --- | --- | --- |
569+
| account_id | <code>number</code> | Dota 2 account ID of the player whose profile page the bot should fetch |
570+
| [callback] | [<code>requestCallback</code>](#module_Dota2..requestCallback) | Called with `err, CMsgDOTAProfileResponse` |
571+
552572
<a name="module_Dota2.Dota2Client+requestHallOfFame"></a>
553573

554574
#### dota2Client.requestHallOfFame(week, [callback])
@@ -640,7 +660,6 @@ All requests are staggered in 200ms intervals and time out after 2s.
640660
Requires the GC to be [ready](#module_Dota2.Dota2Client+event_ready).
641661

642662
**Kind**: instance method of [<code>Dota2Client</code>](#module_Dota2.Dota2Client)
643-
**Async**: Returns a list of promises that resolve to [FantasyPlayer](#module_Dota2.Dota2Client+requestPlayerCardsByPlayer.FantasyPlayer) objects
644663
<a name="module_Dota2.Dota2Client+requestPlayerCardsByPlayer.FantasyPlayer"></a>
645664

646665
##### requestPlayerCardsByPlayer.FantasyPlayer : <code>Object</code>
@@ -1429,6 +1448,17 @@ Emitted in response to a [request for a player's profile card](#module_Dota2.Dot
14291448
| account_id | <code>number</code> | Dota2 account ID of the player whose profile card was fetched. |
14301449
| profileCardResponse | <code>CMsgDOTAProfileCard</code> | The raw response data containing the user's profile card. |
14311450

1451+
<a name="module_Dota2.Dota2Client+event_profileData"></a>
1452+
1453+
#### "profileData" (profileResponse)
1454+
Emitted in response to a [request for a player's profile page](#module_Dota2.Dota2Client+requestProfile)
1455+
1456+
**Kind**: event emitted by [<code>Dota2Client</code>](#module_Dota2.Dota2Client)
1457+
1458+
| Param | Type | Description |
1459+
| --- | --- | --- |
1460+
| profileResponse | <code>CMsgProfileResponse</code> | The raw response data containing the user's profile page. |
1461+
14321462
<a name="module_Dota2.Dota2Client+event_hallOfFameData"></a>
14331463

14341464
#### "hallOfFameData" (week, featured_players, featured_farmer, hallOfFameResponse)

examples/example2.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,15 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {
4444
// COMMUNITY
4545

4646
var accId = 103637655;
47-
// var playerInfo = 0;
47+
var playerInfo = 1;
4848
var playerInfo2 = 0;
4949
// var playerInfo3 = 0;
5050

51-
// if(playerInfo == 1){ // not working - maybe disabled by Valve
52-
// Dota2.requestProfile(accId, true);
53-
// Dota2.on("profileData", function (accId, data) {
54-
// util.log(JSON.stringify(data));
55-
// });
56-
// }
51+
if(playerInfo == 1) {
52+
Dota2.requestProfile(accId, function (err, data) {
53+
util.log(JSON.stringify(data));
54+
});
55+
}
5756

5857
if(playerInfo2 == 1){
5958
Dota2.requestProfileCard(accId, function (accId, data) {

handlers/chat.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -311,23 +311,23 @@ var onUserLeftChannel = function onOtherLeftChannel(message) {
311311
this.emit("chatLeave", channel.channel_name, userWhoLeft.steam_id, userWhoLeft);
312312
this.emit("chatLeft", channel.channel_name);
313313
if (this.debug)
314-
util.log("Left channel " + channel.channel_name);
314+
this.Logger.debug("Left channel " + channel.channel_name);
315315
} else {
316316
this._leaveChatChannelById(userWhoLeft.channel_id);
317317
if (this.debug)
318-
util.log("I left unknown channel " + userWhoLeft.channel_id);
318+
this.Logger.debug("I left unknown channel " + userWhoLeft.channel_id);
319319
}
320320
} else {
321321
if (channel) {
322322
this.emit("chatLeave", channel.channel_name, userWhoLeft.steam_id, userWhoLeft);
323323
// Delete member from cached chatChannel
324324
channel.members = channel.members.filter(item => item.steam_id.notEquals(userWhoLeft.steam_id));
325325
if (this.debug)
326-
util.log(userWhoLeft.steam_id + " left channel " + channel.channel_name);
326+
this.Logger.debug(userWhoLeft.steam_id + " left channel " + channel.channel_name);
327327
} else {
328328
this._leaveChatChannelById(userWhoLeft.channel_id);
329329
if (this.debug)
330-
util.log(userWhoLeft.steam_id + " left unknown channel " + userWhoLeft.channel_id);
330+
this.Logger.debug(userWhoLeft.steam_id + " left unknown channel " + userWhoLeft.channel_id);
331331
}
332332
}
333333
};

handlers/community.js

+41
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ Dota2.Dota2Client.prototype.requestProfileCard = function(account_id, callback)
6868
onProfileCardResponse, callback);
6969
};
7070

71+
/**
72+
* Sends a message to the Game Coordinator requesting `account_id`'s profile page.
73+
* This method is heavily rate limited. When abused, the GC just stops responding.
74+
* Even the regular client runs into this limit when you check too many profiles.
75+
* Provide a callback or listen for {@link module:Dota2.Dota2Client#event:profileData|profileData} event for Game Coordinator's response.
76+
* Requires the GC to be {@link module:Dota2.Dota2Client#event:ready|ready}.
77+
* @alias module:Dota2.Dota2Client#requestProfile
78+
* @param {number} account_id - Dota 2 account ID of the player whose profile page the bot should fetch
79+
* @param {module:Dota2~requestCallback} [callback] - Called with `err, CMsgDOTAProfileResponse`
80+
*/
81+
Dota2.Dota2Client.prototype.requestProfile = function(account_id, callback) {
82+
callback = callback || null;
83+
var _self = this;
84+
85+
/* Sends a message to the Game Coordinator requesting `accountId`'s profile. Listen for `profileData` event for Game Coordinator's response. */
86+
this.Logger.debug("Sending profile request");
87+
88+
var payload = {
89+
"account_id": account_id
90+
};
91+
this.sendToGC( Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgProfileRequest,
92+
Dota2.schema.lookupType("CMsgProfileRequest").encode(payload).finish(),
93+
onProfileResponse, callback);
94+
};
95+
96+
7197
/**
7298
* Sends a message to the Game Coordinator requesting the Hall of Fame data for `week`.
7399
* Provide a callback or listen for the {@link module:Dota2.Dota2Client#event:hallOfFameData|hallOfFameData} event for the Game Coordinator's response.
@@ -180,6 +206,11 @@ Dota2.Dota2Client.prototype.requestPlayerStats = function(account_id, callback)
180206
* @param {CMsgDOTAProfileCard} profileCardResponse - The raw response data containing the user's profile card.
181207
*/
182208
/**
209+
* Emitted in response to a {@link module:Dota2.Dota2Client#requestProfile|request for a player's profile page}
210+
* @event module:Dota2.Dota2Client#profileData
211+
* @param {CMsgProfileResponse} profileResponse - The raw response data containing the user's profile page.
212+
*/
213+
/**
183214
* Emitted in response to a {@link module:Dota2.Dota2Client#requestHallOfFame|request for a player's profile card}
184215
* @event module:Dota2.Dota2Client#hallOfFameData
185216
* @param {number} week - Weeks since unix epoch for which the hall of fame data was fetched
@@ -284,6 +315,16 @@ var onProfileCardResponse = function onProfileCardResponse(message, callback) {
284315
};
285316
handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgClientToGCGetProfileCardResponse] = onProfileCardResponse;
286317

318+
var onProfileResponse = function onProfileResponse(message, callback) {
319+
callback = callback || null;
320+
var profileResponse = Dota2.schema.lookupType("CMsgProfileResponse").decode(message);
321+
322+
this.Logger.debug("Received profile page");
323+
this.emit("profileData", profileResponse);
324+
if (callback) callback(null, profileResponse);
325+
};
326+
handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgProfileResponse] = onProfileResponse;
327+
287328
var onHallOfFameResponse = function onHallOfFameResponse(message, callback) {
288329
callback = callback || null;
289330
var hallOfFameResponse = Dota2.schema.lookupType("CMsgDOTAHallOfFameResponse").decode(message);

handlers/fantasy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Dota2.Dota2Client.prototype.requestPlayerCardsByPlayer = function() {
4545
// Sort cards per player
4646
var players = playercards.reduce((players, card)=>{
4747
var id_attr = card.attribute.filter(attr => attr.def_index == 424)[0];
48-
var account_id = Buffer.from(id_attr.value_bytes, 'base64').readUInt32LE();
48+
var account_id = Buffer.from(id_attr.value_bytes, 'base64').readUInt32LE(0);
4949
// Add player if we haven't seen him yet
5050
if (!players[account_id]) players[account_id] = {'account_id': account_id, 'cards': []};
5151
// Add this card

handlers/helper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ Dota2._parseOptions = function(options, possibleOptions) {
160160
type = possibleOptions[option];
161161
if (type == null) {
162162
if (this.debug) {
163-
util.log("Option " + option + " is not possible.");
163+
this.Logger.debug("Option " + option + " is not possible.");
164164
}
165165
continue;
166166
}
167167
if (typeof value !== type) {
168168
if (this.debug) {
169-
util.log("Option " + option + " must be a " + type + ".");
169+
this.Logger.debug("Option " + option + " must be a " + type + ".");
170170
}
171171
continue;
172172
}

handlers/leagues.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var onLiveLeagueGameUpdate = function onLiveLeagueGameUpdate(message, callback)
7373
callback = callback || null;
7474
var response = Dota2.schema.lookupType("CMsgDOTALiveLeagueGameUpdate").decode(message);
7575

76-
if (this.debugMore) util.log("Live league games: " + response.live_league_games + ".");
76+
if (this.debugMore) this.Logger.debug("Live league games: " + response.live_league_games + ".");
7777
this.emit("liveLeagueGamesUpdate", response.live_league_games);
7878
if (callback) callback(null, response.live_league_games);
7979
};

0 commit comments

Comments
 (0)