Skip to content

Put a command's #id on its answer and nothing else - #65

Open
tomjn wants to merge 1 commit into
ScarylePoo:masterfrom
tomjn:fix/msg-id-scope
Open

tomjn wants to merge 1 commit into
ScarylePoo:masterfrom
tomjn:fix/msg-id-scope

Conversation

@tomjn

@tomjn tomjn commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

A client that sends #5 GETIP bob got #5 on every line the server sent it afterwards, not just the reply. Chat from other players, status changes and broadcasts all arrived wearing an id that had nothing to do with them, until the client's next command replaced it. Handlers that wait on the database failed the other way: by the time the reply was ready the client may have sent something else, so the reply carried that command's id, or none.

Two changes. The id is now restored when a handler returns, so only lines sent while the command is being handled carry it. And a handler that defers work captures the id at that point, so the reply carries the id of the command it answers whatever the client has sent since.

Restoring rather than clearing matters because ChanServ runs a mod command typed into #moderator back through the same dispatch path while that client's SAY is still being handled. Clearing would drop the id from the rest of the outer command.

Offline messages delivered after LOGIN are deliberately left without an id. They are other players' messages arriving late, not the answer to anything, and the point of this change is that an id means "this answers the command you sent".

The message id section of PROTOCOL.md was a documented gap. It now says which lines carry an id and which do not, which is the thing a client author needs in order to rely on this.

One path has no test: a login queued under write-buffer backpressure carries its id through the drain loop by the same mechanism, but I did not find a way to drive backpressure from a test client.

Fixes #60.

The id stayed on the Client after the handler returned, so chat and broadcasts carried it until the next command, while replies from DB callbacks carried whichever id came later. _handle now restores the id when it returns, and callbacks that answer the client put back the id captured when the work was deferred. Offline messages delivered after LOGIN are left without one, because they are other players' messages rather than the answer. Fixes ScarylePoo#60.
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.

A command's #id prefix is added to every later line the client receives, not only to the reply

1 participant