baltica 0.1.23 → 0.1.24

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.
@@ -57,7 +57,6 @@ export declare class Client extends Emitter<ClientEvents> {
57
57
  disconnect(reason?: string): void;
58
58
  private cleanup;
59
59
  startEncryption(iv: Buffer): void;
60
- private waitForSessionReady;
61
60
  /**
62
61
  * Sends Packets to the server.
63
62
  *
@@ -45,20 +45,22 @@ class Client extends shared_1.Emitter {
45
45
  /** Create ClientData to store and handle auth data */
46
46
  this.data = new types_2.ClientData(this);
47
47
  this.raknet.on("disconnect", () => this.cleanup());
48
- this.once("session", () => {
49
- this.sessionReady = true;
50
- });
51
- this.options.offline ? (0, shared_1.createOfflineSession)(this) : (0, shared_1.authenticate)(this);
52
48
  }
53
49
  /** Connect to the server and start sending/receiving packets. */
54
50
  async connect() {
51
+ // Authenticate first before connecting to raknet
52
+ if (this.options.offline) {
53
+ await (0, shared_1.createOfflineSession)(this);
54
+ }
55
+ else {
56
+ await (0, shared_1.authenticate)(this);
57
+ }
58
+ this.sessionReady = true;
55
59
  await this.raknet.connect();
56
60
  this.status = raknet_1.ConnectionStatus.Connecting;
57
61
  this.packetCompressor = new shared_1.PacketCompressor(this);
58
62
  this.handleGamePackets();
59
63
  this.raknet.on("encapsulated", this.handleEncapsulated.bind(this));
60
- // Wait for authentication to complete before sending network settings request
61
- await this.waitForSessionReady();
62
64
  const request = new protocol_1.RequestNetworkSettingsPacket();
63
65
  request.protocol = types_1.ProtocolList[types_1.CurrentVersionConst];
64
66
  this.send(request);
@@ -118,7 +120,6 @@ class Client extends shared_1.Emitter {
118
120
  this._compressionEnabled = true;
119
121
  this.options.compressionMethod = this.packetCompressor.getMethod(packet.compressionMethod);
120
122
  this.options.compressionThreshold = packet.compressionThreshold;
121
- await this.waitForSessionReady();
122
123
  const loginPacket = this.data.createLoginPacket();
123
124
  this.send(loginPacket);
124
125
  });
@@ -205,11 +206,6 @@ class Client extends shared_1.Emitter {
205
206
  this.packetEncryptor = new shared_1.PacketEncryptor(this, iv);
206
207
  this._encryptionEnabled = true;
207
208
  }
208
- async waitForSessionReady() {
209
- while (!this.sessionReady) {
210
- await new Promise((resolve) => setTimeout(resolve, 50));
211
- }
212
- }
213
209
  /**
214
210
  * Sends Packets to the server.
215
211
  *
@@ -81,12 +81,11 @@ async function authenticate(client) {
81
81
  const profile = extractProfile(chains[1]);
82
82
  const sessionToken = await getMultiplayerSessionToken(authflow, client);
83
83
  client.data.loginToken = sessionToken;
84
+ await setupClientProfile(client, profile, chains);
85
+ await setupClientChains(client);
84
86
  const endTime = Date.now();
85
87
  raknet_1.Logger.info(`Authentication with Xbox took ${(endTime - startTime) / 1000}s.`);
86
- await setupClientProfile(client, profile, chains);
87
- setupClientChains(client).then((value) => {
88
- client.emit("session");
89
- });
88
+ client.emit("session");
90
89
  }
91
90
  catch (error) {
92
91
  raknet_1.Logger.error(`Authentication failed: ${error instanceof Error ? error.message : String(error)}`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "baltica",
3
3
  "description": "Library for Minecraft Bedrock Edition community developers.",
4
- "version": "0.1.23",
4
+ "version": "0.1.24",
5
5
  "minecraft": "1.21.130",
6
6
  "main": "dist/index.js",
7
7
  "license": "MIT",