X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=blobdiff_plain;f=src%2FIRCEvents.c;h=2eea34d8ecc1067bddf693e2a721b6a748abeee7;hp=9e0222bcbb1afaabc915d63045ae40a3d30acd7b;hb=HEAD;hpb=706e48b1e666054030c491d864f740071e390038 diff --git a/src/IRCEvents.c b/src/IRCEvents.c index 9e0222b..2eea34d 100644 --- a/src/IRCEvents.c +++ b/src/IRCEvents.c @@ -1,4 +1,4 @@ -/* IRCEvents.c - NeonServ v5.3 +/* IRCEvents.c - NeonServ v5.6 * Copyright (C) 2011-2012 Philipp Kreil (pk910) * * This program is free software: you can redistribute it and/or modify @@ -21,6 +21,7 @@ #include "ChanUser.h" #include "ClientSocket.h" #include "mysqlConn.h" +#include "log.h" struct binding { void *func; @@ -28,7 +29,7 @@ struct binding { struct binding *next; }; -static void **binds; +static void **binds = NULL; #define BIND_TYPE_JOIN 0 #define BIND_TYPE_NICK 1 #define BIND_TYPE_PART 2 @@ -48,10 +49,14 @@ static void **binds; #define BIND_TYPE_REGISTERED 16 #define BIND_TYPE_FREEUSER 17 #define BIND_TYPE_FREECHAN 18 +#define BIND_TYPE_RELOAD 19 +#define BIND_TYPE_FREECLIENT 20 -#define TOTAL_BIND_TYPES 19 +#define TOTAL_BIND_TYPES 21 void init_bind() { + if(binds) + return; binds = calloc(TOTAL_BIND_TYPES, sizeof(*binds)); } @@ -65,6 +70,7 @@ void free_bind() { } } free(binds); + binds = NULL; } void unregister_module_events(int module_id) { @@ -100,11 +106,11 @@ int bind_##NAME(FUNCTYPE *func, int module_id) { \ if(!is_bound(TYPE, func)) { \ struct binding *cbind = malloc(sizeof(*cbind)); \ if (!cbind) { \ - perror("malloc() failed"); \ + printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); \ return 0; \ } \ cbind->func = func; \ - cbind->module_id = module_id \ + cbind->module_id = module_id; \ cbind->next = binds[TYPE]; \ binds[TYPE] = cbind; \ return 1; \ @@ -160,11 +166,7 @@ FUNC_EVENT(nick, nick_func_t, BIND_TYPE_NICK, (struct UserNode *user, char *new_ FUNC_BIND(part, part_func_t, BIND_TYPE_PART) FUNC_UNBIND(part, part_func_t, BIND_TYPE_PART) -FUNC_EVENT(part, part_func_t, BIND_TYPE_PART, (struct ChanUser *chanuser, char *reason), (chanuser, reason)) - -FUNC_BIND(quit, quit_func_t, BIND_TYPE_QUIT) -FUNC_UNBIND(quit, quit_func_t, BIND_TYPE_QUIT) -FUNC_EVENT(quit, quit_func_t, BIND_TYPE_QUIT, (struct UserNode *user, char *reason), (user, reason)) +FUNC_EVENT(part, part_func_t, BIND_TYPE_PART, (struct ChanUser *chanuser, int quit, char *reason), (chanuser, quit, reason)) FUNC_BIND(kick, kick_func_t, BIND_TYPE_KICK) FUNC_UNBIND(kick, kick_func_t, BIND_TYPE_KICK) @@ -216,17 +218,7 @@ FUNC_EVENT(bot_ready, bot_ready_func_t, BIND_TYPE_BOT_READY, (struct ClientSocke 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_EVENT(registered, registered_func_t, BIND_TYPE_REGISTERED, (struct UserNode *user, char *new_mask), (user, new_mask)) FUNC_BIND(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER) FUNC_UNBIND(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER) @@ -235,3 +227,11 @@ FUNC_EVENT(freeuser, freeuser_func_t, BIND_TYPE_FREEUSER, (struct UserNode *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)) + +FUNC_BIND(reload, reload_func_t, BIND_TYPE_RELOAD) +FUNC_UNBIND(reload, reload_func_t, BIND_TYPE_RELOAD) +FUNC_EVENT(reload, reload_func_t, BIND_TYPE_RELOAD, (int initialization), (initialization)) + +FUNC_BIND(freeclient, freeclient_func_t, BIND_TYPE_FREECLIENT) +FUNC_UNBIND(freeclient, freeclient_func_t, BIND_TYPE_FREECLIENT) +FUNC_EVENT(freeclient, freeclient_func_t, BIND_TYPE_FREECLIENT, (struct ClientSocket *client), (client))