Skip to content

Commit

Permalink
don't wait for packets to be sent before processsing new ones + less …
Browse files Browse the repository at this point in the history
…copies
  • Loading branch information
velzie committed Dec 26, 2024
1 parent 75ad075 commit 4327699
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/1.8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ export class EaglerProxy {
break;
case State.Login:
case State.Play:
let pk = packet.readVarInt()!;
let pk = packet.readVarInt(false)!;
switch (pk) {
case Serverbound.PluginMessage:
packet.readVarInt();
let tag = packet.readString();
if (tag.startsWith("EAG|")) {
if (tag == "EAG|Skins-1.8" || tag == "EAG|Capes-1.8") {
Expand All @@ -241,9 +242,7 @@ export class EaglerProxy {
break;
}
default:
let p = new Packet(pk);
p.extend(packet);
await this.net.write(p);
this.net.write(packet);
break;
}
}
Expand All @@ -252,12 +251,13 @@ export class EaglerProxy {
// consumes packets from the network, sends them to eagler
async epoxyRead(packet: Buffer) {
packet = new Buffer(packet.inner); // proto bug
const pk = packet.readVarInt();
let pk;
switch (this.state) {
case State.Handshaking:
// there are no clientbound packets in the handshaking state
break;
case State.Status:
pk = packet.readVarInt();
switch (pk) {
case Clientbound.StatusResponse:
let json = packet.readString();
Expand Down Expand Up @@ -285,15 +285,17 @@ export class EaglerProxy {
else if (body.description.extra) {
response.data.motd = [chatToLegacyString(body.description)];
} else response.data.motd = [body.description.text];

if (body.favicon) {
response.data.icon = true;
}

await this.eagler.write(JSON.stringify(response));

if (body.favicon) {
let image = await createImageBitmap(await (await fetch(body.favicon)).blob());
let image = await createImageBitmap(
await (await fetch(body.favicon)).blob(),
);
let canvas = new OffscreenCanvas(image.width, image.height);
let ctx = canvas.getContext("2d")!;
ctx.drawImage(image, 0, 0);
Expand All @@ -314,6 +316,7 @@ export class EaglerProxy {
}
break;
case State.Login:
pk = packet.readVarInt();
switch (pk) {
case Clientbound.Disconnect:
{
Expand Down Expand Up @@ -389,13 +392,15 @@ export class EaglerProxy {
}
break;
case State.Play:
switch (pk) {
switch (packet.readVarInt(false)) {
case Clientbound.SetCompressionPlay:
packet.readVarInt();
let threshold = packet.readVarInt();
this.decompressor.compressionThresh = threshold;
this.compressor.compressionThresh = threshold;
break;
case Clientbound.PluginMessage:
packet.readVarInt();
let fard = Buffer.new();
fard.extend(packet);
let tag = fard.readString();
Expand All @@ -404,9 +409,7 @@ export class EaglerProxy {
}
default:
// send rest of packet to eagler
let eag = new Packet(pk);
eag.extend(packet);
await this.eagler.write(eag);
this.eagler.write(packet);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Buffer {
}

// you can probably make this better
readVarInt(): number {
readVarInt(take: boolean = true): number {
let index = 0;
let result = 0;
let shift = 0;
Expand All @@ -114,7 +114,7 @@ export class Buffer {
shift += 7;
} while (byte >= 128);

this.take(index);
if (take) this.take(index);
return result;
}

Expand Down

0 comments on commit 4327699

Please sign in to comment.