bedrock-portal 0.7.0 → 0.7.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.
@@ -9,11 +9,14 @@ const xbox_rta_1 = require("xbox-rta");
9
9
  const rest_1 = __importDefault(require("../rest"));
10
10
  const debug = (0, debug_1.default)('bedrock-portal');
11
11
  class Host {
12
+ portal;
13
+ authflow;
14
+ rest;
15
+ rta = null;
16
+ profile = null;
17
+ connectionId = null;
18
+ subscriptionId = (0, uuid_1.v4)();
12
19
  constructor(portal, authflow) {
13
- this.rta = null;
14
- this.profile = null;
15
- this.connectionId = null;
16
- this.subscriptionId = (0, uuid_1.v4)();
17
20
  this.portal = portal;
18
21
  this.authflow = authflow;
19
22
  this.rest = new rest_1.default(this.authflow);
@@ -21,7 +24,6 @@ class Host {
21
24
  async connect() {
22
25
  const auth = await this.authflow.getXboxToken();
23
26
  this.profile = await this.rest.getProfile(auth.userXUID);
24
- // @ts-expect-error - XboxRTA isnt using the #playfab branch
25
27
  this.rta = new xbox_rta_1.XboxRTA(this.authflow);
26
28
  await this.rta.connect();
27
29
  const subResponse = await this.rta.subscribe('https://sessiondirectory.xboxlive.com/connections/');
@@ -5,6 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const debug_1 = __importDefault(require("debug"));
7
7
  class Module {
8
+ name;
9
+ description;
10
+ stopped;
11
+ options;
12
+ debug;
8
13
  constructor(name, description) {
9
14
  this.name = name;
10
15
  this.description = description;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class Player {
4
+ profile;
5
+ session;
4
6
  constructor(profileData, sessionData) {
5
7
  this.profile = {};
6
8
  this.session = {};
package/dist/index.js CHANGED
@@ -17,21 +17,25 @@ const inviteOnMessage_1 = __importDefault(require("./modules/inviteOnMessage"));
17
17
  const redirectFromRealm_1 = __importDefault(require("./modules/redirectFromRealm"));
18
18
  const multipleAccounts_1 = __importDefault(require("./modules/multipleAccounts"));
19
19
  const start_game_1 = require("./common/start_game");
20
- // @ts-expect-error - index.d.ts isn't updated
21
- const bedrock_protocol_1 = require("@lucienhh/bedrock-protocol");
20
+ const bedrock_portal_nethernet_1 = require("bedrock-portal-nethernet");
22
21
  const debug = (0, debug_1.default)('bedrock-portal');
23
22
  const getRandomUint64 = () => {
24
23
  // Generate two 32-bit random integers
25
24
  const high = Math.floor(Math.random() * 0xFFFFFFFF);
26
25
  const low = Math.floor(Math.random() * 0xFFFFFFFF);
27
26
  // Combine them to create a 64-bit unsigned integer
28
- const result = (BigInt(high) << 32n) | BigInt(low);
27
+ const result = (BigInt(high) << BigInt(32)) | BigInt(low);
29
28
  return result;
30
29
  };
31
30
  class BedrockPortal extends tiny_typed_emitter_1.TypedEmitter {
31
+ authflow;
32
+ host;
33
+ options;
34
+ session;
35
+ players;
36
+ modules = new Map();
32
37
  constructor(authflow, options) {
33
38
  super();
34
- this.modules = new Map();
35
39
  this.options = {
36
40
  ip: '',
37
41
  port: 19132,
@@ -41,7 +45,7 @@ class BedrockPortal extends tiny_typed_emitter_1.TypedEmitter {
41
45
  world: {
42
46
  hostName: 'Bedrock Portal v0.6.0',
43
47
  name: 'By LucienHH',
44
- version: '0.6.0',
48
+ version: '0.7.1',
45
49
  memberCount: 0,
46
50
  maxMemberCount: 10,
47
51
  ...options.world,
@@ -69,36 +73,18 @@ class BedrockPortal extends tiny_typed_emitter_1.TypedEmitter {
69
73
  this.players = new Map();
70
74
  await this.host.connect();
71
75
  this.session.name = (0, uuid_1.v4)();
72
- const server = new bedrock_protocol_1.Server({
76
+ const server = new bedrock_portal_nethernet_1.Server({
73
77
  version: '1.21.20', // The server version
74
78
  compressionAlgorithm: 'none',
75
79
  });
76
- server.listenNethernet(this.authflow, this.options.webRTCNetworkId);
77
- server.on('connect', (client) => {
80
+ server.listen(this.authflow, this.options.webRTCNetworkId);
81
+ server.on('connect', client => {
78
82
  client.on('join', () => {
79
83
  console.log(`Client ${client.id} has joined the server.`);
80
- client.write('resource_packs_info', {
81
- must_accept: false,
82
- has_scripts: false,
83
- behaviour_packs: [],
84
- texture_packs: [],
85
- resource_pack_links: [],
86
- });
87
- client.write('resource_pack_stack', {
88
- must_accept: false,
89
- behavior_packs: [],
90
- resource_packs: [],
91
- game_version: '',
92
- experiments: [],
93
- experiments_previously_used: false,
94
- });
95
- client.once('resource_pack_client_response', async (rp) => {
96
- client.write('start_game', start_game_1.start_game);
97
- });
98
- // TODO: Tie this to an event
99
- setTimeout(() => {
84
+ client.write('start_game', start_game_1.start_game);
85
+ client.once('set_player_game_type', () => {
100
86
  client.write('transfer', { server_address: this.options.ip, port: this.options.port });
101
- }, 6000);
87
+ });
102
88
  });
103
89
  });
104
90
  const session = await this.createAndPublishSession();
@@ -192,11 +178,11 @@ class BedrockPortal extends tiny_typed_emitter_1.TypedEmitter {
192
178
  }
193
179
  async createAndPublishSession() {
194
180
  await this.updateSession(this.createSessionBody());
195
- debug(`Created session, name: ${this.session.name}`);
181
+ debug(`Created session, name: ${this.session.name}, ID: ${this.options.webRTCNetworkId}`);
196
182
  await this.host.rest.setActivity(this.session.name);
197
183
  const session = await this.getSession();
198
184
  await this.updateSession({ properties: session.properties });
199
- debug(`Published session, name: ${this.session.name}`);
185
+ debug(`Published session, name: ${this.session.name}, ID: ${this.options.webRTCNetworkId}`);
200
186
  return session;
201
187
  }
202
188
  createSessionBody() {
@@ -8,9 +8,9 @@ const Module_1 = __importDefault(require("../classes/Module"));
8
8
  const Player_1 = __importDefault(require("../classes/Player"));
9
9
  const multipleAccounts_1 = __importDefault(require("./multipleAccounts"));
10
10
  class AutoFriendAdd extends Module_1.default {
11
+ interval = null;
11
12
  constructor() {
12
13
  super('autoFriendAdd', 'Automatically adds followers as friends');
13
- this.interval = null;
14
14
  this.options = {
15
15
  inviteOnAdd: false,
16
16
  conditionToMeet: () => true,
@@ -5,9 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Module_1 = __importDefault(require("../classes/Module"));
7
7
  class IniteOnMessage extends Module_1.default {
8
+ interval = null;
9
+ cache;
8
10
  constructor() {
9
11
  super('initeOnMessage', 'Automatically invite players to the server when they message you');
10
- this.interval = null;
11
12
  this.options = {
12
13
  command: 'invite',
13
14
  checkInterval: 30000,
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Module_1 = __importDefault(require("../classes/Module"));
7
7
  const Host_1 = __importDefault(require("../classes/Host"));
8
8
  class MultipleAccounts extends Module_1.default {
9
+ options;
10
+ peers;
9
11
  constructor() {
10
12
  super('multipleAccounts', 'Make the portal session joinable from multiple accounts');
11
13
  this.options = {
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Module_1 = __importDefault(require("../classes/Module"));
7
7
  const cd = new Set();
8
8
  class RedirectFromRealm extends Module_1.default {
9
+ bedrock;
10
+ client;
11
+ heartbeat = null;
9
12
  constructor() {
10
13
  super('redirectFromRealm', 'Automatically invite players to the server when they join a Realm');
11
- this.heartbeat = null;
12
14
  this.options = {
13
15
  clientOptions: {}, // Options for the bedrock-protocol client
14
16
  chatCommand: {
package/dist/rest.js CHANGED
@@ -7,6 +7,8 @@ const axios_1 = __importDefault(require("axios"));
7
7
  const json_bigint_1 = require("json-bigint");
8
8
  const constants_1 = require("./common/constants");
9
9
  class Rest {
10
+ auth;
11
+ options;
10
12
  constructor(authflow, options = {}) {
11
13
  this.auth = authflow;
12
14
  this.options = options;
@@ -44,8 +46,8 @@ class Rest {
44
46
  payload.data = config.data;
45
47
  return (0, axios_1.default)({
46
48
  ...payload,
47
- transformResponse: [data => (0, json_bigint_1.parse)(data)],
48
- transformRequest: [data => (0, json_bigint_1.stringify)(data)],
49
+ transformResponse: [data => data ? (0, json_bigint_1.parse)(data) : undefined],
50
+ transformRequest: [data => data ? (0, json_bigint_1.stringify)(data) : undefined],
49
51
  }).then(e => e.data);
50
52
  }
51
53
  async sendHandle(payload) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bedrock-portal",
3
- "version": "0.7.0",
3
+ "version": "0.7.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",
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "homepage": "https://github.com/LucienHH/bedrock-portal#readme",
23
23
  "dependencies": {
24
- "@lucienhh/bedrock-protocol": "^3.39.0",
25
24
  "axios": "^1.0.0",
25
+ "bedrock-portal-nethernet": "^1.0.3",
26
26
  "debug": "^4.3.4",
27
27
  "json-bigint": "^1.0.0",
28
28
  "prismarine-auth": "github:LucienHH/prismarine-auth#playfab",