General Plugin Question

Discussion about Perl, TCL or Python scripts and C/C++ plugins (using and writing them).

General Plugin Quest

Postby OmegaDeus » 29 Dec 2008 18:05

I have been trying to write a plugin in c for xchat, and have been reading through http://xchat.org/docs/plugin20.html and I was wondering if there were any more documentation on XChat's API in general. I understand most of what is on that page to an extent, but I have noticed that the document tells you that you have to define xchat_plugin_init, and gives an example of how, but the plugin example shows xchat_plugin_get_info() which is not written about in that document and there is even a mention of xchat_plugin_deinit() that is just mentioned and not explained at all. How can I find all of the functions that I can define in my plugins, and the way to build them so they receive everything that xchat will supply them? Any help in this matter would be greatly appreciated.

Also, I want to enable others to use my script, I'm sure it will have something to do with xchat_hook_print() but am unsure how. Can anyone help me with that? Is this how I would do it:

Code: Select all
xchat_hook_print(pH, "!command", XCHAT_PRI_NORM, myfunc_cb,NULL);


If so, how would I access the information such as channel, nick, and three parameters? Would all of that be supplied to *word[]? Or to do this will I need to define my own text event and tell it what to supply?

Any help would be greatly appreciated.

[edit]Also, I seem to be having an issue where whenever I run my command "/command data data data". It executes the command and does everything its supposed to, but then after the command ends it prints out "Unknown Command. Try /help", any idea what general mistake
would cause this to happen? I've looked through my code and can't see anything that really looks like it's calling another command.[/edit]
OmegaDeus
 
Posts: 1
Joined: 29 Dec 2008 17:44
Location: Paris, IL, USA

Postby 2Points » 29 Dec 2008 19:30

/1 On xchat_plugin_init and friends.

xchat_plugin_init is called by X-Chat the moment it loads your plugin, obviously. As shown in the example, the X-Chat plugin context must be initialized in this function (declared as static xchat_plugin *ph; in the docs). This is necessary since all other function calls you could possibly use require this value as first parameter. There isn't much else to do here except for hooking various events, with xchat_hook_command etc. After this method returns, your plugin should be ready to to whatever you want it to do.

xchat_plugin_deinit is called when either you or X-Chat unload your plugin, i.e. by using the plugin manager or shutting down X-Chat. Implementing this method isn't strictly necessary unless you allocated global memory and/or system resources in your xchat_plugin_init method. In that case, those resources must be freed here unless you want to run into memory/resource leaks.

I'm not really sure what actually calls xchat_plugin_get_info (the plugin manager, maybe?), but I vaguely remember that not implementing this function didn't do any major damage last time I did a C plugin. You might just want to use the code provided in the sample and forget about the method.

And that's all for pre-defined methods already. Everything else is basically xchat_hook_*.

/2 xchat_hook_print
The value you have to pass as const char *name has to be one of the values available in the "Advanced > Text Events" menu of X-Chat. If you want to respond to channel text, you'd have to pass "Channel Message", for example. Your own text isn't included in this hook, you'd have to hook "Your Message" as well. Anyway, with this you can hook any event that causes X-Chat to print something along the way. You'll get the idea when scrolling through the Text Events window.

Now, assuming you'll hook "Channel Message". Every message will be first passed through the callback function you specified (the order in which an event passes through various hooks is specified with the priority argument of xchat_hook_print). A specific number of arguments is always available through char* word[]. The elements of this array correspond to the values seen in the "Text Events" window (e.g. for "Channel message", you'll see that index 1 is nickname, index 2 is text, and index 3 is user mode. This corresponds to word[1], word[2], and word[3]. word[0] is reserved for X-Chat and musn't be modified.).

Since you probably won't be interested in every single message, you'll have to manually check for the trigger here, that is, word[2]. strcmp(word[2], "!trigger"), or whatever floats your boat. Various other information is available with xchat_get_info(), such the channel, network, etc.

The simplest way to get a feel for the hook_print interface is to set up a simple test callback that just prints every element of word.

You might also want to read this thread, there's some info on this subject as well.
User avatar
2Points
 
Posts: 173
Joined: 21 Dec 2006 18:49

Postby Khisanth » 29 Dec 2008 23:59

There isn't actually anything making use of xchat_plugin_get_info right now. At one point someone was going to write a patch to allow you to diable plugin instead of having to move them out of your xchat data dir. xchat_plugin_get_info would have been used to retrieve the information for filling in the columns in the Plugins and Scripts window. The only reason to add that right now is to be future proof in case someone gets around to implementing that feature.
Khisanth
 
Posts: 1724
Joined: 10 Jun 2004 05:23


Return to Scripts and Plugins

Who is online

Users browsing this forum: No registered users and 0 guests