Attempt to fix the server by adding total packet length to the send and receive areas.

This commit is contained in:
zontreck 2024-08-29 11:25:04 -07:00
parent c6b8eec4ed
commit a7e448f6b4
4 changed files with 43 additions and 6 deletions

View file

@ -1,3 +1,3 @@
class Constants {
static const VERSION = "1.2.082924+0756";
static const VERSION = "1.2.082924+1124";
}

View file

@ -203,6 +203,10 @@ class ByteLayer {
_position = 0;
}
void restorePosition(int position) {
_position = position;
}
void clear() {
resetPosition();
_byteBuffer = Uint8List(0);

View file

@ -26,10 +26,20 @@ class PacketServer {
ByteLayer layer = ByteLayer();
try {
sock.listen((data) {
sock.listen((data) async {
layer.writeBytes(data);
}, onDone: () async {
var oldPos = layer.currentPosition;
layer.resetPosition();
int pktTotalExpected = layer.readLong();
if (pktTotalExpected <= layer.length) {
// Allow Processing
} else {
layer.restorePosition(oldPos);
return;
}
layer.resetPosition();
layer.readLong(); // This is unused outside of the above sanity check.
try {
List<int> dataHash = layer.readBytes(256);
int sequenceID = layer.readLong();
@ -68,6 +78,12 @@ class PacketServer {
layer.writeBytes(Hashing.sha256Sum(nbtData));
layer.writeLong(nbtData.lengthInBytes);
layer.writeBytes(nbtData);
nbtData = layer.bytes;
// NOTE: Added a length indicator because SocketServer is apparently... really really dumb in its impl, and has no way to know when all data has been received, so no special event. We just have to check for it based on this initial value.
layer.clear();
layer.writeLong(nbtData.lengthInBytes);
layer.writeBytes(nbtData);
sock.add(layer.bytes);
} else {
@ -91,6 +107,8 @@ class PacketServer {
sock.close();
}
layer.clear();
}, onDone: () {
layer.clear();
}, onError: (E) {
print("ERROR: ${E}");
sock.close();
@ -151,16 +169,31 @@ class PacketClient {
layer.writeLong(packetSequence);
layer.writeLong(nbtData.lengthInBytes);
layer.writeBytes(nbtData);
var tmpBytes = layer.bytes;
layer.clear();
layer.writeLong(tmpBytes.lengthInBytes);
layer.writeBytes(tmpBytes);
Completer responseWait = Completer();
socket!.add(layer.bytes);
socket!.listen((data) {
socket!.listen((data) async {
reply.writeBytes(data);
}, onDone: () async {
var oldPos = reply.currentPosition;
reply.resetPosition();
int lenOfReply = reply.readLong();
if (lenOfReply <= reply.length) {
// We can now process the data
} else {
reply.restorePosition(oldPos);
return;
}
// Validate response validity
reply.resetPosition();
reply.readLong(); // This is unused outside of the sanity check above.
int sequence = reply.readLong();
int successReceipt = reply.readByte();
List<int> serverHash = reply.readBytes(256);

View file

@ -1,6 +1,6 @@
name: libac_dart
description: "Aria's Creations code library"
version: 1.2.082924+0756
version: 1.2.082924+1124
homepage: "https://zontreck.com"