Things you'll need:
- Microsoft Visual C++ Express (I've been having trouble getting the 2010 version to actually download so though I would imagine it works, I can't be entirely certain. This is a link to the 2008 edition which I know works.)
- The main XChat plugin header
- An X-Macro file with the same name as your plugin (More on this later.)
- Some actual code. (We'll be using a slight variation on the sample code from the original doc)
The code:
Code: Select all
#include "xchat-plugin.h"
#include <string.h>
#define PNAME "AutoOp"
#define PDESC "Auto Ops anyone that joins. Use /aop to turn on or off."
#define PVERSION "0.1"
static xchat_plugin *ph; /* plugin handle */
static int enable = 1;
static int join_cb(char *word[], void *userdata)
{
//xchat_printf(ph, "%s \n", word[2]);
if (enable)
{
if(strncmp(word[2],"#music",512)==0){
/* Op ANYONE who joins */
xchat_commandf(ph, "OP %s", word[1]);
}
}
/* word[1] is the nickname, as in the Settings->Advanced->TextEvents window in xchat */
return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
}
static int aop_cb(char *word[], char *word_eol[], void *userdata)
{
if (!enable)
{
enable = 1;
xchat_print(ph, "AutoOping now enabled!\n");
} else
{
enable = 0;
xchat_print(ph, "AutoOping now disabled!\n");
}
return XCHAT_EAT_ALL; /* eat this command so xchat and other plugins can't process it */
}
void xchat_plugin_get_info(char **name, char **desc, char **version, void **reserved)
{
*name = PNAME;
*desc = PDESC;
*version = PVERSION;
}
int xchat_plugin_init(xchat_plugin *plugin_handle,
char **plugin_name,
char **plugin_desc,
char **plugin_version,
char *arg)
{
/* we need to save this for use with any xchat_* functions */
ph = plugin_handle;
/* tell xchat our info */
*plugin_name = PNAME;
*plugin_desc = PDESC;
*plugin_version = PVERSION;
xchat_hook_command(ph, "aop", XCHAT_PRI_NORM, aop_cb, "Usage: aop, Turns OFF/ON Auto Oping", 0);
xchat_hook_print(ph, "Join", XCHAT_PRI_NORM, join_cb, 0);
xchat_print(ph, "AutoOpPlugin loaded successfully!\n");
return 1; /* return 1 for success */
}
Code: Select all
EXPORTS
xchat_plugin_init
xchat_plugin_get_info
1. Have you already downloaded and installed Visual C++? If not, do so now.
2. Creating a working directory for this project. Download the plugin header to the directory. Copy the main code into a blank text file and rename it to what you want you plugin to be called with ".c" as the extension (ex: aop.c). Do the same with the X-Macro except end it with ".def" instead of ".c". You should now have three files: aop.c, aop.def and xchat-plugin.h.
3. Here's where things get tricky. You can't just compile that code with the main Visual C++ IDE (at least, not as far as I know), you need to use the Visual Studio Command Prompt. You can use the Windows Search to find the shortcut or you can try making your own. Just make a new shortcut and, for the location, put this:
Code: Select all
%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"" x86
You should now have a shortcut called Visual Studio Command Prompt or something like that that brings up a command prompt when you open it.
4. Now you just have to enter the commands that are listed in the original documents. No, wait! There's a typo in the command that you have to enter. I mean, honestly, XChat, that is pretty bad. The correct command is:
Code: Select all
cl -O1 -LD -GS -DWIN32 -c aop.c
link /DLL /out:aop.dll /SUBSYSTEM:WINDOWS aop.obj /def:aop.def /base:0x00d40000
Code: Select all
cl -O1 -LD -GS -DWIN32 -c %1.c
link /DLL /out:%1.dll /SUBSYSTEM:WINDOWS %1.obj /def:%1.def /base:0x00d40000
Congrats, you just compiled your first XChat core plugin!
Let me know if you have any questions or comments!