X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FIRCEvents.c;h=b0cbd02a722f955a7276f3687f0f8629d7b2d58d;hb=902ebfe5551be2daa3edf8141bcee91f62c0a5e0;hp=58efd37cc8132351a8a2fbf9c283a88b764eb161;hpb=0f1dc61921eef1db8e404a5a82372e2d1cd55daa;p=NeonServV5.git diff --git a/src/IRCEvents.c b/src/IRCEvents.c index 58efd37..b0cbd02 100644 --- a/src/IRCEvents.c +++ b/src/IRCEvents.c @@ -1,3 +1,19 @@ +/* IRCEvents.c - NeonServ v5.3 + * Copyright (C) 2011-2012 Philipp Kreil (pk910) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ #include "IRCEvents.h" #include "UserNode.h" @@ -8,6 +24,7 @@ struct binding { void *func; + int module_id; struct binding *next; }; @@ -28,8 +45,11 @@ static void **binds; #define BIND_TYPE_INVITE 13 #define BIND_TYPE_RAW 14 #define BIND_TYPE_BOT_READY 15 +#define BIND_TYPE_REGISTERED 16 +#define BIND_TYPE_FREEUSER 17 +#define BIND_TYPE_FREECHAN 18 -#define TOTAL_BIND_TYPES 16 +#define TOTAL_BIND_TYPES 19 void init_bind() { binds = calloc(TOTAL_BIND_TYPES, sizeof(*binds)); @@ -47,6 +67,25 @@ void free_bind() { free(binds); } +void unregister_module_events(int module_id) { + struct binding *cbind, *next, *prev; + int i; + for(i = 0; i < TOTAL_BIND_TYPES; i++) { + prev = NULL; + for(cbind = binds[i]; cbind; cbind = next) { + next = cbind->next; + if(cbind->module_id == module_id) { + if(prev) + prev->next = next; + else + binds[i] = next; + free(cbind); + } else + prev = cbind; + } + } +} + static int is_bound(unsigned char type, void *func) { struct binding *cbind; for(cbind = binds[type]; cbind; cbind = cbind->next) { @@ -57,7 +96,7 @@ static int is_bound(unsigned char type, void *func) { } #define FUNC_BIND(NAME,FUNCTYPE,TYPE) \ -int bind_##NAME(FUNCTYPE *func) { \ +int bind_##NAME(FUNCTYPE *func, int module_id) { \ if(!is_bound(TYPE, func)) { \ struct binding *cbind = malloc(sizeof(*cbind)); \ if (!cbind) { \ @@ -65,6 +104,7 @@ int bind_##NAME(FUNCTYPE *func) { \ return 0; \ } \ cbind->func = func; \ + cbind->module_id = module_id; \ cbind->next = binds[TYPE]; \ binds[TYPE] = cbind; \ return 1; \ @@ -105,7 +145,7 @@ void pre_event(UNUSED_ARG(int type)) { } void post_event(UNUSED_ARG(int type)) { - mysql_free(); + } //EVENTS @@ -173,3 +213,25 @@ FUNC_EVENT(raw, raw_func_t, BIND_TYPE_RAW, (struct ClientSocket *client, char *f FUNC_BIND(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY) FUNC_UNBIND(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY) FUNC_EVENT(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY, (struct ClientSocket *client), (client)) + +FUNC_BIND(registered, registered_func_t, BIND_TYPE_REGISTERED) +FUNC_UNBIND(registered, registered_func_t, BIND_TYPE_REGISTERED) +int event_registered(struct UserNode *old_user, struct UserNode *new_user) { + struct binding *cbind; + int ret = 0; + pre_event(BIND_TYPE_REGISTERED); + for(cbind = binds[BIND_TYPE_REGISTERED]; cbind; cbind = cbind->next) { + registered_func_t *func = cbind->func; + ret |= func(old_user, new_user); + } + post_event(BIND_TYPE_REGISTERED); + return ret; +} + +FUNC_BIND(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER) +FUNC_UNBIND(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER) +FUNC_EVENT(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER, (struct UserNode *user), (user)) + +FUNC_BIND(freechan, freechan_func_t, BIND_TYPE_FREECHAN) +FUNC_UNBIND(freechan, freechan_func_t, BIND_TYPE_FREECHAN) +FUNC_EVENT(freechan, freechan_func_t, BIND_TYPE_FREECHAN, (struct ChanNode *chan), (chan))