The Sock Chat protocol operates on a websocket in text mode. Messages sent between the client and server are a series of concatenated strings delimited by the vertical tab character, represented in most languages by the escape sequence \t
and defined in ASCII as 0x09
. The first string in this concatenation must be the packet identifier.
Updated behaviour is defined through capabilities. Further documentation on their behaviour will be added at a later date.
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.
Any number ranging from -9007199254740991
to 9007199254740991
, Number.MAX_SAFE_INTEGER
and Number.MIN_SAFE_INTEGER
in JavaScript.
Any printable unicode character, except \t
which is used to separate packets.
Extends int
, contains a second based UNIX timestamp.
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.
A string
containing only alphanumeric characters (any case), -
or _
.
Any valid value for the CSS colour
property. Further documentation can be found on MDN.
Message flags alter how a message should be displayed to the client, these are all bool
values. The parts are as follows:
:
should be displayed between the username and the message.
As an example, the most common message flagset is 10010
. This indicates a bold username with a colon separator.
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.
Note that this string MAY be empty if sent by the bot user (-1
).
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. |
These are the packets sent from the client to the server.
Used to prevent the client from closing the session due to inactivity.
Type | Description |
---|---|
string | User ID of the current user. |
Takes a variable number of parameters that are fed into the authentication script associated with the chat.
Type | Description |
---|---|
...string | Any amount of data required to complete authentication. |
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. |
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. |
Informs the server that the user has sent a message.
Commands are described lower in the document.
Type | Description |
---|---|
string | User ID of the current user. |
string | Message text, cannot contain a tab character \t . |
These are the packets sent from the server to the client.
Response to client packet 0
: Ping.
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. |
While authenticated this packet indicates that a new user has joined the server/channel. Before authentication this packet serves as a response to client packet 1
: Authentication.
Informs the client that authentication has succeeded.
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. |
Informs the client that authentication has failed.
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 | 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. |
Informs the client that a user has joined.
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. |
Informs the client that a chat message has been received.
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 <br/> . SharpChat also replaces \t with four sequential space characters. |
string | Message ID. |
message flags | Message flags. |
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. |
Informs the client that a user has disconnected.
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. |
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. |
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. |
Informs the client that a channel has been created.
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. |
Informs the client that details of a channel has changed.
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. |
Informs the client that a channel has been deleted
Type | Description |
---|---|
channel name | Name of the channel to be deleted. |
This packet informs the client about channel switching.
Type | Description |
---|---|
int | Sub-packet ID. |
Informs the client that a user has joined the channel.
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. |
Informs the client that a user has left the channel.
Type | Description |
---|---|
string | User ID of the user leaving the channel. |
string | Message ID associated with this event. |
Informs the client that it has been forcibly switched to a different channel.
Type | Description |
---|---|
channel name | Name of the channel the current user is now present in. |
Informs the client that a message has been deleted.
Type | Description |
---|---|
string | Message ID of the message to be deleted. |
Informs the client about the context of a channel before the client was present.
Type | Description |
---|---|
int | Sub-packet ID. |
Informs the client about users already present in the channel.
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. |
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. |
Informs the client about an existing message in a channel.
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 <br/> . 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. |
Informs the client about the channels on the server.
Type | Description |
---|---|
int | Amount of channels on the server. |
A repetition of a number of fields based on the number above, described below. |
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. |
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.
Type | Description |
---|---|
int | Number indicating what data should be cleared. Modes are described below. |
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. |
Informs the client that they have either been banned or kicked from the server.
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 . |
Informs that another user’s details have been updated.
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. |
Formatting IDs sent by user -1.
Just echo whatever is specified in the first argument.
string
: Message to be broadcast.Informs the client that they are risking getting kicked for flood protection (spam) if they continue sending messages at the same rate.
Informs the client that they have successfully revoked a ban on a user or an IP address.
Provides the client with a list of all banned users and IP addresses.
string
: HTML with the information on the users with the following format: “<a href=”javascript:void(0);” onclick=“Chat.SendMessageWrapper(‘/unban’+ this.innerHTML);”>{0}</a>
” where {0} is the username of the banned user or the banned IP address. The set is separated by “
,
”.
Provides the client with a list of users currently online on the server.
string
: HTML with the information on the users with the following format: “<a href=”javascript:void(0);” onclick=“UI.InsertChatText(this.innerHTML);”>{0}</a>
” where {0} is the username of a user. The current online user is highlighted with “
style=”font-weight: bold;“
” before the closing > of the opening <a> tag. The set is separated by “
,
”.
Provides the client with a list of users currently online in a channel.
string
: HTML with the information on the users with the following format: “<a href=”javascript:void(0);” onclick=“UI.InsertChatText(this.innerHTML);”>{0}</a>
” where {0} is the username of a user. The current online user is highlighted with “
style=”font-weight: bold;“
” before the closing > of the opening <a> tag. The set is separated by “
,
”
Informs the client that a user just connected to the server.
string
: Username of the user.Informs the client that a user just joined a channel they’re in.
string
: Username of the user.Informs the client that a user just disconnected from the server.
string
: Username of the user.Informs the client that a user just left a channel they’re in.
Informs the client that another user has just been kicked.
string
: Username of the user.Informs the client that another user has just been kicked for exceeding the flood protection limit.
string
: Username of the user.Informs the client that another user has been disconnected from the server automatically.
string
: Username of the user.Informs the client that a user has changed their nickname.
string
: Previous username of the user.string
: New username of the user.Informs the client that the channel they attempted to create has been successfully created.
string
: Name of the target channel.Informs the client that the channel they attempted to delete has been successfully deleted.
string
: Name of the target channel.Informs the client that they’ve successfully changed the password of a channel.
Informs the client that they’ve successfully changed the minimum required rank to join a channel.
Shows the IP address of another user to a user with moderation privileges.
string
: Name of the target user.string
: IP address.Informs the client that Something went Wrong.
Informs the client that the command they tried to run does not exist.
string
: Name of the command.Informs the client that they are not allowed to use a command.
string
: Name of the command.Informs the client that the command they tried to run was incorrectly formatted.
string
: Name of the command.Informs the client that the user argument of a command contains a user that is not known by the server.
string
: Name of the target user.Informs the client that they are not allowed to do something because their ranking is too low.
Informs the the client that the name they attempted to choose is already in use by another user.
string
: Name that is in use.Informs the client that they do not have access to the channel they tried to query.
string
: Name of the channel.Informs the client that they are not allowed to kick a user.
string
: Username of the user in question.Informs the client that the ban they tried to revoke was not in place.
string
: Username or IP address in question.Informs the client that the channel they tried to join does not exist.
string
: Name of the channel.Informs the client that they attempted to join a channel they are already in.
string
: Name of the channel.Informs the client that they do not have sufficient rank or permissions to join a channel.
string
: Name of the channel.Informs the client that they must specify a password to join a channel.
string
: Name of the channel.Informs the client that the password they provided to join a channel was invalid.
string
: Name of the channel.Informs the client that the name they tried to give to a channel contains invalid characters.
Informs the client that the name they tried to give to a channel is already used by another channel.
string
: Name of the channel.Informs the client that they are not allowed to delete a channel.
string
: Name of the channel.Informs the client that they are not allowed to edit a channel.
string
: Name of the channel.Informs the client that they are not allowed to delete a message.
Actions sent through messages prefixed with /
. Arguments are described as [name]
, optional arguments as [name?]
. The .
character is ignored in command names (replaced by nothing).
Marks the current user as afk, the first 5 characters from the user string are prefixed uppercase to the current username prefixed by &lt;
and suffixed by &gt;_
resulting in a username that looks like <AWAY>_flash
if /afk away
is ran by the user flash
. If no reason is specified “AFK
” is used.
/afk [reason?]
Temporarily changes the user’s nickname, generally with a prefix such as ~
to avoid name clashing with real users. If the user’s original name or no argument at all is specified, the command returns the user’s name to its original state without the prefix.
/nick [name?]
cmdna
: User is not allowed to change their own nickname.nameinuse
: The specified nickname is already in use by another user.nick
: Username has changed.Sends a private message to another user.
/msg [username] [message]
/whisper
cmderr
: Missing username and/or message arguments.usernf
: Target user could not be found by the server.
Sends a message but with flags 11000
instead of the regular 10010
, used to describe an action.
/me [message]
/action
Requests a list of users either currently online on the server in general or in a channel. If no argument is specified it’ll return all users on the server, if a channel is specified it’ll return all users in that channel.
/who [channel?]
nochan
: The given channel does not exist.whoerr
: The user does not have access to the channel.whochan
: Listing of users in the channel.who
: Listing of users in the server.
Due to an oversight in the original implementation, this command was specified to be both the command for deleting messages and for channels. Fortunately messages always have numeric IDs and channels must start with an alphabetic character. Thus if the argument is entirely numeric this function acts as an alias for /delmsg
, otherwise /delchan
.
/delete [channel name or message id]
Inherits the responses of whichever command is forwarded to.
Switches or joins the current user to a different channel.
/join [channel] [password?]
nochan
: The given channel does not exist.ipchan
: The client does not have the required rank to enter the given channel.nopwchan
: A password is required to enter the given channel.ipwchan
: The password provided was invalid.Leave a specified channel.
/leave [channel]
nocmd
: The client tried to run this command without specifying the MCHAN
capability.Creates a new channel.
/create [rank?] [name...]
If the first argument is numeric, it is taken as the minimum required rank to join the channel. All further arguments are glued with underscores to create the channel name.
cmdna
: The client is not allowed to create channels.cmderr
: The command is formatted incorrectly.rankerr
: The specified rank is higher than the client’s own rank.inchan
: The given channel name contains invalid characters.nischan
: A channel with this name already exists.crchan
: The channel has been created successfully.Deletes an existing channel.
/delchan [name]
cmderr
: The command is formatted incorrectly.nochan
: No channel exists with this name.ndchan
: The client is not allowed to delete this channel.delchan
: The target channel has been deleted.Changes the password for a channel. Removes the password if no argument is given.
/password [password?]
/pwd
cmdna
: The client is not allowed to change the password for this channel.cpwdchan
: The password of the channel has been successfully updated.Changes what user rank is required to enter a channel.
/rank [rank]
/privilege
/priv
cmdna
: The client is not allowed to change the rank of the target channel.rankerr
: Missing rank argument or the given rank is higher than the client’s own rank.cprivchan
: The minimum rank of the channel has been successfully updated.Broadcasts a message as the server/chatbot to all users in all channels.
/say [message]
cmdna
: The client is not allowed to broadcast messages.say
: The broadcasted message.Deletes a given message.
/delmsg [message id]
cmdna
: The client is not allowed to delete messages.cmderr
: The given message ID was invalid.delerr
: The target message does not exist or the client is not allowed to delete this message.Kicks a user from the serer. If not time is specified, then kick expires immediately.
/kick [username] [time?]
cmdna
: The client is not allowed to kick others.usernf
: The target user could not be found on the server.kickna
: The client is trying to kick someone who they are not allowed to kick, or someone that is currently banned.cmderr
: The provided time is invalid.Bans a user and their IP addresses from the server. If no time is specified the ban will never expire.
/ban [user] [time?]
cmdna
: The client is not allowed to kick others.usernf
: The target user could not be found on the server.kickna
: The client is trying to kick someone who they are not allowed to kick, or someone that is currently banned.cmderr
: The provided time is invalid.Revokes a ban currently placed on a user.
/pardon [user]
/unban
cmdna
: The client is not allowed to revoke user bans.notban
: The target user is not banned.unban
: The ban on the target user has been successfully revoked.Revokes a ban currently placed on an IP address.
/pardonip [address]
/unbanip
cmdna
: The client is not allowed to revoke IP bans.notban
: The target address is not banned.unban
: The ban on the target address has been successfully revoked.Retrieves a list of banned users and IP addresses.
/bans
/banned
cmdna
: Not allowed to view banned users and IP addresses.banlist
: The list of banned users and IP addresses.
Retrieves a user’s IP addresses. If the user has multiple connections, multiple ipaddr
responses may be sent.
/ip [username]
whois
cmdna
: The client is not allowed to view IP addresses.usernf
: The target user is not connected to the server.ipaddr
: (One of) The target user’s IP address(es).