I've been working with Trevize's ATCP plugin for a while now, and recently I began modifying it, as you might've deduced from my recent posts here. I've modified it heavily, stripping out bits that weren't needed and updating the functionality a bit. The resulting plugin can now handle any incoming ATCP packet, and it implements a function for sending ATCP messages to the server as well.
The old plugin was restricted to only three messages, and it identified them in BroadcastPlugin() with simple numeric IDs. I changed this so that all message broadcasts had an ID of 1, and the message was packed in with the content in the format "<message>|<content>". I've also added support for enabling of various ATCP command modules, such as 'composer' and 'ping'. Because the plugin needs to know what to enable before connecting, it broadcasts an ID of 0, which client plugins can respond to by calling its EnableModule method. (Thanks to Nick for this technique)
When a module is enabled, various messages included in the module may be sent by the server, which will be broadcast to listening plugins. Modules may also contain client-side messages, such as 'keepalive' which prevents the client from timing out, and 'ping' which speaks for itself. As a basic form of validation, client-side messages can only be sent through the plugin if their associated modules have been enabled. (Basic argument type-checking is also performed on a per-message basis)
To aid in ATCP development, a 'header' file of sorts is included with the plugin, atcp_lua.xml. This file includes definitions such as a variable containing the ATCP plugin's ID, an EnableModuleATCP() function to more easily call the ATCP plugin's EnableModule function, a SendATCP() function that's much the same, and an UnpackATCP() function that splits the broadcast message into two variables (msg and content) and returns them. To use these utilities, add the following line into your plugin file, before the <script> tag:
<include name="atcp_lua.xml" />
Here's an example OnPluginBroadcast definition that shows how easy it is to work with the plugin:
OnPluginBroadcast - function(msg, id, name, text)
if id == idATCP then
if msg == 0 then
EnableModuleATCP("room_brief")
else
msg, text = UnpackATCP(text)
if (msg == "Room.Brief") then
SetStatus(text)
end
end
end
end
Download page: http://www.jonathan.com/atcp
My documentation of ATCP messages: http://www.jonathan.com/atcp/doc.html
References:
1. Trevize's ATCP plugin: http://www.gammon.com.au/forum/bbshowpost.php?id=8915
2. ATCP documentation: http://www.ironrealms.com/nexus/atcp.html
(If Nick, in his infinite wisdom, sees fit to add this plugin to his plugins page, I will be very, very happy. >_>) |