Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
24 May, 2013, 19:20:11 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Plugin System Layout -  (Read 310 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
Netham45
WOOOOOO
President
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 05:57:14
Date Registered: 26 August, 2008, 07:35:31
Location: Denver, Colorado
Posts: 2296


Topic starter
Total Post Ratings: +208

View Profile WWW
« on: 13 July, 2011, 05:14:32 »
0

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
foreach ($file in $directory)
{
     include($file);
     if (doesOnLoad($file))
     {
          OnLoad();
     }
     if (doesOnJoin($file))
     {
          OnJoin();
     }
}
etc...


Thoughts/comments? Cheesy
« Last Edit: 02 November, 2011, 10:30:33 by Netham45 » Logged

Creator of OmnomIRC and SpyBot45
Join LOPN(Lobsters Opposing Pink Names) now, help us fight back!
Message me for more information, and to join now!
Members: Graphmastur;Stefan Bauwens
HOLY SHIT, I HAVE A BLOG



                                     
Put this in your signature if you've played the original WFRNG
Eeems
THE GAME
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: Today at 06:40:06
Date Registered: 14 March, 2009, 03:32:57
Location: Edmonton, Alberta
Posts: 5077


Total Post Ratings: +231

View Profile WWW
« Reply #1 on: 13 July, 2011, 05:26:28 »
0

So thoughts for an alternative layout for the javascript plugin:
pastebin code
So basically instead of registering it, have it in a variable Plugins and just loop through the array when you want to search for stuff. So to get the onjoin event for the plugin you would do this inside the loop. ( i==the iteration in the loop )

1
2
3
4
if(Plugins[i].join!=undefined){
  Plugins[i].join();
}
This way you don't have to call functions to register them, they register themselves. They also use up less function names this way. You could do a little check after loading all the plugins to remove all the ones that don't have the right version info.
So this way a ton less registering is being done and it's all there for you to work with in the end Smiley

EDIT: Also, you could probably come up with a better way to do options. I'd have to think up how to do it though, but I already have a pretty good idea of what I think a better way could look like.
« Last Edit: 13 July, 2011, 05:28:22 by Eeems » Logged

Netham45
WOOOOOO
President
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 05:57:14
Date Registered: 26 August, 2008, 07:35:31
Location: Denver, Colorado
Posts: 2296


Topic starter
Total Post Ratings: +208

View Profile WWW
« Reply #2 on: 13 July, 2011, 05:29:59 »
0

I was being lazy with the options, and yea, your method of it does look like it'll work better.
Logged

Creator of OmnomIRC and SpyBot45
Join LOPN(Lobsters Opposing Pink Names) now, help us fight back!
Message me for more information, and to join now!
Members: Graphmastur;Stefan Bauwens
HOLY SHIT, I HAVE A BLOG



                                     
Put this in your signature if you've played the original WFRNG
Eeems
THE GAME
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: Today at 06:40:06
Date Registered: 14 March, 2009, 03:32:57
Location: Edmonton, Alberta
Posts: 5077


Total Post Ratings: +231

View Profile WWW
« Reply #3 on: 13 July, 2011, 05:33:04 »
0

Thanks Smiley Why I came up with that type of system so quickly is because of a ton of work with dynamic javascript stuff that I've done in the past, coupled with the fact that I use jQuery a lot and some of it's source it like that Tongue

Anywho, my options idea:
For options have it pass another variable to it in the plugin entry. So:

1
2
3
4
5
6
7
options: {
  optionName:{
    type: 'bool',
    default: true
  }
},
At startup it would then quickly parse all the options from the plugins into a Options variable or something for speed and then every time you open the options screen it would dynamically create it for you based on the current setting and what type of option it is. So you can have booleans, text, numbers etc

EDIT: Oh and for getting the options name, this might be useful Tongue http://pietschsoft.com/post/2008/02/28/JavaScript-ForEach-Equivalent.aspx just in case you don't know about it. ( I'm pretty sure it works with objects )

EDIT2: yep it works!

1
2
3
4
>>> a = {t:'adlfj',bla:'herro'}; for(var i in a){console.log(i+": "+a[i]);}
t: adlfj
bla: herro

EDIT3: oh and

1
2
3
4
5
>>> a = {t:'adlfj',bla:'herro'};a[0]='test';for(var i in a){console.log(i+": "+a[i]);}
t: adlfj
bla: herro
0: test

EDIT4: I decided to write up a quick example of a plugin handler. Although it's missing some of the stuff for getting settings, and for displaying the options panel, but all the core stuff is there
http://pastebin.com/CnnhEgcH

EDIT5: bug fixes/more comments http://pastebin.com/FgyG7v3p
« Last Edit: 13 July, 2011, 06:28:56 by Eeems » Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.314 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.