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

Commit

Permalink
Merge pull request #591 from Arcana/dev
Browse files Browse the repository at this point in the history
Various fixes and improvements
  • Loading branch information
Crazy-Duck authored Jun 8, 2018
2 parents 1d9e01c + 1628b95 commit 20562c1
Show file tree
Hide file tree
Showing 25 changed files with 1,854 additions and 494 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "8.9.1"
- "9.2.0"
- "10.1.0"
- "8.11.1"
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Changelog 6.1.0
## General
* Removed some trailing util.log commands
* Protobuf updates
* Attempt to fix mocha not exiting
* Added profile request fuction that allows fetching profile page

# Changelog 6.0.0
## General
Fixed some chat channel bugs
Expand Down
78 changes: 54 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Dota 2 module
* [.requestChatChannels()](#module_Dota2.Dota2Client+requestChatChannels)
* [.requestPlayerMatchHistory(account_id, [options], [callback])](#module_Dota2.Dota2Client+requestPlayerMatchHistory)
* [.requestProfileCard(account_id, [callback])](#module_Dota2.Dota2Client+requestProfileCard)
* [.requestProfile(account_id, [callback])](#module_Dota2.Dota2Client+requestProfile)
* [.requestHallOfFame(week, [callback])](#module_Dota2.Dota2Client+requestHallOfFame)
* [.requestPlayerInfo(account_ids)](#module_Dota2.Dota2Client+requestPlayerInfo)
* [.requestTrophyList(account_id, [callback])](#module_Dota2.Dota2Client+requestTrophyList)
Expand Down Expand Up @@ -149,6 +150,7 @@ Dota 2 module
* ["chatChannelsData" (channels)](#module_Dota2.Dota2Client+event_chatChannelsData)
* ["playerMatchHistoryData" (requestId, matchHistoryResponse)](#module_Dota2.Dota2Client+event_playerMatchHistoryData)
* ["profileCardData" (account_id, profileCardResponse)](#module_Dota2.Dota2Client+event_profileCardData)
* ["profileData" (profileResponse)](#module_Dota2.Dota2Client+event_profileData)
* ["hallOfFameData" (week, featured_players, featured_farmer, hallOfFameResponse)](#module_Dota2.Dota2Client+event_hallOfFameData)
* ["playerInfoData" (playerInfoData)](#module_Dota2.Dota2Client+event_playerInfoData)
* ["trophyListData" (trophyListResponse)](#module_Dota2.Dota2Client+event_trophyListData)
Expand Down Expand Up @@ -218,6 +220,7 @@ Dota 2 module
* [.requestChatChannels()](#module_Dota2.Dota2Client+requestChatChannels)
* [.requestPlayerMatchHistory(account_id, [options], [callback])](#module_Dota2.Dota2Client+requestPlayerMatchHistory)
* [.requestProfileCard(account_id, [callback])](#module_Dota2.Dota2Client+requestProfileCard)
* [.requestProfile(account_id, [callback])](#module_Dota2.Dota2Client+requestProfile)
* [.requestHallOfFame(week, [callback])](#module_Dota2.Dota2Client+requestHallOfFame)
* [.requestPlayerInfo(account_ids)](#module_Dota2.Dota2Client+requestPlayerInfo)
* [.requestTrophyList(account_id, [callback])](#module_Dota2.Dota2Client+requestTrophyList)
Expand Down Expand Up @@ -287,6 +290,7 @@ Dota 2 module
* ["chatChannelsData" (channels)](#module_Dota2.Dota2Client+event_chatChannelsData)
* ["playerMatchHistoryData" (requestId, matchHistoryResponse)](#module_Dota2.Dota2Client+event_playerMatchHistoryData)
* ["profileCardData" (account_id, profileCardResponse)](#module_Dota2.Dota2Client+event_profileCardData)
* ["profileData" (profileResponse)](#module_Dota2.Dota2Client+event_profileData)
* ["hallOfFameData" (week, featured_players, featured_farmer, hallOfFameResponse)](#module_Dota2.Dota2Client+event_hallOfFameData)
* ["playerInfoData" (playerInfoData)](#module_Dota2.Dota2Client+event_playerInfoData)
* ["trophyListData" (trophyListResponse)](#module_Dota2.Dota2Client+event_trophyListData)
Expand Down Expand Up @@ -364,29 +368,29 @@ The lobby the bot is currently in. Falsy if the bot isn't in a lobby.
| --- | --- | --- | --- |
| game_name | <code>string</code> | | Name of the lobby |
| pass_key | <code>string</code> | | Lobby password |
| server_region | [<code>ServerRegion</code>](#module_Dota2.ServerRegion) | <code>module:Dota2.ServerRegion.UNSPECIFIED</code> | Server region where the lobby will be created |
| game_mode | <code>DOTA_GameMode</code> | <code>DOTA_GameMode.DOTA_GAMEMODE_AP</code> | Game mode |
| game_version | <code>DOTAGameVersion</code> | <code>DOTAGameVersion.GAME_VERSION_STABLE</code> | Version of the game |
| cm_pick | <code>DOTA_CM_PICK</code> | <code>DOTA_CM_PICK.DOTA_CM_RANDOM</code> | Who gets first pick |
| allow_cheats | <code>boolean</code> | <code>false</code> | Whether or not to allow cheats |
| fill_with_bots | <code>boolean</code> | <code>false</code> | Whether or not to fill empty slots with bots |
| bot_difficulty_radiant | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for radiant bots, if fill_with_bots is true. |
| bot_difficulty_dire | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for dire bots, if fill_with_bots is true. |
| bot_radiant | <code>number</code> | | Presumably the ID of the custom AI to be applied to radiant bots. |
| bot_dire | <code>number</code> | | Presumably the ID of the custom AI to be applied to dire bots. |
| allow_spectating | <code>boolean</code> | <code>true</code> | Whether or not to allow spectating |
| series_type | <code>SeriesType</code> | <code>NONE</code> | Whether or not the game is part of a series (Bo3, Bo5). |
| radiant_series_wins | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
| dire_series_wins | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
| 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. |
| allchat | <code>boolean</code> | <code>false</code> | Whether or not it's allowed to all-chat |
| dota_tv_delay | <code>LobbyDotaTVDelay</code> | <code>LobbyDotaTV_120</code> | How much time the game should be delayed for DotaTV. |
| leagueid | <code>number</code> | | The league this lobby is being created for. The bot should be a league admin for this to work. |
| custom_game_mode | <code>string</code> | | Name of the custom game |
| custom_map_name | <code>string</code> | | Which map the custom game should be played on |
| custom_difficulty | <code>number</code> | | Difficulty of the custom game |
| custom_game_id | [<code>Long</code>](#external_Long) | | 64bit ID of the custom game mode |
| pause_setting | <code>LobbyDotaPauseSetting</code> | <code>0</code> | Pause setting: 0 - unlimited, 1 - limited, 2 - disabled |
| [server_region] | [<code>ServerRegion</code>](#module_Dota2.ServerRegion) | <code>module:Dota2.ServerRegion.UNSPECIFIED</code> | Server region where the lobby will be created |
| [game_mode] | <code>DOTA_GameMode</code> | <code>DOTA_GameMode.DOTA_GAMEMODE_AP</code> | Game mode |
| [game_version] | <code>DOTAGameVersion</code> | <code>DOTAGameVersion.GAME_VERSION_STABLE</code> | Version of the game |
| [cm_pick] | <code>DOTA_CM_PICK</code> | <code>DOTA_CM_PICK.DOTA_CM_RANDOM</code> | Who gets first pick |
| [allow_cheats] | <code>boolean</code> | <code>false</code> | Whether or not to allow cheats |
| [fill_with_bots] | <code>boolean</code> | <code>false</code> | Whether or not to fill empty slots with bots |
| [bot_difficulty_radiant] | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for radiant bots, if fill_with_bots is true. |
| [bot_difficulty_dire] | <code>BotDifficulty</code> | <code>module:Dota2.BotDifficulty.PASSIVE</code> | The bot difficulty for dire bots, if fill_with_bots is true. |
| [bot_radiant] | <code>number</code> | | Presumably the ID of the custom AI to be applied to radiant bots. |
| [bot_dire] | <code>number</code> | | Presumably the ID of the custom AI to be applied to dire bots. |
| [allow_spectating] | <code>boolean</code> | <code>true</code> | Whether or not to allow spectating |
| [series_type] | <code>SeriesType</code> | <code>NONE</code> | Whether or not the game is part of a series (Bo3, Bo5). |
| [radiant_series_wins] | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
| [dire_series_wins] | <code>number</code> | <code>0</code> | # of games won so far, e.g. for a Bo3 or Bo5. |
| [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. |
| [allchat] | <code>boolean</code> | <code>false</code> | Whether or not it's allowed to all-chat |
| [dota_tv_delay] | <code>LobbyDotaTVDelay</code> | <code>LobbyDotaTV_120</code> | How much time the game should be delayed for DotaTV. |
| [leagueid] | <code>number</code> | | The league this lobby is being created for. The bot should be a league admin for this to work. |
| [custom_game_mode] | <code>string</code> | | Name of the custom game |
| [custom_map_name] | <code>string</code> | | Which map the custom game should be played on |
| [custom_difficulty] | <code>number</code> | | Difficulty of the custom game |
| [custom_game_id] | [<code>Long</code>](#external_Long) | | 64bit ID of the custom game mode |
| [pause_setting] | <code>LobbyDotaPauseSetting</code> | <code>0</code> | Pause setting: 0 - unlimited, 1 - limited, 2 - disabled |

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

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

<a name="module_Dota2.Dota2Client+requestProfile"></a>

#### dota2Client.requestProfile(account_id, [callback])
Sends a message to the Game Coordinator requesting `account_id`'s profile page.
This method is heavily rate limited. When abused, the GC just stops responding.
Even the regular client runs into this limit when you check too many profiles.
Provide a callback or listen for [profileData](#module_Dota2.Dota2Client+event_profileData) event for Game Coordinator's response.
Requires the GC to be [ready](#module_Dota2.Dota2Client+event_ready).

**Kind**: instance method of [<code>Dota2Client</code>](#module_Dota2.Dota2Client)

| Param | Type | Description |
| --- | --- | --- |
| account_id | <code>number</code> | Dota 2 account ID of the player whose profile page the bot should fetch |
| [callback] | [<code>requestCallback</code>](#module_Dota2..requestCallback) | Called with `err, CMsgDOTAProfileResponse` |

<a name="module_Dota2.Dota2Client+requestHallOfFame"></a>

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

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

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

<a name="module_Dota2.Dota2Client+event_profileData"></a>

#### "profileData" (profileResponse)
Emitted in response to a [request for a player's profile page](#module_Dota2.Dota2Client+requestProfile)

**Kind**: event emitted by [<code>Dota2Client</code>](#module_Dota2.Dota2Client)

| Param | Type | Description |
| --- | --- | --- |
| profileResponse | <code>CMsgProfileResponse</code> | The raw response data containing the user's profile page. |

<a name="module_Dota2.Dota2Client+event_hallOfFameData"></a>

#### "hallOfFameData" (week, featured_players, featured_farmer, hallOfFameResponse)
Expand Down
13 changes: 6 additions & 7 deletions examples/example2.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,15 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {
// COMMUNITY

var accId = 103637655;
// var playerInfo = 0;
var playerInfo = 1;
var playerInfo2 = 0;
// var playerInfo3 = 0;

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

if(playerInfo2 == 1){
Dota2.requestProfileCard(accId, function (accId, data) {
Expand Down
8 changes: 4 additions & 4 deletions handlers/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,23 +311,23 @@ var onUserLeftChannel = function onOtherLeftChannel(message) {
this.emit("chatLeave", channel.channel_name, userWhoLeft.steam_id, userWhoLeft);
this.emit("chatLeft", channel.channel_name);
if (this.debug)
util.log("Left channel " + channel.channel_name);
this.Logger.debug("Left channel " + channel.channel_name);
} else {
this._leaveChatChannelById(userWhoLeft.channel_id);
if (this.debug)
util.log("I left unknown channel " + userWhoLeft.channel_id);
this.Logger.debug("I left unknown channel " + userWhoLeft.channel_id);
}
} else {
if (channel) {
this.emit("chatLeave", channel.channel_name, userWhoLeft.steam_id, userWhoLeft);
// Delete member from cached chatChannel
channel.members = channel.members.filter(item => item.steam_id.notEquals(userWhoLeft.steam_id));
if (this.debug)
util.log(userWhoLeft.steam_id + " left channel " + channel.channel_name);
this.Logger.debug(userWhoLeft.steam_id + " left channel " + channel.channel_name);
} else {
this._leaveChatChannelById(userWhoLeft.channel_id);
if (this.debug)
util.log(userWhoLeft.steam_id + " left unknown channel " + userWhoLeft.channel_id);
this.Logger.debug(userWhoLeft.steam_id + " left unknown channel " + userWhoLeft.channel_id);
}
}
};
Expand Down
41 changes: 41 additions & 0 deletions handlers/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ Dota2.Dota2Client.prototype.requestProfileCard = function(account_id, callback)
onProfileCardResponse, callback);
};

/**
* Sends a message to the Game Coordinator requesting `account_id`'s profile page.
* This method is heavily rate limited. When abused, the GC just stops responding.
* Even the regular client runs into this limit when you check too many profiles.
* Provide a callback or listen for {@link module:Dota2.Dota2Client#event:profileData|profileData} event for Game Coordinator's response.
* Requires the GC to be {@link module:Dota2.Dota2Client#event:ready|ready}.
* @alias module:Dota2.Dota2Client#requestProfile
* @param {number} account_id - Dota 2 account ID of the player whose profile page the bot should fetch
* @param {module:Dota2~requestCallback} [callback] - Called with `err, CMsgDOTAProfileResponse`
*/
Dota2.Dota2Client.prototype.requestProfile = function(account_id, callback) {
callback = callback || null;
var _self = this;

/* Sends a message to the Game Coordinator requesting `accountId`'s profile. Listen for `profileData` event for Game Coordinator's response. */
this.Logger.debug("Sending profile request");

var payload = {
"account_id": account_id
};
this.sendToGC( Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgProfileRequest,
Dota2.schema.lookupType("CMsgProfileRequest").encode(payload).finish(),
onProfileResponse, callback);
};


/**
* Sends a message to the Game Coordinator requesting the Hall of Fame data for `week`.
* Provide a callback or listen for the {@link module:Dota2.Dota2Client#event:hallOfFameData|hallOfFameData} event for the Game Coordinator's response.
Expand Down Expand Up @@ -180,6 +206,11 @@ Dota2.Dota2Client.prototype.requestPlayerStats = function(account_id, callback)
* @param {CMsgDOTAProfileCard} profileCardResponse - The raw response data containing the user's profile card.
*/
/**
* Emitted in response to a {@link module:Dota2.Dota2Client#requestProfile|request for a player's profile page}
* @event module:Dota2.Dota2Client#profileData
* @param {CMsgProfileResponse} profileResponse - The raw response data containing the user's profile page.
*/
/**
* Emitted in response to a {@link module:Dota2.Dota2Client#requestHallOfFame|request for a player's profile card}
* @event module:Dota2.Dota2Client#hallOfFameData
* @param {number} week - Weeks since unix epoch for which the hall of fame data was fetched
Expand Down Expand Up @@ -284,6 +315,16 @@ var onProfileCardResponse = function onProfileCardResponse(message, callback) {
};
handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgClientToGCGetProfileCardResponse] = onProfileCardResponse;

var onProfileResponse = function onProfileResponse(message, callback) {
callback = callback || null;
var profileResponse = Dota2.schema.lookupType("CMsgProfileResponse").decode(message);

this.Logger.debug("Received profile page");
this.emit("profileData", profileResponse);
if (callback) callback(null, profileResponse);
};
handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgProfileResponse] = onProfileResponse;

var onHallOfFameResponse = function onHallOfFameResponse(message, callback) {
callback = callback || null;
var hallOfFameResponse = Dota2.schema.lookupType("CMsgDOTAHallOfFameResponse").decode(message);
Expand Down
2 changes: 1 addition & 1 deletion handlers/fantasy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Dota2.Dota2Client.prototype.requestPlayerCardsByPlayer = function() {
// Sort cards per player
var players = playercards.reduce((players, card)=>{
var id_attr = card.attribute.filter(attr => attr.def_index == 424)[0];
var account_id = Buffer.from(id_attr.value_bytes, 'base64').readUInt32LE();
var account_id = Buffer.from(id_attr.value_bytes, 'base64').readUInt32LE(0);
// Add player if we haven't seen him yet
if (!players[account_id]) players[account_id] = {'account_id': account_id, 'cards': []};
// Add this card
Expand Down
4 changes: 2 additions & 2 deletions handlers/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,13 @@ Dota2._parseOptions = function(options, possibleOptions) {
type = possibleOptions[option];
if (type == null) {
if (this.debug) {
util.log("Option " + option + " is not possible.");
this.Logger.debug("Option " + option + " is not possible.");
}
continue;
}
if (typeof value !== type) {
if (this.debug) {
util.log("Option " + option + " must be a " + type + ".");
this.Logger.debug("Option " + option + " must be a " + type + ".");
}
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/leagues.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var onLiveLeagueGameUpdate = function onLiveLeagueGameUpdate(message, callback)
callback = callback || null;
var response = Dota2.schema.lookupType("CMsgDOTALiveLeagueGameUpdate").decode(message);

if (this.debugMore) util.log("Live league games: " + response.live_league_games + ".");
if (this.debugMore) this.Logger.debug("Live league games: " + response.live_league_games + ".");
this.emit("liveLeagueGamesUpdate", response.live_league_games);
if (callback) callback(null, response.live_league_games);
};
Expand Down
Loading

0 comments on commit 20562c1

Please sign in to comment.