I've been toying with the idea of a plugin system for quite some time for both client and server, and eeems was asking me about it earlier, so I thought I'd document some of what I came up with.
Client-sided plugins(for the web client, javascript based):
3 return values:
PLUGIN_CONTINUE - Continue parsing through all plugins, and allow OmnomIRC to display this message normally
PLUGIN_NO_OUTPUT - Continues parsing through all plugins, but causes OmnomIRC not to display the message
PLUGIN_BREAK - stops at this plugin, does not reach any others
Message types:
OnLoad - Fired when OmnomIRC loads - No vars
OnJoin - Fired when someone joins the current channel - Name, Channel
OnPart - Fired when someone parts the current channel - Name, Reason, Channel
OnQuit - Fired when someone quits the current channel - Name, Reason
OnKick - Fired when someone is kicked from the current channel - KickedName, KickerName, Reason, Channel
OnMode - Fired when someone changes modes in the current channel - Name, Modes, Channel
OnTopic - Fired when someone changes the topic in the current channel - Name, Topic, Channel
OnMessage - Fired when someone sends a message in the current channel - Name, Message, Channel
OnMessageHighlight - Fired when someone sends a message that highlights the user in the current channel - Name, Message, Channel
OnAction - Fired when someone sends an action in the current channel - Name, Message, Channel
OnActionHighlight - Fired when someone sends an action that highlights the user in the current channel - Name, Message, Channel
The layout of the javascript plugins will be something like this:
function pluginInfo()
{
pluginName = "OnJoin Example";
pluginVersion = "0.01";
minOmnomIRCVersion = "2.2";
}
function OnJoin()
{
alert(name1 + " has joined " + channel);!
return PLUGIN_CONTINUE;
}
function Options()
{
document.write('<a href="#" onclick="DoThis();">Option!</a><br/>');
}
function DoThis()
{
alert("You clicked my option!");
}
registerPlugin();
registerOnJoin();
registerOptions();
There will be an option in the options page for loading them, and they will be able to output options to the options page. The plugins themselves will be largely responsible for managing their cookies and own options.
Here's what a mockup of the OmnomIRC-side loading code will be:
function loadPlugins()
{
for (var i=0;i<pluginList.length;i++)
{
//Warning: PSEUDO CODE!
scrtag = new script;
scrtag.src = pluginList[i];
body.appendChild(scrtag);
}
}
function registerPlugin()
{
if (minOmnomIRCVersion > OmnomIRCVersion) alert("NOEP.");
loadedPluginList[] = Array(pluginName,pluginVersion,minOmnomIRCVersion);
}
function registerOnJoin()//Replicate for all other events
{
onJoinPlugins[] = Array(loadedPluginList.length,OnJoin);
}
function doOnJoin(name,channel)
{
name = name;
channel = channel;
var output = true;
for (var i=0;i<onJoinPlugins.length;i++)
{
var result = (onJoinPlugins[i][1])();
if (result != PLUGIN_CONTINUE) output=false;
if (result == PLUGIN_BREAK) break;
}
return output;
}
Server-side plugins!
They will have the same events for the time being.
//OmnomIRC v2.2 OnJoin,OnLoad
//Example Plugin
//0.01
function OnJoin()
{
global $name,$channel;
die("$name has joined $channel!");
return PLUGIN_BREAK;
}
function OnLoad()
{
echo "BLARG!!!!!!!!!!!!!!";
return PLUGIN_CONTINUE;
}
And, for the server to load them (this has to be done each page run, I'm not entirely sure how efficient it will be)
This is pseudocode too.
foreach ($file in $directory)
{
include($file);
if (doesOnLoad($file))
{
OnLoad();
}
if (doesOnJoin($file))
{
OnJoin();
}
}
etc...
Thoughts/comments?