bedrock-portal 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -2
- package/dist/index.d.ts +13 -3
- package/dist/index.js +9 -6
- package/dist/modules/inviteOnMessage.js +5 -1
- package/dist/modules/multipleAccounts.js +0 -1
- package/dist/modules/updateMemberCount.d.ts +7 -0
- package/dist/modules/updateMemberCount.js +39 -0
- package/dist/rest.d.ts +1 -1
- package/dist/rest.js +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,6 +133,27 @@ portal.use(Modules.RedirectFromRealm, {
|
|
|
133
133
|
}
|
|
134
134
|
```
|
|
135
135
|
|
|
136
|
+
### UpdateMemberCount
|
|
137
|
+
|
|
138
|
+
> Requires [bedrock-protocol](https://github.com/PrismarineJS/bedrock-protocol) to be installed. `npm install bedrock-protocol`
|
|
139
|
+
|
|
140
|
+
Periodically updates the member count of the session. `#.use(Modules.UpdateMemberCount, options);`
|
|
141
|
+
|
|
142
|
+
Options:
|
|
143
|
+
- **updateInterval**: number - How often to update the member count (default: 60000ms)
|
|
144
|
+
- **updateMaxMemberCount**: boolean - Whether to update the max member count (default: true)
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
const { BedrockPortal, Modules } = require('bedrock-portal');
|
|
148
|
+
|
|
149
|
+
const portal = new BedrockPortal(auth, { ... })
|
|
150
|
+
|
|
151
|
+
portal.use(Modules.UpdateMemberCount, {
|
|
152
|
+
updateInterval: 60000,
|
|
153
|
+
updateMaxMemberCount: false,
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
136
157
|
### AutoFriendAdd
|
|
137
158
|
|
|
138
159
|
Automatically adds the account's followers as friends and invites them to the game. `#.use(Modules.autoFriendAdd);`
|
|
@@ -273,8 +294,11 @@ Emitted when a player is added as a friend. This event is only emitted when the
|
|
|
273
294
|
### portal.on('friendRemoved', (player) => void)
|
|
274
295
|
Emitted when a player is removed as a friend. This event is only emitted when the `autoFriendAdd` module is enabled.
|
|
275
296
|
|
|
276
|
-
### portal.on('
|
|
277
|
-
Emitted when a message is
|
|
297
|
+
### portal.on('messageReceived', (message) => void)
|
|
298
|
+
Emitted when a message is received from a player. This event is only emitted when the `inviteOnMessage` module is enabled.
|
|
299
|
+
|
|
300
|
+
### portal.on('memberCountUpdate', (memberCount) => void)
|
|
301
|
+
Emitted when the member count of the session is updated. This event is only emitted when the `updateMemberCount` module is enabled.
|
|
278
302
|
|
|
279
303
|
## Debugging
|
|
280
304
|
|
package/dist/index.d.ts
CHANGED
|
@@ -7,10 +7,12 @@ import Host from './classes/Host';
|
|
|
7
7
|
import Player from './classes/Player';
|
|
8
8
|
import Module from './classes/Module';
|
|
9
9
|
import { Joinability } from './common/constants';
|
|
10
|
-
import AutoFriendAdd from './modules/
|
|
10
|
+
import AutoFriendAdd from './modules/autoFriendAdd';
|
|
11
11
|
import InviteOnMessage from './modules/inviteOnMessage';
|
|
12
12
|
import RedirectFromRealm from './modules/redirectFromRealm';
|
|
13
13
|
import MultipleAccounts from './modules/multipleAccounts';
|
|
14
|
+
import AutoFriendAccept from './modules/autoFriendAccept';
|
|
15
|
+
import UpdateMemberCount from './modules/updateMemberCount';
|
|
14
16
|
type BedrockPortalOptions = {
|
|
15
17
|
/**
|
|
16
18
|
* The ip of the server to redirect users to.
|
|
@@ -83,8 +85,14 @@ interface PortalEvents {
|
|
|
83
85
|
playerJoin: (player: Player) => void;
|
|
84
86
|
playerLeave: (player: Player) => void;
|
|
85
87
|
messageRecieved: (message: Message) => void;
|
|
88
|
+
messageReceived: (message: Message) => void;
|
|
86
89
|
friendRemoved: (player: Player) => void;
|
|
87
90
|
friendAdded: (player: Player) => void;
|
|
91
|
+
memberCountUpdate: (data: {
|
|
92
|
+
online: number;
|
|
93
|
+
max: number;
|
|
94
|
+
cycle: number;
|
|
95
|
+
}) => void;
|
|
88
96
|
}
|
|
89
97
|
export declare class BedrockPortal extends TypedEmitter<PortalEvents> {
|
|
90
98
|
authflow: Authflow;
|
|
@@ -117,8 +125,9 @@ export declare class BedrockPortal extends TypedEmitter<PortalEvents> {
|
|
|
117
125
|
/**
|
|
118
126
|
* Updates the current member count which is displayed in the Minecraft client.
|
|
119
127
|
* @param count The new member count.
|
|
128
|
+
* @param maxCount The new max member count.
|
|
120
129
|
*/
|
|
121
|
-
updateMemberCount(count: number): Promise<void>;
|
|
130
|
+
updateMemberCount(count: number, maxCount?: number): Promise<void>;
|
|
122
131
|
/**
|
|
123
132
|
* Gets the current session of the BedrockPortal instance.
|
|
124
133
|
*/
|
|
@@ -149,6 +158,7 @@ declare const Modules: {
|
|
|
149
158
|
InviteOnMessage: typeof InviteOnMessage;
|
|
150
159
|
RedirectFromRealm: typeof RedirectFromRealm;
|
|
151
160
|
MultipleAccounts: typeof MultipleAccounts;
|
|
152
|
-
AutoFriendAccept: typeof
|
|
161
|
+
AutoFriendAccept: typeof AutoFriendAccept;
|
|
162
|
+
UpdateMemberCount: typeof UpdateMemberCount;
|
|
153
163
|
};
|
|
154
164
|
export { Modules };
|
package/dist/index.js
CHANGED
|
@@ -13,11 +13,12 @@ const Module_1 = __importDefault(require("./classes/Module"));
|
|
|
13
13
|
exports.Module = Module_1.default;
|
|
14
14
|
const constants_1 = require("./common/constants");
|
|
15
15
|
const Event_1 = __importDefault(require("./handlers/Event"));
|
|
16
|
-
const
|
|
16
|
+
const autoFriendAdd_1 = __importDefault(require("./modules/autoFriendAdd"));
|
|
17
17
|
const inviteOnMessage_1 = __importDefault(require("./modules/inviteOnMessage"));
|
|
18
18
|
const redirectFromRealm_1 = __importDefault(require("./modules/redirectFromRealm"));
|
|
19
19
|
const multipleAccounts_1 = __importDefault(require("./modules/multipleAccounts"));
|
|
20
|
-
const
|
|
20
|
+
const autoFriendAccept_1 = __importDefault(require("./modules/autoFriendAccept"));
|
|
21
|
+
const updateMemberCount_1 = __importDefault(require("./modules/updateMemberCount"));
|
|
21
22
|
const start_game_1 = require("./common/start_game");
|
|
22
23
|
const util_1 = require("./common/util");
|
|
23
24
|
const debug = (0, debug_1.default)('bedrock-portal');
|
|
@@ -135,9 +136,10 @@ class BedrockPortal extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
135
136
|
/**
|
|
136
137
|
* Updates the current member count which is displayed in the Minecraft client.
|
|
137
138
|
* @param count The new member count.
|
|
139
|
+
* @param maxCount The new max member count.
|
|
138
140
|
*/
|
|
139
|
-
async updateMemberCount(count) {
|
|
140
|
-
await this.host.rest.updateMemberCount(this.session.name, count);
|
|
141
|
+
async updateMemberCount(count, maxCount) {
|
|
142
|
+
await this.host.rest.updateMemberCount(this.session.name, count, maxCount);
|
|
141
143
|
}
|
|
142
144
|
/**
|
|
143
145
|
* Gets the current session of the BedrockPortal instance.
|
|
@@ -249,10 +251,11 @@ exports.BedrockPortal = BedrockPortal;
|
|
|
249
251
|
var constants_2 = require("./common/constants");
|
|
250
252
|
Object.defineProperty(exports, "Joinability", { enumerable: true, get: function () { return constants_2.Joinability; } });
|
|
251
253
|
const Modules = {
|
|
252
|
-
AutoFriendAdd:
|
|
254
|
+
AutoFriendAdd: autoFriendAdd_1.default,
|
|
253
255
|
InviteOnMessage: inviteOnMessage_1.default,
|
|
254
256
|
RedirectFromRealm: redirectFromRealm_1.default,
|
|
255
257
|
MultipleAccounts: multipleAccounts_1.default,
|
|
256
|
-
AutoFriendAccept:
|
|
258
|
+
AutoFriendAccept: autoFriendAccept_1.default,
|
|
259
|
+
UpdateMemberCount: updateMemberCount_1.default,
|
|
257
260
|
};
|
|
258
261
|
exports.Modules = Modules;
|
|
@@ -32,7 +32,11 @@ class IniteOnMessage extends Module_1.default {
|
|
|
32
32
|
if (newMessages.length === 0)
|
|
33
33
|
return;
|
|
34
34
|
for (const message of newMessages) {
|
|
35
|
-
portal.
|
|
35
|
+
if (portal.listenerCount('messageRecieved') > 0) {
|
|
36
|
+
console.warn('[Deprecation Warning]: The event \'messageRecieved\' is deprecated and will be removed in a future release. Please use \'messageReceived\' instead.');
|
|
37
|
+
portal.emit('messageRecieved', message.lastMessage);
|
|
38
|
+
}
|
|
39
|
+
portal.emit('messageReceived', message.lastMessage);
|
|
36
40
|
const senderXuid = message.lastMessage.sender;
|
|
37
41
|
if (senderXuid === '0')
|
|
38
42
|
continue;
|
|
@@ -25,7 +25,6 @@ class MultipleAccounts extends Module_1.default {
|
|
|
25
25
|
const peer = new Host_1.default(portal, account);
|
|
26
26
|
await peer.connect();
|
|
27
27
|
if (!peer.profile || !peer.connectionId) {
|
|
28
|
-
// @ts-expect-error - username isn't defined on Authflow
|
|
29
28
|
this.debug(`Failed to connect to ${account.username}`);
|
|
30
29
|
continue;
|
|
31
30
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Module_1 = __importDefault(require("../classes/Module"));
|
|
7
|
+
class UpdateMemberCount extends Module_1.default {
|
|
8
|
+
ping;
|
|
9
|
+
constructor() {
|
|
10
|
+
super('updateMemberCount', 'Periodically updates the member count of the session to the amount of players online');
|
|
11
|
+
this.options = {
|
|
12
|
+
updateInterval: 60000,
|
|
13
|
+
updateMaxMemberCount: true,
|
|
14
|
+
};
|
|
15
|
+
try {
|
|
16
|
+
this.ping = require('bedrock-protocol').ping;
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.trace('bedrock-protocol is not installed, please run "npm i bedrock-protocol" to use this module');
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async run(portal) {
|
|
24
|
+
let cycle = 0;
|
|
25
|
+
setInterval(async () => {
|
|
26
|
+
try {
|
|
27
|
+
const data = await this.ping({ host: portal.options.ip, port: portal.options.port });
|
|
28
|
+
this.debug(`Updating member count to ${data.playersOnline} / ${data.playersMax}`);
|
|
29
|
+
await portal.updateMemberCount(data.playersOnline, this.options.updateMaxMemberCount ? data.playersMax : undefined);
|
|
30
|
+
portal.emit('memberCountUpdate', { online: Number(data.playersOnline), max: Number(data.playersMax), cycle });
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
this.debug(`Error updating member count - ${error.message}`, error);
|
|
34
|
+
}
|
|
35
|
+
cycle++;
|
|
36
|
+
}, this.options.updateInterval);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.default = UpdateMemberCount;
|
package/dist/rest.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export default class Rest {
|
|
|
32
32
|
sendInvite(sessionName: string, xuid: string): Promise<any>;
|
|
33
33
|
getSession(sessionName: string): Promise<RESTSessionResponse>;
|
|
34
34
|
updateSession(sessionName: string, payload: SessionRequest): Promise<RESTSessionResponse>;
|
|
35
|
-
updateMemberCount(sessionName: string, count: number): Promise<void>;
|
|
35
|
+
updateMemberCount(sessionName: string, count: number, maxCount?: number): Promise<void>;
|
|
36
36
|
addConnection(sessionName: string, xuid: string, connectionId: string, subscriptionId: string): Promise<void>;
|
|
37
37
|
updateConnection(sessionName: string, connectionId: string): Promise<void>;
|
|
38
38
|
leaveSession(sessionName: string): Promise<void>;
|
package/dist/rest.js
CHANGED
|
@@ -86,8 +86,9 @@ class Rest {
|
|
|
86
86
|
});
|
|
87
87
|
return response;
|
|
88
88
|
}
|
|
89
|
-
async updateMemberCount(sessionName, count) {
|
|
90
|
-
|
|
89
|
+
async updateMemberCount(sessionName, count, maxCount) {
|
|
90
|
+
const payload = maxCount ? { MemberCount: count, MaxMemberCount: maxCount } : { MemberCount: count };
|
|
91
|
+
await this.updateSession(sessionName, { properties: { custom: payload } });
|
|
91
92
|
}
|
|
92
93
|
async addConnection(sessionName, xuid, connectionId, subscriptionId) {
|
|
93
94
|
const payload = {
|
package/package.json
CHANGED