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

Commit bd4eedf

Browse files
committed
Merge pull request #215 from RJacksonm1/merge-test
v2.0.0
2 parents 219e572 + 7a28c72 commit bd4eedf

24 files changed

+2363
-1819
lines changed

README.md

+248-86
Large diffs are not rendered by default.

handlers/cache.js

+99-91
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,134 @@ var Dota2 = require("../index"),
22
util = require("util");
33

44
var cacheTypeIDs = {
5-
LOBBY: 2004,
6-
PARTY: 2003,
7-
PARTY_INVITE: 2006
5+
LOBBY: 2004,
6+
PARTY: 2003,
7+
PARTY_INVITE: 2006,
8+
LOBBY_INVITE: 2011
89
};
910

1011
// Handlers
11-
function handleSubscribedType(obj_type, object_data)
12-
{
13-
switch(obj_type)
14-
{
15-
// Lobby snapshot.
16-
case cacheTypeIDs.LOBBY:
17-
var lobby = Dota2.schema.CSODOTALobby.decode(object_data);
18-
if(this.debug) util.log("Received lobby snapshot for lobby ID "+lobby.lobby_id);
19-
this.emit("practiceLobbyUpdate", lobby);
20-
this.Lobby = lobby;
21-
break;
22-
// Party snapshot.
23-
case cacheTypeIDs.PARTY:
24-
var party = Dota2.schema.CSODOTAParty.decode(object_data);
25-
if(this.debug) util.log("Received party snapshot for party ID "+party.party_id);
26-
this.emit("partyUpdate", party);
27-
this.Party = party;
28-
break;
29-
// Party invite snapshot.
30-
case cacheTypeIDs.PARTY_INVITE:
31-
var party = Dota2.schema.CSODOTAPartyInvite.decode(object_data);
32-
if(this.debug) util.log("Received party invite snapshot for group ID "+party.group_id);
33-
this.emit("partyInviteUpdate", party);
34-
this.PartyInvite = party;
35-
break;
36-
default:
37-
if(this.debug) util.log("Unknown cache ID: "+obj_type);
38-
break;
39-
}
12+
function handleSubscribedType(obj_type, object_data) {
13+
switch (obj_type) {
14+
// Lobby snapshot.
15+
case cacheTypeIDs.LOBBY:
16+
var lobby = Dota2.schema.CSODOTALobby.decode(object_data);
17+
if (this.debug) util.log("Received lobby snapshot for lobby ID " + lobby.lobby_id);
18+
this.emit("practiceLobbyUpdate", lobby);
19+
this.Lobby = lobby;
20+
break;
21+
// Lobby invite snapshot.
22+
case cacheTypeIDs.LOBBY_INVITE:
23+
var lobby = Dota2.schema.CSODOTALobbyInvite.decode(object_data);
24+
if (this.debug) util.log("Received lobby invite snapshot for group ID " + lobby.group_id);
25+
this.emit("lobbyInviteUpdate", lobby);
26+
this.LobbyInvite = lobby;
27+
break;
28+
// Party snapshot.
29+
case cacheTypeIDs.PARTY:
30+
var party = Dota2.schema.CSODOTAParty.decode(object_data);
31+
if (this.debug) util.log("Received party snapshot for party ID " + party.party_id);
32+
this.emit("partyUpdate", party);
33+
this.Party = party;
34+
break;
35+
// Party invite snapshot.
36+
case cacheTypeIDs.PARTY_INVITE:
37+
var party = Dota2.schema.CSODOTAPartyInvite.decode(object_data);
38+
if (this.debug) util.log("Received party invite snapshot for group ID " + party.group_id);
39+
this.emit("partyInviteUpdate", party);
40+
this.PartyInvite = party;
41+
break;
42+
default:
43+
if (this.debug) util.log("Unknown cache ID: " + obj_type);
44+
break;
45+
}
4046
};
4147

42-
Dota2.Dota2Client.prototype._handleWelcomeCaches = function handleWelcomeCaches(message)
43-
{
44-
var welcome = Dota2.schema.CMsgClientWelcome.decode(message);
45-
var _self = this;
48+
Dota2.Dota2Client.prototype._handleWelcomeCaches = function handleWelcomeCaches(message) {
49+
var welcome = Dota2.schema.CMsgClientWelcome.decode(message);
50+
var _self = this;
4651

47-
if(welcome.outofdate_subscribed_caches)
48-
welcome.outofdate_subscribed_caches.forEach(function(cache){
49-
cache.objects.forEach(function(obj){
50-
handleSubscribedType.call(_self, obj.type_id, obj.object_data[0]);
51-
});
52-
});
52+
if (welcome.outofdate_subscribed_caches)
53+
welcome.outofdate_subscribed_caches.forEach(function(cache) {
54+
cache.objects.forEach(function(obj) {
55+
handleSubscribedType.call(_self, obj.type_id, obj.object_data[0]);
56+
});
57+
});
5358
};
5459

5560
var handlers = Dota2.Dota2Client.prototype._handlers;
5661

5762
var onCacheSubscribed = function onCacheSubscribed(message) {
58-
var subscribe = Dota2.schema.CMsgSOCacheSubscribed.decode(message);
59-
var _self = this;
63+
var subscribe = Dota2.schema.CMsgSOCacheSubscribed.decode(message);
64+
var _self = this;
6065

61-
if(this.debug){
62-
util.log("Cache subscribed, type "+subscribe.objects[0].type_id);
63-
}
66+
if (this.debug) {
67+
util.log("Cache subscribed, type " + subscribe.objects[0].type_id);
68+
}
6469

65-
subscribe.objects.forEach(function(obj){
66-
handleSubscribedType.call(_self, obj.type_id, obj.object_data[0]);
67-
});
70+
subscribe.objects.forEach(function(obj) {
71+
handleSubscribedType.call(_self, obj.type_id, obj.object_data[0]);
72+
});
6873
};
6974
handlers[Dota2.schema.ESOMsg.k_ESOMsg_CacheSubscribed] = onCacheSubscribed;
7075

7176
var onUpdateMultiple = function onUpdateMultiple(message) {
72-
var multi = Dota2.schema.CMsgSOMultipleObjects.decode(message);
73-
var _self = this;
77+
var multi = Dota2.schema.CMsgSOMultipleObjects.decode(message);
78+
var _self = this;
7479

75-
if(multi.objects_modified)
76-
multi.objects_modified.forEach(function(obj){
77-
handleSubscribedType.call(_self, obj.type_id, obj.object_data);
78-
});
80+
if (multi.objects_modified)
81+
multi.objects_modified.forEach(function(obj) {
82+
handleSubscribedType.call(_self, obj.type_id, obj.object_data);
83+
});
7984
};
8085
handlers[Dota2.schema.ESOMsg.k_ESOMsg_UpdateMultiple] = onUpdateMultiple;
8186

8287
var onCreate = function onCreate(message) {
83-
var single = Dota2.schema.CMsgSOSingleObject.decode(message);
84-
var _self = this;
88+
var single = Dota2.schema.CMsgSOSingleObject.decode(message);
89+
var _self = this;
8590

86-
if(this.debug){
87-
util.log("Create, type "+single.type_id);
88-
}
89-
handleSubscribedType.call(_self, single.type_id, single.object_data);
91+
if (this.debug) {
92+
util.log("Create, type " + single.type_id);
93+
}
94+
handleSubscribedType.call(_self, single.type_id, single.object_data);
9095
}
9196
handlers[Dota2.schema.ESOMsg.k_ESOMsg_Create] = onCreate;
9297

9398
var onCacheUnsubscribed = function onCacheUnsubscribed(message) {
94-
var unsubscribe = Dota2.schema.CMsgSOCacheUnsubscribed.decode(message);
95-
var _self = this;
96-
97-
if(this.debug) util.log("Cache unsubscribed, "+unsubscribe.owner_soid.id);
98-
99-
if(this.Lobby && ""+unsubscribe.owner_soid.id === ""+this.Lobby.lobby_id)
100-
{
101-
this.Lobby = null;
102-
this.emit("practiceLobbyCleared");
103-
}else if(this.Party && ""+unsubscribe.owner_soid.id === ""+this.Party.party_id)
104-
{
105-
this.Party = null;
106-
this.emit("partyCleared");
107-
}else if(this.PartyInvite && ""+unsubscribe.owner_soid.id === ""+this.PartyInvite.group_id)
108-
{
109-
this.PartyInvite = null;
110-
this.emit("partyInviteCleared");
111-
}
99+
var unsubscribe = Dota2.schema.CMsgSOCacheUnsubscribed.decode(message);
100+
var _self = this;
101+
102+
if (this.debug) util.log("Cache unsubscribed, " + unsubscribe.owner_soid.id);
103+
104+
if (this.Lobby && "" + unsubscribe.owner_soid.id === "" + this.Lobby.lobby_id) {
105+
this.Lobby = null;
106+
this.emit("practiceLobbyCleared");
107+
} else if (this.LobbyInvite && "" + unsubscribe.owner_soid.id === "" + this.LobbyInvite.group_id) {
108+
this.LobbyInvite = null;
109+
this.emit("lobbyInviteCleared");
110+
} else if (this.Party && "" + unsubscribe.owner_soid.id === "" + this.Party.party_id) {
111+
this.Party = null;
112+
this.emit("partyCleared");
113+
} else if (this.PartyInvite && "" + unsubscribe.owner_soid.id === "" + this.PartyInvite.group_id) {
114+
this.PartyInvite = null;
115+
this.emit("partyInviteCleared");
116+
}
112117
};
113118
handlers[Dota2.schema.ESOMsg.k_ESOMsg_CacheUnsubscribed] = onCacheUnsubscribed;
114119

115120
var onCacheDestroy = function onCacheDestroy(message) {
116-
var destroy = Dota2.schema.CMsgSOSingleObject.decode(message);
117-
var _self = this;
118-
119-
if(this.debug) util.log("Cache destroy, "+destroy.type_id);
120-
121-
if(destroy.type_id === cacheTypeIDs.PARTY_INVITE)
122-
{
123-
this.PartyInvite = null;
124-
this.emit("partyInviteCleared");
125-
}
121+
var destroy = Dota2.schema.CMsgSOSingleObject.decode(message);
122+
var _self = this;
123+
124+
if (this.debug) util.log("Cache destroy, " + destroy.type_id);
125+
126+
if (destroy.type_id === cacheTypeIDs.PARTY_INVITE) {
127+
this.PartyInvite = null;
128+
this.emit("partyInviteCleared");
129+
}
130+
if (destroy.type_id === cacheTypeIDs.LOBBY_INVITE) {
131+
this.LobbyInvite = null;
132+
this.emit("lobbyInviteCleared");
133+
}
126134
};
127-
handlers[Dota2.schema.ESOMsg.k_ESOMsg_CacheDestroy] = onCacheDestroy;
135+
handlers[Dota2.schema.ESOMsg.k_ESOMsg_Destroy] = onCacheDestroy;

0 commit comments

Comments
 (0)