<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>XChat 2.0 Plugin Interface</title>
<style type="text/css">
<!--
body {
font-family: sans-serif;
background-color: #FFFBF0;
}
.cmd {
background-color: #dddddd;
color: #990066
}
.bbox {
font-family: monospace;
color: #fdfdfd;
background-color: #000;
border: 1px solid #00f;
padding: 4px;
text-align: left;
margin-left: 32px;
margin-right: 32px;
}
.box {
background-color: #ddddee;
border: 1px solid #000;
padding: 4px;
text-align: left;
margin-left: 32px;
margin-right: 32px;
}
-->
</style>
</head>
<body bgcolor="#FFFBF0" text="#000" link="#607060" vlink="#607060" alink="#607060">
<h1>XChat 2.0 Plugin Interface</h1>
<small>
<font size="-12">plugin20.html revision 2.86</font>
<br>Latest version of this document is available at: <a href="http://xchat.org/docs/plugin20.html">http://xchat.org/docs/plugin20.html</a></small>
<h2>1. Documentation:</h2>
<blockquote>
<a href="#intro">1.0 Introduction</a>
<br><a href="#sample">1.1 Sample plugin</a>
<br><a href="#word">1.2 What is word and word_eol?</a>
<br><a href="#lists">1.3 Lists and fields</a>
<br><a href="#win32">1.4 Plugins on Windows (Win32)</a>
<br><a href="#gui">1.5 Controlling the GUI</a>
<br> <a href="#gui">1.5.1 Basic Control</a>
<br> <a href="#menu">1.5.2 Custom Menu Items</a>
<br> <a href="#tray">1.5.3 System Tray</a>
<br><a href="#unicode">1.6 Handling UTF-8/Unicode strings</a>
</blockquote>
<h2>2. Function reference:</h2>
<blockquote>
<a href="#xchat_hook_command">xchat_hook_command</a>
<br><a href="#xchat_hook_fd">xchat_hook_fd</a>
<br><a href="#xchat_hook_print">xchat_hook_print</a>
<br><a href="#xchat_hook_server">xchat_hook_server</a>
<br><a href="#xchat_hook_timer">xchat_hook_timer</a>
<br><a href="#xchat_unhook">xchat_unhook</a>
<br>
<br><a href="#xchat_command">xchat_command</a>
<br><a href="#xchat_commandf">xchat_commandf</a>
<br><a href="#xchat_print">xchat_print</a>
<br><a href="#xchat_printf">xchat_printf</a>
<br><a href="#xchat_emit_print">xchat_emit_print</a>
<br><a href="#xchat_send_modes">xchat_send_modes</a>
<br>
<br><a href="#xchat_find_context">xchat_find_context</a>
<br><a href="#xchat_get_context">xchat_get_context</a>
<br><a href="#xchat_get_info">xchat_get_info</a>
<br><a href="#xchat_get_prefs">xchat_get_prefs</a>
<br><a href="#xchat_set_context">xchat_set_context</a>
<br>
<br><a href="#xchat_nickcmp">xchat_nickcmp</a>
<br><a href="#xchat_strip">xchat_strip</a>
<br><a href="#xchat_free">xchat_free</a>
<br>
<br><a href="#xchat_pluginpref_set_str">xchat_pluginpref_set_str</a>
<br><a href="#xchat_pluginpref_get_str">xchat_pluginpref_get_str</a>
<br><a href="#xchat_pluginpref_set_int">xchat_pluginpref_set_int</a>
<br><a href="#xchat_pluginpref_get_int">xchat_pluginpref_get_int</a>
<br><a href="#xchat_pluginpref_delete">xchat_pluginpref_delete</a>
<br><a href="#xchat_pluginpref_list">xchat_pluginpref_list</a>
<br>
<br><a href="#lists">xchat_list_get</a>
<br><a href="#lists">xchat_list_free</a>
<br><a href="#lists">xchat_list_fields</a> (not documented yet)
<br><a href="#lists">xchat_list_next</a>
<br><a href="#lists">xchat_list_str</a>
<br><a href="#lists">xchat_list_int</a>
<br><a href="#lists">xchat_list_time</a>
<br>
<br><a href="#xchat_plugingui_add">xchat_plugingui_add</a> (not documented yet)
<br><a href="#xchat_plugingui_remove">xchat_plugingui_remove</a> (not documented yet)
</blockquote><br>
<h3><a name=intro>Introduction</a></h3>
Plugins for XChat are written in C. The interface aims to keep 100%
binary compatability. This means that if you upgrade XChat, you will
not need to recompile your plugins, they'll continue to work. The
interface doesn't depend on any structures and offsets, so compiler
versions shouldn't have an impact either. The only real requirement of
an XChat plugin, is that it define a "xchat_plugin_init" symbol. This
is your entry point function, see the example below. You should make
all your global variables and functions <i>static</i>, so that a symbol
is not exported. There is no harm in exporting these symbols, but they
are not necessary and only pollute the name-space. Plugins are compiled as shared objects
(.so files), for example:
<br><br>
Most UNIX systems:<pre>
gcc -Wl,--export-dynamic -Wall -O1 -shared -fPIC myplugin.c -o myplugin.so
</pre>
MacOSX:<pre>
gcc -no-cpp-precomp -g -O2 -Wall -bundle -flat_namespace -undefined suppress -o myplugin.so myplugin.c
</pre>
See the <a href="#win32">Windows section</a> on how to compile a plugin
using visual studio.
<p>
All strings passed to and from plugins are encoded in UTF-8, regardless
of locale. <a href="#unicode">What does this mean</a>?
</p><br>
<h3><a name=sample>Sample plugin</a></h3>
This simple plugin autoOps anyone who joins a channel you're in. It also
adds a new command /AUTOOPTOGGLE, which can be used to turn the feature ON
or OFF. Every XChat plugin must define an xchat_plugin_init function, this
is the normal entry point. xchat_plugin_deinit is optional.
<br>
<div style="color: #ffffff; background-color: #111199;">
<pre>
<font color="#00ff00">#include </font><font color="#00ffff">"xchat-plugin.h"</font>
<font color="#00ff00">#define PNAME </font><font color="#00ffff">"AutoOp"</font>
<font color="#00ff00">#define PDESC </font><font color="#00ffff">"Auto Ops anyone that joins"</font>
<font color="#00ff00">#define PVERSION </font><font color="#00ffff">"0.1"</font>
<font color="#ffa500"><b>static</b></font> xchat_plugin *ph; <font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> plugin handle </b></font><font color="#bebebe"><b>*/</b></font>
<font color="#ffa500"><b>static</b></font> <font color="#ffa500"><b>int</b></font> enable = <font color="#00ffff">1</font>;
<font color="#ffa500"><b>static</b></font> <font color="#ffa500"><b>int</b></font> join_cb(<font color="#ffa500"><b>char</b></font> *word[], <font color="#ffa500"><b>void</b></font> *userdata)
{
<font color="#ffff00">if</font> (enable)
<font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> Op ANYONE who joins </b></font><font color="#bebebe"><b>*/</b></font>
xchat_commandf(ph, <font color="#00ffff">"OP </font><font color="#ff00ff">%s</font><font color="#00ffff">"</font>, word[<font color="#00ffff">1</font>]);
<font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> word[1] is the nickname, as in the Settings->Advanced->TextEvents window in xchat </b></font><font color="#bebebe"><b>*/</b></font>
<font color="#ffff00">return</font> XCHAT_EAT_NONE; <font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> don't eat this event, xchat needs to see it! </b></font><font color="#bebebe"><b>*/</b></font>
}
<font color="#ffa500"><b>static</b></font> <font color="#ffa500"><b>int</b></font> autooptoggle_cb(<font color="#ffa500"><b>char</b></font> *word[], <font color="#ffa500"><b>char</b></font> *word_eol[], <font color="#ffa500"><b>void</b></font> *userdata)
{
<font color="#ffff00">if</font> (!enable)
{
enable = <font color="#00ffff">1</font>;
xchat_print(ph, <font color="#00ffff">"AutoOping now enabled!</font><font color="#ff00ff">\n</font><font color="#00ffff">"</font>);
} <font color="#ffff00">else</font>
{
enable = <font color="#00ffff">0</font>;
xchat_print(ph, <font color="#00ffff">"AutoOping now disabled!</font><font color="#ff00ff">\n</font><font color="#00ffff">"</font>);
}
<font color="#ffff00">return</font> XCHAT_EAT_ALL; <font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> eat this command so xchat and other plugins can't process it </b></font><font color="#bebebe"><b>*/</b></font>
}
<font color="#ffa500"><b>void</b></font> xchat_plugin_get_info(<font color="#ffa500"><b>char</b></font> **name, <font color="#ffa500"><b>char</b></font> **desc, <font color="#ffa500"><b>char</b></font> **version, <font color="#ffa500"><b>void</b></font> **reserved)
{
*name = PNAME;
*desc = PDESC;
*version = PVERSION;
}
<font color="#ffa500"><b>int</b></font> xchat_plugin_init(xchat_plugin *plugin_handle,
<font color="#ffa500"><b>char</b></font> **plugin_name,
<font color="#ffa500"><b>char</b></font> **plugin_desc,
<font color="#ffa500"><b>char</b></font> **plugin_version,
<font color="#ffa500"><b>char</b></font> *arg)
{
<font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> we need to save this for use with any xchat_* functions </b></font><font color="#bebebe"><b>*/</b></font>
ph = plugin_handle;
<font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> tell xchat our info </b></font><font color="#bebebe"><b>*/</b></font>
*plugin_name = PNAME;
*plugin_desc = PDESC;
*plugin_version = PVERSION;
xchat_hook_command(ph, <font color="#00ffff">"AutoOpToggle"</font>, XCHAT_PRI_NORM, autooptoggle_cb, <font color="#00ffff">"Usage: AUTOOPTOGGLE, Turns OFF/ON Auto Oping"</font>, <font color="#00ffff">0</font>);
xchat_hook_print(ph, <font color="#00ffff">"Join"</font>, XCHAT_PRI_NORM, join_cb, <font color="#00ffff">0</font>);
xchat_print(ph, <font color="#00ffff">"AutoOpPlugin loaded successfully!</font><font color="#ff00ff">\n</font><font color="#00ffff">"</font>);
<font color="#ffff00">return</font> <font color="#00ffff">1</font>; <font color="#bebebe"><b>/*</b></font><font color="#bebebe"><b> return 1 for success </b></font><font color="#bebebe"><b>*/</b></font>
}
</pre>
</div>
<h3><a name=word>What's word and word_eol?</a></h3>
They are arrays of strings. They contain the parameters the user entered
for the particular command. For example, if you executed:
<pre>
/command NICK hi there
word[1] is command
word[2] is NICK
word[3] is hi
word[4] is there
word_eol[1] is command NICK hi there
word_eol[2] is NICK hi there
word_eol[3] is hi there
word_eol[4] is there
</pre>
These arrays are simply provided for your convenience. You are NOT allowed
to alter them. Both arrays are limited to 32 elements (index 31). word[0] and
word_eol[0] are reserved and should not be read.
<br><br><br>
<h3><a name=lists>Lists and Fields</a></h3>
Lists of information (DCCs, Channels, Userlist etc) can be retreived
with xchat_list_get. All fields are READ ONLY and must be copied if
needed for a long time after calling xchat_list_str. The types of lists and fields available are:
<blockquote>
"channels" - list of channels, querys and their servers.
<blockquote><table border=1>
<tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr>
<tr><td>channel</td><td>Channel or query name</td><td>string</td></tr>
<tr><td>chantypes</td><td>Channel types e.g. "#!&"<br><small>(Added in version 2.0.9. Older versions will return NULL)</small></td><td>string</td>
<tr><td>context</td><td>(xchat_context *) pointer. Can be used with xchat_set_context</td><td>string</td></tr>
<tr><td>flags</td><td>Server/Channel Bits:<br>
<table>
<tr><td>Bit #</td><td>Value</td><td>Description</td></tr>
<tr><td>0</td><td>1</td><td>Connected</td></tr>
<tr><td>1</td><td>2</td><td>Connecting in Progress</td></tr>
<tr><td>2</td><td>4</td><td>You are away</td></tr>
<tr><td>3</td><td>8</td><td>End of MOTD (Login complete)</td></tr>
<tr><td>4</td><td>16</td><td>Has WHOX (ircu)</td></tr>
<tr><td>5</td><td>32</td><td>Has IDMSG (FreeNode)</td></tr>
<tr><td>6</td><td>64</td><td>Hide Join/Part Messages</td></tr>
<tr><td>7</td><td>128</td><td>unused (was Color Paste in old versions)</td></tr>
<tr><td>8</td><td>256</td><td>Beep on Message</td></tr>
<tr><td>9</td><td>512</td><td>Blink Tray</td></tr>
<tr><td>10</td><td>1024</td><td>Blink Task Bar</td></tr>
</table>
<br><small>(Bits 0-5 added in 2.0.9. Bits 6-8 added in 2.6.6. Bit 9 added in 2.8.0. Bit 10 in 2.8.6)</small></td><td>int</td></tr>
<tr><td>id</td><td>Unique server ID<br><small>(Added in version 2.0.8. Older versions will return -1)</small></td><td>int</td></tr>
<tr><td>lag</td><td>Lag in milliseconds<br><small>(Added in version 2.6.8. Older versions will return -1)</small></td><td>int</td>
<tr><td>maxmodes</td><td>Maximum modes per line<br><small>(Added in version 2.0.9. Older versions will return -1)</small></td><td>int</td>
<tr><td>network</td><td>Network name to which this channel belongs<br><small>(Added in version 2.0.2. Older versions will return NULL)</small></td><td>string</td></tr>
<tr><td>nickprefixes</td><td>Nickname prefixes e.g. "@+"<br><small>(Added in version 2.0.9. Older versions will return NULL)</small></td><td>string</td>
<tr><td>nickmodes</td><td>Nickname mode chars e.g. "ov"<br><small>(Added in version 2.0.9. Older versions will return NULL)</small></td><td>string</td>
<tr><td>queue</td><td>Number of bytes in the send-queue<br><small>(Added in version 2.6.8. Older versions will return -1)</small></td><td>int</td>
<tr><td>server</td><td>Server name to which this channel belongs</td><td>string</td></tr>
<tr><td>type</td><td>Type of context this is: 1-Server 2-Channel 3-Dialog<br><small>(Added in version 2.0.2. Older versions will return -1)</small></td><td>int</td></tr>
<tr><td>users</td><td>Number of users in this channel<br><small>(Added in version 2.0.8. Older versions will return -1)</small></td><td>int</td></tr>
</table>
</blockquote>
"dcc" - list of DCC file transfers. Fields:
<blockquote> <table border=1>
<tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr>
<tr><td>address32</td><td>Address of the remote user (ipv4 address)</td><td>int</td></tr>
<tr><td>cps</td><td>Bytes per second (speed)</td><td>int</td></tr>
<tr><td>destfile</td><td>Destination full pathname</td><td>string</td></tr>
<tr><td>file</td><td>File name</td><td>string</td></tr>
<tr><td>nick</td><td>Nickname of person who the file is from/to</td><td>string</td></tr>
<tr><td>port</td><td>TCP port number</td><td>int</td></tr>
<tr><td>pos</td><td>Bytes sent/received</td><td>int</td></tr>
<tr><td>poshigh</td><td>Bytes sent/received, high order 32 bits</td><td>int</td></tr>
<tr><td>resume</td><td>Point at which this file was resumed (or zero if it was not resumed)</td><td>int</td></tr>
<tr><td>resumehigh</td><td>Point at which this file was resumed, high order 32 bits</td><td>int</td></tr>
<tr><td>size</td><td>File size in bytes, low order 32 bits (cast it to unsigned)</td><td>int</td></tr>
<tr><td>sizehigh</td><td>File size in bytes, high order 32 bits</td><td>int</td></tr>
<tr><td>status</td><td>DCC Status: 0-Queued 1-Active 2-Failed 3-Done 4-Connecting 5-Aborted</td><td>int</td></tr>
<tr><td>type</td><td>DCC Type: 0-Send 1-Receive 2-ChatRecv 3-ChatSend</td><td>int</td></tr>
</table>
</blockquote>
"ignore" - current ignore list.
<blockquote> <table border=1>
<tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr>
<tr><td>mask</td><td>Ignore mask. .e.g: *!*@*.aol.com</td><td>string</td></tr>
<tr><td>flags</td><td>Bit field of flags. 0=Private 1=Notice 2=Channel 3=Ctcp<br>
4=Invite 5=UnIgnore 6=NoSave 7=DCC</td><td>int</td></tr>
</table>
</blockquote>
"notify" - list of people on notify.
<blockquote> <table border=1>
<tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr>
<tr><td>networks</td><td>Networks to which this nick applies. Comma separated. May be NULL.
<br><small>(Added in version 2.6.8)</small></td><td>string</td></tr>
<tr><td>nick</td><td>Nickname</td><td>string</td></tr>
<tr><td>flags</td><td>Bit field of flags. 0=Is online.</td><td>int</td></tr>
<tr><td>on</td><td>Time when user came online.</td><td>time_t</td></tr>
<tr><td>off</td><td>Time when user went offline.</td><td>time_t</td></tr>
<tr><td>seen</td><td>Time when user the user was last verified still online.</td><td>time_t</td></tr>
</table>
<small>The entire "notify" list was added in xchat 2.0.8. Fields are
only valid for the context when xchat_list_get() was called
(i.e. you get information about the user ON THAT ONE SERVER ONLY). You
may cycle through the "channels" list to find notify information for every
server.</small>
</blockquote>
"users" - list of users in the current channel.
<blockquote> <table border=1>
<tr bgcolor="#dddddd"><td>Name</td><td>Description</td><td>Type</td></tr>
<tr><td>away</td><td>Away status (boolean)<br><small>(Added in version 2.0.6. Older versions will return -1)</small></td><td>int</td></tr>
<tr><td>lasttalk</td><td>Last time the user was seen talking<br><small>(Added in version 2.4.2. Older versions will return -1)</small></td><td>time_t</td></tr>
<tr><td>nick</td><td>Nick name</td><td>string</td></tr>
<tr><td>host</td><td>Host name in the form: user@host (or NULL if not known).</td><td>string</td></tr>
<tr><td>prefix</td><td>Prefix character, .e.g: @ or +. Points to a single char.</td><td>string</td></tr>
<tr><td>realname</td><td>Real name or NULL<br><small>(Added in version 2.8.6)</small></td><td>string</td></tr>
<tr><td>selected</td><td>Selected status in the user list, only works for retrieving the user list of the focused tab<br><small>(Added in version 2.6.1. Older versions will return -1)</small></td><td>int</td></tr>
</table>
</blockquote>
</blockquote>
Example:
<br>
<pre>
list = xchat_list_get(ph, <font color="#f800f8">"dcc"</font>);
<font color="#a02828"><b>if</b></font>(list)
{
xchat_print(ph, <font color="#f800f8">"--- DCC LIST ------------------</font><font color="#6858c8">\n</font><font color="#f800f8">"</font>
<font color="#f800f8">"File To/From KB/s Position</font><font color="#6858c8">\n</font><font color="#f800f8">"</font>);
<font color="#a02828"><b>while</b></font>(xchat_list_next(ph, list))
{
xchat_printf(ph, <font color="#f800f8">"</font><font color="#6858c8">%6s</font><font color="#f800f8"> </font><font color="#6858c8">%10s</font><font color="#f800f8"> </font><font color="#6858c8">%.2f</font><font color="#f800f8"> </font><font color="#6858c8">%d</font><font color="#6858c8">\n</font><font color="#f800f8">"</font>,
xchat_list_str(ph, list, <font color="#f800f8">"file"</font>),
xchat_list_str(ph, list, <font color="#f800f8">"nick"</font>),
xchat_list_int(ph, list, <font color="#f800f8">"cps"</font>) / <font color="#f800f8">1024</font>,
xchat_list_int(ph, list, <font color="#f800f8">"pos"</font>));
}
xchat_list_free(ph, list);
}
</pre>
<br>
<h3><a name=win32>Plugins on Windows (Win32)</a></h3>
Yes, it can be done. All you need is either
<a href="http://msdn.microsoft.com/visualc/vctoolkit2003/">MSVC</a> (Visual Studio) or
<a href="http://www.mingw.org">MINGW</a>, both these compilers are free to download.
Simply compile your plugin as a DLL. You should have the following files:
<ul>
<li><a href="http://xchat.org/docs/xchat-plugin.h">xchat-plugin.h</a> - Main Plugin header</li>
<li>plugin.c - Your plugin, you need to write this one :)</li>
<li>plugin.def - A simple text file containing the following:</li>
</ul>
<div class=box>
EXPORTS<br>
xchat_plugin_init<br>
xchat_plugin_deinit<br>
xchat_plugin_get_info<br>
</div>
<br>Leave out <i>xchat_plugin_deinit</i> if you don't intend to define that
function. Then, to compile, type this at your command prompt:<br><br>
<div class=bbox>
<font color="#00FF00">MSVC</font>
<br> cl -O1 -MD -G5 -DWIN32 -c plugin.c<br>
<br> link /DLL /out:plugin.dll /SUBSYSTEM:WINDOWS plugin.obj /def:plugin.def /base:0x00d40000
<br><br>
<font color="#00FF00">GCC (MINGW)</font>
<br> gcc -Wall -Os -DWIN32 -c plugin.c<br>
<br> dllwrap --def plugin.def --dllname plugin.dll plugin.o<br><br>
</div>
<br>For a complete example, have a look at the source code of the <a href="http://xchat.org/win32/testing/xcdns-src.zip">DNS Plugin</a>, which also contains a Makefile.
<br><br>
<font color=red>Caveat:</font> Plugins compiled on Win32 MUST have a
global variable called <b>ph</b>, which is the plugin_handle, much like
in the <a href="#sample">sample plugin</a> above.
<br><br>
<h3><a name=gui>Controlling the GUI</a></h3>
<p>
A simple way to perform basic GUI functions is to use the /GUI command.
You can execute this command through the input-box, or by calling
xchat_command(ph, "GUI .....");.
</p>
<blockquote>
<table border=0 cellpadding=4>
<tr><td>GUI ATTACH</td><td>Same function as "Attach Window" in the XChat menu (new for 2.6.2).</td></tr>
<tr><td>GUI DETACH</td><td>Same function as "Detach Tab" in the XChat menu (new for 2.6.2).</td></tr>
<tr><td>GUI APPLY</td><td>Similar to clicking OK in the settings window. Execute this after /SET to activate GUI changes (new for 2.8.0)</td></tr>
<tr><td>GUI COLOR <i>n</i></td><td>Change the tab color of the current context, where n is a number from 0 to 3.</td></tr>
<tr><td>GUI FOCUS</td><td>Focus the current window or tab.</td></tr>
<tr><td>GUI FLASH</td><td>Flash the taskbar button. It will flash only if the window isn't focused and will stop when it is focused by the user.</td></tr>
<tr><td>GUI HIDE</td><td>Hide the main xchat window completely (this is used by the Systray plugin).</td></tr>
<tr><td>GUI ICONIFY</td><td>Iconify (minimize to taskbar) the current xchat window.</td></tr>
<tr><td>GUI MSGBOX <i>text</i></td><td>Displays a asynchronous message box with your text (new for 2.4.5).</td></tr>
<tr><td>GUI SHOW</td><td>Show the main xchat window (if currently hidden).</td></tr>
</table>
</blockquote>
<p>
Note, the FLASH, ICONIFY and COLOR args were added in xchat 2.0.8, they
will not work with previous versions.
</p>
<a name=menu>Starting from 2.4.5 you can add your own items to the menu bar. The menu command has this syntax</a>:
<pre>
MENU [-eX] [-i<ICONFILE>] [-k<mod>,<key>] [-m] [-pX] [-rX,group] [-tX] {ADD|DEL} <path> [command] [unselect command]</pre>
For example:
<pre>
MENU -p5 ADD FServe
MENU ADD "FServe/Show File List" "fs list"
MENU ADD FServe/-
MENU -k4,101 -t1 ADD "FServe/Enabled" "fs on" "fs off"
MENU -e0 ADD "FServe/Do Something" "fs action"
</pre>
In the example above, it would be recommended to execute "MENU DEL FServe" inside your xchat_plugin_deinit function. The special item with name "-" will add a separator line.
<br><br>
Parameters and flags:
<blockquote>
<table border=1 cellpadding=4 rules=all>
<tr><td>-eX</td><td>Set enable flag to X. -e0 for disable, -e1 for enable. This lets you create a disabled (shaded) item.</td></tr>
<tr><td>-iFILE</td><td>Use an icon filename FILE (new for 2.8.0). Not supported for toggles or radio items.</td></tr>
<tr><td>-k<mod>,<key></td><td>Specify a keyboard shortcut. "mod" is the modifier which is a bitwise OR of: 1-SHIFT 4-CTRL 8-ALT in decimal. "key" is the key value in decimal, e.g. -k5,101 would specify SHIFT-CTRL-E.</td></tr>
<tr><td>-m</td><td>Specify that this label should be treated as <a href="http://developer.gnome.org/doc/API/2.0/pango/PangoMarkupFormat.html">Pango Markup</a> language. Since forward slash ("/") is already used in menu paths, you should replace closing tags with an ASCII 003 instead e.g.: xchat_command(ph, "MENU -m ADD \"<b>Bold Menu<\003b>\""); (new for 2.6.6).</td></tr>
<tr><td>-pX</td><td>Specify a menu item's position number. e.g. -p5 will cause the item to be inserted in the 5th place. New for 2.8.0: If the position is a negative number, it will be used as an offset from the bottom/right-most item.</td></tr>
<tr><td>-rX,group</td><td>Specify a radio menu item, with initial state X and a group name (new for 2.8.0). The group name should be the exact label of another menu item (without the path) that this item will be grouped with. For radio items, only a select command will be executed (no unselect command).</td></tr>
<tr><td>-tX</td><td>Specify a toggle menu item with an initial state. -t0 for an "unticked" item and -t1 for a "ticked" item.</td></tr>
</table>
</blockquote>
If you want to change an item's toggle state or enabled flag,
just ADD an item with exactly the same name and command and specify the -tX -eX parameters you need.
<br><br>It's also possible to add items to XChat's existing menus, for example:<br>
<pre> MENU ADD "Settings/Sub Menu"
MENU -t0 ADD "Settings/Sub Menu/My Setting" myseton mysetoff
</pre>
However, internal names and layouts of XChat's menu may change in the future, so use at own risk.
<br><br>
Here is an example of Radio items:
<pre> MENU ADD "Language"
MENU -r1,"English" ADD "Language/English" cmd1
MENU -r0,"English" ADD "Language/Spanish" cmd2
MENU -r0,"English" ADD "Language/German" cmd3</pre>
<br>
From 2.8.0, you can also change menus other than the main one (i.e popup menus). Currently they are:
<blockquote>
<table border=1 cellpadding=4 rules=all>
<tr bgcolor="#999999"><td>Root Name</td><td>Menu</td></tr>
<tr><td>$TAB</td><td>Tab menu (right click a channel/query tab or treeview row)</td></tr>
<tr><td>$TRAY</td><td>System Tray menu</td></tr>
<tr><td>$URL</td><td>URL link menu</td></tr>
<tr><td>$NICK</td><td>Userlist nick-name popup menu</td></tr>
<tr><td>$CHAN</td><td>Menu when clicking a channel in the text area (since 2.8.4)</td></tr>
</table>
</blockquote>
<pre>
Example: MENU -p0 ADD "$TAB/Cycle Channel" cycle
</pre>
<br>
<a name=tray>Starting from 2.8.0 you can manipulate XChat's system tray icon using the /TRAY command</a>:
<pre>
Usage:
TRAY -f <timeout> <file1> [<file2>] Flash tray between two icons. Leave off file2 to use default xchat icon.
TRAY -f <filename> Set tray to a fixed icon.
TRAY -i <number> Flash tray with an internal icon.
<small>2=Message 5=Highlight 8=Private 11=File</small>
TRAY -t <text> Set the tray tooltip.
TRAY -b <title> <text> Set the tray balloon.
<small>Supported on Windows from 2.8.1 and 2.8.2 on Linux (libnotify required on Linux).</small>
</pre>
Filenames can be ICO or PNG format. PNG format is supported on Linux/BSD and Windows XP (but requires installation of GDI+ on Windows 2000). Set a timeout of -1 to use XChat's default.
<br><br>
<h3><a name=unicode>Handling UTF-8/Unicode strings</a></h3>
<p>
The XChat plugin API specifies that strings passed to and from xchat must be encoded in UTF-8.
<br><br>
What does this mean for the plugin programmer? You just have to be a little careful when
passing strings obtained from IRC to system calls. For example, if you're writing a file-server
bot, someone might message you a filename. Can you pass this filename directly to open()? Maybe!
If you're lazy... The correct thing to do is to convert the string to "system locale encoding",
otherwise your plugin will fail on non-ascii characters.
<br><br>
Here are examples on how to do this conversion on Unix and Windows. In this example, someone will
CTCP you the message "SHOWFILE <filename>".
<br><br>
</p>
<pre>
static int ctcp_cb(char *word[], char *word_eol[], void *userdata)
{
if(strcmp(word[1], "SHOWFILE") == 0)
{
get_file_name(nick, word[2]);
}
return XCHAT_EAT_XCHAT;
}
static void get_file_name(char *nick, char *fname)
{
char buf[256];
FILE *fp;
<font color="#777777"> /* the fname is in UTF-8, because it came from the xchat API */</font>
</pre><font color="#33aa44">#ifdef _WIN32</font><pre>
wchar_t wide_name[MAX_PATH];
<font color="#777777"> /* convert UTF-8 to WIDECHARs (aka UTF-16LE) */</font>
if (MultiByteToWideChar(CP_UTF8, 0, fname, -1, wide_name, MAX_PATH) < 1)
return;
<font color="#777777"> /* now we have WIDECHARs, so we can _wopen() or CreateFileW(). */
/* _wfopen actually requires NT4, Win2000, XP or newer. */</font>
fp = _wfopen(wide_name, "r");
</pre><font color="#33aa44">#else</font><pre>
char *loc_name;
<font color="#777777"> /* convert UTF-8 to System Encoding */</font>
loc_name = g_filename_from_utf8(fname, -1, 0, 0, 0);
if(!loc_name)
return;
<font color="#777777"> /* now open using the system's encoding */</font>
fp = fopen(loc_name, "r");
g_free(loc_name);
</pre><font color="#33aa44">#endif</font><pre>
if (fp)
{
while (fgets (buf, sizeof(buf), fp))
{
<font color=