Attempt to fix the server by adding total packet length to the send and receive areas.
This commit is contained in:
parent
c6b8eec4ed
commit
a7e448f6b4
4 changed files with 43 additions and 6 deletions
|
@ -1,3 +1,3 @@
|
||||||
class Constants {
|
class Constants {
|
||||||
static const VERSION = "1.2.082924+0756";
|
static const VERSION = "1.2.082924+1124";
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,6 +203,10 @@ class ByteLayer {
|
||||||
_position = 0;
|
_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void restorePosition(int position) {
|
||||||
|
_position = position;
|
||||||
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
resetPosition();
|
resetPosition();
|
||||||
_byteBuffer = Uint8List(0);
|
_byteBuffer = Uint8List(0);
|
||||||
|
|
|
@ -26,10 +26,20 @@ class PacketServer {
|
||||||
ByteLayer layer = ByteLayer();
|
ByteLayer layer = ByteLayer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sock.listen((data) {
|
sock.listen((data) async {
|
||||||
layer.writeBytes(data);
|
layer.writeBytes(data);
|
||||||
}, onDone: () async {
|
var oldPos = layer.currentPosition;
|
||||||
layer.resetPosition();
|
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 {
|
try {
|
||||||
List<int> dataHash = layer.readBytes(256);
|
List<int> dataHash = layer.readBytes(256);
|
||||||
int sequenceID = layer.readLong();
|
int sequenceID = layer.readLong();
|
||||||
|
@ -68,6 +78,12 @@ class PacketServer {
|
||||||
layer.writeBytes(Hashing.sha256Sum(nbtData));
|
layer.writeBytes(Hashing.sha256Sum(nbtData));
|
||||||
layer.writeLong(nbtData.lengthInBytes);
|
layer.writeLong(nbtData.lengthInBytes);
|
||||||
layer.writeBytes(nbtData);
|
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);
|
sock.add(layer.bytes);
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,6 +107,8 @@ class PacketServer {
|
||||||
sock.close();
|
sock.close();
|
||||||
}
|
}
|
||||||
layer.clear();
|
layer.clear();
|
||||||
|
}, onDone: () {
|
||||||
|
layer.clear();
|
||||||
}, onError: (E) {
|
}, onError: (E) {
|
||||||
print("ERROR: ${E}");
|
print("ERROR: ${E}");
|
||||||
sock.close();
|
sock.close();
|
||||||
|
@ -151,16 +169,31 @@ class PacketClient {
|
||||||
layer.writeLong(packetSequence);
|
layer.writeLong(packetSequence);
|
||||||
layer.writeLong(nbtData.lengthInBytes);
|
layer.writeLong(nbtData.lengthInBytes);
|
||||||
layer.writeBytes(nbtData);
|
layer.writeBytes(nbtData);
|
||||||
|
var tmpBytes = layer.bytes;
|
||||||
|
layer.clear();
|
||||||
|
layer.writeLong(tmpBytes.lengthInBytes);
|
||||||
|
layer.writeBytes(tmpBytes);
|
||||||
|
|
||||||
Completer responseWait = Completer();
|
Completer responseWait = Completer();
|
||||||
|
|
||||||
socket!.add(layer.bytes);
|
socket!.add(layer.bytes);
|
||||||
|
|
||||||
socket!.listen((data) {
|
socket!.listen((data) async {
|
||||||
reply.writeBytes(data);
|
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
|
// Validate response validity
|
||||||
reply.resetPosition();
|
reply.resetPosition();
|
||||||
|
reply.readLong(); // This is unused outside of the sanity check above.
|
||||||
int sequence = reply.readLong();
|
int sequence = reply.readLong();
|
||||||
int successReceipt = reply.readByte();
|
int successReceipt = reply.readByte();
|
||||||
List<int> serverHash = reply.readBytes(256);
|
List<int> serverHash = reply.readBytes(256);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: libac_dart
|
name: libac_dart
|
||||||
description: "Aria's Creations code library"
|
description: "Aria's Creations code library"
|
||||||
version: 1.2.082924+0756
|
version: 1.2.082924+1124
|
||||||
homepage: "https://zontreck.com"
|
homepage: "https://zontreck.com"
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue