Fixed a bug with customization string decoding, where empty state was not being handled correctly

This commit is contained in:
Ziggy
2025-01-10 23:20:43 +01:00
parent de65655f27
commit 68310ffdc8
2 changed files with 15 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -92,7 +92,9 @@ class CustomizationString : Encodable, MongoPersistable {
}
override fun decode(data: NetBuffer) {
val stream = CustomizationStringInputStream(data.array)
val buffer = data.array
if (buffer.isEmpty()) return
val stream = CustomizationStringInputStream(buffer)
stream.read() // version - should be 0x02
val variableCount = stream.read()
for (i in 0 until variableCount) {

View File

@@ -1,5 +1,5 @@
/***********************************************************************************
* Copyright (c) 2024 /// Project SWG /// www.projectswg.com *
* Copyright (c) 2025 /// Project SWG /// www.projectswg.com *
* *
* ProjectSWG is an emulation project for Star Wars Galaxies founded on *
* July 7th, 2011 after SOE announced the official shutdown of Star Wars Galaxies. *
@@ -78,6 +78,16 @@ class TestCustomizationString {
assertEquals(-100, decoded.get("/private/index_color_tattoo"))
}
@Test
fun decodeEmptyCustomizationString() {
// Customization string with no variables. Can happen when creating a new character of a species that has no hair, for example. In this case, the hair customization string is empty.
val string = CustomizationString()
val encoded = string.encode()
val decoded = CustomizationString()
assertDoesNotThrow { decoded.decode(NetBuffer.wrap(encoded)) }
}
@ParameterizedTest
@MethodSource("provideRealWorldValues")
fun testRealWorld(input: ByteArray) {