While the zChat Protocol is similar to the protocol used by MUDMaster, it is not the same, and is not formally compatible. zChat recognizes both the zChat Protocol and the MUDMaster protocol. For details on the MUDMaster Chat protocol, contact it's author directly.
The zChat protocol was designed to support enhanced chat security, and to be a robust network protocol. In fact, zChat looks very much like any other TCP/IP protocol.
So, the Client "calls" the Server, and the Server answers.
Send the following data through a normal TCP/IP packet. The TCP/IP packet contains the IP address and Port number of the Server being called. The data in the connection request packet is:
ZCHAT:<ChatName>\t<ChatID>\lf<ClientIPAddress><ClientPort>\lf<SecurityInfo>
The ClientPort is formatted as a five-digit number with leading zeros. The sprintf syntax is: "ZCHAT:%s\t%s\n%s%-5u\n%s". Optional information can be included in the connection request by adding another \lf after the SecurityInfo and then sending the optional data.
The client then waits for a response from the Server
When the Server receives a Connection Request, it must determine whether or not to accept the connection.
The Server accepts the connection request if the Server is set up to accept calls (not in Do Not Disturb mode). If the Server is not in Auto-Accept mode, the user on the Server is prompted whether to accept the call or not. Also, if the SecurityInfo is a PGP-encrypted message, the | characters are replaced with the original CR/LF characters, and is decrypted with PGP 2.62. The output of the PGP decryption is checked to see if a valid digital signature was present. If the digital signature was valid and the contents of the encrypted message was "SecID", the connection is accepted. If SecurityInfo was not a PGP message, it is simply checked against the Security Phrase that the Server has listed for this Client (based upon the ClientChatName and ChatID). If the Security Phrase stored on the Server matches what is sent by the client, the connection is accepted. Finally, if the SecurityInfo field is empty, the connection is accepted.
To accept a connection, the Server sends a TCP/IP packet back to the client with the data:
YES:<ServerChatName>\lf
Also at this time, the Server sends several zChat commands including: Version, Icon, Status, Stamp, EmailAddr. See the Commands section below for more details on these commands.
If the Server is not accepting connections or if the security tests fail, or if the Server wants to reject the request for any other reason, it sends a TCP/IP packet back to the client with the data:
NO
Note that the Server should not generate any spam on the screen until a connection is accepted. This prevents hackers from generating text on the Server's screen by repeatedly trying to connect. Of course, these attempts may be logged.
When the Client receives the Connection Request Response, it takes the appropriate action. If the Connection Request was accepted, the Client then sends zChat commands including: Version, Icon, Status, Stamp, and EmailAddr. See the Commands section below for more details on these commands.
Either the Client or the Server may terminate a chat connection at any time by simply closing the network socket. Note that zChat connections are persistent; they remain open. Once the socket is closed, it can only be opened again by initiating a new Connection Request as described above.
Once the chat connection is open, the Client and the Server can communicate by sending commands. Commands are normal TCP/IP packets that contain the following data format:
<CommandID><Length><Data>
Name Change (1)
The Data is the new ChatName. This is broadcast to all open chat connections whenever the user changes their chat name.
Request Connections (2)
This is used to query the public connections that someone else has. The receiver responds with a Connection List command described below. The Data for the Request Connections command is empty.
Connection List (3)
The response to the Request Connections command above. The Data sent by the receiver is:
<IPAddr>,<Port>,<IPAddr>,<Port> etc
If there is no IP Address for a connection, the string "<Unknown>" is sent in place of the IP Address field. For example, the Data field might look like:
192.168.0.2,4050,<Unknown>,4050,192.168.0.1,4000
Only data for Public connections are sent. Private connections are kept private.
When the Sender of the initial Request Connections command receives the Connection List data, it then makes an attempt to connect to each one of the connections sent.
Text Everybody (4)
Data is the StampedText to send. The Sender formats the entire message to be displayed (like "<Name> chats to everybody: hello") so the the Receiver just has to display the message. The Sender should only send this command to connections that it is not ignoring.
StampedText has the format
<Stamp><Text>
where Stamp is a 4-byte session ID number. When Sending, send your Stamp Code, which is the random number you generated and broadcast when zChat first started. If the received Stamp value matches the Receivers Stamp ID, the message is ignored (since it represents a message loop).
Text may be PGP signed with the Sender's SecretKey. If so, the Receiver must decrypt the message using the Sender's PublicKey before displaying it.
As the Receiver, if the connection is not being ignored, print the Text message. Then check to see if you are "serving" any other connections. For connections that you are serving, echo the Text to those connections so that they see the message as well.
In zChat, the "serving" flag is set by the zChat user. Connections are not automatically flagged as being "served" or not; it is left as a user choice.
Text Personal (5)
Like the Text Everybody command, but the Text is only sent by the Sender to a single Receiver. The Sender formats the entire message to be displayed (like "<Name> chats to you: hello"). The Receiver simply displays the message.
StampedText has the format
<Stamp><Text>
where Stamp is a 4-byte session ID number. When Sending, send your Stamp Code, which is the random number you generated and broadcast when zChat first started. If the received Stamp value matches the Receivers Stamp ID, the message is ignored (since it represents a message loop).
The Text may be PGP signed with the Sender's SecretKey and encrypted the Receiver's PublicKey. If so, the Receiver must decrypt the message before displaying it.
Text Group (6)
Like the Text Everybody command, but the Text is sent to a specific group of connections. The Data field is:
<Stamp><GroupName><Text>
where GroupName is a 15-character string, padded with spaces on the left, that gives the Name of the group. The Sender formats the entire message to be displayed (like "<Name> chats to the group <GroupName>: hello"). The Receiver simply displays the message.
Stamp is a 4-byte session ID number. When Sending, send your Stamp Code, which is the random number you generated and broadcast when zChat first started. If the received Stamp value matches the Receivers Stamp ID, the message is ignored (since it represents a message loop).
The Text may be PGP signed with the Sender's SecretKey and encrypted the Receiver's PublicKey. If so, the Receiver must decrypt the message before displaying it.
As the Receiver, if the connection is not being ignored, print the Text message. Then check to see if you are "serving" any other connections. For connections that you are serving that are part of the same GroupName, forward the message to them also.
Message (7)
Data is the Text of the message
This is used to send system messages to another connection. The Receiver simply prints the message. zChat displays system messages on the status bar instead of in the main output window and keeps a separate log of them. For example, if a connection tries to send you a file and you are not to allow files from that user, you would use the Message command to send a message like "Not accepting files at this time."
Version (19)
Data is the Version string.
This is used to send the version of the Chat client being used. If zChat is running as a zMUD plugin, the version of zMUD being used is also sent. The Receiver simply notes this information and can display it when requested by the user.
File Start (20)
This is sent to initiate a file transfer. The Sender sends this command with a Data format of:
<FileName>,<Length>
FileName is just the name of the file, and not the Path.
Length is the length of the file to be sent in bytes.
When the Receiver gets this command, it first checks to see if it is accepting file transfers. If not, it should sent a File Deny command back to the Sender. If files are being accepted, any path information in the Filename is stripped, and an attempt is made to create the file. If successful, the Receiver then requests the file contents by sending a File Block Request command. If the file creation fails, the File Deny command is sent.
File Deny (21)
This is sent by the Receiver of the File Start command if there is a reason it cannot accept the file. The Data for this command is a Message explaining the reason for the failure. It might be something like "File already exists". The Receiver of this File Deny message should print the Message and clean up any preparation that was made to transfer a file.
File Block Request (22)
This is sent by the Receiver of the File Start command whenever it is ready for a block of file data. The Receiver of this message (the Sender of the File Start command) should send the next block of file data using the File Block command below. If there is no more data to send, the File End command should be sent.
File Block (23)
This command is used to actually send a block of file data. The Data is the raw data to be sent and can be any length. zChat sends data in blocks of 1024 bytes. The last block might be smaller than this. The Receiver of this data should write it to the file being created and then request the next block by sending a Block Request when it is ready.
File End (24)
This command is sent in response to a Block Request when there is no more data to be sent. The Data field is empty. When the Receiver gets this message, it should close the file it has created and report to the user that the file was received properly.
File Cancel (25)
Can be sent by either side to abort a file transfer in progress. The side sending the file should close the file and clean up. The side receiving the file should close and delete the partial file and report that the transfer was cancelled. The Data field is empty for this command.
Ping Request (26)
This command is used to determine the round-trip delay time between the two ends of a chat connection. The Sender sets the Data field to anything it wants, but it is usually the Clock value at the time the command is sent. The Receiver of this command simply echoes the Data field back to the Sender using the Ping Reponse command below.
Ping Response (27)
Sent in response to the Ping Request. The Data field is the same data received from the Ping Request. When the Sender of the Ping Request gets this data back, it can compare the Clock value in the data field that is returned (which is the time when the initial Ping Request was sent) to the current Clock value to determine how much time passed in transit.
Peek Connections (28)
Like the Request Connections command, this is used to examine all public connections of another person. However, instead of connecting to each connection, the connections are just displayed. The Receiver of this command sends the Peek List response. The Data field is empty.
Peek List (29)
In response to a Peek Connections command, a list of current Public connections is sent in the Data field with the form:
<IPAddr>,<Port>,<IPAddr>,<Port> etc
If the IP Address is not known, "<Unknown>" is sent instead of the address. This is the same format as the list used in the Connection List command.
When the Sender of the Peek Connections command gets the Peek List response, the list of connections are displayed on the screen.
Snoop (30)
Sends a request to start/stop snooping data from a chat connection. The Data field is empty. The Receiver of this message decides whether to allow snooping or not. If denied, a Message command is sent back. Otherwise, the Receiver goes into Snoop mode and sends data using the Snoop Data command below
Snoop Data (31)
Send by a client in Snoop mode. The Data is the text that was just received. Basically, the client in Snoop mode echoes any text that it receives to any connections that are snooping it. This allows other clients to see the same data on their screen. The client can exit snoop mode at any time and simply stop sending Snoop Data packets.
Icon (100)
Used to broadcast your custom graphical icon. Data is the raw image data. Currently this data is in Windows Bitmap format.
Status (101)
Used to broadcast your current status to all your connections. Data is a single byte, with the value:
Whenever the status of the chat client changes, this command is broadcast to all chat connections. Normal means the user is actively using the chat client. InActive means that the user is using some other program on their system and the chat client is not necessarily visible. AFK means that no keyboard or mouse activity has been detected in a while and the user is probably away from the computer
Email Address (102)
The Data field is the Email Address of the user. Sent to all chat connections when the user wishes to broadcast their email address for offline communications.
Request PGP Key (103)
Sent to request the user's Public PGP key. The Receiver of this message should respond with the PGP Key command below, or a Message command to deny the request. The Data field is empty.
PGP Key (104)
Used to send the user's Public PGP key to a chat connection. Usually sent in response to a Request PGP Key message, but can be sent anytime you wish to broadcast a Public Key. The Data field is the Public PGP Key.
Send Command (105)
Used to send a zMUD command line to another user. The Data field is the entire zMUD command line. The Receiver of this command can choose to execute the command line, or it can send a Message denying the request if commands are not allowed from this user.
Stamp (106)
Data value is a random number generated when zChat starts and is broadcast to all users. This stamp is also sent in all Text commands (TextEverybody, TextPersonal, TextGroup). If Text message is received with the same Stamp code as the client, the message is ignored to prevent message loops.
When this message is received, the Stamp value received is compared with the clients stamp value. If they are the same, the receiver generates a new random number and broadcasts it to all of its connections. This ensures that every connection maintains a unique stamp value.
Page modified on July 23, 2001