mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Ensure PacketSize includes opcode.
This commit is contained in:
parent
32616884ad
commit
d8e8159d8c
@ -174,17 +174,17 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
byte[] ProcessReceived(byte[] buffer) {
|
byte[] ProcessReceived(byte[] buffer) {
|
||||||
if (buffer.Length == 0) return buffer;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int length = GetDataSize(buffer);
|
int size = PacketSize(buffer);
|
||||||
if (length == -2) return new byte[1]; // WoM get request
|
if (size == -2) return new byte[1]; // WoM get request
|
||||||
if (length == -1) return new byte[0]; // invalid packet
|
if (size == -1) return new byte[0]; // invalid packet
|
||||||
if (buffer.Length < length) return buffer;
|
|
||||||
|
|
||||||
|
if (buffer.Length < size) return buffer;
|
||||||
HandlePacket(buffer);
|
HandlePacket(buffer);
|
||||||
byte[] remaining = new byte[buffer.Length - length - 1];
|
if (buffer.Length == size) return new byte[0];
|
||||||
Buffer.BlockCopy(buffer, length + 1, remaining, 0, buffer.Length - length - 1);
|
|
||||||
|
byte[] remaining = new byte[buffer.Length - size];
|
||||||
|
Buffer.BlockCopy(buffer, size, remaining, 0, remaining.Length);
|
||||||
return ProcessReceived(remaining);
|
return ProcessReceived(remaining);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Server.ErrorLog(e);
|
Server.ErrorLog(e);
|
||||||
@ -192,22 +192,22 @@ namespace MCGalaxy {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetDataSize(byte[] buffer) {
|
int PacketSize(byte[] buffer) {
|
||||||
switch (buffer[0]) {
|
switch (buffer[0]) {
|
||||||
case (byte)'G': return -2; //For wom
|
case (byte)'G': return -2; //For wom
|
||||||
case Opcode.Handshake: return 130;
|
case Opcode.Handshake: return 131;
|
||||||
case Opcode.SetBlockClient:
|
case Opcode.SetBlockClient:
|
||||||
if (!loggedIn) goto default;
|
if (!loggedIn) goto default;
|
||||||
return 8;
|
return 9;
|
||||||
case Opcode.EntityTeleport:
|
case Opcode.EntityTeleport:
|
||||||
if (!loggedIn) goto default;
|
if (!loggedIn) goto default;
|
||||||
return 9;
|
return 10;
|
||||||
case Opcode.Message:
|
case Opcode.Message:
|
||||||
if (!loggedIn) goto default;
|
if (!loggedIn) goto default;
|
||||||
return 65;
|
return 66;
|
||||||
case Opcode.CpeExtInfo: return 66;
|
case Opcode.CpeExtInfo: return 67;
|
||||||
case Opcode.CpeExtEntry: return 68;
|
case Opcode.CpeExtEntry: return 69;
|
||||||
case Opcode.CpeCustomBlockSupportLevel: return 1;
|
case Opcode.CpeCustomBlockSupportLevel: return 2;
|
||||||
default:
|
default:
|
||||||
if (!dontmindme)
|
if (!dontmindme)
|
||||||
Leave("Unhandled message id \"" + buffer[0] + "\"!", true);
|
Leave("Unhandled message id \"" + buffer[0] + "\"!", true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user