baltica 0.1.32 → 2.0.0

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.
Files changed (77) hide show
  1. package/dist/bridge/bridge-player.d.ts +2 -2
  2. package/dist/bridge/bridge-player.js +30 -22
  3. package/dist/bridge/bridge.d.ts +3 -5
  4. package/dist/bridge/bridge.js +23 -20
  5. package/dist/bridge/types/bridge-options.d.ts +1 -1
  6. package/dist/bridge/types/bridge-options.js +3 -3
  7. package/dist/bridge/types/bridge-player-events.d.ts +4 -16
  8. package/dist/bridge/types/index.d.ts +1 -0
  9. package/dist/bridge/types/index.js +1 -0
  10. package/dist/client/client.d.ts +31 -64
  11. package/dist/client/client.js +210 -272
  12. package/dist/client/index.d.ts +3 -3
  13. package/dist/client/index.js +3 -3
  14. package/dist/client/types/client-events.d.ts +3 -11
  15. package/dist/client/types/client-options.d.ts +34 -60
  16. package/dist/client/types/client-options.js +18 -48
  17. package/dist/client/types/index.d.ts +1 -4
  18. package/dist/client/types/index.js +1 -4
  19. package/dist/client/types/login/index.d.ts +1 -0
  20. package/dist/client/{worker → types/login}/index.js +1 -2
  21. package/dist/client/types/login/login-data.d.ts +87 -0
  22. package/dist/client/types/login/login-data.js +257 -0
  23. package/dist/index.d.ts +0 -1
  24. package/dist/index.js +0 -1
  25. package/dist/server/index.d.ts +1 -1
  26. package/dist/server/index.js +1 -1
  27. package/dist/server/player.d.ts +16 -38
  28. package/dist/server/player.js +138 -137
  29. package/dist/server/server.d.ts +5 -5
  30. package/dist/server/server.js +30 -27
  31. package/dist/server/types/index.d.ts +2 -2
  32. package/dist/server/types/index.js +2 -2
  33. package/dist/server/types/player-events.d.ts +2 -2
  34. package/dist/server/types/server-events.d.ts +2 -5
  35. package/dist/server/types/server-options.d.ts +3 -15
  36. package/dist/server/types/server-options.js +2 -14
  37. package/dist/shared/index.d.ts +1 -4
  38. package/dist/shared/index.js +1 -4
  39. package/dist/shared/serializer/index.d.ts +2 -0
  40. package/dist/shared/serializer/index.js +18 -0
  41. package/dist/shared/serializer/packet-compressor.d.ts +14 -0
  42. package/dist/shared/{packet-compressor.js → serializer/packet-compressor.js} +45 -40
  43. package/dist/shared/serializer/packet-encryptor.d.ts +14 -0
  44. package/dist/shared/{packet-encryptor.js → serializer/packet-encryptor.js} +21 -34
  45. package/dist/shared/types/index.d.ts +1 -1
  46. package/dist/shared/types/index.js +1 -1
  47. package/dist/shared/types/protocol.d.ts +9 -0
  48. package/dist/shared/types/protocol.js +8 -0
  49. package/package.json +12 -28
  50. package/.extra/logo.png +0 -0
  51. package/README.md +0 -232
  52. package/dist/client/skin-loader.d.ts +0 -38
  53. package/dist/client/skin-loader.js +0 -156
  54. package/dist/client/types/client-data.d.ts +0 -28
  55. package/dist/client/types/client-data.js +0 -201
  56. package/dist/client/types/login-data.d.ts +0 -18
  57. package/dist/client/types/login-data.js +0 -26
  58. package/dist/client/types/payload.d.ts +0 -73
  59. package/dist/client/types/payload.js +0 -98
  60. package/dist/client/worker/index.d.ts +0 -2
  61. package/dist/client/worker/worker-client.d.ts +0 -18
  62. package/dist/client/worker/worker-client.js +0 -107
  63. package/dist/client/worker/worker.d.ts +0 -4
  64. package/dist/client/worker/worker.js +0 -115
  65. package/dist/shared/auth/authentication.d.ts +0 -43
  66. package/dist/shared/auth/authentication.js +0 -454
  67. package/dist/shared/auth.d.ts +0 -24
  68. package/dist/shared/auth.js +0 -481
  69. package/dist/shared/emitter.d.ts +0 -14
  70. package/dist/shared/emitter.js +0 -80
  71. package/dist/shared/packet-compressor.d.ts +0 -13
  72. package/dist/shared/packet-encryptor.d.ts +0 -22
  73. package/dist/shared/types/global.d.ts +0 -36
  74. package/dist/shared/types/global.js +0 -38
  75. /package/dist/client/{types/skin → skin}/Skin.json +0 -0
  76. /package/dist/client/{types/skin → skin}/index.d.ts +0 -0
  77. /package/dist/client/{types/skin → skin}/index.js +0 -0
@@ -1,13 +1,13 @@
1
+ import { Emitter } from "@baltica/utils";
1
2
  import { Client } from "../client";
2
3
  import type { Player } from "../server";
3
4
  import type { Bridge } from "./bridge";
4
5
  import type { BridgePlayerEvents } from "./types";
5
- import { Emitter } from "../shared";
6
6
  export declare class BridgePlayer extends Emitter<BridgePlayerEvents> {
7
7
  bridge: Bridge;
8
8
  player: Player;
9
9
  client: Client;
10
10
  constructor(player: Player, bridge: Bridge);
11
11
  private onHandshake;
12
- handlePacket(rawBuffer: Buffer, clientBound: boolean): void;
12
+ routePacket(rawBuffer: Buffer, clientBound: boolean): void;
13
13
  }
@@ -2,48 +2,56 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BridgePlayer = void 0;
4
4
  const protocol_1 = require("@serenityjs/protocol");
5
+ const utils_1 = require("@baltica/utils");
5
6
  const client_1 = require("../client");
6
- const shared_1 = require("../shared");
7
- class BridgePlayer extends shared_1.Emitter {
7
+ class BridgePlayer extends utils_1.Emitter {
8
+ bridge;
9
+ player;
10
+ client;
8
11
  constructor(player, bridge) {
9
12
  super();
10
13
  this.player = player;
11
14
  this.bridge = bridge;
12
- this.player.once("ClientToServerHandshakePacket", this.onHandshake.bind(this));
15
+ this.player.once("ClientToServerHandshakePacket", (packet) => this.onHandshake(packet));
13
16
  }
14
- onHandshake(packet) {
17
+ onHandshake(_packet) {
15
18
  this.client = new client_1.Client({
16
19
  address: this.bridge.options.destination.address,
17
20
  port: this.bridge.options.destination.port,
18
21
  offline: this.bridge.options.offline,
19
22
  });
20
- this.client.cancelPastLogin = true;
23
+ this.client.stopPastLogin = true;
21
24
  this.client.once("PlayStatusPacket", (packet) => {
22
- if (packet.status !== protocol_1.PlayStatus.LoginSuccess)
23
- throw new Error("Login failed");
24
- this.client.processPacket = (buffer) => {
25
- this.handlePacket(buffer, true);
25
+ if (packet.status !== protocol_1.PlayStatus.LoginSuccess) {
26
+ utils_1.Logger.error("Bridge login failed");
27
+ return;
28
+ }
29
+ this.client.handlePacket = (buffer) => {
30
+ this.routePacket(buffer, true);
26
31
  };
27
- this.player.processPacket = (buffer) => {
28
- this.handlePacket(buffer, false);
32
+ this.player.handlePacket = (buffer) => {
33
+ this.routePacket(buffer, false);
29
34
  };
30
35
  });
31
- this.client.on("DisconnectPacket", (packet) => this.bridge.disconnect(this));
32
- this.player.on("DisconnectPacket", (packet) => this.bridge.disconnect(this));
33
- this.on("clientBound-DisconnectPacket", (signal) => this.bridge.disconnect(this));
34
- this.on("serverBound-DisconnectPacket", (signal) => this.bridge.disconnect(this));
35
- this.bridge.on("disconnect", () => this.bridge.disconnect(this));
36
+ this.client.on("DisconnectPacket", () => this.bridge.disconnect(this));
37
+ this.player.on("DisconnectPacket", () => this.bridge.disconnect(this));
38
+ this.on("clientBound-DisconnectPacket", () => this.bridge.disconnect(this));
39
+ this.on("serverBound-DisconnectPacket", () => this.bridge.disconnect(this));
36
40
  this.client.connect();
37
41
  }
38
- handlePacket(rawBuffer, clientBound) {
42
+ routePacket(rawBuffer, clientBound) {
39
43
  let buffer = rawBuffer;
40
44
  const id = (0, protocol_1.getPacketId)(rawBuffer);
41
45
  const PacketClass = protocol_1.Packets[id];
42
- const event = PacketClass
43
- ? `${clientBound ? "client" : "server"}Bound-${PacketClass.name}`
44
- : "Unknown";
45
- if (this.hasListeners(event) &&
46
- event !== "Unknown") {
46
+ if (!PacketClass) {
47
+ if (clientBound)
48
+ this.player.send(buffer);
49
+ else
50
+ this.client.send(buffer);
51
+ return;
52
+ }
53
+ const event = `${clientBound ? "client" : "server"}Bound-${PacketClass.name}`;
54
+ if (this.listenerCount(event) > 0) {
47
55
  const ctx = {
48
56
  packet: new PacketClass(buffer).deserialize(),
49
57
  cancelled: false,
@@ -1,15 +1,13 @@
1
- import type { ForceArray } from "../shared/emitter";
1
+ import { Emitter } from "@baltica/utils";
2
2
  import { Server } from "../server";
3
3
  import { BridgePlayer } from "./bridge-player";
4
4
  import { type BridgeOptions } from "./types";
5
5
  import type { BridgeEvents } from "./types/bridge-events";
6
- export declare class Bridge extends Server {
6
+ export declare class Bridge extends Emitter<BridgeEvents> {
7
7
  options: BridgeOptions;
8
+ server: Server;
8
9
  private clients;
9
10
  constructor(options: Partial<BridgeOptions>);
10
11
  start(): Promise<void>;
11
12
  disconnect(player: BridgePlayer): void;
12
- emit: <K extends keyof BridgeEvents>(name: K, ...args: ForceArray<BridgeEvents[K]>) => void;
13
- on: <K extends keyof BridgeEvents>(name: K, callback: (...args: ForceArray<BridgeEvents[K]>) => void) => void;
14
- once: <K extends keyof BridgeEvents>(name: K, callback: (...args: ForceArray<BridgeEvents[K]>) => void) => void;
15
13
  }
@@ -1,41 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Bridge = void 0;
4
+ const utils_1 = require("@baltica/utils");
4
5
  const protocol_1 = require("@serenityjs/protocol");
5
6
  const server_1 = require("../server");
6
7
  const bridge_player_1 = require("./bridge-player");
7
8
  const types_1 = require("./types");
8
- class Bridge extends server_1.Server {
9
+ class Bridge extends utils_1.Emitter {
10
+ options;
11
+ server;
12
+ clients = new Map();
9
13
  constructor(options) {
10
- super(options);
11
- this.clients = new Map();
12
- this.options = {
13
- ...types_1.defaultBridgeOptions,
14
- ...options,
15
- };
14
+ super();
15
+ this.options = { ...types_1.defaultBridgeOptions, ...options };
16
+ this.server = new server_1.Server(this.options);
16
17
  }
17
18
  async start() {
18
- super.start();
19
- // @ts-ignore
20
- this.on("playerConnect", (player) => {
19
+ await this.server.start();
20
+ this.server.on("playerConnect", (player) => {
21
21
  const bridgePlayer = new bridge_player_1.BridgePlayer(player, this);
22
- console.log(`Player ${player.connection.getAddress().address} connected to bridge`);
23
- const key = `${player.connection.getAddress().address}:${player.connection.getAddress().port}`;
22
+ const key = player.connection.identifier;
23
+ utils_1.Logger.info(`Player ${key} connected to bridge`);
24
24
  this.clients.set(key, bridgePlayer);
25
25
  this.emit("connect", bridgePlayer);
26
26
  });
27
27
  }
28
28
  disconnect(player) {
29
- console.log("Disconnecting player", player.player.username);
30
- const disconnect = new protocol_1.DisconnectPacket();
31
- disconnect.hideDisconnectScreen = false;
32
- disconnect.message = new protocol_1.DisconnectMessage("Client leaving", "");
33
- disconnect.reason = protocol_1.DisconnectReason.LegacyDisconnect;
34
- player.client.send(disconnect.serialize());
29
+ utils_1.Logger.info(`Disconnecting player ${player.player.username}`);
30
+ try {
31
+ const packet = new protocol_1.DisconnectPacket();
32
+ packet.hideDisconnectScreen = false;
33
+ packet.message = new protocol_1.DisconnectMessage("Client leaving", "");
34
+ packet.reason = protocol_1.DisconnectReason.LegacyDisconnect;
35
+ player.client?.send(packet.serialize());
36
+ }
37
+ catch { }
35
38
  this.emit("disconnect", player);
36
- const key = `${player.player.connection.getAddress().address}:${player.player.connection.getAddress().port}`;
39
+ const key = player.player.connection.identifier;
37
40
  this.clients.delete(key);
38
- this.onDisconnect(player.player);
41
+ this.server.onDisconnect(player.player);
39
42
  }
40
43
  }
41
44
  exports.Bridge = Bridge;
@@ -1,4 +1,4 @@
1
- import { type ServerOptions } from "../../index";
1
+ import { type ServerOptions } from "../../server";
2
2
  export type BridgeOptions = ServerOptions & {
3
3
  destination: {
4
4
  address: string;
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultBridgeOptions = void 0;
4
- const index_1 = require("../../index");
4
+ const server_1 = require("../../server");
5
5
  exports.defaultBridgeOptions = {
6
- ...index_1.defaultServerOptions,
6
+ ...server_1.defaultServerOptions,
7
7
  destination: {
8
- address: "193.180.211.84",
8
+ address: "127.0.0.1",
9
9
  port: 19132,
10
10
  },
11
11
  offline: false,
@@ -1,24 +1,12 @@
1
1
  import type * as Protocol from "@serenityjs/protocol";
2
2
  import type { PacketNames } from "../../shared/types";
3
- export type BridgeEventSignal = {
4
- packet: InstanceType<(typeof Protocol)[PacketNames]>;
3
+ export type BridgePacketSignal<T = Protocol.DataPacket> = {
4
+ packet: T;
5
5
  cancelled: boolean;
6
6
  modified: boolean;
7
7
  };
8
8
  export type BridgePlayerEvents = {
9
- [K in PacketNames as `clientBound-${K}`]: [
10
- signal: {
11
- packet: InstanceType<(typeof Protocol)[K]>;
12
- cancelled: boolean;
13
- modified: boolean;
14
- }
15
- ];
9
+ [K in PacketNames as `clientBound-${K}`]: [signal: BridgePacketSignal<InstanceType<(typeof Protocol)[K]>>];
16
10
  } & {
17
- [K in PacketNames as `serverBound-${K}`]: [
18
- signal: {
19
- packet: InstanceType<(typeof Protocol)[K]>;
20
- cancelled: boolean;
21
- modified: boolean;
22
- }
23
- ];
11
+ [K in PacketNames as `serverBound-${K}`]: [signal: BridgePacketSignal<InstanceType<(typeof Protocol)[K]>>];
24
12
  };
@@ -1,2 +1,3 @@
1
1
  export * from "./bridge-options";
2
+ export * from "./bridge-events";
2
3
  export * from "./bridge-player-events";
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./bridge-options"), exports);
18
+ __exportStar(require("./bridge-events"), exports);
18
19
  __exportStar(require("./bridge-player-events"), exports);
@@ -1,70 +1,37 @@
1
- import { Client as RaknetClient, ConnectionStatus } from "@sanctumterra/raknet";
2
- import { DataPacket, type StartGamePacket } from "@serenityjs/protocol";
3
- import { Emitter, PacketCompressor, PacketEncryptor, type Profile } from "../shared";
4
- import { ClientData, type ClientEvents, type ClientOptions } from "./types";
5
- import { WorkerClient } from "./worker";
6
- /**
7
- * Client class represents a Minecraft Bedrock Edition client.
8
- * It handles connection, authentication, packet processing, encryption, and communication with the server.
9
- * It supports both online and offline modes, as well as worker threads for networking.
10
- * It emits various events for packet handling and connection status changes.
11
- * It does not handle game logic; that is left to the user of the class.
12
- * It is designed to be extensible and customizable through options and event listeners.
13
- * Thanks for reading my yap session. :)
14
- */
1
+ import { Priority, Client as Raknet } from "@baltica/raknet";
2
+ import { Emitter } from "@baltica/utils";
3
+ import { ClientEvents, ClientOptions, LoginData, PlayerProfile } from "./types";
4
+ import { PacketEncryptor } from "../shared/serializer/packet-encryptor";
5
+ import { PacketCompressor } from "../shared/serializer/packet-compressor";
6
+ import { CompressionMethod, StartGamePacket } from "@serenityjs/protocol";
15
7
  export declare class Client extends Emitter<ClientEvents> {
16
- /** Client Options that change decisions duh. */
17
8
  options: ClientOptions;
18
- /** Raknet Connection (Normal or Worker) */
19
- raknet: RaknetClient | WorkerClient;
20
- /** Whether session is ready and we are set to go and connect. */
21
- sessionReady: boolean;
22
- /** Authentication profile */
23
- profile: Profile;
24
- /** Whether encryption is enabled or not */
25
- _encryptionEnabled: boolean;
26
- /** Whether compression is enabled or not */
27
- _compressionEnabled: boolean;
28
- /** Client username (This will be set automatically based on authentication and offline mode) */
29
- username: string;
30
- /** Client Data for auth and login. */
31
- data: ClientData;
32
- /** Client status in this attempted connection */
33
- status: ConnectionStatus;
34
- /** Packet Compression (class for simplicfication) */
9
+ raknet: Raknet;
10
+ packetEncryptor: PacketEncryptor | null;
35
11
  packetCompressor: PacketCompressor;
36
- /** Packet Encryptor (class for simplification) */
37
- packetEncryptor: PacketEncryptor;
38
- /** Secret Key bytes */
39
- secretKeyBytes: Buffer;
40
- /** IV bytes for Encryption */
41
- iv: Buffer;
42
- /** StartGameData that includes a lot of importand data */
12
+ profile: PlayerProfile;
13
+ loginData: LoginData;
14
+ stopPastLogin: boolean;
43
15
  startGameData: StartGamePacket;
44
- /** Whether we should continue after sending Login (Proxy use) */
45
- cancelPastLogin: boolean;
46
- private disconnectReason?;
47
16
  constructor(options: Partial<ClientOptions>);
48
- /** Connect to the server and start sending/receiving packets. */
49
- connect(): Promise<[StartGamePacket]>;
50
- private handleEncapsulated;
51
- /**
52
- * Packets must be decompressed and decrypted already
53
- */
54
- processPacket(buffer: Buffer): void;
55
- /** Do not call this, leaving it public incase someone needs to override this for some reason. */
56
- handleGamePackets(): void;
57
- disconnect(reason?: string): void;
58
- private cleanup;
59
- startEncryption(iv: Buffer): void;
60
- /**
61
- * Sends Packets to the server.
62
- *
63
- * Please use send for important packets and queue for less important packets.
64
- */
65
- private sendPacket;
66
- send(packet: DataPacket | Buffer): void;
67
- queue(packet: DataPacket | Buffer): void;
68
- /** Fully destroy the client and clean up all resources */
69
- destroy(): void;
17
+ connect(): Promise<void>;
18
+ private registerHandshakeHandlers;
19
+ private onNetworkSettings;
20
+ private onServerHandshake;
21
+ enableEncryption(secretKeyBytes: Buffer, iv: Buffer): void;
22
+ private registerLoginSequenceHandlers;
23
+ private onResourcePacksInfo;
24
+ private onResourcePackStack;
25
+ private onStartGame;
26
+ private onPlayStatus;
27
+ private registerDiagnosticHandlers;
28
+ private authenticate;
29
+ private authenticateOffline;
30
+ private authenticateOnline;
31
+ private applyAuthResult;
32
+ private requestNetworkSettings;
33
+ send(packet: Buffer | Buffer[], priority?: Priority, compressionMethod?: CompressionMethod): void;
34
+ onEncapsulated(packet: Buffer): void;
35
+ handlePacket(buffer: Buffer): void;
36
+ sendUncompressed(packet: Buffer, priority?: Priority): void;
70
37
  }