|
1 | 1 | /** |
2 | 2 | * node-steam-groups |
3 | | - * node-steam extension which adds group functions |
| 3 | + * Custom node-steam handler which provides group functions |
4 | 4 | * Author: Michael Scholtz <michael.scholtz@outlook.com> |
5 | 5 | * Licence: MIT |
6 | 6 | */ |
7 | 7 | var ByteBuffer = require('bytebuffer'); |
8 | 8 |
|
| 9 | +module.exports = SteamGroups; |
| 10 | + |
| 11 | +function SteamGroups(steamClient) { |
| 12 | + this._client = steamClient; |
| 13 | +} |
| 14 | + |
9 | 15 | /** |
10 | | - * Export single function which injects new methods into Steam. |
| 16 | + * Invite another user to specific Steam group |
11 | 17 | */ |
12 | | -module.exports = function(Steam) { |
13 | | - var EMsg = Steam.EMsg; |
14 | | - var prototype = Steam.SteamClient.prototype; |
15 | | - |
16 | | - prototype.acceptGroup = function(steamIdGroup) { |
17 | | - this._send(EMsg.ClientAcknowledgeClanInvite, GroupMessages.MsgClientAcknowledgeClanInvite.serialize({ |
| 18 | +SteamGroups.prototype.inviteUserToGroup = function(steamIdGroup, steamIdInvited) { |
| 19 | + this._client.send({ |
| 20 | + msg: EMsg.ClientInviteUserToClan |
| 21 | + }, |
| 22 | + MsgClientInviteUserToClan.serialize({ |
| 23 | + steamIdInvited: steamIdInvited, |
18 | 24 | steamIdGroup: steamIdGroup, |
19 | | - acceptInvite: 1 |
20 | | - })); |
21 | | - }; |
| 25 | + unknown: 1 // I really don't know |
| 26 | + }) |
| 27 | + ); |
| 28 | +}; |
22 | 29 |
|
23 | | - prototype.declineGroup = function(steamIdGroup) { |
24 | | - this._send(EMsg.ClientAcknowledgeClanInvite, GroupMessages.MsgClientAcknowledgeClanInvite.serialize({ |
| 30 | +/** |
| 31 | + * Accept/decline group invite |
| 32 | + */ |
| 33 | +SteamGroups.prototype.acknowledgeGroupInvite = function(steamIdGroup, response) { |
| 34 | + this._client.send({ |
| 35 | + msg: EMsg.ClientAcknowledgeClanInvite |
| 36 | + }, |
| 37 | + MsgClientAcknowledgeClanInvite.serialize({ |
25 | 38 | steamIdGroup: steamIdGroup, |
26 | | - acceptInvite: 0 |
27 | | - })); |
28 | | - }; |
| 39 | + response: +response |
| 40 | + }) |
| 41 | + ); |
| 42 | +}; |
29 | 43 |
|
30 | | - prototype.groupInvite = function(steamIdGroup, steamIdInvited) { |
31 | | - this._send(EMsg.ClientInviteUserToClan, GroupMessages.MsgClientInviteUserToClan.serialize({ |
32 | | - steamIdInvited: steamIdInvited, |
33 | | - steamIdGroup: steamIdGroup, |
34 | | - unknown: 1 |
35 | | - })); |
36 | | - }; |
| 44 | +/** |
| 45 | + * Define additional EMsg codes |
| 46 | + */ |
| 47 | +var EMsg = { |
| 48 | + ClientInviteUserToClan: 744, |
| 49 | + ClientAcknowledgeClanInvite: 745 |
37 | 50 | }; |
38 | 51 |
|
39 | 52 | /** |
40 | 53 | * Define additional Steam messages |
41 | 54 | */ |
42 | | -var GroupMessages = {}; |
43 | | - |
44 | 55 | // Sending group invites |
45 | 56 | var MsgClientInviteUserToClan = { |
46 | | - baseSize: 17, |
47 | | - |
48 | 57 | serialize: function(object) { |
49 | 58 | var buffer = new ByteBuffer(17, ByteBuffer.LITTLE_ENDIAN); |
50 | 59 |
|
51 | 60 | buffer.writeUint64(ByteBuffer.Long.fromString(object.steamIdInvited) || 0); |
52 | 61 | buffer.writeUint64(ByteBuffer.Long.fromString(object.steamIdGroup) || 0); |
53 | 62 | buffer.writeUint8(object.unknown || 0); |
54 | 63 |
|
55 | | - return buffer.flip(); |
| 64 | + return buffer.flip().toBuffer(); |
56 | 65 | } |
57 | 66 | }; |
58 | 67 |
|
59 | | -GroupMessages.MsgClientInviteUserToClan = MsgClientInviteUserToClan; |
60 | | - |
61 | 68 | // Accepting/declining group invites |
62 | 69 | var MsgClientAcknowledgeClanInvite = { |
63 | | - baseSize: 9, |
64 | | - |
65 | 70 | serialize: function(object) { |
66 | 71 | var buffer = new ByteBuffer(9, ByteBuffer.LITTLE_ENDIAN); |
67 | 72 |
|
68 | 73 | buffer.writeUint64(ByteBuffer.Long.fromString(object.steamIdGroup) || 0); |
69 | | - buffer.writeUint8(object.acceptInvite || 0); |
| 74 | + buffer.writeUint8(object.response || 0); |
70 | 75 |
|
71 | | - return buffer.flip(); |
| 76 | + return buffer.flip().toBuffer(); |
72 | 77 | } |
73 | 78 | }; |
74 | | - |
75 | | -GroupMessages.MsgClientAcknowledgeClanInvite = MsgClientAcknowledgeClanInvite; |
|
0 commit comments