diff options
Diffstat (limited to 'src/modules/demos')
-rw-r--r-- | src/modules/demos/catserv/Makefile | 9 | ||||
-rw-r--r-- | src/modules/demos/catserv/README | 4 | ||||
-rw-r--r-- | src/modules/demos/catserv/catserv_extern.h | 11 | ||||
-rw-r--r-- | src/modules/demos/catserv/catserv_messages.c | 14 | ||||
-rw-r--r-- | src/modules/demos/catserv/catserv_messages.h | 10 | ||||
-rw-r--r-- | src/modules/demos/catserv/ircd_catserv.c | 112 | ||||
-rw-r--r-- | src/modules/demos/catserv/makefile.win32 | 4 | ||||
-rw-r--r-- | src/modules/demos/catserv/meow.c | 9 | ||||
-rw-r--r-- | src/modules/demos/catserv/meow.h | 9 | ||||
-rw-r--r-- | src/modules/demos/catserv/purr.c | 8 | ||||
-rw-r--r-- | src/modules/demos/catserv/purr.h | 9 | ||||
-rw-r--r-- | src/modules/demos/events.c | 82 | ||||
-rw-r--r-- | src/modules/demos/hs_conf.c | 74 | ||||
-rw-r--r-- | src/modules/demos/hs_moo.c | 119 |
14 files changed, 474 insertions, 0 deletions
diff --git a/src/modules/demos/catserv/Makefile b/src/modules/demos/catserv/Makefile new file mode 100644 index 000000000..5b2f4efa3 --- /dev/null +++ b/src/modules/demos/catserv/Makefile @@ -0,0 +1,9 @@ +SRCS= ircd_catserv.c \ + catserv_messages.c \ + meow.c \ + purr.c + +TARGET=ircd_catserv + +include ../Makefile.sub + diff --git a/src/modules/demos/catserv/README b/src/modules/demos/catserv/README new file mode 100644 index 000000000..c3d3f7084 --- /dev/null +++ b/src/modules/demos/catserv/README @@ -0,0 +1,4 @@ +This is an EXAMPLE module, it serves no real purpose. + +This module was broken down into multiple files to demonstrate how multiple files can be used. + diff --git a/src/modules/demos/catserv/catserv_extern.h b/src/modules/demos/catserv/catserv_extern.h new file mode 100644 index 000000000..02c21addb --- /dev/null +++ b/src/modules/demos/catserv/catserv_extern.h @@ -0,0 +1,11 @@ +#ifndef CATSERV_DEFS_H +#define CATSERV_DEFS_H + +#ifdef _WIN32 +extern __declspec(dllexport) char *s_CatServ; +#else +E char *s_CatServ; +#endif + +#endif + diff --git a/src/modules/demos/catserv/catserv_messages.c b/src/modules/demos/catserv/catserv_messages.c new file mode 100644 index 000000000..e11235b4e --- /dev/null +++ b/src/modules/demos/catserv/catserv_messages.c @@ -0,0 +1,14 @@ +#include "catserv_messages.h" +#include "module.h" +#include "meow.h" +#include "purr.h" + +void addMessageList(void) +{ + Command *c; + c = createCommand("meow", do_meow, NULL, -1, -1, -1, -1, -1); + moduleAddCommand(Catserv_cmdTable, c, MOD_UNIQUE); + c = createCommand("purr", do_purr, NULL, -1, -1, -1, -1, -1); + moduleAddCommand(Catserv_cmdTable, c, MOD_UNIQUE); +} + diff --git a/src/modules/demos/catserv/catserv_messages.h b/src/modules/demos/catserv/catserv_messages.h new file mode 100644 index 000000000..bb3f82dd0 --- /dev/null +++ b/src/modules/demos/catserv/catserv_messages.h @@ -0,0 +1,10 @@ +#ifndef CATSERV_MESSAGES_H +#define CATSERV_MESSAGES_H + +#include "module.h" + +CommandHash *Catserv_cmdTable[MAX_CMD_HASH]; +void addMessageList(void); + +#endif + diff --git a/src/modules/demos/catserv/ircd_catserv.c b/src/modules/demos/catserv/ircd_catserv.c new file mode 100644 index 000000000..ae34d6161 --- /dev/null +++ b/src/modules/demos/catserv/ircd_catserv.c @@ -0,0 +1,112 @@ +/** + * Simple module to load up a client called CatServ and process commands for it + * This module is an example, and has no useful purpose! + * + * Please visit http://modules.anope.org for useful modules! + * + **/ + +#include "module.h" +#include "catserv_messages.h" + +#define AUTHOR "Anope" +#define VERSION "$Id$" + +int my_privmsg(char *source, int ac, char **av); + +void addClient(char *nick, char *realname); +void delClient(void); +void catserv(User * u, char *buf); + +char *s_CatServ = "CatServ"; + +int AnopeInit(int argc, char **argv) +{ + Message *msg = NULL; + int status; +#ifdef IRC_UNREAL32 + if (UseTokens) { + msg = createMessage("!", my_privmsg); + } else { + msg = createMessage("PRIVMSG", my_privmsg); + } +#else + msg = createMessage("PRIVMSG", my_privmsg); +#endif + status = moduleAddMessage(msg, MOD_HEAD); + if (status == MOD_ERR_OK) { + addClient(s_CatServ, "meow!"); + addMessageList(); + } + moduleAddAuthor(AUTHOR); + moduleAddVersion(VERSION); + alog("ircd_catserv.so: loaded, message status [%d]", status); + return MOD_CONT; +} + +void AnopeFini(void) +{ + delClient(); +} + +int my_privmsg(char *source, int ac, char **av) +{ + User *u; + char *s; + + /* First, some basic checks */ + if (ac != 2) + return MOD_CONT; /* bleh */ + if (!(u = finduser(source))) { + return MOD_CONT; + } /* non-user source */ + if (*av[0] == '#') { + return MOD_CONT; + } + /* Channel message */ + /* we should prolly honour the ignore list here, but i cba for this... */ + s = strchr(av[0], '@'); + if (s) { + *s++ = 0; + if (stricmp(s, ServerName) != 0) + return MOD_CONT; + } + if ((stricmp(av[0], s_CatServ)) == 0) { /* its for US! */ + catserv(u, av[1]); + return MOD_STOP; + } else { /* ok it isnt us, let the old code have it */ + return MOD_CONT; + } +} + +void addClient(char *nick, char *realname) +{ + anope_cmd_bot_nick(nick, "catserv", "meow.meow.land", realname, "+"); +} + +void delClient(void) +{ + anope_cmd_quit(s_CatServ, "QUIT :Module Unloaded!"); +} + +/*****************************************************************************/ +/* Main CatServ routine. */ +void catserv(User * u, char *buf) +{ + char *cmd, *s; + + cmd = strtok(buf, " "); + + if (!cmd) { + return; + } else if (stricmp(cmd, "\1PING") == 0) { + if (!(s = strtok(NULL, ""))) + s = "\1"; + notice(s_CatServ, u->nick, "\1PING %s", s); + } else if (skeleton) { + notice_lang(s_CatServ, u, SERVICE_OFFLINE, s_CatServ); + } else { + mod_run_cmd(s_CatServ, u, Catserv_cmdTable, cmd); + } +} + diff --git a/src/modules/demos/catserv/makefile.win32 b/src/modules/demos/catserv/makefile.win32 new file mode 100644 index 000000000..638704440 --- /dev/null +++ b/src/modules/demos/catserv/makefile.win32 @@ -0,0 +1,4 @@ +SRCS=ircd_catserv.c purr.c catserv_messages.c meow.c +TARGET=ircd_catserv.dll + +include ..\Makefile.sub.win32 diff --git a/src/modules/demos/catserv/meow.c b/src/modules/demos/catserv/meow.c new file mode 100644 index 000000000..9279eec0b --- /dev/null +++ b/src/modules/demos/catserv/meow.c @@ -0,0 +1,9 @@ +#include "meow.h" + +#include "catserv_extern.h" + +int do_meow(User * u) { + notice(s_CatServ, u->nick, "MEOW!"); + return MOD_STOP; +} + diff --git a/src/modules/demos/catserv/meow.h b/src/modules/demos/catserv/meow.h new file mode 100644 index 000000000..0f28673a0 --- /dev/null +++ b/src/modules/demos/catserv/meow.h @@ -0,0 +1,9 @@ +#ifndef CATSERV_MEOW_H +#define CATSERV_MEOW_H + +#include "module.h" + +int do_meow(User * u); + +#endif + diff --git a/src/modules/demos/catserv/purr.c b/src/modules/demos/catserv/purr.c new file mode 100644 index 000000000..5a39dc26e --- /dev/null +++ b/src/modules/demos/catserv/purr.c @@ -0,0 +1,8 @@ +#include "purr.h" +#include "catserv_extern.h" + +int do_purr(User * u) +{ + notice(s_CatServ, u->nick, "PURR!"); + return MOD_STOP; +} diff --git a/src/modules/demos/catserv/purr.h b/src/modules/demos/catserv/purr.h new file mode 100644 index 000000000..a92e421f6 --- /dev/null +++ b/src/modules/demos/catserv/purr.h @@ -0,0 +1,9 @@ +#ifndef CATSERV_PURR_H +#define CATSERV_PURR_H + +#include "module.h" + +int do_purr(User * u); + +#endif + diff --git a/src/modules/demos/events.c b/src/modules/demos/events.c new file mode 100644 index 000000000..dad0fd0e6 --- /dev/null +++ b/src/modules/demos/events.c @@ -0,0 +1,82 @@ +/** + * Simple module to show the usage of event messages and hooks + * This module is an example, and has no useful purpose! + * + * Please visit http://modules.anope.org for useful modules! + * + **/ + +#include "module.h" + +#define AUTHOR "Anope" +#define VERSION "$Id$" + +int my_nick(char *source, int ac, char **av); +int my_save(int argc, char **argv); +int do_moo(int argc, char **argv); + +int AnopeInit(int argc, char **argv) +{ + EvtMessage *msg = NULL; + EvtHook *hook = NULL; + int status; + msg = createEventHandler("NICK", my_nick); + status = moduleAddEventHandler(msg); + + hook = createEventHook(EVENT_DB_SAVING, my_save); + status = moduleAddEventHook(hook); + + + hook = createEventHook(EVENT_BOT_FANTASY, do_moo); + status = moduleAddEventHook(hook); + + moduleAddAuthor(AUTHOR); + moduleAddVersion(VERSION); + return MOD_CONT; +} + +void AnopeFini(void) +{ + /* unloading */ +} + +int my_nick(char *source, int ac, char **av) +{ + alog("Internal Event - nick is %s",av[0]); + return MOD_CONT; +} + +int my_save(int argc, char **argv) +{ + if(argc>=1) { + if (!stricmp(argv[0], EVENT_START)) { + alog("Saving the databases! has started"); + } else { + alog("Saving the databases is complete"); + } + } + return MOD_CONT; +} + +/** + * command to be called when a EVENT_BOT_FANTASY event is recived. + * @param argc The paramater count for this event. + * @param argv[0] The cmd used. + * @param argv[1] The nick of the command user. + * @param argv[2] The channel name the command was used in. + * @param argv[3] The rest of the text after the command. + * @return MOD_CONT or MOD_STOP + **/ +int do_moo(int argc, char **argv) { + ChannelInfo *ci; + if(argc>=3) { /* We need at least 3 arguments */ + if(stricmp(argv[0],"moo")==0) { /* is it meant for us? */ + if((ci = cs_findchan(argv[2]))) { /* channel should always exist */ + anope_cmd_privmsg(ci->bi->nick, ci->name, "%cACTION moo's at %s %c",1,argv[1],1); + return MOD_STOP; /* We've dealt with it, dont let others */ + } + } + } + return MOD_CONT; /* guess it wasnt for us, pass it on */ +} + diff --git a/src/modules/demos/hs_conf.c b/src/modules/demos/hs_conf.c new file mode 100644 index 000000000..45b4bb330 --- /dev/null +++ b/src/modules/demos/hs_conf.c @@ -0,0 +1,74 @@ +#include "module.h" + +#define AUTHOR "Anope" +#define VERSION "1" + +/** + * Default setting to be used if no confing value is found + **/ +#define DEFAULT_SETTING "moo" + +int mShowSetting(User *u); +int mReadConfig(int argc, char **argv); + +char *setting; + +int AnopeInit(int argc, char **argv) { + Command *c; + EvtHook *hook; + int status = 0; + + setting = NULL; + + mReadConfig(0,NULL); + + c = createCommand("SHOW",mShowSetting,NULL,-1,-1,-1,-1,-1); + status = moduleAddCommand(HOSTSERV, c, MOD_HEAD); + + hook = createEventHook(EVENT_RELOAD, mReadConfig); + status = moduleAddEventHook(hook); + + if(status!=MOD_ERR_OK) { + return MOD_STOP; + } + return MOD_CONT; +} + +/** + * free the globals when we close + **/ +void AnopeFini(void) { + if(setting) + free(setting); +} + +/** + * Simple function to show the user the current config setting + **/ +int mShowSetting(User *u) { + notice(s_HostServ,u->nick,"Setting in use is [%s]",setting); + return MOD_CONT; +} + +/** + * Load the config setting up, this will be called whenever + * the EVENT_RELOAD event is recived. + **/ +int mReadConfig(int argc, char **argv) { + char *tmp=NULL; + Directive d[] = {{"HSConfigSetting", {{PARAM_STRING, PARAM_RELOAD, &tmp}}}}; + moduleGetConfigDirective(d); + + if(setting) { + free(setting); + } + if(tmp) { + setting = tmp; + } else { + setting = sstrdup(DEFAULT_SETTING); + } + return MOD_CONT; +} + + +/* EOF */ diff --git a/src/modules/demos/hs_moo.c b/src/modules/demos/hs_moo.c new file mode 100644 index 000000000..b65e83bb6 --- /dev/null +++ b/src/modules/demos/hs_moo.c @@ -0,0 +1,119 @@ +/** + * This is an EXAMPLE module, which adds the "moo" command to HostServ + * + * This command does NOT do anything useful at all! + * + * Please visit http://modules.anope.org for useful modules! + * + **/ +#include "module.h" + +#define AUTHOR "Anope" /* Set the Author for a modinfo reply */ +#define VERSION "$Id$" /* Set the version for a modinfo reply */ + +int hs_moo_show(User * u); /* Function to use when a /hs moo command is recived */ +int test(int argc, char **argv); +void myHostServHelp(User *u); /* Function to display out help in a /hs help response */ +int myHostServMooHelp(User *u); /* Function to display help to _everyone_ when a /hs help moo is called*/ +int myHostServMooRegHelp(User *u); /* Function to display extra help to regular-users when a /hs help moo is called*/ +int myHostServMooOperHelp(User *u); /* Function to display extra help to opers when a /hs help moo is called*/ +int myHostServMooAdminHelp(User *u); /* Function to display extra help to admins when a /hs help moo is called*/ +int myHostServMooRootHelp(User *u); /* Function to display extra help to roors when a /hs help moo is called*/ + +int AnopeInit(int argc, char **argv) /* This will be executed when the module is loaded */ +{ + Command *c; /* Pointer to a Command */ + int status = 0; /* the status of our new command */ + c = createCommand("moo", hs_moo_show, NULL, -1, -1, -1, -1, -1); /* Create a new command "moo" pointing to hs_moo */ + + moduleAddHelp(c,myHostServMooHelp); /* add help for all users to this command */ + moduleAddRegHelp(c,myHostServMooRegHelp); /* add extra regular-user only help to this command */ + moduleAddOperHelp(c,myHostServMooOperHelp); /* add extra oper only help to this command */ + moduleAddAdminHelp(c,myHostServMooAdminHelp); /* add extra admin only help to this command */ + moduleAddRootHelp(c,myHostServMooRootHelp); /* add extra root only help to this command */ + + moduleSetHostHelp(myHostServHelp); /* add us to the .hs help list */ + + status = moduleAddCommand(HOSTSERV, c, MOD_HEAD); /* Add the command to the HOSTSERV cmd table */ + + /* Check if we have any argv's */ + if(argc>0) { + /* we do, the first will be the nick of the person modload'ing us */ + /* or NULL if we were auto-loaded */ + if(argv[0]) { + alog("hs_moo was modloaded by: [%s]",argv[0]); + } else { + alog("hs_moo was automatically loaded by anope"); + } + } + alog("hs_moo.so: Add Command 'moo' Status: %d",status); /* Log the command being added */ + + moduleAddCallback("test",time(NULL)+dotime("15s"),test,0,NULL); /* set a call-back function to exec in 3 mins time */ + moduleDelCallback("test"); + moduleAddAuthor(AUTHOR); /* tell Anope about the author */ + moduleAddVersion(VERSION); /* Tell Anope about the verison */ + + if(status!=MOD_ERR_OK) { + return MOD_STOP; + } + return MOD_CONT; +} + +int hs_moo_show(User * u) +{ + notice(s_HostServ, u->nick, "MOO! - This command was loaded via a module!"); /* Just notice the user */ + return MOD_STOP; /* MOD_STOP means we will NOT pass control back to other */ +} /* modules waiting to handle the /hs moo command! */ + +int test(int argc, char **argv) { + alog("CallBack from hs_moo with %d paramaters",argc); + return MOD_CONT; +} + +void AnopeFini(void) +{ + /* module is unloading */ +} + +/***************************************************************************************************************************************/ +/* The code below here shows various ways of dealing with the module help system */ +/***************************************************************************************************************************************/ + +void myHostServHelp(User *u) { + notice(s_HostServ,u->nick, " MOO Moo's at the user!"); /* this will appear in the help list */ +} + +int myHostServMooHelp(User *u) { + notice(s_HostServ,u->nick,"Syntax: Moo"); /* this will be sent to everyone who does /msg hostserv help moo */ + notice(s_HostServ,u->nick,"This command is an example provided"); + notice(s_HostServ,u->nick,"by the Anope development team."); + return MOD_CONT; /* allow any other module's with help for /hs moo to run */ +} + +int myHostServMooRootHelp(User *u) { /* this will only be sent to ROOTS ONLY who /msg hostserv moo */ + myHostServMooAdminHelp(u); /* this line lets us show roots the ADMIN help as well as the root help */ + notice(s_HostServ,u->nick,"Only roots will see this part of the help"); + return MOD_CONT; +} + +int myHostServMooAdminHelp(User *u) { /* this will only be sent to ADMINS ONLY who /msg hostserv moo */ + myHostServMooOperHelp(u); /* this line lets us show admins the OPER help as well as the admin help */ + notice(s_HostServ,u->nick,"Only admins will see this part of the help"); + notice(s_HostServ,u->nick,"why not visit us on www.anope.org ?"); + return MOD_CONT; +} + +int myHostServMooOperHelp(User *u) { /* this will only be sent to OPERS ONLY who /msg hostserv moo */ + notice(s_HostServ,u->nick,"Only opers will see this part of the help"); + notice(s_HostServ,u->nick,"for more help/support with modules"); + notice(s_HostServ,u->nick,"visit us on irc.anope.org #anope! :)"); + return MOD_CONT; +} + +int myHostServMooRegHelp(User *u) { /* this will only be sent to REGULAR USERS ONLY who /msg hostserv moo */ + notice(s_HostServ,u->nick,"Only non-opers will see this part of the help"); + notice(s_HostServ,u->nick,"as we've left it hidden from opers"); + return MOD_CONT; +} + +/* EOF */ |