<fontcolor="#bebebe"><b>/*</b></font><fontcolor="#bebebe"><b> word[1] is the nickname, as in the Settings->Advanced->TextEvents window in xchat </b></font><fontcolor="#bebebe"><b>*/</b></font>
<fontcolor="#ffff00">return</font> XCHAT_EAT_NONE; <fontcolor="#bebebe"><b>/*</b></font><fontcolor="#bebebe"><b> don't eat this event, xchat needs to see it! </b></font><fontcolor="#bebebe"><b>*/</b></font>
xchat_print(ph, <fontcolor="#00ffff">"AutoOping now enabled!</font><fontcolor="#ff00ff">\n</font><fontcolor="#00ffff">"</font>);
} <fontcolor="#ffff00">else</font>
{
enable = <fontcolor="#00ffff">0</font>;
xchat_print(ph, <fontcolor="#00ffff">"AutoOping now disabled!</font><fontcolor="#ff00ff">\n</font><fontcolor="#00ffff">"</font>);
}
<fontcolor="#ffff00">return</font> XCHAT_EAT_ALL; <fontcolor="#bebebe"><b>/*</b></font><fontcolor="#bebebe"><b> eat this command so xchat and other plugins can't process it </b></font><fontcolor="#bebebe"><b>*/</b></font>
<fontcolor="#bebebe"><b>/*</b></font><fontcolor="#bebebe"><b> we need to save this for use with any xchat_* functions </b></font><fontcolor="#bebebe"><b>*/</b></font>
ph = plugin_handle;
<fontcolor="#bebebe"><b>/*</b></font><fontcolor="#bebebe"><b> tell xchat our info </b></font><fontcolor="#bebebe"><b>*/</b></font>
<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>
<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>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, <fontcolor="#f800f8">"dcc"</font>);
<fontcolor="#a02828"><b>if</b></font>(list)
{
xchat_print(ph, <fontcolor="#f800f8">"--- DCC LIST ------------------</font><fontcolor="#6858c8">\n</font><fontcolor="#f800f8">"</font>
<br>For a complete example, have a look at the source code of the <ahref="http://xchat.org/win32/testing/xcdns-src.zip">DNS Plugin</a>, which also contains a Makefile.
<br><br>
<fontcolor=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 <ahref="#sample">sample plugin</a> above.
<br><br>
<h3><aname=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>
<tableborder=0cellpadding=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>
<aname=menu>Starting from 2.4.5 you can add your own items to the menu bar. The menu command has this syntax</a>:
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>
<tableborder=1cellpadding=4rules=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 <ahref="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:
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.
<b>Prototype:</b> xchat_hook *xchat_hook_fd(xchat_plugin *ph, int fd, int flags, xchat_fd_cb *callb, void *userdata);
<br>
<br><b>Description:</b> Hooks a socket or file descriptor. WIN32: Passing a pipe from MSVCR71, MSVCR80 or other variations is not supported at this time.
<br>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).
<br><b>fd:</b> The file descriptor or socket.
<br><b>flags:</b> One or more of XCHAT_FD_READ, XCHAT_FD_WRITE, XCHAT_FD_EXCEPTION, XCHAT_FD_NOTSOCKET. Use bitwise OR to combine them.
XCHAT_FD_NOTSOCKET tells xchat that the provided <b>fd</b> is not a socket, but a "MSVCRT.DLL" pipe.
<br><b>callb:</b> Callback function. This will be called when the socket is available for reading/writing or exception (depending on your chosen <b>flags</b>)
<br><b>userdata:</b> Pointer passed to the callback function.</blockquote>
<b>Returns:</b> Pointer to the hook. Can be passed to xchat_unhook.
<br><b>Description:</b> Registers a function to trap any print events.
The event names may be any available in the "Advanced > Text Events" window.
There are also some extra "special" events you may hook using this function.
Currently they are:<blockquote>
"Open Context" - Called when a new xchat_context is created.
<br>"Close Context" - Called when a xchat_context pointer is closed.
<br>"Focus Tab" - Called when a tab is brought to front.
<br>"Focus Window" - Called a toplevel window is focused, or the main
tab-window is focused by the window manager.
<br>"DCC Chat Text" - Called when some text from a DCC Chat arrives. It provides these elements in the word[] array:<blockquote>word[1] Address
<br>word[2] Port
<br>word[3] Nick
<br>word[4] The Message
</blockquote>
"Key Press" - Called when some keys are pressed in the input-box (since 2.4.2). It provides these elements in the word[] array:<blockquote>word[1] Key Value
<br>word[2] State Bitfield (shift, capslock, alt)
<br>word[3] String version of the key
<br>word[4] Length of the string (may be 0 for unprintable keys)
</blockquote>
</blockquote>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).
<br><b>name:</b> Name of the print event (as in Edit Event Texts Window).
<br><b>pri:</b> Priority of this command. Use XCHAT_PRI_NORM.
<br><b>callb:</b> Callback function. This will be called when this event name is printed.
<br><b>userdata:</b> Pointer passed to the callback function.</blockquote>
<b>Returns:</b> Pointer to the hook. Can be passed to xchat_unhook.
<br>
<br><b>Example:</b>
<blockquote>
<pre>
static int youpart_cb(char *word[], void *userdata)
{
xchat_printf(ph, "You have left channel %s\n", word[3]);
return XCHAT_EAT_XCHAT; /* dont let xchat do its normal printing */
<br><b>Description:</b> Unhooks any hook registered with xchat_hook_print/server/timer/command. When plugins are unloaded, all of its hooks are automatically
removed, so you don't need to call this within your xchat_plugin_deinit() function.
<br>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).
<br><b>hook:</b> Pointer to the hook, as returned by xchat_hook_*.
<br></blockquote>
<b>Returns:</b> The userdata you originally gave to xchat_hook_*.
<br><b>Description:</b> Finds a context based on a channel and servername. If servname is NULL, it finds any channel (or query) by the given name. If channel is NULL, it finds the front-most tab/window of the given servname. If NULL is given for both arguments, the currently focused tab/window will be returned.<br>
Changed in 2.6.1. If servname is NULL, it finds the channel (or query) by the given name in the same server group as the current context. If that doesn't exists then find any by the given name.
<br>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).
<br><b>servname:</b> Servername or NULL.
<br><b>channel:</b> Channelname or NULL.
<br>
</blockquote>
<b>Returns:</b> Context pointer (for use with xchat_set_context) or NULL.
<tr><td>host</td><td>real hostname of the server you connected to.</td></tr>
<tr><td>inputbox</td><td>the input-box contents, what the user has typed (since 2.4.1).</td></tr>
<tr><td>libdirfs</td><td>library directory. e.g. /usr/lib/xchat. The same directory used for auto-loading plugins (since 2.4.0).<small>This string isn't necessarily UTF-8, but local file system encoding.</small></td></tr>
<tr><td>modes</td><td>channel modes, if known, or NULL (since 2.8.1).</td></tr>
<tr><td>network</td><td>current network name or NULL.</td></tr>
<tr><td>nick</td><td>your current nick name.</td></tr>
<tr><td>nickserv</td><td>nickserv password for this network or NULL (since 2.4.3).</td></tr>
<tr><td>server</td><td>current server name (what the server claims to be). NULL if you are not connected.</td></tr>
<tr><td>win_status</td><td>window status: "active", "hidden" or "normal" (since 2.0.9).</td>
<tr><td>xchatdir</td><td>xchat config directory, e.g.: /home/user/.xchat2 <small>This string is encoded in UTF-8, which means you _should_ convert it to "locale" encoding before using functions like open() or OpenFile(). For best <ahref="#unicode">Unicode support</a> on Linux, convert this string using g_filename_from_utf8 and on Windows convert this string to UTF-16LE (wide) and use OpenFileW() etc.</small></td></tr>
<tr><td>xchatdirfs</td><td>xchat config directory, e.g.: /home/user/.xchat2 (since 2.0.9).<small>This string is encoded in local file system encoding, making it ideal for direct use with functions like open() or OpenFile(). For real Unicode support on Windows, it's best not to use xchatdirfs, but xchatdir instead.</small></td></tr>
</table>
</blockquote>
</blockquote>
<b>Returns:</b> A string of the requested information, or NULL. This string must
not be freed and must be copied if needed after the call to xchat_get_info.
<b>Prototype:</b> int xchat_nickcmp(xchat_plugin *ph, const char *s1, const char *s2);
<br>
<br><b>Description:</b> Performs a nick name comparision, based on the current server connection. This might be a RFC1459 compliant string compare, or
plain ascii (in the case of DALNet). Use this to compare channels and nicknames. The function works the same way as strcasecmp.
<br>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).
<br><b>s1:</b> String to compare.
<br><b>s2:</b> String to compare s1 to.
<br>
</blockquote>
<b>Quote from RFC1459:</b>
<blockquote>
Because of IRC's scandanavian origin, the characters {}| are
considered to be the lower case equivalents of the characters []\,
respectively. This is a critical issue when determining the
equivalence of two nicknames.
</blockquote>
<b>Returns:</b>
An integer
less than, equal to, or greater than zero if s1 is found,
respectively, to be less than, to match, or be greater than s2.
<br><br><br>
<h3><aclass=cmdname="xchat_strip"> xchat_strip() </a><small>(new for 2.4.2)</small></h3>
<b>Prototype:</b> char *xchat_strip(xchat_plugin *ph, const char *str, int len, int flags);
<br>
<br><b>Description:</b> Strips mIRC color codes and/or text attributes (bold, underlined etc) from the given string and returns a newly allocated string.
<br>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).
<br><b>str:</b> String to strip.
<br><b>len:</b> Length of the string (or -1 for NULL terminated).
<br><b>flags:</b> Bit-field of flags: 0-Strip mIRC colors, 1-Strip text attributes.
<br>
</blockquote>
<b>Returns:</b>
A newly allocated string or NULL for failure. You must free this string with xchat_free.
<br><br><b>Example:</b>
<blockquote>
<pre>
{
char *new_text;
/* strip both colors and attributes by using the 0 and 1 bits (1 BITWISE-OR 2) */
<h3><aclass=cmdname="xchat_pluginpref_delete"> xchat_pluginpref_delete() </a><small>(new for 2.8.10)</small></h3>
<b>Prototype:</b> int xchat_pluginpref_delete (xchat_plugin *ph, const char *var);
<br>
<br><b>Description:</b> Deletes a plugin-specific setting from a plugin-specific config file.
<br>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).
<br><b>var:</b> Name of the setting to delete.
<br>
</blockquote>
<b>Returns:</b> 1 for success, 0 for failure. If the given setting didn't exist, it also returns 1, so 1 only indicates that the setting won't exist after the call.
<br><br><br>
<h3><aclass=cmdname="xchat_pluginpref_list"> xchat_pluginpref_list() </a><small>(new for 2.8.10)</small></h3>
<b>Prototype:</b> int xchat_pluginpref_list (xchat_plugin *ph, const char *dest);
<br>
<br><b>Description:</b> Builds a comma-separated list of the currently saved settings from a plugin-specific config file.
<br>
<br><b>Arguments:</b>
<blockquote><b>ph:</b> Plugin handle (as given to xchat_plugin_init).