Skip to content

Commit ea50f4c

Browse files
committed
Check if the buffer was read 100%, to improve confidence in packet decoding logic
1 parent 0f1fc9c commit ea50f4c

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/test/java/com/projectswg/holocore/test/resources/GenericPlayer.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/***********************************************************************************
22
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
33
* *
4-
* ProjectSWG is the first NGE emulator for Star Wars Galaxies founded on *
4+
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
55
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
6-
* Our goal is to create an emulator which will provide a server for players to *
7-
* continue playing a game similar to the one they used to play. We are basing *
8-
* it on the final publish of the game prior to end-game events. *
6+
* Our goal is to create one or more emulators which will provide servers for *
7+
* players to continue playing a game similar to the one they used to play. *
98
* *
109
* This file is part of Holocore. *
1110
* *
@@ -30,6 +29,7 @@
3029
import com.projectswg.common.data.CRC;
3130
import com.projectswg.common.data.encodables.tangible.Posture;
3231
import com.projectswg.common.data.location.Location;
32+
import com.projectswg.common.network.NetBuffer;
3333
import com.projectswg.common.network.NetworkProtocol;
3434
import com.projectswg.common.network.packets.SWGPacket;
3535
import com.projectswg.common.network.packets.swg.zone.*;
@@ -95,7 +95,12 @@ public void sendPacket(SWGPacket packet) {
9595
private static void encodeAndDecode(SWGPacket packet) {
9696
try {
9797
// This doesn't actually test the encoding and decoding of the packet, but it does test that the packet can be encoded and decoded without throwing an exception
98-
NetworkProtocol.decode(NetworkProtocol.encode(packet));
98+
NetBuffer data = NetworkProtocol.encode(packet);
99+
NetworkProtocol.decode(data);
100+
int remaining = data.remaining();
101+
if (remaining > 0) {
102+
throw new RuntimeException("Encoded packet buffer had more data that wasn't read during decoding. Bytes remaining: " + remaining);
103+
}
99104
} catch (Throwable t) {
100105
throw new RuntimeException("Failed to encode and decode packet", t);
101106
}

0 commit comments

Comments
 (0)