Skip to content

Commit

Permalink
Merge pull request #1384 from madsboddum/1383
Browse files Browse the repository at this point in the history
Fixed client crash when being granted a quest #1383
  • Loading branch information
Josh-Larson authored Oct 30, 2023
2 parents 3fb66f7 + 0c78eec commit e40fd29
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ class PlayerObject(objectId: Long) : IntangibleObject(objectId, BaselineType.PLA

val completedQuests by play8::completedQuests
val activeQuests by play8::activeQuests
var activeQuest by play8::activeQuest

val quests: Map<CRC, Quest>
get() = play8.getQuests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
val completedQuests = _completedQuests.wrapper(obj)
private val _activeQuests = SWGBitSet(8, 5)
val activeQuests = _activeQuests.wrapper(obj)
private val quests = SWGMap<CRC, Quest>(8, 7)
private val quests = SWGMap<CRC, Quest>(8, 6)

var forcePower by IndirectBaselineDelegate(obj = obj, value = 100, page = 8, update = 2)
var maxForcePower by IndirectBaselineDelegate(obj = obj, value = 100, page = 8, update = 3)
var activeQuest by IndirectBaselineDelegate(obj = obj, value = 0, page = 8, update = 6)

fun getExperience(): Map<String, Int> {
return Collections.unmodifiableMap(experience)
Expand Down Expand Up @@ -115,8 +114,7 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
bb.addInt(maxForcePower) // 3
bb.addObject(_completedQuests) // 4
bb.addObject(_activeQuests) // 5
bb.addInt(activeQuest) // 6
bb.addObject(quests) // 7
bb.addObject(quests) // 6
bb.incrementOperandCount(8)
}

Expand All @@ -127,7 +125,6 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
data.putInteger("maxForcePower", maxForcePower)
data.putByteArray("completedQuests", _completedQuests.toByteArray())
data.putByteArray("activeQuests", _activeQuests.toByteArray())
data.putInteger("activeQuest", activeQuest)
data.putMap("quests", quests)
}

Expand All @@ -142,13 +139,14 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
maxForcePower = data.getInteger("maxForcePower", maxForcePower)
_completedQuests.read(data.getByteArray("completedQuests"))
_activeQuests.read(data.getByteArray("activeQuests"))
activeQuest = data.getInteger("activeQuest", activeQuest)
quests.putAll(data.getMap("quests", CRC::class.java, Quest::class.java))
}

fun addQuest(questName: String) {
val crc = CRC(questName)
quests[crc] = Quest()
val quest = Quest()
quest.ownerId = obj.objectId
quests[crc] = quest
sendQuestUpdate()
}

Expand Down Expand Up @@ -240,7 +238,7 @@ internal class PlayerObjectOwner(private val obj: PlayerObject) : MongoPersistab
}

private fun sendQuestUpdate() {
obj.sendDelta(8, 7, quests)
obj.sendDelta(8, 6, quests)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class Quest : Encodable, MongoPersistable {
}
var isRewardReceived = false
var counter = 0
var ownerId: Long = 0

override fun decode(data: NetBuffer) {
data.long
ownerId = data.long
val newActiveTasks = BitSet.valueOf(data.getArray(java.lang.Short.BYTES))
val newCompletedTasks = BitSet.valueOf(data.getArray(java.lang.Short.BYTES))
isComplete = data.boolean
counter = data.int
isRewardReceived = data.boolean

// Must be set at the end to avoid being overwritten on the setter for `isComplete`
activeTasks.clear()
Expand All @@ -65,16 +65,15 @@ class Quest : Encodable, MongoPersistable {

override fun encode(): ByteArray {
val buffer = NetBuffer.allocate(length)
buffer.addLong(0) // ID for quest giver?
buffer.addLong(ownerId)
buffer.addRawArray(Arrays.copyOf(activeTasks.toByteArray(), java.lang.Short.BYTES))
buffer.addRawArray(Arrays.copyOf(completedTasks.toByteArray(), java.lang.Short.BYTES))
buffer.addBoolean(isComplete)
buffer.addInt(counter)
buffer.addBoolean(isRewardReceived)
return buffer.array()
}

override val length: Int = 18
override val length: Int = 17

override fun readMongo(data: MongoData) {
activeTasks = BitSet.valueOf(data.getByteArray("activeSteps"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ class QuestSerializationTest {
@Test
fun `test quest encode decode`() {
val q = Quest()
q.ownerId = 1234
q.addActiveTask(1)
q.addCompletedTask(2)
q.counter = 15
q.isRewardReceived = true

val decoded = Quest()
decoded.decode(NetBuffer.wrap(q.encode()))

assertEquals(1234, decoded.ownerId)
assertTrue(decoded.getActiveTasks().contains(1))
assertEquals(15, decoded.counter)
assertEquals(true, decoded.isRewardReceived)
assertArrayEquals(q.encode(), decoded.encode())
}

Expand Down

0 comments on commit e40fd29

Please sign in to comment.