Skip to content

Chat private messages (protocol v2) - #15291

Open
Fanfblrik wants to merge 2 commits into
yairm210:masterfrom
Fanfblrik:feature/chat-private-messages
Open

Chat private messages (protocol v2)#15291
Fanfblrik wants to merge 2 commits into
yairm210:masterfrom
Fanfblrik:feature/chat-private-messages

Conversation

@Fanfblrik

@Fanfblrik Fanfblrik commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Chat protocol v2: optional outbound userId on chat messages (null = public broadcast). Public chat unchanged when omitted.
  • Server maps websocket sessions to authenticated user ids and delivers private messages only to sender + recipient sessions subscribed to the game. Relayed payload uses private: true (no recipient id/name on the wire). chatVersion is 2 when chat is enabled.
  • ChatPopup shows a To: selector (Everyone + other human major civs) when chatVersion >= 2. Private lines render as Sender (private): text. Spectators / Unknown keep Everyone-only.
  • ignoreUnknownKeys enabled on client/server chat JSON for forward compatibility.

Test plan

  • .\gradlew :core:compileKotlin :server:compileKotlin
  • Against a v2 server jar: open chat → recipient list appears; public messages still visible to all
  • A → B private: only A and B see it; C does not
  • Against chatVersion 1 / 0: no recipient selector; public chat works as before
  • Unknown/spectator: no private targets (Everyone only)
  • Sender (private) display is clear enough without recipient name in the log

Route optional toPlayerId on the server to sender+recipient sessions only, bump chatVersion to 2, and add a recipient selector in ChatPopup when the server supports it.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Fanfblrik

Copy link
Copy Markdown
Contributor Author

Merge order: if landing more than one of these chat PRs, please merge in this sequence to avoid conflicts / lost behavior:

  1. Chat: nation-colored names, white body #15289 — nation-colored name + white message body
  2. Persist multiplayer chat history on this device (opt-in) #15290 — local on-device chat history (opt-in)
  3. Chat private messages (protocol v2) #15291 — private messages (chat protocol v2)

Reason: all three touch ChatPopup / ChatStore. #15291 does not include #15289's coloring, and #15290/#15291 disagree on message storage shape (Pair vs ChatMessageEntry / toCivName), so out-of-order merges need a careful rebase.

@Fanfblrik

Copy link
Copy Markdown
Contributor Author

Happy to rebase / fix merge conflicts (and any review feedback) — just say the word.

@touhidurrr

touhidurrr commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

is toCivName really necessary?
For server if userId is provided then the server should send the message to designated userId only.
When a private message is sent, the server can just add private: true to say that this message is only for you. And when personal == true, you can display (private) after civName
A full userId is not necessary.

Comment thread core/src/com/unciv/logic/multiplayer/chat/ChatStore.kt Outdated
Comment thread core/src/com/unciv/logic/multiplayer/chat/ChatWebSocket.kt Outdated
Comment thread core/src/com/unciv/logic/multiplayer/chat/ChatWebSocket.kt Outdated
@touhidurrr

Copy link
Copy Markdown
Contributor

So, mainly too many unnecessary properties.

@touhidurrr

Copy link
Copy Markdown
Contributor

Ok @Fanfblrik , I have added your protocol v2 support in UncivServer.xyz. The gist of it is below:

  1. To send a private message include userId field to payload
  2. If a message is a private message, the server sent message has private: true on, otherwise private maybe omitted or be false.

Kindly test with the server and see if it works.

@touhidurrr

Copy link
Copy Markdown
Contributor

Also, I think you need to add a 4th pull request or modify this to add UI support for sending private messages.

@Fanfblrik

Copy link
Copy Markdown
Contributor Author

I was just doing some testing.

image

Address review: drop toCivName/toPlayerId echo; render (private); left-align To: selector.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Fanfblrik

Copy link
Copy Markdown
Contributor Author

Addressed review feedback in 3cd1e0a82:

  • Outbound: userId for private routing (null = public)
  • Inbound: private: true only — no toCivName / recipient id echo
  • UI: Sender (private): …; To: selector left-aligned with its label
  • Local two-client test: public + private delivery looks good; (private) without recipient name is fine in the log

@touhidurrr

Copy link
Copy Markdown
Contributor

Addressed review feedback in 3cd1e0a82:

  • Outbound: userId for private routing (null = public)
  • Inbound: private: true only — no toCivName / recipient id echo
  • UI: Sender (private): …; To: selector left-aligned with its label
  • Local two-client test: public + private delivery looks good; (private) without recipient name is fine in the log

Does UncivServer.xyz work?

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.

2 participants