Skip to content

fix: Sync config changes to LAN clients on save#22

Merged
turtton merged 2 commits intomainfrom
fix/19
Mar 11, 2026
Merged

fix: Sync config changes to LAN clients on save#22
turtton merged 2 commits intomainfrom
fix/19

Conversation

@turtton
Copy link
Owner

@turtton turtton commented Mar 11, 2026

Summary

  • 設定画面で保存時に ConfigSyncPayload を接続中の全プレイヤーへブロードキャストするように修正
  • ConfigSyncPayload.broadcastToAll(server) を追加し、設定画面の save ハンドラから呼び出し

Closes #19

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) }
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
client.server?.let { ConfigSyncPayload.broadcastToAll(it) }
client.server?.let { server ->
server.execute { ConfigSyncPayload.broadcastToAll(server) }
}

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +37
val payload = ConfigSyncPayload(CTServerConfig.instance.tankBucketCapacity)
for (player in server.playerManager.playerList) {
ServerPlayNetworking.send(player, payload)
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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()
}
}

Copilot uses AI. Check for mistakes.
クライアントスレッドからの playerList アクセスを避けるため、
server.execute でサーバースレッドにディスパッチする
@turtton turtton merged commit 003b605 into main Mar 11, 2026
2 checks passed
@turtton turtton deleted the fix/19 branch March 11, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Sync config changes to LAN clients on save

2 participants