diff --git a/Changes b/Changes index 4de7813dd..0ce68cf58 100644 --- a/Changes +++ b/Changes @@ -347,3 +347,4 @@ - Using ERR_NOPRIVLEDGES (says you aren't oper) - Disabled commands allowed by unregistered users from registered users - Removed networks/unrealircd.conf +- Added Hooks, only one working now is HOOKTYPE_LOCAL_QUIT diff --git a/include/modules.h b/include/modules.h index d01812982..96ad96041 100644 --- a/include/modules.h +++ b/include/modules.h @@ -21,6 +21,8 @@ #define MOD_VERSION 1 #define MAXMODULES 50 +#define MAXHOOKTYPES 20 + #ifdef _WIN32 #define DLLFUNC _declspec(dllexport) #define irc_dlopen(x,y) LoadLibrary(x) @@ -55,10 +57,18 @@ struct moduleInfo }; extern ModuleInfo *module_buffer; - +extern Hook *Hooks[MAXHOOKTYPES]; +extern Hook *global_i; void module_init(void); int load_module(char *module); int unload_module(char *name); vFP module_sym(char *name); +void add_Hook(int hooktype, int (*func)()); +void del_Hook(int hooktype, int (*func)()); + +#define RunHook(hooktype,x) for (global_i = Hooks[hooktype]; global_i; global_i = global_i->next) (*global_i->func)(x) + +#define HOOKTYPE_LOCAL_QUIT 1 + diff --git a/include/struct.h b/include/struct.h index f216d80ed..316cc62fa 100644 --- a/include/struct.h +++ b/include/struct.h @@ -27,7 +27,6 @@ #include "common.h" #include "sys.h" #include "hash.h" -#include "modules.h" #include #include #ifdef ZIP_LINKS @@ -102,6 +101,8 @@ typedef struct Command aCommand; typedef struct SMember Member; typedef struct SMembership Membership; typedef struct SMembershipL MembershipL; +typedef struct _irchook Hook; + #ifdef NEED_U_INT32_T typedef unsigned int u_int32_t; /* XXX Hope this works! */ #endif @@ -924,6 +925,7 @@ struct _configflag_ban #define CRULE_AUTO 1 + struct _configitem { ConfigFlag flag; ConfigItem *prev, *next; @@ -1067,6 +1069,12 @@ struct _configitem_allow_channel { char *channel; }; +struct _irchook { + ConfigFlag flag; + Hook *prev, *next; + int (*func)(); +}; + /* * statistics structures */ @@ -1365,6 +1373,7 @@ extern char *gnulicense[]; #include "ssl.h" #endif #define HASH_TEST HASH_CHECK +#include "modules.h" #endif /* __struct_include__ */ diff --git a/src/modules.c b/src/modules.c index a8eca9532..685f9d6b3 100644 --- a/src/modules.c +++ b/src/modules.c @@ -43,11 +43,15 @@ #include "h.h" ModuleInfo *Modules[MAXMODULES]; +Hook *Hooks[MAXHOOKTYPES]; +Hook *global_i = NULL; int modules_loaded = 0; + ModuleInfo *module_buffer; void module_init(void) { bzero(Modules, sizeof(Modules)); + bzero(Hooks, sizeof(Hooks)); modules_loaded = 0; } @@ -235,7 +239,7 @@ int m_module(aClient *cptr, aClient *sptr, int parc, char *parv[]) if (parc < 3) { sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), - me.name, parv[0], "MODULES LOAD"); + me.name, parv[0], "MODULE LOAD"); return 0; } sendto_realops("Trying to load module %s", parv[2]); @@ -248,7 +252,7 @@ int m_module(aClient *cptr, aClient *sptr, int parc, char *parv[]) if (parc < 3) { sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), - me.name, parv[0], "MODULES UNLOAD"); + me.name, parv[0], "MODULE UNLOAD"); return 0; } sendto_realops("Trying to unload module %s", parv[2]); @@ -279,4 +283,24 @@ int m_module(aClient *cptr, aClient *sptr, int parc, char *parv[]) return 1; } +void add_Hook(int hooktype, int (*func)()) +{ + Hook *p; + + p = (Hook *) MyMallocEx(sizeof(Hook)); + p->func = func; + add_ConfigItem((ConfigItem *) p, (ConfigItem **) &Hooks[hooktype]); +} + +void del_Hook(int hooktype, int (*func)()) +{ + Hook *p; + + for (p = Hooks[hooktype]; p; p = p->next) + if (p->func == func) + { + del_ConfigItem((ConfigItem *) p, (ConfigItem **) &Hooks[hooktype]); + return; + } +} diff --git a/src/s_conf.c b/src/s_conf.c index 5f484ee8a..a3af04e0d 100644 --- a/src/s_conf.c +++ b/src/s_conf.c @@ -306,7 +306,7 @@ ConfigItem *del_ConfigItem(ConfigItem *item, ConfigItem **list) int config_error_flag = 0; /* Small function to bitch about stuff */ -static void config_error(char *format, ...) +void config_error(char *format, ...) { va_list ap; char buffer[1024]; diff --git a/src/s_misc.c b/src/s_misc.c index d9dd711d5..3de5e6d79 100644 --- a/src/s_misc.c +++ b/src/s_misc.c @@ -474,6 +474,7 @@ int exit_client(cptr, sptr, from, comment) sptr->flags |= FLAGS_CLOSING; if (IsPerson(sptr)) { + RunHook(HOOKTYPE_LOCAL_QUIT, sptr); sendto_umode(UMODE_OPER | UMODE_CLIENT, "*** Notice -- Client exiting: %s (%s@%s) [%s]", sptr->name, sptr->user->username,