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 #300 from RJacksonm1/dev
Browse files Browse the repository at this point in the history
Update to 4.0.1
  • Loading branch information
jimmydorry authored Jun 28, 2016
2 parents 2373e6f + 6075e4e commit bea2b55
Show file tree
Hide file tree
Showing 22 changed files with 618 additions and 136 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
examples/config.js
examples/sentry
test/config.js
test/sentry
node_modules
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- "6.2.0"
- "6.2.1"
- "4.4.5"
60 changes: 38 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ node-dota2
A node-steam plugin for Dota 2, consider it in alpha state.

Check out my blog post (my only blog post), [Extending node-dota2](https://blog.rjackson.me/extending-node-dota2/), for a rough overview of adding new functionality to the library.
A fair warning, while the way you search for new functionality is still the same, quite a lot has changed (and been simplified) implementation wise.
It is now easier to implement new functionality than it was back when this blog was written.

## Upgrade guide

Expand All @@ -21,20 +23,37 @@ A few backwards incompatible API changes were included with version 4.0.0.
* `requestTeamIDByName`
* `requestTeamMemberProfile`
* The `teamData` event now throws an extra parameter `league_id`
* The `matchMakingStatsData` event's first two parameters changed as the old values no longer exist.
* The `matchMinimalDetailsData` event now returns the `last_match` bool as first argument.

## Installation and setup
* `npm install steam; npm install` in the repository root (install Steam first to work around a node-steam#222)
* Copy `config.js.example` to `config.js` and edit appropriately
* Run the example script: `node example.js`
* If you receive Error 63 you need to provide a Steam Guard code by setting the Steam Guard code in `config.js` and launching again.
* Make sure to use at least version 4.4.5 of node js

## Initializing
Parameters:
* `steamClient` - Pass a SteamClient instance to use to send & receive GC messages.
* `debug` - A boolean noting whether to print information about operations to console.
* `debugMore` - A boolean noting whether to print extended debug information. Activating this will log messages for each proto message exchanged with the GC.

```js
var Steam = require('steam'),
steamClient = new Steam.SteamClient(),
dota2 = require('dota2'),
Dota2 = new dota2.Dota2Client(steamClient, true);
Dota2 = new dota2.Dota2Client(steamClient, true, false);
```

## Examples
The `examples` directory contains two Dota2 bots as an example. One contains commented-out dota2 methods, the other has boolean activated methods.
Both examples show how to interact with the library.

## Testing
There is a partial automated test suite for node-dota2, which is located in the test directory.
You need to configure the `STEAM_USERNAME` and `STEAM_PASSWORD` environment variables to be able to run it.
You can launch the tests by running the file with mocha.

##Properties
###AccountID
Expand Down Expand Up @@ -170,22 +189,30 @@ Requests the authenticated user's team data.

Requests the profile for a given team.

**Warning** protobuf no longer exists, function is now deprecated.

#### requestTeamMemberProfile(steam_id, [callback]) - DEPRECATED
* `steam_id` - Steam ID of the user whose team profile you want
* `[callback]` - optional callback, returns args: `err, response`.

Requests the profile of the team a given user belongs to.

**Warning** protobuf no longer exists, function is now deprecated.

#### requestTeamIDByName(team_name, [callback]) - DEPRECATED
* `team_name` - Name of a team
* `[callback]` - optional callback, returns args: `err, response`.

Requests the ID for a given team name.

#### requestProTeamList([callback])
**Warning** protobuf no longer exists, function is now deprecated.

#### requestProTeamList([callback]) - STATUS UNKNOWN
* `[callback]` - optional callback, returns args: `err, response`.

Requests the list of pro teams
Requests the list of pro teams.

**Warning** this request no longer triggers a response from the GC. This might be temporary.

### Community
#### requestPlayerMatchHistory(account_id, [options], [callback])
Expand All @@ -208,7 +235,7 @@ Provide a callback or listen for the `playerMatchHistoryData` for the GC's respo

Sends a message to the Game Coordinator requesting `account_id`'s profile data. Provide a callback or listen for `profileData` event for Game Coordinator's response. Requires the GC to be ready (listen for the `ready` event before calling).

**This functionality is currently disabled by Valve**
**Warning** Valve's privacy policy has become stricter since reborn. This function is now reserved for internal use.

#### requestProfileCard (account_id, [callback])
* `account_id` - Account ID (lower 32-bits of a 64-bit Steam ID) of the user whose profile card you wish to view.
Expand Down Expand Up @@ -273,8 +300,6 @@ Note: There is a server-side rate-limit of 100 requests per 24 hours on this me

Sends a message to the Game Coordinator requesting the match details for matches corresponding to `match_ids`. Provide a callback or listen for `matchMinimalDetailsData` event for Game Coordinator's response. Requires the GC to be ready (listen for the `ready` event before calling).

Note: `jimmydorry` was lazy when implementing this, so the `match_ids` variable only accepts a single matchID right now. It was only implemented to prove that it was leaking data for anonymous users. Someone that wants to use this method should go fixup the copy-paste job, to make it more useful.

#### requestMatchmakingStats()

Sends a message to the Game Coordinator requesting some matchmaking stats. Listen for the `matchmakingStatsData` event for the Game Coordinator's response (cannot take a callback because of Steam's backend, or RJackson's incompetence; not sure which). Requires the GC to be ready (listen for the `ready` event before calling).
Expand Down Expand Up @@ -345,9 +370,9 @@ Sends a message to the Game Coordinator requesting to join a lobby. Provide a c
* `series_type`: Use the series type enum.
* `radiant_series_wins`: # of games won so far, e.g. for a Bo3 or Bo5.
* `dire_series_wins`: # of games won so far, e.g. for a Bo3 or Bo5.
* `allchat`: Enable all chat?
* `allchat`: Enable all chat for VOIP
* `league_id`: The league this lobby is being created for. Optional
* `dota_tv_delay`: TODO.
* `dota_tv_delay`: Number of seconds the game should be delayed for DotaTV.
* `custom_game_mode`: TODO.
* `custom_map_name`: TODO.
* `custom_difficulty`: TODO.
Expand Down Expand Up @@ -675,17 +700,17 @@ Emitted when GC responds to the `requestmatchDetails` method.

See the [protobuf schema](https://github.com/SteamRE/SteamKit/blob/master/Resources/Protobufs/dota/dota_gcmessages_client.proto#L1571) for `matchDetailsData`'s object structure.

### `matchMinimalDetailsData` (`match_id`, `matchMinimalDetailsData`)
* `match_id` - Match ID whom the data is associatd with.
### `matchMinimalDetailsData` (`matchMinimalDetailsData`)
* `last_match` - Bool, usage unknown
* `matchMinimalDetailsData` - The raw match details data object.

Emitted when GC responds to the `requestMatchMinimalDetails` method.

See the [protobuf schema](https://github.com/SteamRE/SteamKit/blob/5acc8bb72bb7fb79ad08723a431fcbfe90669230/Resources/Protobufs/dota/dota_gcmessages_client.proto#L621-L650) for `matchMinimalDetailsData`'s object structure.

### `matchmakingStatsData` (`searchingPlayersByGroup`, `disabledGroups`, `matchmakingStatsResponse`)
* `searchingPlayersByGroup` - Current players searching for matches per group.
* `disabledGroups` - Bitmask corresponding to groups in `searchingPlayersByGroup`. Groups marked as disabled will have a value of 0.
### `matchmakingStatsData` (`matchgroups_version`, `match_groups`, `matchmakingStatsResponse`)
* `matchgroups_version` - Version of the current list of match groups.
* `match_groups` - Array of CMsgMatchmakingMatchGroupInfo objects. Contains info on the number of people searching and ping penalty.
* `matchmakingStatsResponse` - Raw response object.

Emitted when te GC response to the `requestMatchmakingStats` method. The array order dictates which matchmaking groups the figure belongs to.
Expand Down Expand Up @@ -924,14 +949,5 @@ Use this to pass valid server region data to `createPracticeLobby`.

Use this to pass valid game mode data to `createPracticeLobby`.

## Testing
There is no automated test suite for node-dota2 (I've no idea how I'd make one for the stuff this does :o), however there the `test` directory does contain a Steam bot with commented-out dota2 methods; you can use this bot to test the library.

### Setting up
* `npm install steam; npm install` in the repository root (install Steam first to work around a node-steam#222)
* Copy `config.js.example` to `config.js` and edit appropriately
* Run the test script: `node test.js`
* If you receive Error 63 you need to provide a Steam Guard code by setting the Steam Guard code in `config.js` and launching again.
* Make sure to use at least version 0.12 of node js


42 changes: 35 additions & 7 deletions examples/example2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var steam = require("steam"),
util = require("util"),
fs = require("fs"),
crypto = require("crypto"),
dota2 = require("./"),
dota2 = require("../"),
steamClient = new steam.SteamClient(),
steamUser = new steam.SteamUser(steamClient),
steamFriends = new steam.SteamFriends(steamClient),
Expand Down Expand Up @@ -89,9 +89,22 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {

if(creatingLobby == 1){ // sets only password, nothing more
var lobbyPassword = "ap";
var lobbyName = "Lobby Name";

Dota2.createPracticeLobby(lobbyPassword, lobbyName, function(err, data){
var properties = {
"game_name": "MyLobby",
"server_region": 3,
"game_mode": 2,
"series_type": 2,
"game_version": 1,
"allow_cheats": false,
"fill_with_bots": false,
"allow_spectating": true,
"pass_key": lobbyPassword,
"radiant_series_wins": 0,
"dire_series_wins": 0,
"allchat": true
}

Dota2.createPracticeLobby(lobbyPassword, properties, function(err, data){
// util.log(JSON.stringify(data));
});
}
Expand All @@ -116,6 +129,19 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {
});
}

// ----------------------------------

// SOURCETV

var sourceGames = 0;

if (sourceGames == 1) {
Dota2.requestSourceTVGames();
Dota2.on('sourceTVGamesData', (gamesData) => {
util.log(gamesData);
});
}

});

Dota2.on("unready", function onUnready() {
Expand Down Expand Up @@ -143,16 +169,18 @@ onSteamError = function onSteamError(error) {
};

steamUser.on('updateMachineAuth', function(sentry, callback) {
fs.writeFileSync('sentry', sentry.bytes)
var hashedSentry = crypto.createHash('sha1').update(sentry.bytes).digest();
fs.writeFileSync('sentry', hashedSentry)
util.log("sentryfile saved");

callback({ sha_file: crypto.createHash('sha1').update(sentry.bytes).digest() });
callback({ sha_file: hashedSentry});
});

var logOnDetails = {
"account_name": global.config.steam_user,
"password": global.config.steam_pass,
};
if (global.config.steam_guard_code) logOnDetails.auth_code = global.config.steam_guard_code;

try {
var sentry = fs.readFileSync('sentry');
Expand All @@ -171,4 +199,4 @@ steamClient.on('connected', function() {
steamClient.on('logOnResponse', onSteamLogOn);
steamClient.on('loggedOff', onSteamLogOff);
steamClient.on('error', onSteamError);
steamClient.on('servers', onSteamServers);
steamClient.on('servers', onSteamServers);
16 changes: 14 additions & 2 deletions handlers/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,13 @@ var onOtherLeftChannel = function onOtherLeftChannel(message) {
var channel = this._getChannelById(otherLeft.channel_id);
// Check if it is me that left the channel
if ("" + otherLeft.steam_id === "" + this._client.steamID) {
if (this.debug) util.log("Left channel " + channel.channel_name);
if (this.debug) {
if (channel) {
util.log("Left channel " + channel.channel_name);
} else {
util.log("This probably should be physically impossible, but whatever: you managed to leave a channel you didn't know you were in, congratulations...");
}
}
this.emit("chatLeave",
channel.channel_name,
otherLeft.steam_id,
Expand All @@ -202,7 +208,13 @@ var onOtherLeftChannel = function onOtherLeftChannel(message) {
if ("" + item.channel_id == "" + channel.channel_id) return false;
});
} else {
if (this.debug) util.log(otherLeft.steam_id + " left channel " + channel.channel_name);
if (this.debug) {
if (channel) {
util.log(otherLeft.steam_id + " left channel " + channel.channel_name);
} else {
util.log(otherLeft.steam_id + " left channel " + otherLeft.channel_id + " (PS: why do I get messages from a chat I don't know? Did you kill me D: ?)");
}
}
this.emit("chatLeave",
channel.channel_name,
otherLeft.steam_id,
Expand Down
28 changes: 14 additions & 14 deletions handlers/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ Dota2.Dota2Client.prototype.requestPlayerMatchHistory = function(account_id, opt
onPlayerMatchHistoryResponse, callback);
};

Dota2.Dota2Client.prototype.requestProfile = function(account_id, request_name, callback) {
callback = callback || null;
var _self = this;
// Dota2.Dota2Client.prototype.requestProfile = function(account_id, request_name, callback) {
// callback = callback || null;
// var _self = this;

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

var payload = new Dota2.schema.CMsgDOTAProfileRequest({
"account_id": account_id,
"request_name": request_name,
"engine": 1
});
this.sendToGC( Dota2.schema.EDOTAGCMsg.k_EMsgGCProfileRequest,
payload,
onProfileResponse, callback);
};
// var payload = new Dota2.schema.CMsgDOTAProfileRequest({
// "account_id": account_id,
// "request_name": request_name,
// "engine": 1
// });
// this.sendToGC( Dota2.schema.EDOTAGCMsg.k_EMsgGCProfileRequest,
// payload,
// onProfileResponse, callback);
// };

Dota2.Dota2Client.prototype.requestProfileCard = function(account_id, callback) {
callback = callback || null;
Expand Down
7 changes: 4 additions & 3 deletions handlers/match.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var onMatchMinimalDetailsResponse = function onMatchMinimalDetailsResponse(messa
/*if (this.debug)*/
util.log("Received match minimal data for: " + matchMinimalDetailsResponse.matches.match_id);
this.emit("matchMinimalDetailsData",
matchMinimalDetailsResponse.matches.match_id,
matchMinimalDetailsResponse.last_match,
matchMinimalDetailsResponse);
if (callback) callback(null, matchMinimalDetailsResponse);
} else {
Expand All @@ -142,14 +142,15 @@ var onMatchMinimalDetailsResponse = function onMatchMinimalDetailsResponse(messa
};
handlers[Dota2.schema.EDOTAGCMsg.k_EMsgClientToGCMatchesMinimalResponse] = onMatchMinimalDetailsResponse;

// TODO: replace first two parameters by matchmakingStatsResponse.match_groups
var onMatchmakingStatsResponse = function onMatchmakingStatsResponse(message) {
// Is not Job ID based - can't do callbacks.
var matchmakingStatsResponse = Dota2.schema.CMsgDOTAMatchmakingStatsResponse.decode(message);

if (this.debug) util.log("Received matchmaking stats");
this.emit("matchmakingStatsData",
matchmakingStatsResponse.searching_players_by_group_source2,
matchmakingStatsResponse.disabled_groups_source2,
matchmakingStatsResponse.matchgroups_version,
matchmakingStatsResponse.match_groups,
matchmakingStatsResponse);
};
handlers[Dota2.schema.EDOTAGCMsg.k_EMsgGCMatchmakingStatsResponse] = onMatchmakingStatsResponse;
Expand Down
3 changes: 3 additions & 0 deletions handlers/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Dota2.Dota2Client.prototype.requestTeamMemberProfile = function requestTeamMembe
onTeamProfileResponse, callback);
}
*/

// No longer gets a response from the GC
Dota2.Dota2Client.prototype.requestProTeamList = function requestProTeamList(callback) {
// Request the list of pro teams
callback = callback || null;
Expand Down Expand Up @@ -115,6 +117,7 @@ var onTeamIDByNameResponse = function onTeamIDByNameResponse(message, callback)
};
handlers[Dota2.schema.EDOTAGCMsg.k_EMsgGCTeamIDByNameResponse] = onTeamIDByNameResponse;*/

// No longer gets triggered
var onProTeamListResponse = function onProTeamListResponse(message, callback) {
var teams = Dota2.schema.CMsgDOTAProTeamListResponse.decode(message);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dota2",
"version": "4.0.0",
"version": "4.0.1",
"dependencies": {
"bignumber.js": "^2.1.0",
"deferred": "^0.7.2",
Expand Down
5 changes: 3 additions & 2 deletions proto/dota_client_enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ enum ETournamentTeamState {
k_ETournamentTeamState_NodeMax = 1024;
k_ETournamentTeamState_Eliminated = 14003;
k_ETournamentTeamState_Forfeited = 14004;
k_ETournamentTeamState_Refunded = 14005;
k_ETournamentTeamState_Finished1st = 15001;
k_ETournamentTeamState_Finished2nd = 15002;
k_ETournamentTeamState_Finished3rd = 15003;
Expand Down Expand Up @@ -68,8 +67,10 @@ enum ETournamentNodeState {
k_ETournamentNodeState_A_WonByForfeit = 7;
k_ETournamentNodeState_B_WonByForfeit = 8;
k_ETournamentNodeState_A_Bye = 9;
k_ETournamentNodeState_A_Forfeit = 10;
k_ETournamentNodeState_A_Abandoned = 10;
k_ETournamentNodeState_ServerFailure = 11;
k_ETournamentNodeState_A_TimeoutForfeit = 12;
k_ETournamentNodeState_A_TimeoutRefund = 13;
}

enum EDOTAGroupMergeResult {
Expand Down
Loading

0 comments on commit bea2b55

Please sign in to comment.