diff --git a/Protocol.md b/Protocol.md index 7e4fe59..de0991c 100644 --- a/Protocol.md +++ b/Protocol.md @@ -12,28 +12,30 @@ Further documentation on their behaviour will be added at a later date. ### `bool` A value that indicates a true or a false state. `0` represents false and anything non-`0` represents true, please stick to `1` for representing true though. - ### `int` Any number ranging from `-9007199254740991` to `9007199254740991`, `Number.MAX_SAFE_INTEGER` and `Number.MIN_SAFE_INTEGER` in JavaScript. - ### `string` Any printable unicode character, except `\t` which is used to separate packets. - ### `timestamp` Extends `int`, contains a second based UNIX timestamp. +### `user name` +A `string` containing a user's name. + +If the user currently has an AFK tag set through the `/afk`, it is prefixed by `<AFK>_`. +The `AFK` text can be replaced by any text supplied to the `/afk` command as an argument, the original PHP Sock Chat and SharpChat force this text to uppercase and limit it to 5 characters. + +If prefixed by a `~`, it is not the user's actual name but a nick name. ### `channel name` A `string` containing only alphanumeric characters (any case), `-` or `_`. - -### `color` -Any valid value for the CSS `color` property. +### `colour` +Any valid value for the CSS `colour` property. Further documentation can be found [on MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value). - ### `message flags` Message flags alter how a message should be displayed to the client, these are all `bool` values. The parts are as follows: @@ -46,34 +48,19 @@ The parts are as follows: As an example, the most common message flagset is `10010`. This indicates a bold username with a colon separator. - -### `user permissions` -User permissions are a set of flags separated by either the form feed character (`\f` / `0x0C`) or a space ( / `0x20`). +### `user perms` +User permissions are a set of flags separated by either the form feed character (`\f` / `0x0C`) or a space (' ' / `0x20`). The reason there are two options is due to a past mixup that we now have to live with. Which of the methods is used remains consistent per server however, so the result of a test can be cached. - - - - - - - - - - - - - - - - - - - - - -
intRank of the user. Used to determine what channels a user can access or what other users the user can moderate.
boolIndicates whether the user the ability kick/ban/unban others.
boolIndicates whether the user can access the logs. This should always be 0, unless the client has a dedicated log view that can be accessed without connecting to the chat server.
boolIndicates whether the user can set an alternate display name.
intIndicates whether the user can create channel. If 0 the user cannot create channels, if 1 the user can create channels but they are to disappear when all users have left it and if 2 the user can create channels that permanently stay in the channel assortment.
+| Type | Description | +|:------:| ----------- | +| `int` | Rank of the user. Used to determine what channels a user can access or what other users the user can moderate. | +| `bool` | Indicates whether the user the ability kick/ban/unban others. | +| `bool` | Indicates whether the user can access the logs. This should always be `0`, unless the client has a dedicated log view that can be accessed without connecting to the chat server. | +| `bool` | Indicates whether the user can set an alternate display name. | +| `int` | Indicates whether the user can create channel. If `0` the user cannot create channels, if `1` the user can create channels but they are to disappear when all users have left it and if `2` the user can create channels that permanently stay in the channel assortment. | + ## Client Packets @@ -82,23 +69,35 @@ These are the packets sent from the client to the server. ### Packet `0`: Ping Used to prevent the client from closing the session due to inactivity. - - - - - -
stringUser ID
+| Type | Description | +|:--------:| ----------- | +| `string` | User ID of the current user. | ### Packet `1`: Authentication Takes a variable number of parameters that are fed into the authentication script associated with the chat. - - - - - -
...stringAny amount of data required to complete authentication
+| Type | Description | +|:-----------:| ----------- | +| `...string` | Any amount of data required to complete authentication. | + +#### Original Sock Chat phpBB format +Although the specification was never strict on the format, the original client and server combo included only a single authentication extension for phpBB. +Flashii Hajime, Sakura and early Misuzu also used this same format. + +| Type | Description | +|:--------:| ----------- | +| `string` | User ID of the authenticating user. | +| `string` | Session token for the authenticating user. | + +#### Flashii Chat format +In order to support multiple authentication methods more easily, Flashii Chat currently uses a format similar to the HTTP Authorization header, where the first field is the authentication method and the second field is the authentication token. +Previously, this was achieved using prefixes to the session token part of phpBB format. + +| Type | Description | +|:--------:| ----------- | +| `string` | Authentication method, for example `Bearer` for an OAuth2 bearer token, or `Misuzu` for using the `msz_auth` cookie value. | +| `string` | Authentication token, for example the OAuth2 bearer token value, or the Misuzu authentication cookie. | ### Packet `2`: Message @@ -106,16 +105,10 @@ Informs the server that the user has sent a message. Commands are described lower in the document. - - - - - - - - - -
stringUser ID
stringMessage text, may not contain \t
+| Type | Description | +|:--------:| ----------- | +| `string` | User ID of the current user. | +| `string` | Message text, cannot contain a tab character `\t`. | ## Server Packets @@ -124,12 +117,9 @@ These are the packets sent from the server to the client. ### Packet `0`: Pong Response to client packet `0`: Ping. - - - - - -
stringA string containing pong. Previously SharpChat sent the current Unix timestamp here, but has since been updated to conform to the Original Sock Chat server formatting.
+| Type | Description | +|:--------:| ----------- | +| `string` | A string containing `pong`. Previously SharpChat sent the current Unix timestamp here, but has since been updated to conform to the Original Sock Chat server formatting. | ### Packet `1`: Join/Auth @@ -138,532 +128,255 @@ While authenticated this packet indicates that a new user has joined the server/ #### Successful authentication response Informs the client that authentication has succeeded. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
stringy
stringUser ID
stringUsername
colorUsername color
user permissionsUser permissions
channel nameDefault channel the user will join following this packet
intMaximum length for messages sent by the client
- +| Type | Description | +|:--------------:| ----------- | +| `string` | `y` to indicate a successful authentication attempt. | +| `string` | User ID of the authenticated user. | +| `user name` | User name of the authenticated user. | +| `colour` | User colour of the authenticated user. | +| `user perms` | Permissions for the authenticated user. | +| `channel name` | Default channel the user will join following this packet. | +| `int` | Maximum length for messages sent by the client. NOTE: While the original PHP server did not send this data, the bundled client did look for it. | #### Failed authentication response Informs the client that authentication has failed. - - - - - - - - - - - - - -
stringn
string - Reason for failure. -
    -
  • authfail: Authentication data is invalid.
  • -
  • userfail: Username in use.
  • -
  • sockfail: A connection has already been started (used to cap maximum connections to 5 in SharpChat).
  • -
  • joinfail: User attempting to authenticate is banned.
  • -
-
timestampIf joinfail this contains expiration time of the ban, otherwise it is empty.
+| Type | Description | +|:-----------:| ----------- | +| `string` | `n` to indicate a failed authentication attempt. | +| `string` | A reason string indicating the reason why the authentication attempt failed, options are listed below. | +| `timestamp` | If included, indicates a ban expiration timestamp. Usually paired with the `joinfail` reason string. | +##### Reason strings +| Reason | Explanation | +| ---------- | ----------- | +| `authfail` | Provided authentication data cannot be verified with an existing user or session. | +| `joinfail` | Authentication data was correct, but the user is banned. The third field will contain an expiration timestamp. | +| `sockfail` | Current socket connection is already authenticated. PHP Chat did not allow the same user account to be in chat more than once. SharpChat allows simultaneous connections, so this is used to put a cap on the maximum amount of connections a single user may have. As of writing this, the maximum number is `5`, however this may change in the future. | +| `userfail` | A user with the same user name is already in chat. PHP Chat did not allow the same user account to be in chat more than once. SharpChat allows simultaneous connections, so this is used as a generic fallback reason in that implementation. If it occurs, a critical error happened on the backend. | #### User joining Informs the client that a user has joined. - - - - - - - - - - - - - - - - - - - - - - - - - -
timestampTime the user joined
stringUser ID
stringUsername
colourUsername color
user permissionsUser permissions
stringMessage ID
+| Type | Description | +|:------------:| ----------- | +| `timestamp` | Timestamp at which the user joined. | +| `string` | User ID of the joining user. | +| `user name` | User name of the joining user. | +| `colour` | User colour for the joining user. | +| `user perms` | Permissions for the joining user. | +| `string` | Message ID associated with this event. | ### Packet `2`: Chat message Informs the client that a chat message has been received. - - - - - - - - - - - - - - - - - - - - - -
timestampTime when the message was received by the server
string - User ID. - If -1 this message is an informational message from the server and the next field takes on a special form. -
string -

Message, sanitised by the server

-

- If this is an informational message this field is formatted as follows and concatenated by the form feed character \f, respresented in ASCII by 0x0C. Bot message formats are described lower in the document. - - - - - - - - - - - - - -
int - Message type. -
    -
  • 0 for a normal informational message.
  • -
  • 1 for an error.
  • -
-
stringAn id of a string in the legacy language files.
...stringAny number of parameters used to format the language string.
-

-
stringMessage ID
message flagsMessage flags
+| Type | Description | +|:---------------:| ----------- | +| `timestamp` | Timestamp at which the message was received by the server. | +| `string` | User ID of the author. If `-1` the message body will contain a formatted informational message documented below. | +| `string` | Message body. If this isn't an informational message, it is sanitised by the server: `<`, `>` and `\n` are replaced by `<`, `>` and `
`. SharpChat also replaces `\t` with four sequential space characters. | +| `string` | Message ID. | +| `message flags` | Message flags. | + +#### Informational message formatting +If this is an informational message this field is formatted as follows and concatenated by the form feed character `\f`, respresented in ASCII by `0x0C`. +Bot message formats are described lower in the document. + +| Type | Description | +|:-----------:| ----------- | +| `bool` | If `1`, this message should be displayed as an error message. If `0`, it should be displayed as a normal informational message. | +| `string` | Informational message format name. List of formats is described below. | +| `...string` | Any number of parameters required by the format string. | ### Packet `3`: User disconnect Informs the client that a user has disconnected. - - - - - - - - - - - - - - - - - - - - - -
stringUser ID
stringUsername
string - One of four disconnect reasons. -
    -
  • leave: The user gracefully left, e.g. "x logged out".
  • -
  • timeout: The user lost connection unexpectedly, e.g. "x timed out".
  • -
  • kick: The user has been kicked, e.g. "x has been kicked".
  • -
  • flood: The user has been kicked for exceeding the flood protection limit, e.g. "x has been kicked for spam".
  • -
-
timestampTime when the user disconnected
stringMessage ID
+| Type | Description | +|:-----------:| ----------- | +| `string` | User ID of the disconnecting user. | +| `user name` | User name of the disconnecting user. | +| `string` | Reason for disconnecting, described below. | +| `timestamp` | Timestamp when the user disconnected. | +| `string` | Message ID associated with this event. | + +#### Disconnect reasons +| Reason | Explanation | +| --------- | ----------- | +| `leave` | User gracefully left, e.g. "xyz logged out". | +| `kick` | User got banned, kicked or otherwise unvoluntarily had their session terminated, e.g. "xyz has been kicked". | +| `flood` | User got kicked for exceeding the flood protection limit, e.g. "xyz has been kicked for spam". | +| `timeout` | User lost connection unexpectedly after not sending pings in a timely fashion, e.g. "xyz timed out". The original PHP Sock Chat implementation did not support this and was added later by SharpChat. Support could be added by modifying the language file, so we're letting this slide. | ### Packet `4`: Channel event -This packet informs the user about channel related updates. The only consistent parameter across sub-packets is the first one described as follows. - - - - - - -
int - Channel information update event ID. -
    -
  • 0: A channel has been created.
  • -
  • 1: A channel has been updated.
  • -
  • 2: A channel has been deleted.
  • -
-
+This packet informs the user about channel related updates. +The only consistent parameter across sub-packets is the first one described as follows. +| Type | Description | +|:-----:| -------------- | +| `int` | Sub-packet ID. | #### Sub-packet `0`: Channel creation Informs the client that a channel has been created. - - - - - - - - - - - - - -
channel nameThe name of the new channel
boolIndicates whether the channel is password protected
boolIndicates whether the channel is temporary, meaning the channel will be deleted after the last person departs
- +| Type | Description | +|:--------------:| ----------- | +| `channel name` | Name of the new channel. | +| `bool` | Indicates whether the channel is password protected (non-`0`) or not (`0`). | +| `bool` | Indicates whether the channel is temporary (non-`0`) or not (`0`). In the original PHP Chat implementation this would mean a channel gets deleted after the last person departs from it. | #### Sub-packet `1`: Channel update Informs the client that details of a channel has changed. - - - - - - - - - - - - - - - - - -
channel nameOld/current name of the channel
channel nameNew name of the channel
boolIndicates whether the channel is password protected
boolIndicates whether the channel is temporary, meaning the channel will be deleted after the last person departs
- +| Type | Description | +|:--------------:| ----------- | +| `channel name` | Previous name of the channel. | +| `channel name` | New name of the channel. | +| `bool` | Indicates whether the channel is password protected (non-`0`) or not (`0`). | +| `bool` | Indicates whether the channel is temporary (non-`0`) or not (`0`). In the original PHP Chat implementation this would mean a channel gets deleted after the last person departs from it. | #### Sub-packet `2`: Channel deletion Informs the client that a channel has been deleted - - - - - -
channel nameName of the channel that has been deleted
+| Type | Description | +|:--------------:| ----------- | +| `channel name` | Name of the channel to be deleted. | ### Packet `5`: Channel switching This packet informs the client about channel switching. - - - - - -
int - Channel information update event ID. -
    -
  • 0: A user joined the channel. Sent to all users in said channel.
  • -
  • 1: A user left the channel. Sent to all users in said channel.
  • -
  • 2: The client is to forcibly join a channel.
  • -
-
- +| Type | Description | +|:-----:| -------------- | +| `int` | Sub-packet ID. | #### Sub-packet `0`: Channel join Informs the client that a user has joined the channel. - - - - - - - - - - - - - - - - - - - - - -
stringUser ID
stringUsername
colorUsername color
user permissionsUser permissions
stringMessage ID
- +| Type | Description | +|:------------:| ----------- | +| `string` | User ID of the user joining the channel. | +| `user name` | User name of the user joining the channel. | +| `colour` | User colour of the user joining the channel. | +| `user perms` | Permissions of the user joining the channel. | +| `string` | Message ID associated with this event. | #### Sub-packet `1`: Channel departure Informs the client that a user has left the channel. - - - - - - - - - -
stringUser ID
stringMessage ID
- +| Type | Description | +|:------------:| ----------- | +| `string` | User ID of the user leaving the channel. | +| `string` | Message ID associated with this event. | #### Sub-packet `2`: Forced channel switch Informs the client that it has been forcibly switched to a different channel. - - - - - -
channel nameThe name of the channel that the user has been switched to
+| Type | Description | +|:--------------:| ----------- | +| `channel name` | Name of the channel the current user is now present in. | ### Packet `6`: Message deletion Informs the client that a message has been deleted. - - - - - -
stringMessage ID of the deleted message
+| Type | Description | +|:--------:| ----------- | +| `string` | Message ID of the message to be deleted. | ### Packet `7`: Context information Informs the client about the context of a channel before the client was present. - - - - - -
int - Context event ID. -
    -
  • 0: Users present in the current channel.
  • -
  • 1: A message already in the channel, occurs more than once per channel.
  • -
  • 2: Channels on the server.
  • -
-
+| Type | Description | +|:-----:| -------------- | +| `int` | Sub-packet ID. | #### Sub-packet `0`: Existing users Informs the client about users already present in the channel. - - - - - - - - - -
intAmount of users present in the channel
Context UserAn amount of repetitions of this object based on the number in the previous param, the object is described below
- -##### Context User object - - - - - - - - - - - - - - - - - - - - - - -
stringUser ID
stringUsername
colorUsername color
user permissionsUser permissions
boolWhether the user should be visible in the users list
+| Type | Description | +|:-----:| ----------- | +| `int` | Amount of users present in the current channel. | +| | A repetition of a number of fields based on the number above, described below. | +##### Context user information +| Type | Description | +|:------------:| ----------- | +| `string` | User ID of this already present user. | +| `user name` | User name of this already present user. | +| `colour` | User colour of this already present user. | +| `user perms` | Permissions of this already present user. | +| `bool` | If non-`0` this user should be displayed in a user list, if `0` this user should be treated as invisible. Used by bot mods in the original PHP implementation. | #### Sub-packet `1`: Existing message Informs the client about an existing message in a channel. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
timestampTime when the message was received by the server
stringUser ID
stringUsername
colorUsername color
user permissionsUser permissions
stringMessage text, functions the same as described in Packet 2: Chat message
stringMessage ID
boolWhether the client should notify the user about this message
message flagsMessage flags
- +| Type | Description | +|:---------------:| ----------- | +| `timestamp` | Timestamp at which the message was received by the server. | +| `string` | User ID of the author. If `-1` the message body will contain a formatted informational message documented below. | +| `user name` | User name of the author of this message. | +| `colour` | User colour of the author of this message. | +| `user perms` | Permissions of the author of this message. | +| `string` | Message body. If this isn't an informational message, it is sanitised by the server: `<`, `>` and `\n` are replaced by `<`, `>` and `
`. SharpChat also replaces `\t` with four sequential space characters. | +| `string` | Message ID. | +| `bool` | If non-`0` this message should trigger notifications (sounds, banners, etc) on the client. | +| `message flags` | Message flags. | #### Sub-packet `2`: Channels Informs the client about the channels on the server. - - - - - - - - - -
intAmount of channels on the channel
Context ChannelAn amount of repetitions of this object based on the number in the previous param, the object is described below
- -##### Context Channel object - - - - - - - - - - - - - - -
channel nameName of the channel
boolIndicates whether the channel is password protected
boolIndicates whether the channel is temporary, meaning the channel will be deleted after the last person departs
+| Type | Description | +|:-----:| ----------- | +| `int` | Amount of channels on the server. | +| | A repetition of a number of fields based on the number above, described below. | +##### Context channel information +| Type | Description | +|:--------------:| ----------- | +| `channel name` | Name of the new channel. | +| `bool` | Indicates whether the channel is password protected (non-`0`) or not (`0`). | +| `bool` | Indicates whether the channel is temporary (non-`0`) or not (`0`). In the original PHP Chat implementation this would mean a channel gets deleted after the last person departs from it. | ### Packet `8`: Context clearing Informs the client that the context has been cleared. +This packet can be safely ignored, its behaviour can be implicitly handled when required according to the table below. - - - - - -
int - Number indicating what has been cleared. -
    -
  • 0: The message list has been cleared.
  • -
  • 1: The user list has been cleared.
  • -
  • 2: The channel list has been cleared.
  • -
  • 3: Both the message and user listing have been cleared.
  • -
  • 4: The message, user and channel listing have all been cleared.
  • -
-
+| Type | Description | +|:-----:| ----------- | +| `int` | Number indicating what data should be cleared. Modes are described below. | + +#### Context clear modes +| Mode | Explanation | +|:----:| ----------- | +| `0` | Only the message history should be cleared. Does not normally occur. | +| `1` | Only the user list should be cleared. Does not normally occur. | +| `2` | Only the channel list should be cleared. Does not normally occur. | +| `3` | Clear the message history and user list. Occurs upon switching (or being switched) to another channel. | +| `4` | Clear the message history, user list and channel list. Does not normally occur. | ### Packet `9`: Forced disconnect Informs the client that they have either been banned or kicked from the server. - - - - - - - - - -
bool -
    -
  • 0: The client has been kicked, can reconnect immediately.
  • -
  • 1: The client has been banned, can reconnect after the timestamp (documented below) in the next param has expired.
  • -
-
timestampBan expiration time, not present when the first argument is 0.
+| Type | Description | +|:-----------:| ----------- | +| `bool` | If non-`0`, the next field will be defined and contain an expiration time. If `0`, the user can rejoin immediately. | +| `timestamp` | Ban expiration timestamp, present when the first field is non-`0`. | ### Packet `10`: User update Informs that another user's details have been updated. - - - - - - - - - - - - - - - - - -
stringUser ID of the affected user
stringNew username
colorNew username color
user permissionsUser permissions
+| Type | Description | +|:------------:| ----------- | +| `string` | User ID of the updated user. | +| `user name` | New user name of the updated user. | +| `colour` | New user colour for the updated user. | +| `user perms` | New permissions for the updated user. | ## Bot Messages