games/voxels: encode JoinRequest kind so join requests are not dropped
- Commit
437fbcdbcf3f95bc474f3ee4c3f129f1aa5e5896- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 11:55 UTC (29 days ago)
- Parents
b50d835
JoinRequest.kind defaults to "req", and kotlinx.serialization omits default values, so sealed join requests reached owners without the discriminator pullInbox sorts on. They were misclassified as invites, failed Invite decoding (no key field), and were silently dropped - the MenuActivity approve/deny flow could never receive a request. Annotate kind with @EncodeDefault(ALWAYS) so "kind":"req" is always on the wire. Invite/member/signed-op payloads are unchanged; older receivers ignore the extra field (ignoreUnknownKeys), and requests sealed by older senders remain unreadable (they carry no kind and no Invite key, so there is nothing to recover them from). Verified with a fake-relay JVM test (separate test commit): a sealed join request now round-trips through pullInbox as a request. (cherry picked from commit b20501bc166c5e0e08b869e7d3ac5c7aef258129)
Diff
games/voxels/src/main/java/com/vayunmathur/games/voxels/network/VoxelsSync.kt
diff --git a/games/voxels/src/main/java/com/vayunmathur/games/voxels/network/VoxelsSync.kt b/games/voxels/src/main/java/com/vayunmathur/games/voxels/network/VoxelsSync.ktindex c82e4337c1..e5719432c7 100644--- a/games/voxels/src/main/java/com/vayunmathur/games/voxels/network/VoxelsSync.kt+++ b/games/voxels/src/main/java/com/vayunmathur/games/voxels/network/VoxelsSync.kt@@ -23,6 +23,8 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock+import kotlinx.serialization.EncodeDefault+import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json import kotlin.io.encoding.Base64@@ -232,6 +234,13 @@ object VoxelsSync { // --- Live sync + presence over WebSocket --- + /**+ * Test seam: when set, replaces the relay HTTP transport ([raw] calls this+ * instead of [NetworkClient.performRequest]). Null in production, so the+ * real relay is used exactly as before.+ */+ internal var relayTransport: (suspend (path: String, bodyJson: String) -> com.vayunmathur.library.network.SimpleResponse?)? = null+ @Volatile private var wsSession: WsSession? = null private var liveJob: Job? = null private var liveChannel: String? = null@@ -322,7 +331,7 @@ object VoxelsSync { @Suppress("TooGenericExceptionCaught") private suspend inline fun <reified T> raw(path: String, body: T) = try {- NetworkClient.performRequest(+ relayTransport?.invoke(path, json.encodeToString(body)) ?: NetworkClient.performRequest( url = "$URL$path", method = "POST", headers = mapOf("Content-Type" to "application/json"),@@ -357,8 +366,11 @@ object VoxelsSync { ) /** A request to join a world, sealed to the owner. Public ids only — no key. */+ @OptIn(ExperimentalSerializationApi::class) @Serializable data class JoinRequest(- val kind: String = "req",+ // The discriminator must reach the wire: with the default omitted,+ // pullInbox misclassifies requests as invites and drops them.+ @EncodeDefault(EncodeDefault.Mode.ALWAYS) val kind: String = "req", val worldId: String, val requesterId: String, val name: String = "",