Repository navigation
Migrate line protocol and nickname support #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TonyTown6033
wants to merge
2
commits into
main
Choose a base branch
from
migrate/4-line-protocol-nickname
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # HAT line protocol | ||
|
|
||
| The server speaks a small, line-based text protocol over TCP. Every frame is a | ||
| single line terminated by `\n` (a trailing `\r` is accepted and stripped). | ||
|
|
||
| ## Connecting and authentication | ||
|
|
||
| 1. The client opens a TCP connection. | ||
| 2. The server sends `SYS authenticating`. | ||
| 3. The client sends the access token printed by the server as its first line. | ||
| 4. On success the server sends `SYS connected; type /help to see available commands`. | ||
| On failure it sends `ERR invalid access token` and closes the connection. | ||
|
|
||
| The token line is compared exactly (after trailing newline removal). A wrong or | ||
| missing token ends the connection. | ||
|
|
||
| ## Client to server | ||
|
|
||
| | Command | Meaning | | ||
| | --- | --- | | ||
| | `MSG <text>` | Send a chat message. `<text>` must not be empty. | | ||
| | `NICK <name>` | Request a nickname change. | | ||
|
|
||
| Any other line is answered with `ERR unknown protocol command`. Blank lines are | ||
| ignored. Lines longer than 4 KiB are rejected with `ERR message is too long`. | ||
|
|
||
| ### Nickname rules | ||
|
|
||
| - 1 to 16 characters. | ||
| - ASCII letters, digits, `_` and `-` only. | ||
| - Case-insensitive uniqueness: a nickname in use by another client is rejected. | ||
|
|
||
| On success the server replies with `YOU <name>` and tells everyone else | ||
| `NICK <old> <new>`. On failure it replies with `ERR <reason>`. | ||
|
|
||
| ## Server to client | ||
|
|
||
| | Message | Meaning | | ||
| | --- | --- | | ||
| | `SYS <text>` | Informational/server event (join, leave, welcome). | | ||
| | `MSG <nick> <text>` | A chat message from `<nick>`. | | ||
| | `NICK <old> <new>` | Another client changed nickname. | | ||
| | `YOU <nick>` | The recipient's own (possibly new) nickname. | | ||
| | `ERR <reason>` | A rejected request or rate-limit notice. | | ||
|
|
||
| Nicknames are assigned as `user-<port>` on connect until changed. | ||
|
|
||
| ## Rate limiting and bans | ||
|
|
||
| - At most one accepted message per 250 ms per client. | ||
| - Messages sent faster get `ERR you are sending messages too quickly` and count | ||
| as a violation. The violation counter resets after an accepted message. | ||
| - Reaching 10 violations bans the client's IP for 10 minutes with | ||
| `ERR too many rapid messages; you are banned for 10 minutes`, then the | ||
| connection is closed. | ||
| - A connection from a banned IP receives | ||
| `ERR temporarily banned; try again in <seconds> seconds` and is closed. | ||
|
|
||
| ## Out of scope | ||
|
|
||
| This document covers only the stable text protocol migrated to `main`. File | ||
| transfer (`PUT`/`GET`/`LS`), remote execution (`EXEC`) and LLM (`LLM`) commands | ||
| are not part of this protocol on `main`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TCP can split a valid UTF-8
MSGorSYSframe at any byte. When a read ends inside a multibyte character, this conversion fails and the error path discards the entire chunk rather than retaining it for the next read, so ordinary Unicode chat messages can lose their prefix or never render; buffer raw bytes through a newline before decoding a complete frame.Useful? React with 👍 / 👎.