moved cmds to extra files and loading binds from the database
authorpk910 <philipp@zoelle1.de>
Wed, 17 Aug 2011 03:15:19 +0000 (05:15 +0200)
committerpk910 <philipp@zoelle1.de>
Wed, 17 Aug 2011 03:15:19 +0000 (05:15 +0200)
bot_NeonServ.c
cmd_neonserv_modes.c [new file with mode: 0644]
cmd_neonserv_users.c [new file with mode: 0644]
modcmd.c
modcmd.h

index 1621d3c5a8497663f9f7fdc573482c623e222f74..7237bcf10652e885d1354affd78534f1f0dc4d68 100644 (file)
@@ -16,19 +16,11 @@ static const struct default_language_entry msgtab[] = {
     {NULL, NULL}
 };
 
-static CMD_BIND(neonserv_cmd_users) {
-    struct ChanUser *chanuser;
-    putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name);
-    for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
-        putsock(client, "PRIVMSG %s :  %s!%s@%s [%s]  rights: %d", chan->name, chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "*"), chanuser->flags);
-    }
-}
-
-static CMD_BIND(neonserv_cmd_modes) {
-    char modeBuf[MAXLEN];
-    getModeString(chan, modeBuf);
-    putsock(client, "PRIVMSG %s :Modes: %s", chan->name, modeBuf);
-}
+/*
+INCLUDE ALL CMD's HERE
+*/
+#include "cmd_neonserv_users.c"
+#include "cmd_neonserv_modes.c"
 
 static void neonserv_bot_ready(struct ClientSocket *client) {
     MYSQL_RES *res;
@@ -70,7 +62,14 @@ static void start_bots() {
         printf_mysql_query("SELECT `command`, `function`, `parameters`, `global_access` FROM `bot_binds` WHERE `botid` = '%d'", client->clientid);
         res2 = mysql_use();
         while ((row = mysql_fetch_row(res2)) != NULL) {
-            
+            if(bind_cmd_to_command(BOTID, row[0], row[1])) {
+                if(row[2] && strcmp(row[2], "")) {
+                    bind_set_parameters(BOTID, row[0], row[2]);
+                }
+                if(atoi(row[3]) > 0) {
+                    bind_set_gaccess(BOTID, row[0], atoi(row[3]));
+                }
+            }
         }
     }
 }
@@ -84,8 +83,6 @@ void init_NeonServ() {
     start_bots();
     bind_bot_ready(neonserv_bot_ready);
     set_trigger_callback(BOTID, neonserv_trigger_callback);
-    bind_cmd_to_command(BOTID, "users", "users");
-    bind_cmd_to_command(BOTID, "modes", "modes");
     
     register_default_language_table(msgtab);
 }
diff --git a/cmd_neonserv_modes.c b/cmd_neonserv_modes.c
new file mode 100644 (file)
index 0000000..b2240aa
--- /dev/null
@@ -0,0 +1,6 @@
+
+static CMD_BIND(neonserv_cmd_modes) {
+    char modeBuf[MAXLEN];
+    getModeString(chan, modeBuf);
+    putsock(client, "PRIVMSG %s :Modes: %s", chan->name, modeBuf);
+}
diff --git a/cmd_neonserv_users.c b/cmd_neonserv_users.c
new file mode 100644 (file)
index 0000000..3011259
--- /dev/null
@@ -0,0 +1,8 @@
+
+static CMD_BIND(neonserv_cmd_users) {
+    struct ChanUser *chanuser;
+    putsock(client, "PRIVMSG %s :[BOT JOIN] Users on this Channel:", chan->name);
+    for(chanuser = getChannelUsers(chan, NULL); chanuser; chanuser = getChannelUsers(chan, chanuser)) {
+        putsock(client, "PRIVMSG %s :  %s!%s@%s [%s]  rights: %d", chan->name, chanuser->user->nick, chanuser->user->ident, chanuser->user->host, ((chanuser->user->flags & USERFLAG_ISAUTHED) ? chanuser->user->auth : "*"), chanuser->flags);
+    }
+}
index 96b0c8bc5204cecf603d2df0f979876bf54c4e51..469de2e20f5a10ddb08a5d9ed9dbef8045332a46 100644 (file)
--- a/modcmd.c
+++ b/modcmd.c
@@ -336,6 +336,7 @@ int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func) {
     cbind->cmd = strdup(cmd);
     cbind->func = func;
     cbind->parameters = NULL;
+    cbind->access = 0;
     cbind->flags = 0;
     cbind->next = cmd_binds[bind_index];
     cmd_binds[bind_index] = cbind;
@@ -365,6 +366,7 @@ int bind_cmd_to_command(int botid, char *cmd, char *func) {
     cbind->func = cmdfunc;
     cbind->next = cmd_binds[bind_index];
     cbind->parameters = NULL;
+    cbind->access = 0;
     cbind->flags = 0;
     cmd_binds[bind_index] = cbind;
     return 1;
@@ -429,3 +431,11 @@ void free_modcmd() {
     trigger_callbacks = NULL;
 }
 
+void bind_set_parameters(int botid, char *cmd, char *parameters) {
+    
+}
+
+void bind_set_gaccess(int botid, char *cmd, int access) {
+    
+}
+
index 30c0fd07439cbd872ca7d0efb5faf152cd86202b..8b189863927a6b8756057f999cf02101833ee21f 100644 (file)
--- a/modcmd.h
+++ b/modcmd.h
@@ -32,6 +32,7 @@ struct cmd_binding {
     struct cmd_function *func;
     unsigned int flags;
     char *parameters;
+    int access;
     
     struct cmd_binding *next;
 };
@@ -53,5 +54,7 @@ int bind_cmd_to_function(int botid, char *cmd, struct cmd_function *func);
 int bind_cmd_to_command(int botid, char *cmd, char *func);
 int unbind_cmd(int botid, char *cmd);
 struct ClientSocket *getTextBot();
+void bind_set_parameters(int botid, char *cmd, char *parameters);
+void bind_set_gaccess(int botid, char *cmd, int access);
 
 #endif
\ No newline at end of file