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 #555 from Arcana/staging
Browse files Browse the repository at this point in the history
6.0.0 Merge
  • Loading branch information
Crazy-Duck authored Nov 25, 2017
2 parents dcdba61 + 1c2ae36 commit 254e40b
Show file tree
Hide file tree
Showing 22 changed files with 342 additions and 221 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.1.2"
- "6.11.0"
- "8.9.1"
- "9.2.0"
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
# Changelog 6.0.0
## General
Fixed some chat channel bugs

## API changes
### Methods
#### requestLeaguesInMonth
Proto message was removed so corresponding function also removed

#### destroyLobby
New function for lobby host that destroys the lobby

### Events
#### leaguesInMonthData
Removed because Valve removed proto message

# Changelog 5.2.0
## Dependency changes
Nothing new, just some updates

## API changes
### methods
### Methods
#### requestPlayerCardsByPlayer
Now parses the bonuses

Expand Down
78 changes: 31 additions & 47 deletions README.md

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions examples/example2.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {

// COMMUNITY

var accId = 63470426;
var accId = 103637655;
// var playerInfo = 0;
var playerInfo2 = 0;
// var playerInfo3 = 0;
Expand Down Expand Up @@ -106,8 +106,9 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {

// LOBBY

var creatingLobby = 1;
var leavingLobby = 1;
var creatingLobby = 0;
var leavingLobby = 0;
var destroyLobby = 0;
var lobbyChannel = "";

if(creatingLobby == 1){ // sets only password, nothing more
Expand Down Expand Up @@ -151,6 +152,18 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {
}, 10000);
}

if(destroyLobby == 1){
setTimeout(function(){
Dota2.destroyLobby(function(err, data){
if (err) {
util.log(err + ' - ' + JSON.stringify(data));
} else {
if(lobbyChannel) Dota2.leaveChat(lobbyChannel);
}
});
}, 10000);
}

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

// TEAM
Expand Down Expand Up @@ -186,8 +199,10 @@ var onSteamLogOn = function onSteamLogOn(logonResp) {
Dota2.on("inventoryUpdate", inventory => {
// Time-out so inventory property is updated
setTimeout(()=>{
Promise.all(Dota2.requestPlayerCardsByPlayer()).then(cards => console.log(cards));
}, 1000);
Promise.all(Dota2.requestPlayerCardsByPlayer()).then(cards => {
fs.writeFileSync('cards.js',JSON.stringify(cards));
});
}, 10000);
});
}
});
Expand Down
11 changes: 8 additions & 3 deletions handlers/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,9 @@ handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgGCJoinChatChannelRes
var onChatMessage = function onChatMessage(message) {
/* Chat channel message from another user. */
var chatData = Dota2.schema.lookupType("CMsgDOTAChatMessage").decode(message);
var channel = this._getChannelById(chatData.channel_id);
var channel = this._getChannelById(chatData.channel_id) || {
channel_name: "Unknown"
};

this.Logger.debug("Received chat message from " + chatData.persona_name + " in channel " + channel.channel_name);
this.emit("chatMessage",
Expand All @@ -278,8 +280,11 @@ handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgGCChatMessage] = onC
var onOtherJoinedChannel = function onOtherJoinedChannel(message) {
/* Someone joined a chat channel you're in. */
var otherJoined = Dota2.schema.lookupType("CMsgDOTAOtherJoinedChatChannel").decode(message);
var channel = this._getChannelById(otherJoined.channel_id);
this.Logger.debug(otherJoined.steam_id + " joined channel " + channel.channel_name);
var channel = this._getChannelById(otherJoined.channel_id) || {
channel_name: "Unknown",
members: []
};
this.Logger.debug(otherJoined.steam_id + " joined channel " + channel.channel_name);
this.emit("chatJoin",
channel.channel_name,
otherJoined.persona_name,
Expand Down
65 changes: 0 additions & 65 deletions handlers/leagues.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@ var Dota2 = require("../index"),
util = require("util");

// Methods
/**
* Sends a message to the Game Coordinator requesting data on leagues being played in the given month.
* Provide a callback or listen for {@link module:Dota2.Dota2Client#event:leaguesInMonthData|leaguesInMonthData} for the Game Coordinator's response.
* Requires the GC to be {@link module:Dota2.Dota2Client#event:ready|ready}.
* @alias module:Dota2.Dota2Client#requestLeaguesInMonth
* @param {number} [month=(new Date()).getMonth()] - Month (MM) you want to query data for. **IMPORTANT NOTE**: Month is zero-aligned, not one-aligned; so Jan = 00, Feb = 01, etc.
* @param {number} [year=(new Date()).getFullYear()] - Year (YYYY) you want to query data for.
* @param {number} [tier=0] - Search only for a specific tier of tournaments.
* @param {module:Dota2~requestCallback} [callback] - Called with `err, CMsgDOTALeaguesInMonthResponse`
*/
Dota2.Dota2Client.prototype.requestLeaguesInMonth = function(month, year, tier, callback) {
var _self = this;
var now = new Date();

// Month & year default to current time values
month = month === undefined ? now.getMonth() : month;
year = year || now.getFullYear();
tier = tier || 0;
callback = callback || null;

this.Logger.debug("Sending CMsgDOTALeaguesInMonthRequest");

var payload = {
'month': month,
'year': year,
'tier': tier
};
this.sendToGC( Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgGCLeaguesInMonthRequest,
Dota2.schema.lookupType("CMsgDOTALeaguesInMonthRequest").encode(payload).finish(),
onLeaguesInMonthResponse, callback);
};

/**
* Requests info on all available official leagues from the GC.
Expand Down Expand Up @@ -67,25 +36,6 @@ Dota2.Dota2Client.prototype.requestTopLeagueMatches = function() {
};

// Events
/**
* Emitted in response to a {@link module:Dota2.Dota2Client#requestLeaguesInMonth|request for the leagues in a given month}.
* The leagues that are returned are those which have one or more matches in the given month.
* They can however also have other matches in a different month.
* @event module:Dota2.Dota2Client#leaguesInMonthData
* @param {number} month - Month this data represents.
* @param {number} year - Year this data represents
* @param {Object[]} leagues - List of leagues that have matches in the given month
* @param {number} leagues[].league_id - ID of the league
* @param {Object[]} leagues[].schedule - The scheduled games in this league. Might contain matches in other months.
* @param {number} leagues[].schedule[].block_id - ID of the schedule block
* @param {number} leagues[].schedule[].start_time - Unix timestamp of the start time of this scheduled match
* @param {boolean} leagues[].schedule[].finals - Whether or not this is a finals game
* @param {string} leagues[].schedule[].comment - Comment about this scheduled block; often the team names & position in bracket
* @param {Object[]} leagues[].schedule[].teams - The teams duking it out in this match
* @param {number} leagues[].schedule[].teams[].team_id - ID of the team. Not every participating team seems to be hooked up to Dota 2's team system, so 0 entries can happen
* @param {string} leagues[].schedule[].teams[].name - Name of the team
* @param {external:Long} leagues[].schedule[].teams[].logo - Logo of the team
*/
/**
* Emitted when the GC sends a `CMsgDOTALiveLeagueGameUpdate`.
* @event module:Dota2.Dota2Client#liveLeagueGamesUpdate
Expand Down Expand Up @@ -119,21 +69,6 @@ Dota2.Dota2Client.prototype.requestTopLeagueMatches = function() {
// Handlers
var handlers = Dota2.Dota2Client.prototype._handlers;

var onLeaguesInMonthResponse = function onLeaguesInMonthResponse(message, callback) {
callback = callback || null;
var response = Dota2.schema.lookupType("CMsgDOTALeaguesInMonthResponse").decode(message);

if (response.eresult === 1) {
this.Logger.debug("Received leagues in month response " + response.eresult);
this.emit("leaguesInMonthData", response.month, response.year, response.leagues);
if (callback) callback(null, response);
} else {
this.Logger.error("Received a bad leaguesInMonthResponse");
if (callback) callback(response.eresult, response);
}
};
handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgGCLeaguesInMonthResponse] = onLeaguesInMonthResponse;

var onLiveLeagueGameUpdate = function onLiveLeagueGameUpdate(message, callback) {
callback = callback || null;
var response = Dota2.schema.lookupType("CMsgDOTALiveLeagueGameUpdate").decode(message);
Expand Down
46 changes: 45 additions & 1 deletion handlers/lobbies.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Dota2._lobbyOptions = {
* @property {number} [custom_difficulty] - Difficulty of the custom game
*
* @property {external:Long} [custom_game_id] - 64bit ID of the custom game mode
*
* @property {LobbyDotaPauseSetting} [pause_setting=0] - Pause setting: 0 - unlimited, 1 - limited, 2 - disabled
*/

// Methods
Expand Down Expand Up @@ -381,7 +383,7 @@ Dota2.Dota2Client.prototype.leavePracticeLobby = function(callback) {
callback = callback || null;
var _self = this;

/* Sends a message to the Game Coordinator requesting `matchId`'s match details. Listen for `matchData` event for Game Coordinator's response. */
/* Sends a message to the Game Coordinator requesting to leave the lobby. Listen for `practiceLobby` event for Game Coordinator's response. */
this.Logger.debug("Sending match CMsgPracticeLobbyLeave request");

var payload = {};
Expand All @@ -390,6 +392,25 @@ Dota2.Dota2Client.prototype.leavePracticeLobby = function(callback) {
onPracticeLobbyResponse, callback);
};

/**
* Destroy the current lobby. Requires you to be the host.
* Provide a callback or listen for the {@link module:Dota2.Dota2Client#event:lobbyDestroyed|lobbyDestroyed} event for the GC's response.
* Requires the GC to be {@link module:Dota2.Dota2Client#event:ready|ready}.
* @alias module:Dota2.Dota2Client#destroyLobby
* @param {module:Dota2~requestCallback} [callback] - Called with `err, CMsgDOTADestroyLobbyResponse`
**/
Dota2.Dota2Client.prototype.destroyLobby = function(callback) {
callback = callback || null;

/* Sends a message to the Game Coordinator requesting to destroy the lobby. Listen for `lobbyDestroyed` event for Game Coordinator's response. */
this.Logger.debug("Sending match CMsgPracticeLobbyLeave request");

var payload = {};
this.sendToGC( Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgDestroyLobbyRequest,
Dota2.schema.lookupType("CMsgDOTADestroyLobbyRequest").encode(payload).finish(),
onDestroyLobbyResponse, callback);
}

/**
* Abandons the current game.
* Provide a callback or listen for the {@link module:Dota2.Dota2Client#event:practiceLobbyResponse|practiceLobbyResponse} event for the GC's response.
Expand Down Expand Up @@ -538,6 +559,12 @@ Dota2.Dota2Client.prototype.respondLobbyInvite = function(id, accept) {
};

// Events
/**
* Event that's emitted when attempting to destroy the lobby
* @event module:Dota2.Dota2Client#lobbyDestroyed
* @param {CMsgDOTADestroyLobbyResponse.Result} result - Result code, 0 is SUCCESS, 1 is ERROR_UNKNOWN
* @param {Object} response - The raw response object
**/
/**
* Event that's emitted whenever the bot joins a lobby
* @event module:Dota2.Dota2Client#practiceLobbyJoinResponse
Expand Down Expand Up @@ -578,6 +605,23 @@ Dota2.Dota2Client.prototype.respondLobbyInvite = function(id, accept) {
// Handlers
var handlers = Dota2.Dota2Client.prototype._handlers;

var onDestroyLobbyResponse = function onDestroyLobbyResponse(message, callback) {
callback = callback || null;
var lobbyDestroyed = Dota2.schema.lookupType("CMsgDOTADestroyLobbyResponse").decode(message);

this.Logger.debug("Received destroy lobby response "+lobbyDestroyed.result);
this.emit("lobbyDestroyed", lobbyDestroyed.result, lobbyDestroyed);

if (callback) {
if (lobbyDestroyed.result === Dota2.schema.lookupEnum("CMsgDOTADestroyLobbyResponse.Result").values.SUCCESS) {
callback(null, lobbyDestroyed);
} else {
callback(lobbyDestroyed.result, lobbyDestroyed);
}
}
}
handlers[Dota2.schema.lookupEnum("EDOTAGCMsg").values.k_EMsgDestroyLobbyResponse ] = onDestroyLobbyResponse;

var onPracticeLobbyJoinResponse = function onPracticeLobbyJoinResponse(message, callback) {
callback = callback || null;
var practiceLobbyJoinResponse = Dota2.schema.lookupType("CMsgPracticeLobbyJoinResponse").decode(message);
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Dota2.schema = Protobuf.loadSync(folder.map(filename => __dirname + '/proto/' +
* @fires module:Dota2.Dota2Client#event:practiceLobbyJoinResponse
* @fires module:Dota2.Dota2Client#event:practiceLobbyListData
* @fires module:Dota2.Dota2Client#event:practiceLobbyResponse
* @fires module:Dota2.Dota2Client#event:lobbyDestroyed
* @fires module:Dota2.Dota2Client#event:friendPracticeLobbyListData
* @fires module:Dota2.Dota2Client#event:inviteCreated
* @fires module:Dota2.Dota2Client#event:partyUpdate
Expand All @@ -77,7 +78,6 @@ Dota2.schema = Protobuf.loadSync(folder.map(filename => __dirname + '/proto/' +
* @fires module:Dota2.Dota2Client#event:hallOfFameData
* @fires module:Dota2.Dota2Client#event:playerCardRoster
* @fires module:Dota2.Dota2Client#event:playerCardDrafted
* @fires module:Dota2.Dota2Client#event:leaguesInMonthData
* @fires module:Dota2.Dota2Client#event:liveLeagueGamesUpdate
* @fires module:Dota2.Dota2Client#event:leagueData
* @fires module:Dota2.Dota2Client#event:topLeagueMatchesData
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "dota2",
"version": "5.2.0",
"version": "6.0.0",
"dependencies": {
"deferred": "^0.7.8",
"long": "^3.2.0",
"merge": "^1.2.0",
"moment": "^2.18.1",
"moment": "^2.19.1",
"protobufjs": "^6.8.0",
"steam": "^1.4.0",
"winston": "^2.3.1"
},
"devDependencies": {
"mocha": "^3.5.0",
"should": "^13.0.0"
"mocha": "^4.0.0",
"should": "^13.1.3"
},
"scripts": {
"update": "bash update_proto.sh",
Expand Down
4 changes: 0 additions & 4 deletions proto/base_gcmessages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,6 @@ message CMsgReplicateConVars {
repeated .CMsgConVarValue convars = 1;
}

message CMsgConsumableExhausted {
optional int32 item_def_id = 1;
}

message CMsgItemAcknowledged {
optional uint32 account_id = 1;
optional uint32 inventory = 2;
Expand Down
Loading

0 comments on commit 254e40b

Please sign in to comment.