diff --git a/src/Connection.ts b/src/Connection.ts index a8d95b7..e7e4cd0 100644 --- a/src/Connection.ts +++ b/src/Connection.ts @@ -83,7 +83,7 @@ class Connection extends Listener { } @measureExecutionTime - public async connect(): Promise { + public async connect(): Promise<[Advertisement, StartGamePacket]> { return await this.initializeSession(); } @@ -151,10 +151,14 @@ class Connection extends Listener { } @measureExecutionTime - private initializeSession(): Promise { + private initializeSession(): Promise<[Advertisement, StartGamePacket]> { return new Promise((resolve, reject) => { - this.on("session", async () => { - resolve(await this.handleSessionStart()); + let Advertisement_: Advertisement; + this.once("session", async () => { + Advertisement_ = await this.handleSessionStart(); + }); + this.once("StartGamePacket", (packet: StartGamePacket) => { + resolve([Advertisement_, packet]); }); this.options.offline ? createOfflineSession(this) : authenticate(this); }); diff --git a/src/tools/connect.ts b/src/tools/connect.ts index 1ea489a..2865d5b 100644 --- a/src/tools/connect.ts +++ b/src/tools/connect.ts @@ -111,8 +111,9 @@ const client = new Client({ console.time("Connection"); // writeToLog("Starting connection..."); -client.connect().then((ad) => { +client.connect().then(([ad, packet]) => { console.timeEnd("Connection"); + console.log(ad) // writeToLog(`Connected successfully: ${JSON.stringify(ad)}`); });