rewrote IRC cache parser to be (hopefully) more stable
[NeonServV5.git] / src / IRCEvents.c
index eb29a094ff23f8c3ea238b1c3ea81c488afb1d5f..56bc57e16e51b06ac89ef9836157cdfb85f78ad5 100644 (file)
@@ -1,4 +1,4 @@
-/* IRCEvents.c - NeonServ v5.3
+/* IRCEvents.c - NeonServ v5.4
  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
  * 
  * This program is free software: you can redistribute it and/or modify
@@ -24,6 +24,7 @@
 
 struct binding {
     void *func;
+    int module_id;
     struct binding *next;
 };
 
@@ -66,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) {
@@ -76,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) { \
@@ -84,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; \
@@ -139,11 +160,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)
@@ -195,17 +212,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)