Auno.org: 18.5 | Live servers: 18.8.23 | Test servers:

AO Chat

AOChat, a PHP class for talking with the Anarchy Online chat servers. It requires the sockets extension (to connect to the chat server..) from PHP 4.2.0+ and either the GMP or BCMath extension (for generating and calculating the login keys) to work. Alternatively you can use the AOKex PHP module for generating keys.

I used a decompiled version of the official java chat client and Slicer's AO::Chat perl module as a reference for this class.

This class is not finished, and improvements, ideas and comments are very welcome. Also, I'd be happy to know if you use this code for anything. The code is distributed under the GNU General Public License.

Click here to view the highlited PHP source code
Click here to download the PHP source code

Update! Dec 20 2014
aokex is now available at https://github.com/saaros/aokex, the rest of my AO code should follow shortly.

Update! Nov 30 2005
AOChat.php rev. 1.19 is here!

revision 1.19
date: 2005/11/29 23:22:46;  author: os;  state: Exp;  lines: +283 -249
. Rewrote extended message handling.  It can now parse more messages,
  and adding new messages is trivial.  It does not parse everything
  though, since that would've had a set of its own problems.
  The ~& encoded messages are now decoded into readable format by
  default, and an object containing all the relevant variables is
  passed as an extra message argument to the callback.
. Fixed a bug in lookup_group and get_gname to handle channels with
  the high bit set in their ids.
. Moved packetmap out of global scope.

Update! Nov 25 2005
After 13 months the new version of AOChat.php is here. It supports the new messages in AO 16.1, but it also requires PHP 5, so it might not be usable as-is for everyone. Here's the list of changes:

revision 1.18
date: 2005/11/25 08:54:05;  author: os;  state: Exp;  lines: +264 -32
. Requires PHP 5 (for new object model).
. Support for AOkex PHP-extension.
. Fixed a bug in AOChatQueue that.  It previously only dispatched
  one message per round.
. Group messages are now queued just like tells.
. Support for new "extended" messages introduced in 16.1 patch.

Update! May 9 2005
Jürgen Erhard has written a python implementation of AOChat, get it from his website!

Update! Jan 7 2005
I wrote a PHP extension to handle AO key exchange, you can use it with php >= 5.0.2 (and of course earlier) versions in place of the PHP-only implementation. Binaries are not available and I have no idea of how to compile this thing for Windows, Unix instructions are inside the tarball that you can get from here.

Update! Oct 28 2004

revision 1.17
date: 2004/10/28 14:09:12;  author: pickett;  state: Exp;  lines: +212 -123
. License changed from BSD to GPL
. Implement prioritized queues for message handling
. Tells now use a queue to prevent AO flood protection from kicking in
. Make sure we do not attempt to add ourselves to our buddy list, doing so
  causes the AO chat server to reset our connection
. New method iteration():
  - called by wait_for_packet()
  - if the application is using its own select() calls a call to AOChat
    object's iteration() is required every now and then (in every round of
    loop) to make sure that the message queues are flushed properly
. Ability to prioritize some tells over others:
  - $aoc->tellqueue->push(AOC_PRIORITY_HIGH, $user, $message)

Update! Jul 4 2004

revision 1.15
date: 2004/07/04 15:03:59;  author: pickett;  state: Exp;  lines: +33 -33
. Clarified DH key exchange
. Added AOCP_PRIVGRP_REFUSE message type

Update! May 25 2004

revision 1.14
date: 2004/05/25 16:56:25;  author: pickett;  state: Exp;  lines: +7 -18
. gmp_init() the modulo before passing it to gmp_powm().  PHP 4.3.5 or 4.3.6
  broke things
. wait_for_packet() now returns NULL instead of false if there is no packet
  to be fetcher.  false is only returned in case of failure

Update! Apr 11 2004

revision 1.13
date: 2004/04/11 22:26:22;  author: pickett;  state: Exp;  lines: +202 -84
. connect() now issues a warning and returns false instead of dying if
  the connection fails
. Added disconnect() function for clearing the state and disconnecting
  from servers
. Added group_join, group_leave and group_status functions for joining,
  leaving (muting), and checking status of 'public' chat channels
. Buddy information is now caught and there are 2 new functions,
  buddy_online and buddy_exists
. Added new packet type AOCP_CHAT_NOTICE, renamed AOCP_GROUP_JOIN to
  AOCP_GROUP_ANNOUNCE
. Various random cleanups

Update! Mar 30 2004

revision 1.12
date: 2004/03/30 12:20:50;  author: pickett;  state: Exp;  lines: +206 -145
. wait_for_packet() now automatically sends pings when needed
. Added buddy_remove_unknown() function
. Added 's' type outgoing packets
. Use define()d names for message types instead of the raw numbers

Update! Mar 23 2004

revision 1.11
date: 2004/03/23 14:34:35;  author: pickett;  state: Exp;  lines: +102 -70
. Fixed aochat_crypt() on BE platforms
. Fixed socket_block_read() by replacing it with read_data()
. Fixed privategroup_invite() function and added privategroup_kick_all()
. Allow connecting to non-standard (7012) ports
. Added some comments about various functions
. Included BSD license in the top

Update! Dec 10 2003
The AOChat.php class has been updated to revision 1.10. No really major changes, but there are now functions available for for example sending pings, adding and removing buddies, joining, kicking and sending messages to private groups. Also it should be a little more stable.

revision 1.10
date: 2003/12/10 14:19:43;  author: pickett;  state: Exp;  lines: +131 -61
. Allow easy connecting to other dimensions than RK1
. New functions for sending pings, adding and removing buddies, joining
  kicking and sending messages to private groups
. Blocking socket read until we get enough data
. Require PHP 4.2.0
. Some code cleanups and comments

Update! Jun 17 2003
I have updated libaochat (the C port) slightly, no new features, but some bugs that prevented it from providing any useful data were fixed, and it should now (once again) generate valid keys. Available here.

Update! Apr 17 2003
A slightly newer version of the C code is available here. It is still very incomplete implementation of the protocol.

Update! Nov 14 2002
I ported some parts of the PHP code to C, mainly the login key generation, the code is available as a tar.gz ball here.

Update! Jun 14 2002
GMP is no longer neccessary, the class now also works with BCMath extension, which is available for Windows users, too.


BatMUD