Skip to content

Instantly share code, notes, and snippets.

@thatlittlegit
Last active July 3, 2018 17:25
Show Gist options
  • Save thatlittlegit/d5eeaf3a880673375c72d9ed36659434 to your computer and use it in GitHub Desktop.
Save thatlittlegit/d5eeaf3a880673375c72d9ed36659434 to your computer and use it in GitHub Desktop.
A simple chat protocol.

SimpleChat Protocol (sc) 0.1.0

A simple chat protocol designed to be easily usable by means of Telnet/Netcat.

All input on the assigned port (103) is, assuming no other expectations are met, forwarded to all users (in the room, if applicable) in the format of id&room&username&message, where id is a unique identifier for the message. This ID can be a UUID, nanoid, incrementing integer, etc. room MUST be empty if rooms are not being used.

All communication on the port shall be in UTF-8 format; messages SHOULD NOT be longer than 216 bytes. A server allowing longer (perhaps configured as such) should have 'longmsg' in the build information in the version (i.e. 0.0.3-authreq.longmsg).

When a user first connects to the port, the server shall send the version of SC it is designed for in SemVer format to the client, with some optional build information to pass supported features. The client shall then adapt as necessary to this version, leaving the server if necessary.

The first non-command input is a suggested username. If the username contains spaces, is already taken or starts with an underscore, then NOTOK with no newline is to be sent back to the user, and the connection terminated.

When a user with a valid username joins, a message is sent to all users from _ with the username. If a user disconnects, a message is sent with an underscore followed by the username.

If the input starts with a forward-slash, it is interpreted as a command. A command can be one of the following (capitalization insensitive):

  • /MOTD: Standard informational message. Might be requested on join.
  • /USRS: Lists all users connected to the server, separated by tabs.
  • /PING: Should respond with PONG. Users can be kicked if idle for 10 minutes.
  • /ISCD: Checks if a command exists. If the parameter is implemented as a command, Y shall be returned; otherwise N. The parameter MAY be a PCRE regex if the server supports it; if so, 'pcreiscd' MUST be in the build ID string.
  • /CMDS: Lists all commands supported by the server, separated by tabs.

In addition, the following additional comamnds may be used, and SHOULD be supported by a server if noted as such. Any other commands MAY be implemented, and disabled.

Rooms

Should be implemented by a server. The default room is #welcome. A user MUST NOT get messages from a room they are not in.

  • /CROM: The server replies with the current room.
  • /JNRM: Joins a room denoted by a space, i.e. /JNRM hi. If a pound-sign is not at the start of the room identifier, it shall be added. If the room does not exist, authentication is invalid, et cetra NOTOK with a newline is to be sent but the connection remain intact.
  • /LVRM: Leaves a room; see /JNRM.
  • /ROMS: The server replies with the valid rooms separated by tabs.

Authentication

  • /PGPA: Base64'd PGP-clearsigned message which has the UTC date and time in ISO-8601 format, with no time zone, followed by a newline. Output should be identical to the Linux command date -Iseconds -u | sed 's/+.*//' | gpg --clearsign | base64 -w0. If the time is incorrect by more than ten seconds, the user shall be kicked with NOTOK. If the user does not submit this information before his username, the server (if configured) MAY kick the user. If the server is configured as such, the version number's build ID MUST contain 'authreq' (i.e. 0.0.2-authreq)

Reactions

  • /RECT: React to a message with a emoji shortcode compatible with Gemoji or a Unicode character, in the format /RECT <message id> <shortcode>; i.e. /RECT cf34da3 :+1:. Reacting twice MUST de-react to the message.

Profile Icons

  • /ICON: Gets the icon for a user in a Base64 PNG format, at a square size of 96x96 pixels or higher; i.e. /ICON thatlittlegit yields this. If the user does not have an icon, then a base64'd null-byte (U+0000) shall be sent.

Examples

Average session:

User 1 Server Sends User 2 hears User 2 sees in his UI
thatlittlegit 993&&_&thatlittlegit 993&&_&thatlittlegit thatlittlegit has joined
Hello, World! PB&J 994&&thatlittlegit&Hello, World! PB&J 994&&thatlittlegit&Hello, World! PB&J thatlittlegit: Hello, World! PB&J
/USRS thatlittlegit\tjoe
/MOTD Helo helo!
(disconnects) 995&&_&_thatlittlegit 995_&_thatlittlegit thatlittlegit has left

Invalid username:

User 1 Server User 2 hears User 2 sees in his UI
/USRS thatlittlegit\tjoe
thatlittlegit NOTOK
(terminated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment