Add a failsafe to prevent server crash

This commit is contained in:
zontreck 2024-05-22 16:41:36 -07:00
parent f5d1d741cb
commit fe181555ef
2 changed files with 26 additions and 20 deletions

View file

@ -16,27 +16,31 @@ class PacketServer {
print(
"New connection from ${sock.remoteAddress.address}:${sock.remotePort}");
sock.listen((data) async {
S2CStatusResponse response = S2CStatusResponse();
try {
CompoundTag tag = await NbtIo.readFromStream(data);
C2SRequestPacket request = C2SRequestPacket();
request.decodeTag(tag);
try {
sock.listen((data) async {
S2CStatusResponse response = S2CStatusResponse();
try {
CompoundTag tag = await NbtIo.readFromStream(data);
C2SRequestPacket request = C2SRequestPacket();
request.decodeTag(tag);
PacketResponse reply = await request.handlePacket();
// Server uses NBT to communicate
sock.add(await NbtIo.writeToStream(reply.replyDataTag));
} catch (E) {
response.reason = "Malformed request packet";
PacketResponse reply = await request.handlePacket();
// Server uses NBT to communicate
sock.add(await NbtIo.writeToStream(reply.replyDataTag));
} catch (E, stack) {
response.reason = "Malformed request packet";
sock.add(
await NbtIo.writeToStream(response.encodeTag() as CompoundTag));
}
}, onDone: () {
sock.add(
await NbtIo.writeToStream(response.encodeTag() as CompoundTag));
}
}, onDone: () {
sock.close();
}, onError: () {
sock.close();
});
} catch (E) {
sock.close();
}, onError: () {
sock.close();
});
}
}
}
}
@ -53,9 +57,11 @@ class PacketClient {
try {
socket = await Socket.connect(IPAddress, 25306);
connected = true;
} catch (E) {
} catch (E, stack) {
connected = false;
socket = null;
print(stack);
}
}

View file

@ -1,6 +1,6 @@
name: libac_flutter
description: "Aria's Creations code library"
version: 1.0.9
version: 1.0.10
homepage: "https://zontreck.com"
environment: