bedrock-portal 0.8.2 → 0.8.3

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 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);`
@@ -276,6 +297,9 @@ Emitted when a player is removed as a friend. This event is only emitted when th
276
297
  ### portal.on('messageRecieved', (message) => void)
277
298
  Emitted when a message is recieved from a player. This event is only emitted when the `inviteOnMessage` module is enabled.
278
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.
302
+
279
303
  ## Debugging
280
304
 
281
305
  You can enable some debugging output using the `DEBUG` enviroment variable. Through node.js, you can add `process.env.DEBUG = 'bedrock-portal*'` at the top of your code.
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ import AutoFriendAdd from './modules/autoFriendAccept';
11
11
  import InviteOnMessage from './modules/inviteOnMessage';
12
12
  import RedirectFromRealm from './modules/redirectFromRealm';
13
13
  import MultipleAccounts from './modules/multipleAccounts';
14
+ import UpdateMemberCount from './modules/updateMemberCount';
14
15
  type BedrockPortalOptions = {
15
16
  /**
16
17
  * The ip of the server to redirect users to.
@@ -85,6 +86,11 @@ interface PortalEvents {
85
86
  messageRecieved: (message: Message) => void;
86
87
  friendRemoved: (player: Player) => void;
87
88
  friendAdded: (player: Player) => void;
89
+ memberCountUpdate: (data: {
90
+ online: number;
91
+ max: number;
92
+ cycle: number;
93
+ }) => void;
88
94
  }
89
95
  export declare class BedrockPortal extends TypedEmitter<PortalEvents> {
90
96
  authflow: Authflow;
@@ -117,8 +123,9 @@ export declare class BedrockPortal extends TypedEmitter<PortalEvents> {
117
123
  /**
118
124
  * Updates the current member count which is displayed in the Minecraft client.
119
125
  * @param count The new member count.
126
+ * @param maxCount The new max member count.
120
127
  */
121
- updateMemberCount(count: number): Promise<void>;
128
+ updateMemberCount(count: number, maxCount?: number): Promise<void>;
122
129
  /**
123
130
  * Gets the current session of the BedrockPortal instance.
124
131
  */
@@ -150,5 +157,6 @@ declare const Modules: {
150
157
  RedirectFromRealm: typeof RedirectFromRealm;
151
158
  MultipleAccounts: typeof MultipleAccounts;
152
159
  AutoFriendAccept: typeof AutoFriendAdd;
160
+ UpdateMemberCount: typeof UpdateMemberCount;
153
161
  };
154
162
  export { Modules };
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ 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
20
  const autoFriendAccept_2 = __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.
@@ -254,5 +256,6 @@ const Modules = {
254
256
  RedirectFromRealm: redirectFromRealm_1.default,
255
257
  MultipleAccounts: multipleAccounts_1.default,
256
258
  AutoFriendAccept: autoFriendAccept_2.default,
259
+ UpdateMemberCount: updateMemberCount_1.default,
257
260
  };
258
261
  exports.Modules = Modules;
@@ -0,0 +1,7 @@
1
+ import { BedrockPortal } from '..';
2
+ import Module from '../classes/Module';
3
+ export default class UpdateMemberCount extends Module {
4
+ ping: any;
5
+ constructor();
6
+ run(portal: BedrockPortal): Promise<void>;
7
+ }
@@ -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
- await this.updateSession(sessionName, { properties: { custom: { MemberCount: Number(count) } } });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bedrock-portal",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Creates a joinable session in Minecraft Bedrock Edition that can route players to their a specified host",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",