Ok, posto volentieri il codice (bhe, cambio un po le parole, perche' skerzosamente l'ho fatto volgare... se dico che il plugin si chiama "fanculizzati", puoi immaginera cosa faccia quando si da un nick al comando : )
Pero', ho ancora dei dubbi... per fortuna sono riusto a compilarlo (mi dava un po di problemi), funziona, ma non come volevo.
codice:
// header per i plugin di xchat
#include "xchat-plugin.h"
/**** LE GLOBALI VANNO STATIC ****/
// handler per il plugin
static xchat_plugin *ph;
// se il plugin e' attivo
static int enable = 1;
// callback che esegue il comando
static int saluta_cb(char *word[], char *word_eol[], void *userdata)
{
if (enable)
xchat_printf(ph ,"CIAO %s\n", word[2]); // world[2] dovrebbe essere il nick
return XCHAT_EAT_NONE; /* don't eat this event, xchat needs to see it! */
// ( commento lasciato come l'ho trovato )
}
static int toggle_saluto(char *word[], char *word_eol[], void *userdata)
{
if (!enable)
{
enable = 1;
xchat_print(ph, "Saluto now enabled!\n");
} else
{
enable = 0;
xchat_print(ph, "Saluto now disabled!\n");
}
return XCHAT_EAT_ALL; /* eat this command so xchat and other plugins can't process it */
}
// questo e' l'entry point del plugin
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 */
// suppongo sia l'haldler assegnato dal programma principale per l'utilizzo di questo plugin
ph = plugin_handle;
*plugin_name = "Saluta";
*plugin_desc = "Saluta the persons u want :)";
*plugin_version = "0.1";
// creo un nuovo comando
xchat_hook_command(ph, "saluta", XCHAT_PRI_NORM, saluta_cb, "Usage: SALUTA <nick>", 0);
xchat_hook_command(ph, "SalutoToggle", XCHAT_PRI_NORM, toggle_saluto, "Usage: SALUTOTOGGLE", 0);
xchat_print(ph, "Saluta loaded successfully!\n"); // messaggio di avviso in xchat
return 1; /* return 1 for success */
}
Va compilato come shared object
La struttura e' semplice ma interessante... piu' o meno si riesce a capire come puo' essere gestito un plugin, ma sarebbe interessante vedere anche il main.
Se ho un po di tempo magari analizzo direttamente il sorgente di xchat. Spero ci sia un file a parte per i plugin
ciauz