changed Makefile; build all commands as an own file
[NeonServV5.git] / IRCEvents.c
index c0b7eacea9fb9c080a8d7331a99d5a178d130209..58efd37cc8132351a8a2fbf9c283a88b764eb161 100644 (file)
@@ -4,6 +4,7 @@
 #include "ChanNode.h"
 #include "ChanUser.h"
 #include "ClientSocket.h"
+#include "mysqlConn.h"
 
 struct binding {
     void *func;
@@ -26,13 +27,26 @@ static void **binds;
 #define BIND_TYPE_PRIVCTCP   12
 #define BIND_TYPE_INVITE     13
 #define BIND_TYPE_RAW        14
+#define BIND_TYPE_BOT_READY  15
 
-#define TOTAL_BIND_TYPES     15
+#define TOTAL_BIND_TYPES     16
 
 void init_bind() {
     binds = calloc(TOTAL_BIND_TYPES, sizeof(*binds));
 }
 
+void free_bind() {
+    struct binding *cbind, *next;
+    int i;
+    for(i = 0; i < TOTAL_BIND_TYPES; i++) {
+        for(cbind = binds[i]; cbind; cbind = next) {
+            next = cbind->next;
+            free(cbind);
+        }
+    }
+    free(binds);
+}
+
 static int is_bound(unsigned char type, void *func) {
     struct binding *cbind;
     for(cbind = binds[type]; cbind; cbind = cbind->next) {
@@ -77,13 +91,23 @@ void unbind_##NAME(FUNCTYPE *func) { \
 #define FUNC_EVENT(NAME,FUNCTYPE,TYPE,PDECLARATION,PLIST) \
 int event_##NAME PDECLARATION { \
     struct binding *cbind; \
+    pre_event(TYPE); \
     for(cbind = binds[TYPE]; cbind; cbind = cbind->next) { \
         FUNCTYPE *func = cbind->func; \
         func PLIST; \
     } \
+    post_event(TYPE); \
     return 1; \
 }
 
+void pre_event(UNUSED_ARG(int type)) {
+
+}
+
+void post_event(UNUSED_ARG(int type)) {
+    mysql_free();
+}
+
 //EVENTS
 
 FUNC_BIND(join, join_func_t, BIND_TYPE_JOIN)
@@ -140,9 +164,12 @@ FUNC_EVENT(privctcp, privctcp_func_t, BIND_TYPE_PRIVCTCP, (struct UserNode *user
 
 FUNC_BIND(invite, invite_func_t, BIND_TYPE_INVITE)
 FUNC_UNBIND(invite, invite_func_t, BIND_TYPE_INVITE)
-FUNC_EVENT(invite, invite_func_t, BIND_TYPE_INVITE, (struct UserNode *user, char *channel), (user, channel))
+FUNC_EVENT(invite, invite_func_t, BIND_TYPE_INVITE, (struct ClientSocket *client, struct UserNode *user, char *channel), (client, user, channel))
 
 FUNC_BIND(raw, raw_func_t, BIND_TYPE_RAW)
 FUNC_UNBIND(raw, raw_func_t, BIND_TYPE_RAW)
 FUNC_EVENT(raw, raw_func_t, BIND_TYPE_RAW, (struct ClientSocket *client, char *from, char *cmd, char **argv, int argc), (client, from, cmd, argv, argc))
 
+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))