home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / micq.zip / icq091.txt < prev    next >
Text File  |  1998-07-10  |  38KB  |  782 lines

  1. ########################
  2. ##  THE ICQ PROTOCOL  ##
  3. ########################
  4.  
  5. Version 0.91
  6. Last update 12 April 1998
  7. (Minor update 11 May 1998)
  8. Created by Magnus Ihse (d95-mih@nada.kth.se)
  9. Copyright ⌐ 1998
  10.  
  11. The home page of this specification is
  12. http://www.student.nada.kth.se/~d95-mih/icq/
  13. To participate in the mailing list icq-devel, send a mail to
  14. majordomo@tjsgroup.com, with the message body consisting only of the
  15. line "subscribe icq-devel".
  16.  
  17. About this document
  18. -------------------
  19. Please note: I am in no way affiliated with Mirabilis. This is an unofficial
  20. specification, based solely on TCP/UDP packet traces and my own guesswork. 
  21. This means that the information in here might be (and probably _will_ be
  22. :-)) incorrect. It also means that even _if_ some parts of this specification
  23. _is_ correct, they may change at any moment due to the Divine Will of 
  24. Mirabilis.
  25.  
  26. I am a computer science student at the Royal Institute of Technology in
  27. Sweden, and this is a hobby project - something I have been doing in my 
  28. free time (i.e., late in the nights :-)). This means that I don't have 
  29. much time to spend on updating this document.
  30.  
  31. Recently I have received a lot of requests for this document, and many
  32. persons have offered to help me complete and correct it. I am very thankful
  33. for such help, and all contributions will of cource receive proper credit.
  34. Otherwere in this document is described in more detail what you can do to
  35. help, and how you should do it.
  36.  
  37. Legal information
  38. -----------------
  39. Aa far as I can tell (but I am not a laywer), the way I have extracted
  40. this information complies with Mirabilis License agreement, which states:
  41. "You agree not to reverse engineer, decompile or disassemble the software." 
  42. I have not reverse engineered, decompiled or disassembled the software
  43. (i.e. Mirabilis ICQ client) to get this information. I have only been
  44. looking at the TCP and UDP packets send out from, and received by, my
  45. computer.
  46.  
  47. If you are a Mirabilis employee, and you feel that this document still
  48. violates the Licence agreement, or if you on other grounds think that
  49. this document is dubious - please contact me as soon as possible!
  50. (My e-mail address given at top of this document.)
  51.  
  52.  
  53. Copyright
  54. ---------
  55. This document is protected under internation copyright law. You may
  56. not modify this document. You may, however, make an unlimited number
  57. of copies of this document, as long as it is kept intact. You may
  58. freely distribute this document electronically (on the Internet or 
  59. otherwise) or on paper.
  60.  
  61. Any trademarks mentioned in this text belongs to their respective owner.
  62.  
  63. Disclaimer
  64. ----------
  65. LICENSE AGREEMENT
  66.  
  67. This document and the information present herein is provided by Magnus Ihse
  68. ("the Author") for your personal use only. You agree to the full 
  69. responsibility for the results of your use of this document or the information 
  70. present herein.
  71.  
  72. By using this document or the information present herein, you accept
  73. the terms of this license agreement.
  74.  
  75. THIS INFORMATION IS PROVIDED ON AN "AS IS" BASIS. THE AUTHOR MAKES NO 
  76. WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THOSE OF 
  77. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THIS 
  78. DOCUMENT AND THE INFORMATION PRESENT HEREIN. THE AUTHOR DOES NOT WARRANT, 
  79. GUARANTEE OR MAKE ANY REPRESENTATIONS REGARDING THE USE OR THE RESULTS OF 
  80. THE USE OF THIS DOCUMENT OR THE INFORMATION PRESENT HEREIN, IN TERMS OF THE 
  81. ACCURACY, RELIABILITY, QUALITY, VALIDITY, STABILITY, COMPLETENESS, 
  82. CURRENTNESS, OR OTHERWISE. THE ENTIRE RISK OF USING THE INFORMATION PRESENT 
  83. IN THIS DOCUMENT IS ASSUMED BY THE USER.
  84.  
  85. IN NO EVENT WILL THE AUTHOR BE LIABLE TO ANY PARTY (i) FOR ANY DIRECT, 
  86. INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, 
  87. BUT NOT LIMITED TO, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS 
  88. INTERRUPTION, LOSS OF PROGRAMS OR INFORMATION, AND THE LIKE), OR ANY OTHER 
  89. DAMAGES ARISING IN ANY WAY OUT OF THE AVAILABILITY, USE, RELIANCE ON, OR 
  90. INABILITY TO USE THIS DOCUMENT OR THE INFORMATION PRESENT HEREIN, EVEN IF 
  91. THE AUTHOR HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, AND 
  92. REGARDLESS OF THE FORM OF ACTION, WHETHER IN CONTRACT, TORT, OR OTHERWISE; 
  93. OR (ii) FOR ANY CLAIM ATTRIBUTABLE TO ERRORS, OMISSIONS, OR OTHER 
  94. INACCURACIES IN, OR DESTRUCTIVE PROPERTIES OF ANY INFORMATION.
  95.  
  96. Writing an ICQ clone
  97. --------------------
  98. Since the public release of this document, at least two different ICQ clones
  99. have been created. They are at the time of writing very much under 
  100. development, but are at least partly functioning. :-) More information can
  101. be found on my web page, or through the icq-devel mailing list.
  102. (For web page URL or subscription information, see top of this document.)
  103.  
  104. What needs to be done
  105. ---------------------
  106. The worst deficiency of this document is the lack of information about 
  107. version 3 and version 4 of the protocol. These versions are used by ICQ98
  108. (older beta versions of ICQ98 seems to have used only version 3, the latest
  109. version as of today seems to use both version 3 and version 4). This document
  110. only describes version 2 of the protocol, which was used by versions up to
  111. but not including ICQ98 (I think v1.113 was the latest version of ICQ using 
  112. version 2 of the protocol). Note that the ICQ version numbers refer to the
  113. Windows 95/NT version of ICQ. I think that the Mac and Java version still
  114. uses version 2, but I haven't checked this (please correct me if I'm wrong!).
  115.  
  116. So, what's the difference between version 2 and 3/4? As far as I can tell,
  117. the major difference is that all packets in version 3/4 has some sort of 
  118. unique code attached to it. I think it is part of an anti-spoof scheme, but
  119. I am not sure. I have not been able to figure out how this code is generated,
  120. and I definitely need help on this. There are also minor changes in the 
  121. packet format. The basic structure still seems intact, however.
  122.  
  123. That this document doesn't cover version 3 and 4 doesn't mean that it can't
  124. be used for building an ICQ clone, however. Mirabilis servers still supports
  125. version 2 clients (or at least they did when I last checked). There is 
  126. reason to suspect that this might change some day, since the version 1
  127. clients have been phased out, and are not useable any more.
  128.  
  129. Furthermore are there some fields in the packets which I just couldn't figure
  130. out. You will find these marked "Unknown", and some typical value in the 
  131. Content column.
  132.  
  133. Many packet types are missing from this description for sure. If Mirabilis
  134. have used all multiples of 10 for their codes, there seem to be a lot of
  135. them missing. :-)
  136.  
  137. There is much about the peer-to-peer communication that still is not
  138. clear to me. (This protocol seems not to have changed in ICQ98, however.)
  139.  
  140. And finally, some of the features of ICQ have not even been addressed in this
  141. document. This includes file transfer and chat, but also some of the new
  142. features of ICQ98.
  143.  
  144. If you can help in filling any of these gaps, or correct the information
  145. given here, please do not hesitate to contact me! I'd prefer if you
  146. send an e-mail to d95-mih@nada.kth.se with subject "ICQ Update".
  147. (Please note! Sending an empty mail with the subject "ICQ Update" does
  148. NOT mean that I'll mail you a copy of the spec when it's updated! If
  149. you are interested in keeping up to date with the ICQ specification, please
  150. join the mailing list instead.)
  151.  
  152. Introduction
  153. ------------
  154. Communication with persons online is done through a direct TCP connection
  155. to that person. All other communication is done through UDP packets sent to
  156. the ICQ server. All UDP packets must be acknowledged by the receiver.
  157. Retransmission will occur in 10 seconds if a acknowledgement is not
  158. received. After 6 unsuccessfull transmissions, a B_MESSAGE_ACK message will
  159. be sent. The whole procedure is repeated 2 times. If there is still no
  160. reply, the ICQ client will assume the user to be disconneced.
  161.  
  162. Before any communication between users can take place, the client must
  163. register at the server by logging in. During the login process, the client
  164. sends information about itself to the server, including its IP address, the
  165. TCP port reserved for ICQ, the user's password and the user's contact list.
  166. From now on, the client will assume itself to be 'connected', and will every
  167. now and then send a 'keep alive' message to the server. This keep alive
  168. message performs two functions: it makes the client sure that it still has
  169. access to the server, and it makes the server sure that the user is still
  170. online. By default, the client will 'connect' to the server on UDP port 4000.
  171.  
  172. Functions such as sending messages to offline users, getting information
  173. about a user, searching for users in the ICQ Global Directory and changing
  174. password is done by sending UDP packets to the ICQ server. These packets do
  175. all follow a simple template, including the senders UIN, a special code
  176. indicating which function the server should perform, and optional
  177. parameters.
  178.  
  179. When a user sends a message/URL/etc to another user that is currently
  180. connected, the ICQ client will establish a TCP connection directly to that
  181. user, and send the message using a format similar (but not identical) to the
  182. format used by the UDP packet messaging. After the message has been sent,
  183. the TCP connection is not closed, but instead kept open and used for future
  184. messages to that user. The connection is closed when either of the two users
  185. disconnect from their ICQ connection.
  186.  
  187. Please note that throughout this document, all numbers are in hexadecimal
  188. unless stated otherwise. Integers consisting of more than one byte is stored
  189. with the least significant byte first, and the most significant byte last
  190. (as is usual on the PC/Intel architecture). All text strings etc are
  191. preceded by a two byte long LENGTH field, indicating the length of the
  192. string. All strings are also NULL terminated, i.e. followed by the byte with
  193. the value 00. When reading packets, either information may be used to
  194. determine the length of the string, but when sending both must be present.
  195. All strings are coded as usual MS Windows texts, i.e. in ISO Latin-1
  196. charset, and lines terminated by CR/LF. (Not all strings may contain line
  197. breaks. This should be clear from context.)
  198.  
  199.  
  200.  
  201.          COMMUNICATION BETWEEN SERVER AND CLIENT USING UDP
  202.          =================================================
  203.  
  204.  
  205. The UDP packet sent from the client to the server has the following general
  206. layout:
  207.  
  208.  Length   Content (if fixed)    Name             Description
  209.  ------   ------------------    ----             -----------
  210.  2 bytes  02 00                 VERSION          Identifies the packet as an ICQ packet
  211.  2 bytes  xx xx                 COMMAND          Code for service the server should provide
  212.  2 bytes  xx xx                 SEQ_NUM          Sequence number
  213.  4 bytes  xx xx xx xx           UIN              The senders UIN
  214.  variable                       PARAMETERS       0 or more parameters (depending on COMMAND)
  215.  
  216. The UDP packet sent from the server to the client has the following general
  217. layout:
  218.  
  219.  Length   Content (if fixed)    Name             Description
  220.  ------   ------------------    ----             -----------
  221.  2 bytes  02 00                 VERSION          Identifies the packet as an ICQ packet
  222.  2 bytes  xx xx                 COMMAND          Code for service the server should provide
  223.  2 bytes  xx xx                 SEQ_NUM          Sequence number
  224.  variable                       PARAMETERS       0 or more parameters (depending on COMMAND)
  225.  
  226. The VERSION field is present on all ICQ packets, and identifies the packet
  227. as a ICQ message. The SEQ_NUM contains a sequence number for the packet. All
  228. packets must have a unique sequence number (unless it is a retransmission).
  229. This is used to avoid confusion if a UDP packet is lost or duplicated (as
  230. may happen). Normally, the SEQ_NUM of the current packet is <the SEQ_NUM of
  231. the previous packet> + 1. Note that the server and the client has separate
  232. numbering, so that SEQ_NUM = 3 of a packet sent from the server is different
  233. from SEQ_NUM = 3 of a packet sent from the client. Note also that the server
  234. start counting on 00 00, and the client start counting on 01 00.
  235.  
  236. The following commands are available for the client to send to the server:
  237.  
  238.  Code        Name             Description
  239.  ----        ----             -----------
  240.  0A 00       ACK              Acknowledgement
  241.  0E 01       SEND_MESSAGE     Send message through server (to offline user)
  242.  E8 03       LOGIN            Login on server
  243.  06 04       CONTACT_LIST     Inform the server of my contact list
  244.  1A 04       SEARCH_UIN       Search for user using his/her UIN
  245.  24 04       SEARCH_USER      Search for user using his/her name or e-mail
  246.  2E 04       KEEP_ALIVE       Sent to indicate connection is still up
  247.  38 04       SEND_TEXT_CODE   Send special message to server as text
  248.  4C 04       LOGIN_1          Sent during login
  249.  60 04       INFO_REQ         Request basic information about a user
  250.  6A 04       EXT_INFO_REQ     Request extended information about a user
  251.  9C 04       CHANGE_PASSWORD  Change the user's password
  252.  D8 04       STATUS_CHANGE    User has changed online status (Away etc)
  253.  28 05       LOGIN_2          Sent during login
  254.  
  255. Not yet described in detail (v0.1 of this document)
  256.  0A 05       UPDATE_INFO      Update my basic information
  257.  B0 04       UPDATE_EXT_INFO  Update my extended information
  258.  3C 05       ADD_TO_LIST      Add user to my contact list
  259.  56 04       REQ_ADD_TO_LIST  Request authorization to add to contact list
  260.  BA 04       QUERY_SERVERS    Query the server about address to other servers
  261.  C4 04       QUERY_ADDONS     Query the server about globally defined add-ons
  262.  EC 04       NEW_USER_1       Ask for permission to add a new user
  263.  FC 03       NEW_USER_REG     Register a new user
  264.  A6 04       NEW_USER_INFO    Send basic information about a new user
  265.  42 04       CMD_X1           *Unknown
  266.  56 04       MSG_TO_NEW_USER  Send a message to a user not on my contact list
  267.  (this one is also used to request permission to add someone with 'authorize'
  268.  status to your contact list)
  269.  
  270. The following commands can be sent from the server to the client, either as
  271. a response to a client command, or to notify the client of some event.
  272.  
  273.  Code        Name             Description
  274.  ----        ----             -----------
  275.  0A 00       ACK              Acknowledgement
  276.  5A 00       LOGIN_REPLY      Login reply
  277.  6E 00       USER_ONLINE      User on contact list is online/has changed online status
  278.  78 00       USER_OFFLINE     User on contact list has gone offline
  279.  8C 00       USER_FOUND       User record found matching search criteria
  280.  DC 00       RECEIVE_MESSAGE  Message sent while offline/through server
  281.  A0 00       END_OF_SEARCH    No more USER_FOUND will be sent
  282.  18 01       INFO_REPLY       Return basic information about a user
  283.  22 01       EXT_INFO_REPLY   Return extended information about a user
  284.  A4 01       STATUS_UPDATE    User on contact list has changed online status (Away etc)
  285.  
  286. Not yet described in detail (v0.1 of this document)
  287.  1C 02       REPLY_X1         *Unknown (returned during login)
  288.  E6 00       REPLY_X2         *Unknown (confirm my UIN?)
  289.  E0 01       UPDATE_REPLY     Confirmation of basic information update
  290.  C8 00       UPDATE_EXT_REPLY Confirmation of extended information update
  291.  46 00       NEW_USER_UIN     Confirmation of creation of new user and newly assigned UIN
  292.  B4 00       NEW_USER_REPLY   Confirmation of new user basic information
  293.  82 00       QUERY_REPLY      Response to QUERY_SEVERS or QUERY_ADDONS
  294.  C2 01       SYSTEM_MESSAGE   System message with URL'ed button
  295.  
  296. The UDP messages will now be examined in closer detail.
  297.  
  298.  
  299.  
  300.          MESSAGES SENT BY THE CLIENT
  301.          ===========================
  302.  
  303.  
  304. ACK (0A 00)  Acknowledgement
  305. ---
  306.  
  307. Parameters: None
  308.  
  309. NOTE! Unlike all other commands, in ACK the field SEQ_NUM contains the
  310. sequence number of the *server's* packet the client wishes to acknowledge.
  311. Note further that an ACK should *not* be acknowledged!
  312.  
  313.  
  314. SEND_MESSAGE (0E 01)  Send message through server (to offline user)
  315. ------------
  316.  
  317. Parameters:
  318.  Length   Content (if fixed)    Name             Description
  319.  ------   ------------------    ----             -----------
  320.  4 bytes  xx xx xx xx           RECEIVER_UIN     UIN of the user the message is sent to
  321.  2 bytes  (see below)           MESSAGE_TYPE     Type of message being sent
  322.  2 bytes  xx xx                 LENGTH           Length of MESSAGE including NULL
  323.  variable                       MESSAGE          The message, ended by a NULL (00)
  324.  
  325. MESSAGE_TYPE can be one of the following:
  326.  01 00 - the message is a normal message
  327.  04 00 - the message is an URL, and actually consists of two parts,
  328.  separated by the code FE.
  329. The first part is the description of the URL, and the second part is the
  330. actual URL.
  331.  
  332.  
  333. LOGIN (E8 03)  Login on server
  334. -----
  335.  
  336. Parameters:
  337.  Length   Content (if fixed)    Name             Description
  338.  ------   ------------------    ----             -----------
  339.  4 bytes  xx xx xx xx           PORT             The TCP port to use for incoming connections
  340.  2 bytes  xx xx                 LENGTH           Length of PASSWORD including NULL
  341.  variable                       PASSWORD         The user's password + NULL (max 8 chars)
  342.  4 bytes  78 00 00 00           X1               *Unknown
  343.  4 bytes  xx xx xx xx           USER_IP          The user's IP address
  344.  1 byte   04                    X2               *Unknown
  345.  4 bytes  xx xx xx xx           STATUS           Users online status (normally 00 00 00 00)
  346.  4 bytes  02 00 00 00           X3               *Unknown
  347.  2 bytes  xx xx                 LOGIN_SEQ_NUM    Login sequence number
  348.  4 bytes  00 00 00 00           X4               *Unknown
  349.  4 bytes  08 00 78 00           X5               *Unknown
  350.  
  351.  
  352. CONTACT_LIST (06 04)  Inform the server of my contact list
  353. ------------
  354.  
  355. Parameters:
  356.  Length   Content (if fixed)    Name             Description
  357.  ------   ------------------    ----             -----------
  358.  2 bytes  xx xx                 NUM_CONTACTS     Number of contacts following
  359. {4 bytes  xx xx xx xx           UIN              UIN of user on contact list }
  360. The last field is repeated for as many users as NUM_CONTACTS indicate.
  361.  
  362. The server will send online/offline notification to client only of users
  363. registered using CONTACT_LIST.
  364.  
  365.  
  366. SEARCH_UIN (1A 04)  Search for user using his/her UIN
  367. ----------
  368.  
  369. Parameters:
  370.  Length   Content (if fixed)    Name             Description
  371.  ------   ------------------    ----             -----------
  372.  2 bytes  xx xx                 SEARCH_SEQ_NUM   Search sequence number
  373.  4 bytes  xx xx xx xx           SEARCHED_UIN     The UIN to search for
  374.  
  375. The SEARCH_SEQ_NUM should be a unique number, to distinguish from other
  376. searches. The reply from the server will contain the SEARCH_SEQ_NUM of the
  377. search, to facitilate matching query and answer.
  378.  
  379.  
  380. SEARCH_USER (24 04)  Search for user using his/her name or e-mail
  381. -----------
  382.  
  383. Parameters:
  384.  Length   Content (if fixed)    Name             Description
  385.  ------   ------------------    ----             -----------
  386.  2 bytes  xx xx                 SEARCH_SEQ_NUM   Search sequence number
  387.  2 bytes  xx xx                 LENGTH           Length of NICK_NAME including NULL
  388.  variable                       NICK_NAME        Nick name to search for, NULL terminated
  389.  2 bytes  xx xx                 LENGTH           Length of FIRST_NAME including NULL
  390.  variable                       FIRST_NAME       First name to search for, NULL terminated
  391.  2 bytes  xx xx                 LENGTH           Length of LAST_NAME including NULL
  392.  variable                       LAST_NAME        Nick name to search for, NULL terminated
  393.  2 bytes  xx xx                 LENGTH           Length of E_MAIL including NULL
  394.  variable                       E_MAIL           E-mail to search for, NULL terminated
  395.  
  396. Note that search fields (NICK_NAME, FIRST_NAME, LAST_NAME, E_MAIL) may be
  397. empty, but not all at the same time, i.e. at least one field must contain
  398. data. Note also that you may only search either on E_MAIL (in which the
  399. other fields must be empty), or on name (in which E_MAIL must be empty, and
  400. one or more of the other fields must contain data).
  401.  
  402.  
  403. KEEP_ALIVE (2E 04)  Sent to indicate connection is still up
  404. ----------
  405.  
  406. Parameters: None
  407.  
  408. This command should be sent at regular intervals (normally every 2 minutes,
  409. or 120 seconds) from the client to the server.
  410.  
  411.  
  412. SEND_TEXT_CODE (38 04)  Send special message to server as text
  413. --------------
  414.  
  415. Parameters:
  416.  Length   Content (if fixed)    Name             Description
  417.  ------   ------------------    ----             -----------
  418.  2 bytes  xx xx                 LENGTH           Length of TEXT_CODE including NULL
  419.  variable                       TEXT_CODE        Message to send to server, NULL terminated
  420.  2 bytes  xx xx                 X1               *Unknown (code, usually 04 00 or 05 00)
  421.  
  422. The TEXT_CODE can contain for instance:
  423.  "B_USER_DISCONNECTED" (in which case the X1 field should containt 05 00) if
  424.   the user has disconnected.
  425.  "B_MESSAGE_ACK" (in which case the X1 field should containt 05 00) if the
  426.   client has problem connecting to the server. This is a request for the
  427.   server to answer immediately to the client.
  428.  
  429.  
  430. LOGIN_1 (4C 04)  Sent during login
  431. -------
  432.  
  433. Parameters: None
  434.  
  435. This is sent during login. The exact purpose of this command is *Unknown.
  436.  
  437.  
  438. INFO_REQ (60 04)  Request basic information about a user
  439. --------
  440.  
  441. Parameters:
  442.  Length   Content (if fixed)    Name             Description
  443.  ------   ------------------    ----             -----------
  444.  2 bytes  xx xx                 INFO_SEQ_NUM     Information sequential number
  445.  4 bytes  xx xx xx xx           QUERY_UIN        UIN of user to request information about
  446.  
  447. The server will respond with a INFO_REPLY, with the same INFO_SEQ_NUM.
  448.  
  449.  
  450. EXT_INFO_REQ (6A 04)  Request extended information about a user
  451. ------------
  452.  
  453. Parameters:
  454.  Length   Content (if fixed)    Name             Description
  455.  ------   ------------------    ----             -----------
  456.  2 bytes  xx xx                 INFO_SEQ_NUM     Information sequential number
  457.  4 bytes  xx xx xx xx           QUERY_UIN        UIN of user to request information about
  458.  
  459. The server will respond with a EXT_INFO_REPLY, with the same INFO_SEQ_NUM.
  460.  
  461.  
  462. CHANGE_PASSWORD (9C 04)  Change the user's password
  463. ---------------
  464.  
  465. Parameters:
  466.  Length   Content (if fixed)    Name             Description
  467.  ------   ------------------    ----             -----------
  468.  2 bytes  xx xx                 PASSWORD_SEQ_NUM Password changing sequential number
  469.  2 bytes  xx xx                 LENGTH           Length of NEW_PASSWORD including NULL
  470.  variable                       NEW_PASSWORD     The new password, NULL terminated (max 8 chars)
  471.  
  472.  
  473. STATUS_CHANGE (D8 04)  User has changed online status (Away etc)
  474. -------------
  475.  
  476. Parameters:
  477.  Length   Content (if fixed)    Name             Description
  478.  ------   ------------------    ----             -----------
  479.  4 bytes  (see below)           STATUS           User's online status (Away etc)
  480.  
  481. The STATUS may take four different values:
  482.  00 00 00 00 = Online/connected
  483.  01 00 00 00 = Away
  484.  11 00 00 00 = Do Not Disturb (DND)
  485.  00 01 00 00 = Invisible
  486.  
  487.  
  488. LOGIN_2 (28 05)  Sent during login
  489. -------
  490.  
  491. Parameters:
  492.  Length   Content (if fixed)    Name             Description
  493.  ------   ------------------    ----             -----------
  494.  1 byte   00                    X1               *Unknown
  495.  
  496.  
  497.  
  498.          MESSAGES SENT BY THE SERVER
  499.          ===========================
  500.  
  501.  
  502. ACK (0A 00)  Acknowledgement
  503. ---
  504.  
  505. Parameters: None
  506.  
  507. NOTE! Unlike all other commands, in ACK the field SEQ_NUM contains the
  508. sequence number of the *client's* packet the server acknowledges. Note
  509. further that an ACK should *not* be acknowledged!
  510.  
  511.  
  512. LOGIN_REPLY (5A 00)  Login reply
  513. -----------
  514.  
  515. Parameters:
  516.  Length   Content (if fixed)    Name             Description
  517.  ------   ------------------    ----             -----------
  518.  4 bytes  xx xx xx xx           USER_UIN         The user's UIN
  519.  4 bytes  xx xx xx xx           USER_IP          The user's IP address
  520.  2 bytes  xx xx                 LOGIN_SEQ_NUM    Login sequence number
  521.  4 bytes  01 00 01 00           X1               *Unknown
  522.  4 bytes  xx 00 16 00           X2               *Unknown (xx=19 or 18)
  523.  4 bytes  8C 00 00 00           X3               *Unknown
  524.  4 bytes  78 00 05 00           X4               *Unknown
  525.  6 bytes  0A 00 05 00 01 00     X5               *Unknown
  526.  
  527. This is sent from the server upon receipt of a LOGIN. The LOGIN_SEQ_NUM is
  528. the same as in the corresponding LOGIN.
  529.  
  530.  
  531. USER_ONLINE (6E 00)  User on contact list is online/has changed online status
  532. -----------
  533.  
  534. Parameters:
  535.  Length   Content (if fixed)    Name             Description
  536.  ------   ------------------    ----             -----------
  537.  4 bytes  xx xx xx xx           REMOTE_UIN       The UIN of the user who has logged in
  538.  4 bytes  xx xx xx xx           REMOTE_IP        The IP address of the user
  539.  4 bytes  xx xx xx xx           REMOTE_PORT      The TCP port of the user
  540.  4 bytes  xx xx xx xx           REMOTE_REAL_IP   The actual IP address of the user
  541.  1 byte   04                    X1               *Unknown
  542.  4 bytes  xx xx xx xx           STATUS           New status of the user
  543.  4 bytes  02 00 00 00           X2               *Unkown
  544.  
  545. The REMOTE_IP is the "outer" IP address of the remote user, the
  546. REMOTE_REAL_IP is the "inner" IP address. These two will be identical unless
  547. the remote user is behind a firewall. The REMOTE_IP is the "official" IP
  548. address, as shown e.g. by the Info box in the client. The REMOTE_PORT is the
  549. TCP port number to use when the client wishes to open a direct connection
  550. to the remote user.
  551.  
  552.  
  553. USER_OFFLINE (78 00)  User on contact list has gone offline
  554. ------------
  555.  
  556. Parameters:
  557.  Length   Content (if fixed)    Name             Description
  558.  ------   ------------------    ----             -----------
  559.  4 bytes  xx xx xx xx           REMOTE_UIN       The UIN of the user who has logged out
  560.  
  561.  
  562. USER_FOUND (8C 00)  User record found matching search criteria
  563. ----------
  564.  
  565. Parameters:
  566.  Length   Content (if fixed)    Name             Description
  567.  ------   ------------------    ----             -----------
  568.  2 bytes  xx xx                 SEARCH_SEQ_NUM   Search sequence number
  569.  4 bytes  xx xx xx xx           FOUND_UIN        Found user's UIN
  570.  2 bytes  xx xx                 LENGTH           Length of NICK_NAME including NULL
  571.  variable                       NICK_NAME        Found user's nick name, NULL terminated
  572.  2 bytes  xx xx                 LENGTH           Length of FIRST_NAME including NULL
  573.  variable                       FIRST_NAME       Found user's first name, NULL terminated
  574.  2 bytes  xx xx                 LENGTH           Length of LAST_NAME including NULL
  575.  variable                       LAST_NAME        Found user's last name, NULL terminated
  576.  2 bytes  xx xx                 LENGTH           Length of E_MAIL including NULL
  577.  variable                       E_MAIL           Found user's e-mail, NULL terminated
  578.  1 byte   xx                    AUTHORIZE        User's authorization status
  579.  
  580. For each user found matching the criterion, a USER_FOUND will be returned.
  581. When all USER_FOUND's have been sent, the server will send an END_OF_SEARCH.
  582. If no users where found matching the criterion, an END_OF_SEARCH will be
  583. sent immediately, and no USER_FOUND will be sent. The AUTHORIZE determine
  584. wether the user allow anyone to include him/her on their contact list, or
  585. wether the user must accept first. Possible values of AUTHORIZE:
  586.  00 = The user must authorize the client to include him/her on the client's
  587.  contact list
  588.  01 = The user allows anyone to include him/her on their contact list
  589.  
  590.  
  591. RECEIVE_MESSAGE (DC 00)  Message sent while offline/through server
  592. ---------------
  593.  
  594. Parameters:
  595.  Length   Content (if fixed)    Name             Description
  596.  ------   ------------------    ----             -----------
  597.  4 bytes  xx xx xx xx           REMOTE_UIN       The sending user's UIN
  598.  2 bytes  xx xx                 YEAR             The year the message was sent
  599.  1 byte   xx                    MONTH            The month the message was sent
  600.  1 byte   xx                    DAY              The day of the month the message was sent
  601.  1 byte   xx                    HOUR             The hour the message was sent in GMT
  602.  1 byte   xx                    MINUTE           The minute the message was sent
  603.  2 bytes  xx xx                 TYPE             The type of message (message, URL, etc)
  604.  2 bytes  xx xx                 LENGTH           Length of MESSAGE including NULL
  605.  variable                       MESSAGE          The message sent, NULL terminated
  606.  
  607. Note that the HOUR contains the local time - 1 (unless GMT is involved
  608. somehow?). The TYPE identifies the type of message this is:
  609.  01 00 = Normal message
  610.  04 00 = URL (MESSAGE contains first the description, then a FE, and then
  611.  the actual URL)
  612.  0C 00 = 'You were added' message. (MESSAGE contains: <nick name> FE <first
  613.  name> FE <last name> FE <e-mail> FE <ASCII authorize>. The <ASCII
  614.  authorize> is '1' (31) if the user allows anyone to add him/her to their
  615.  contact list, and '0' (30) otherwise.)
  616.  
  617.  
  618. END_OF_SEARCH (A0 00)  No more USER_FOUND will be sent
  619. -------------
  620.  
  621. Parameters:
  622.  Length   Content (if fixed)    Name             Description
  623.  ------   ------------------    ----             -----------
  624.  2 bytes  xx xx                 SEARCH_SEQ_NUM   Search sequence number
  625.  1 byte   xx                    MORE_FOUND       More users found but not displayed?
  626.  
  627. If MORE_FOUND is 00, then the returned USER_FOUND's contain information
  628. about all matching users. If MORE_FOUND is 01 however, then the server has
  629. found more users matching, but will not display more matches. The limit is
  630. drawn by 40 users. If a search request results in more than 40 matches,
  631. only the 40 first will be sent to the client, and MORE_FOUND will be set to
  632. 01.
  633.  
  634.  
  635. INFO_REPLY (18 01)  Return basic information about a user
  636. ----------
  637.  
  638. Parameters:
  639.  Length   Content (if fixed)    Name             Description
  640.  ------   ------------------    ----             -----------
  641.  2 bytes  xx xx                 INFO_SEQ_NUM     Information sequence number
  642.  4 bytes  xx xx xx xx           REMOTE_UIN       The remote user's UIN
  643.  2 bytes  xx xx                 LENGTH           Lenght of NICK_NAME including NULL
  644.  variable                       NICK_NAME        The remote user's nick name
  645.  2 bytes  xx xx                 LENGTH           Lenght of FIRST_NAME including NULL
  646.  variable                       FIRST_NAME       The remote user's first name
  647.  2 bytes  xx xx                 LENGTH           Lenght of LAST_NAME including NULL
  648.  variable                       LAST_NAME        The remote user's last name
  649.  2 bytes  xx xx                 LENGTH           Lenght of E_MAIL including NULL
  650.  variable                       E_MAIL           The remote user's e-mail
  651.  1 byte   xx                    AUTHORIZE        User's authorization status
  652.  
  653. Note that the parameters are identical to command USER_FOUND (8C 00). For
  654. more information about the fields, see USER_FOUND.
  655.  
  656. EXT_INFO_REPLY (22 01)  Return extended information about a user
  657. --------------
  658.  
  659. Parameters:
  660.  Length   Content (if fixed)    Name             Description
  661.  ------   ------------------    ----             -----------
  662.  2 bytes  xx xx                 INFO_SEQ_NUM     Information sequence number
  663.  4 bytes  xx xx xx xx           REMOTE_UIN       The remote user's UIN
  664.  2 bytes  xx xx                 LENGTH           Lenght of CITY including NULL
  665.  variable                       CITY             The remote user's city
  666.  2 bytes  xx xx                 COUNTRY_CODE     The remote user's country code
  667.  1 byte   xx                    COUNTRY_STATUS   Indicates if COUNTRY_CODE is entered or not
  668.  2 bytes  xx xx                 LENGTH           Lenght of STATE including NULL
  669.  variable                       STATE            The remote user's state (USA only)
  670.  2 bytes  xx xx                 AGE              The remote user's age
  671.  1 byte   xx                    SEX              The remote user's sex
  672.  2 bytes  xx xx                 LENGTH           Lenght of PHONE including NULL
  673.  variable                       PHONE            The remote user's city
  674.  2 bytes  xx xx                 LENGTH           Lenght of HOME_PAGE including NULL
  675.  variable                       HOME_PAGE        The remote user's city
  676.  2 bytes  xx xx                 LENGTH           Lenght of ABOUT including NULL
  677.  variable                       ABOUT            The remote user's city
  678.  
  679. The code used in COUNTRY_CODE is the international telephone prefix, e.g.
  680. 01 00 (1) for the USA, 2C 00 (44) for the UK, 2E 00 (46) for Sweden, etc.
  681. COUNTRY_STATUS is normally FE, unless the remote user has not entered a
  682. country, in which casse COUNTRY_CODE will be FF FF, and COUNTRY_STATUS will
  683. be 9C. The field AGE has the value FF FF if the user has not entered his/her
  684. age. The field SEX has three (!) possible values:
  685.  00 = Not specified
  686.  01 = Female
  687.  02 = Male
  688. The ABOUT field is an optional free form field that allows the user to make
  689. a personal presentation of himself/herself.
  690.  
  691.  
  692. STATUS_UPDATE (A4 01)  User on contact list has changed online status (Away etc)
  693. -------------
  694.  
  695. Parameters:
  696.  Length   Content (if fixed)    Name             Description
  697.  ------   ------------------    ----             -----------
  698.  4 bytes  xx xx xx xx           REMOTE_UIN       UIN of the user whos status has changed
  699.  4 bytes  xx xx xx xx           STATUS           The new online status of the user
  700.  
  701. The online status in STATUS is the same as used in STATUS_CHANGE (D8 04).
  702. See STATUS_CHANGE for details.
  703.  
  704.  
  705.  
  706.          COMMUNICATION BETWEEN TWO CLIENTS USING TCP (Peer to peer mode)
  707.          ===============================================================
  708.  
  709. When a user wishes to send a message, an URL etc, to another user (called
  710. the "remote" user as opposite to the "local" user), the local user first
  711. checks to see if a TCP connection already is established to that user. If
  712. so is the case, then that connection will be used. If not, the user checks
  713. the remote users IP address and port number (information sent to the user
  714. from the server when the remote user logged in), and makes a connection to
  715. that address. Typical port numbers are in the range 1200-1300 (decimal).
  716. When a new connection is formed, a CHANNEL_INIT message must be sent. From
  717. there on, however, every time the user wishes to send a message, a
  718. CHANNEL_MESSAGE is sent. All messages sent must be acknowledged by the other
  719. side, using CHANNEL_ACK. Furthermore, all messages is replied to by another
  720. message from the receiver - which most often is empty, unless the user has
  721. posted a Away/DND message, in case this will be sent as a reply.
  722.  
  723. The TCP communication is similar to the UDP communication, in that all
  724. communication is done trough separate packets (often, but now always
  725. associated with individual TCP packets). Each packet must contain the
  726. packet's length (excluding the length count) as the first two bytes. Most
  727. messages contains the senders UIN as the next field.
  728.  
  729. CHANNEL_INIT  Initiate inter-user communication using TCP
  730. ------------
  731.  
  732. Parameters:
  733.  Length   Content (if fixed)    Name             Description
  734.  ------   ------------------    ----             -----------
  735.  2 bytes  1A 00                 LENGTH           Length of this packet
  736.  1 byte   FF                    INIT_IDENT       Identifies this packet as an initiation
  737.  4 bytes  02 00 00 00           X1               *Unknown
  738.  4 bytes  00 00 00 00           X2               *Unknown
  739.  4 bytes  xx xx xx xx           MY_UIN           The local user's UIN
  740.  4 bytes  xx xx xx xx           MY_IP            The user's IP address
  741.  4 bytes  xx xx xx xx           MY_IP_REAL       The user's actual IP address
  742.  1 byte   04                    X3               *Unknown
  743.  4 bytes  xx xx xx xx           MY_PORT          The user's TCP port for incoming messages
  744.  
  745. Note that the port used for the "outgoing" connection is different from
  746. MY_PORT, the port other clients use to connect to this client. For the
  747. difference between MY_IP and MY_IP_REAL, see USER_ONLINE.
  748.  
  749. CHANNEL_MESSAGE  Send message to online user
  750. ------------
  751.  
  752. Parameters:
  753.  Length   Content (if fixed)    Name             Description
  754.  ------   ------------------    ----             -----------
  755.  2 bytes  xx xx                 LENGTH           Length of this packet
  756.  4 bytes  xx xx xx xx           UIN              The local user's UIN
  757.  2 bytes  02 00                 VERSION          Identifies this as a ICQ packet
  758.  2 bytes  EE 07                 MSG_COMMAND      The message type for CHANNEL_MESSAGE
  759.  2 bytes  00 00                 X1               *Unknown
  760.  4 bytes  xx xx xx xx           UIN_2            The local user's UIN
  761.  2 bytes  xx xx                 TYPE             Message type
  762.  2 bytes  xx xx                 LENGTH           Length of MESSAGE including NULL
  763.  variable                       MESSAGE          The message to be sent, NULL terminated
  764.  4 bytes  xx xx xx xx           MY_IP_REAL       The user's actual IP address
  765.  4 bytes  xx xx xx xx           MY_IP            The user's IP address
  766.  4 bytes  xx xx xx xx           PORT             The user's TCP port for incoming messages
  767.  1 byte   04                    X2               *Unknown
  768.  2 bytes  00 00                 X3               *Unknown
  769.  2 bytes  xx xx                 CMD_TYPE         Identifies message as new message or reply
  770.  4 bytes  xx xx xx xx           X4               *Unknown (checksum? sequence number?)
  771.  
  772. The TYPE is the same as described in RECEIVE_MESSAGE. The difference between
  773. MY_IP and MY_IP_REAL is described in USER_ONLINE. The CMD_TYPE can have two
  774. possible values:
  775.  10 00 = This is a new ('real', user initiated) message
  776.  00 00 = This is an auto reply
  777. The auto reply is sent as an acknowledgement to all 'real' messages. They
  778. usually contains an empty message, but if the remote user is 'Away' or in
  779. DND mode, the reply will contain the Away/DND message. The X4 field is a
  780. bit tricky. It is always between 00 FF FF FF and FF FF FF FF, but the exact
  781. function of the field is unknown.
  782.