chat_protocol.txt 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. Mud Master Chat Protocol
  2. Establishing a Connection
  3. Caller: Once a connection is made the caller sends a connection string;
  4. which looks like: "CHAT:<chat name>\n<ip address><port>". The sprintf
  5. syntax is: "CHAT:%s\n%s%-5u". The port must be 5 characters, padded on the
  6. right side with spaces. Once this string has been sent it waits for a
  7. response from the other side. If a "NO" is received the call is cancelled.
  8. If the call was accepted the string "YES:<chat name>\n" is received.
  9. Receiver
  10. When a socket call is detected it accepts the socket then waits
  11. for the "CHAT:" string to be send from the caller. If the receiver wishes
  12. to deny the call, the string "NO" needs to be sent back to the caller. To
  13. accept the call, the string "YES:<chat name>\n" is sent back.
  14. Chat Data Blocks
  15. A chat data block looks like this: <block ID byte><data><end of data byte>.
  16. All data dealing with needs to follow this format with a couple exceptions.
  17. The connection process doesn't use the data blocks and the file transfer
  18. blocks are a fixed size and don't need the <end of data> byte.
  19. Default Port
  20. The default port should always be 4050.
  21. Below is a list of the <block ID> values:
  22. #define CHAT_NAME_CHANGE 1
  23. #define CHAT_REQUEST_CONNECTIONS 2
  24. #define CHAT_CONNECTION_LIST 3
  25. #define CHAT_TEXT_EVERYBODY 4
  26. #define CHAT_TEXT_PERSONAL 5
  27. #define CHAT_TEXT_GROUP 6
  28. #define CHAT_MESSAGE 7
  29. #define CHAT_DO_NOT_DISTURB 8
  30. #define CHAT_VERSION 19
  31. #define CHAT_FILE_START 20
  32. #define CHAT_FILE_DENY 21
  33. #define CHAT_FILE_BLOCK_REQUEST 22
  34. #define CHAT_FILE_BLOCK 23
  35. #define CHAT_FILE_END 24
  36. #define CHAT_FILE_CANCEL 25
  37. #define CHAT_PING_REQUEST 26
  38. #define CHAT_PING_RESPONSE 27
  39. #define CHAT_PEEK_CONNECTIONS 28
  40. #define CHAT_PEEK_LIST 29
  41. #define CHAT_SNOOP_START 30
  42. #define CHAT_SNOOP_DATA 31
  43. #define CHAT_END_OF_COMMAND 255
  44. The <end of data> byte is 255:
  45. <CHAT_NAME_CHANGE><new name><CHAT_END_OF_COMMAND>
  46. When a user changes their chat name the new name needs to be broadcast to
  47. all of their connections.
  48. <CHAT_REQUEST_CONNECTIONS><CHAT_END_OF_COMMAND>
  49. The sender requests connections from another connection asking to see all the
  50. people that person has marked as public, then try to connect to all of those
  51. yourself.
  52. <CHAT_CONNECTION_LIST><address>,<port>,<address>,<port><CHAT_END_OF_COMMAND>
  53. The receiver needs to put all the ip addresses and port numbers in a comma
  54. delimited string and send them back as a connection list.
  55. <CHAT_TEXT_EVERYBODY><text to send><CHAT_END_OF_COMMAND>
  56. Used to send some chat text to everybody. All the text you want to be
  57. displayed needs to be generated on the sender's side, including the line
  58. feeds and the "<chat name> chats to everybody" string.
  59. Receiver:
  60. If the chat connection isn't being ignored, you simply print the
  61. string. If you have any connections marked as being served you need to echo
  62. this string to those connections. Or if this is coming from a connection
  63. being served, you need to echo to all your other connections. This allows
  64. people who cannot connect directly to each other to connect with a 3rd
  65. person who *can* connect to both and be a server for them.
  66. <CHAT_TEXT_PERSONAL><text to send><CHAT_END_OF_COMMAND>
  67. This works the same way as CHAT_TEXT_EVERYBODY as far as what you need to
  68. send. The text should obviously be changed so the person receiving knows
  69. this was a personal chat and not broadcast to everybody. "\n%s chats to
  70. you, '%s'\n"
  71. Receiver:
  72. Just print the string that comes in if you aren't ignoring this connection.
  73. <CHAT_TEXT_GROUP><group><text to send><CHAT_END_OF_COMMAND>
  74. Used when you send text to a specific group of connections. Works basically
  75. the same as the other text commands. The group name is a 15 character
  76. string. It *must* be 15 characters long, pad it on the right with spaces
  77. to fill it out. "\n%s chats to the group, '%s'\n"
  78. Receiver:
  79. Just print the string that comes in if you aren't ignoring this
  80. connection.
  81. <CHAT_MESSAGE><message><CHAT_END_OF_COMMAND>
  82. This is used to send a message to another chat connection. An example of
  83. this is when you try to send a command (action, alias, etc) to another chat
  84. connection and they don't have you flagged as accepting commands. In that
  85. case a chat message is sent back to the sender telling them that command are
  86. not being accepted. To let the other side know the message is generated
  87. from the chat program it is a good idea to make the string resemble
  88. something like: "\n<CHAT> %s is not allowing commands.\n"
  89. Receiver: Just print the message string.
  90. <CHAT_VERSION><version string><CHAT_END_OF_COMMAND>
  91. This is used to send your client's name and version.
  92. <CHAT_FILE_START><filename,length><CHAT_END_OF_COMMAND>
  93. This is sent to start sending a chat connection a file. The filename should
  94. be just the filename and not a path. Length is the size of the file in
  95. bytes.
  96. Receiver:
  97. First should check to make sure you are allowing files from this
  98. connection. Make sure the filename is valid and that the length was
  99. trasnmitted. MM by default won't allow you to overwrite files; which keeps
  100. people from messing with file already in your directory. If for any reason
  101. the data isn't valid or you don't want to accept files from this person a
  102. CHAT_FILE_DENY should be sent back to abort the transfer. If you want to
  103. continue with the transfer you need to start it off by requesting a block of
  104. data with CHAT_FILE_BLOCK_REQUEST.
  105. <CHAT_FILE_DENY><message><CHAT_END_OF_COMMAND>
  106. This is used when a CHAT_FILE_START has been received and you want to
  107. prevent the transfer from continuing. <message> is a string telling the
  108. reason it was denied. For example, if the file already existed you might
  109. deny it with: "File already exists."
  110. Receiver:
  111. Print the deny message. Deal with cleaning up any files you
  112. opened when you tried to start the transfer.
  113. <CHAT_FILE_BLOCK_REQUEST><CHAT_END_OF_COMMAND>
  114. Sent to request the next block of data in a transfer.
  115. Receiver:
  116. Need to create a file block to be sent back. File blocks are
  117. fixed length so they don't need the CHAT_END_OF_COMMAND byte. If the end of
  118. file is reached need to send a CHAT_FILE_END close up the files and let the
  119. user know it is done sending.
  120. <CHAT_FILE_BLOCK><block of data>
  121. A file block is 500 bytes. A file block is ALWAYS 500 bytes so no CHAT_END_OF_COMMAND should be added.
  122. Receiver:
  123. The receiver needs to keep track of the number of bytes written to
  124. properly write the last block of data. If you keep track of the bytes
  125. written you know when to expect that last block that probably doesn't have a
  126. full 500 bytes to be saved. File transfers are receiver driven, so for each
  127. block of data you accept, you need to send another CHAT_FILE_BLOCK_REQUEST
  128. back out to get more data.
  129. <CHAT_FILE_END><CHAT_END_OF_COMMAND>
  130. Close up your files and be done with it. This command isn't required for TinTin since it keeps track of the file transfer progress itself.
  131. <CHAT_FILE_CANCEL><CHAT_END_OF_COMMAND>
  132. Either side can send this command to abort a file transfer in progress.
  133. <CHAT_PING_REQUEST><timing data><CHAT_END_OF_COMMAND>
  134. The timing data is up to the ping requester. TinTin sends a 64 bit time stamp.
  135. <CHAT_PING_RESPONSE><timing data><CHAT_END_OF_COMMAND>
  136. Send back the timing data is the data that was sent with the CHAT_PING_REQUEST.
  137. <CHAT_PEEK_CONNECTIONS><CHAT_END_OF_COMMAND>
  138. The sender requests connections from another connection asking to see all the
  139. people that person has marked as public.
  140. <CHAT_PEEK_LIST><address>~<port>~<name>~<CHAT_END_OF_COMMAND>
  141. The receiver needs to put all the ip addresses, port numbers, and names in a
  142. tilda delimited string and send them back as a peek list.
  143. <CHAT_SNOOP_START><CHAT_END_OF_COMMAND>
  144. The sender requests to start or stop snooping data from a chat connection.
  145. The Receiver decides whether to allow snooping or not.
  146. <CHAT_SNOOP_DATA><message><CHAT_END_OF_COMMAND>
  147. Send by a client in snoop or forward mode. The message should be echoed by
  148. the receiver, but not be further forwarded to avoid infinite loops.