Sock Chat Protocol Information

The 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, sent as an int.

Newer versions of the protocol are implemented as extensions, a client for Version 1 should have no trouble using a server built for Version 2 as long as authentication is understood.

The current stable version of the protocol is Version 1.

Types

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.

channel name

A string containing only alphanumeric characters (any case), - or _.

color

Any valid value for the CSS color property. Further documentation can be found on MDN.

message flags

Message flags alter how a message should be displayed to the client, these are all bool values. 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). 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.

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

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.

string User ID

Packet 1: Authentication

Takes a variable number of parameters that are fed into the authentication script associated with the chat.

...string Any amount of data required to complete authentication

Packet 2: Message

Informs the server that the user has sent a message.

Commands are described lower in the document.

string User ID
string Message text, may not contain \t

Server Packets

These are the packets sent from the server to the client.

Packet 0: Pong

Response to client packet 0: Ping.

timestamp Time the packet was sent to the client Originally this field contained the string pong, but this value was completely unused and can be safely replaced.

Packet 1: Join/Auth

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.

Successful authentication response

Informs the client that authentication has succeeded.

string y
string User ID
string Username
color Username color
user permissions User permissions
channel name Default channel the user will join following this packet
int Maximum length for messages sent by the client

Failed authentication response

Informs the client that authentication has failed.

string n
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.
timestamp If joinfail this contains expiration time of the ban, otherwise it is empty.

User joining

Informs the client that a user has joined.

timestamp Time the user joined
string User ID
string Username
colour Username color
user permissions User permissions
string Sequence ID

Packet 2: Chat message

Informs the client that a chat message has been received.

timestamp Time 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.
string An id of a string in the legacy language files.
...string Any number of parameters used to format the language string.

string Sequence ID
message flags Message flags

Packet 3: User disconnect

Informs the client that a user has disconnected.

string User ID
string Username
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".
timestamp Time when the user disconnected
string Sequence ID

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.

Sub-packet 0: Channel creation

Informs the client that a channel has been created.

channel name The name of the new channel
bool Indicates whether the channel is password protected
bool Indicates whether the channel is temporary, meaning the channel will be deleted after the last person departs

Sub-packet 1: Channel update

Informs the client that details of a channel has changed.

channel name Old/current name of the channel
channel name New name of the channel
bool Indicates whether the channel is password protected
bool Indicates whether the channel is temporary, meaning the channel will be deleted after the last person departs

Sub-packet 2: Channel deletion

Informs the client that a channel has been deleted

channel name Name of the channel that has been 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.

Sub-packet 0: Channel join

Informs the client that a user has joined the channel.

string User ID
string Username
color Username color
user permissions User permissions
string Sequence ID

Sub-packet 1: Channel departure

Informs the client that a user has left the channel.

string User ID
string Sequence ID

Sub-packet 2: Forced channel switch

Informs the client that it has been forcibly switched to a different channel.

channel name The name of the channel that the user has been switched to

Packet 6: Message deletion

Informs the client that a message has been deleted.

string Sequence ID of the deleted message

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.

Sub-packet 0: Existing users

Informs the client about users already present in the channel.

int Amount of users present in the channel
Context User An amount of repetitions of this object based on the number in the previous param, the object is described below
Context User object
string User ID
string Username
color Username color
user permissions User permissions
bool Whether the user should be visible in the users list

Sub-packet 1: Existing message

Informs the client about an existing message in a channel.

timestamp Time when the message was received by the server
string User ID
string Username
color Username color
user permissions User permissions
string Message text, functions the same as described in Packet 2: Chat message
string Sequence ID
bool Whether the client should notify the user about this message
message flags Message flags

Sub-packet 2: Channels

Informs the client about the channels on the server.

int Amount of channels on the channel
Context Channel An amount of repetitions of this object based on the number in the previous param, the object is described below
Context Channel object
channel name Name of the channel
bool Indicates whether the channel is password protected
bool Indicates whether the channel is temporary, meaning the channel will be deleted after the last person departs

Packet 8: Context clearing

Informs the client that the context has been cleared.

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.

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.
timestamp Ban expiration time

Packet 10: User update

Informs that another user's details have been updated.

string User ID of the affected user
string New username
color New username color
user permissions User permissions

Bot Messages

Formatting IDs sent by user -1.

Informational

say: Broadcast

Just echo whatever is specified in the first argument.

Arguments

flwarn: Flood protection warning

Informs the client that they are risking getting kicked for flood protection (spam) if they continue sending messages at the same rate.

unban: Ban revocation confirmation

Informs the client that they have successfully revoked a ban on a user or an IP address.

banlist: List of banned entities

Provides the client with a list of all banned users and IP addresses.

Arguments

who: List of online users

Provides the client with a list of users currently online on the server.

Arguments

whochan: List of users in a channel.

Provides the client with a list of users currently online in a channel.

Arguments

join: User connected

Informs the client that a user just connected to the server.

Arguments

jchan: User joined channel

Informs the client that a user just joined a channel they're in.

Arguments

leave: User disconnected

Informs the client that a user just disconnected from the server.

Arguments

lchan: User left channel

Informs the client that a user just left a channel they're in.

kick: User has been kicked

Informs the client that another user has just been kicked.

Arguments

flood: User exceeded flood limit

Informs the client that another user has just been kicked for exceeding the flood protection limit.

Arguments

timeout: User has timed out

Informs the client that another user has been disconnected from the server automatically.

Arguments

nick: User has changed their nickname

Informs the client that a user has changed their nickname.

Arguments

crchan: Channel creation confirmation

Informs the client that the channel they attempted to create has been successfully created.

Arguments

delchan: Channel deletion confirmation

Informs the client that the channel they attempted to delete has been successfully deleted.

Arguments

cpwdchan: Channel password update confirmation

Informs the client that they've successfully changed the password of a channel.

cprivchan: Channel rank update confirmation

Informs the client that they've successfully changed the minimum required rank to join a channel.

ipaddr: IP address

Shows the IP address of another user to a user with moderation privileges.

Arguments

Errors

generr: Generic Error

Informs the client that Something went Wrong.

nocmd: Command not found

Informs the client that the command they tried to run does not exist.

Arguments

cmdna: Command not allowed

Informs the client that they are not allowed to use a command.

Arguments

cmderr: Command format error

Informs the client that the command they tried to run was incorrectly formatted.

Arguments

usernf: User not found

Informs the client that the user argument of a command contains a user that is not known by the server.

Arguments

rankerr: Rank error

Informs the client that they are not allowed to do something because their ranking is too low.

nameinuse: Name in use

Informs the the client that the name they attempted to choose is already in use by another user.

Arguments

whoerr: User listing error

Informs the client that they do not have access to the channel they tried to query.

Arguments

kickna: Kick or ban not allowed

Informs the client that they are not allowed to kick a user.

Arguments

notban: Not banned

Informs the client that the ban they tried to revoke was not in place.

Arguments

nochan: Channel not found

Informs the client that the channel they tried to join does not exist.

Arguments

samechan: Already in channel

Informs the client that they attempted to join a channel they are already in.

Arguments

ipchan: Channel join not allowed

Informs the client that they do not have sufficient rank or permissions to join a channel.

Arguments

nopwchan: No password provided

Informs the client that they must specify a password to join a channel.

Arguments

ipwchan: No password provided

Informs the client that the password they provided to join a channel was invalid.

Arguments

inchan: Invalid channel name

Informs the client that the name they tried to give to a channel contains invalid characters.

nischan: Channel name in use

Informs the client that the name they tried to give to a channel is already used by another channel.

Arguments

ndchan: Channel deletion error

Informs the client that they are not allowed to delete a channel.

Arguments

namchan: Channel edit error

Informs the client that they are not allowed to edit a channel.

Arguments

delerr: Message deletion error

Informs the client that they are not allowed to delete a message.

Commands

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).

/afk: Setting status to away

Marks the current user as afk, the first 5 characters from the user string are prefixed uppercase to the current username prefixed by < and suffixed by >_ 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.

Format

/afk [reason?]

/nick: Change nickname

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.

Format

/nick [name?]

Responses

/msg: Sending a Private Message

Sends a private message to another user.

Format

/msg [username] [message]

Aliases

Responses

/me: Describing an action

Sends a message but with flags 11000 instead of the regular 10010, used to describe an action.

Format

/me [message]

Aliases

/who: Requesting a user list

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.

Format

/who [channel?]

Responses

/delete: Deleting a message or channel

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.

Format

/delete [channel name or message id]

Responses

Inherits the responses of whichever command is forwarded to.

/join: Joining a channel

Switches or joins the current user to a different channel.

Format

/join [channel] [password?]

Responses

/leave: Leaving a channel

Leave a specified channel.

Format

/leave [channel]

Responses

/create: Creating a channel

Creates a new channel.

Format

/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.

Responses

/delchan: Deleting a channel

Deletes an existing channel.

Format

/delchan [name]

Responses

/password: Update channel password

Changes the password for a channel. Removes the password if no argument is given.

Format

/password [password?]

Aliases

Responses

/rank: Update channel minimum rank

Changes what user rank is required to enter a channel.

Format

/rank [rank]

Aliases

Responses

/say: Broadcast a message

Broadcasts a message as the server/chatbot to all users in all channels.

Format

/say [message]

Responses

/delmsg: Deleting a message

Deletes a given message.

Format

/delmsg [message id]

Responses

/kick: Kick a user

Kicks a user from the serer. If not time is specified, then kick expires immediately.

Format

/kick [username] [time?]

Responses

/ban: Bans a user

Bans a user and their IP addresses from the server. If no time is specified the ban will never expire.

Format

/ban [user] [time?]

Responses

/pardon: Revokes a user ban

Revokes a ban currently placed on a user.

Format

/pardon [user]

Aliases

Responses

/pardonip: Revokes an IP address ban

Revokes a ban currently placed on an IP address.

Format

/pardonip [address]

Aliases

Responses

/bans: List of bans

Retrieves a list of banned users and IP addresses.

Format

/bans

Aliases

Responses

/ip: Retrieve IP addresses

Retrieves a user's IP addresses. If the user has multiple connections, multiple ipaddr responses may be sent.

Format

/ip [username]

Aliases

Responses

Sock Chat V1 was created by MallocNull
Markdown parsing by a modified version of Parsedown
Maintained Flashwave
This page is automatically generated using Protocol.md from the Sharp Chat repository.
Loaded in 1.63208 seconds.