Conversation
There was a problem hiding this comment.
Pull request overview
Adds a mechanism to re-sync server config to connected LAN clients when the host saves changes from the in-game config UI, addressing #19 (config was previously only synced on player join).
Changes:
- Add
ConfigSyncPayload.broadcastToAll(server)to send the latest server config payload to all connected players. - Invoke the broadcast from the config screen save handler when running an integrated (non-external) server.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/kotlin/net/turtton/connectedtank/network/ConfigSyncPayload.kt | Adds a helper to broadcast config sync payload to all connected players. |
| src/client/kotlin/net/turtton/connectedtank/config/CTConfigScreen.kt | Calls the new broadcast helper after saving server config in singleplayer/LAN host context. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .save { | ||
| if (!isExternalServer) { | ||
| CTServerConfig.instance.save() | ||
| client.server?.let { ConfigSyncPayload.broadcastToAll(it) } |
There was a problem hiding this comment.
ConfigSyncPayload.broadcastToAll is invoked from the config screen save callback (client/UI thread), but it iterates server.playerManager.playerList and calls ServerPlayNetworking.send(...), which should be done on the integrated server thread to avoid race conditions with player list/network handler. Consider scheduling the broadcast via server.execute { ... } (or otherwise dispatching to the server thread) before calling broadcastToAll.
| client.server?.let { ConfigSyncPayload.broadcastToAll(it) } | |
| client.server?.let { server -> | |
| server.execute { ConfigSyncPayload.broadcastToAll(server) } | |
| } |
| val payload = ConfigSyncPayload(CTServerConfig.instance.tankBucketCapacity) | ||
| for (player in server.playerManager.playerList) { | ||
| ServerPlayNetworking.send(player, payload) | ||
| } |
There was a problem hiding this comment.
broadcastToAll(server) assumes it is safe to access server.playerManager.playerList and send packets immediately; however, this can be called from non-server threads (e.g., UI thread via the config screen). To prevent potential concurrent access issues, consider enforcing server-thread execution inside this method (dispatch to server.execute { ... }, or clearly document/guard the thread requirement).
| val payload = ConfigSyncPayload(CTServerConfig.instance.tankBucketCapacity) | |
| for (player in server.playerManager.playerList) { | |
| ServerPlayNetworking.send(player, payload) | |
| } | |
| val broadcastAction = { | |
| val payload = ConfigSyncPayload(CTServerConfig.instance.tankBucketCapacity) | |
| for (player in server.playerManager.playerList) { | |
| ServerPlayNetworking.send(player, payload) | |
| } | |
| } | |
| if (server.isOnThread) { | |
| broadcastAction() | |
| } else { | |
| server.execute { | |
| broadcastAction() | |
| } | |
| } |
クライアントスレッドからの playerList アクセスを避けるため、 server.execute でサーバースレッドにディスパッチする
Summary
ConfigSyncPayloadを接続中の全プレイヤーへブロードキャストするように修正ConfigSyncPayload.broadcastToAll(server)を追加し、設定画面の save ハンドラから呼び出しCloses #19