Skip to content

Commit

Permalink
Make .connect return a promise of StartGamePacket
Browse files Browse the repository at this point in the history
  • Loading branch information
AnyBananaGAME committed Nov 25, 2024
1 parent 1de3409 commit 28cdb55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Connection extends Listener {
}

@measureExecutionTime
public async connect(): Promise<Advertisement> {
public async connect(): Promise<[Advertisement, StartGamePacket]> {
return await this.initializeSession();
}

Expand Down Expand Up @@ -151,10 +151,14 @@ class Connection extends Listener {
}

@measureExecutionTime
private initializeSession(): Promise<Advertisement> {
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);
});
Expand Down
3 changes: 2 additions & 1 deletion src/tools/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
});

Expand Down

0 comments on commit 28cdb55

Please sign in to comment.