added possibility to edit command flags (cmd_modcmd)
[NeonServV5.git] / src / modcmd.c
index 9af13218fc32a47f7a12efe713d5b83fadce5763..03b24d8351b984f6a9b53df311e9c79ce1ee0292 100644 (file)
@@ -204,7 +204,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 statistics_commands++;
             total_triggered++;
             cbind->triggered++;
-            if((cbind->func->flags & CMDFLAG_FUNCMD)) {
+            if((BIND_FLAGS(cbind) & CMDFLAG_FUNCMD)) {
                 if(!sent_chan)
                     break;
                 chan = sent_chan;
@@ -224,7 +224,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                     if (argc >= MAXNUMPARAMS)
                         break;
                     while ((escape || *args != ' ') && *args) {
-                        if((cbind->func->flags & CMDFLAG_ESCAPE_ARGS) && *args == '\\') {
+                        if((BIND_FLAGS(cbind) & CMDFLAG_ESCAPE_ARGS) && *args == '\\') {
                             escape = 1;
                             offset++;
                         } else if(escape)
@@ -242,7 +242,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 }
             }
             argv = arga;
-            if(argc != 0 && argv[0][0] == '#' && !(cbind->func->flags & CMDFLAG_CHAN_PARAM)) {
+            if(argc != 0 && argv[0][0] == '#' && !(BIND_FLAGS(cbind) & CMDFLAG_CHAN_PARAM)) {
                 struct ChanNode *chan2 = getChanByName(argv[0]);
                 if(chan2) {
                     argv += 1;
@@ -307,7 +307,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                                     }
                                     args_pos++;
                                 }
-                            } else if((cbind->func->flags & CMDFLAG_EMPTY_ARGS)) {
+                            } else if((BIND_FLAGS(cbind) & CMDFLAG_EMPTY_ARGS)) {
                                 uargs[uargc++] = args_buffer + args_pos;
                                 args_buffer[args_pos++] = '\0';
                             } else if(c) {
@@ -334,11 +334,11 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 reply(tmp_text_client, user, "MODCMD_LESS_PARAM_COUNT");
                 break;
             }
-            if((cbind->func->flags & CMDFLAG_REQUIRE_CHAN) && !chan) {
+            if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_CHAN) && !chan) {
                 reply(tmp_text_client, user, "MODCMD_CHAN_REQUIRED");
                 break;
             }
-            if(((cbind->func->flags & CMDFLAG_CHECK_AUTH) || (chan && chan != sent_chan && !isUserOnChan(user, chan))) && !(user->flags & USERFLAG_ISAUTHED)) {
+            if(((BIND_FLAGS(cbind) & CMDFLAG_CHECK_AUTH) || (chan && chan != sent_chan && !isUserOnChan(user, chan))) && !(user->flags & USERFLAG_ISAUTHED)) {
                 //check auth...
                 struct command_check_user_cache *data = malloc(sizeof(*data));
                 char **temp_argv = malloc(argc*sizeof(*temp_argv));
@@ -376,8 +376,8 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
     MYSQL_ROW row;
     int uaccess;
     char requested_uaccess = 0;
-    int eventflags = (cbind->func->flags & (CMDFLAG_LOG | CMDFLAG_OPLOG));
-    if((cbind->func->flags & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
+    int eventflags = (BIND_FLAGS(cbind) & (CMDFLAG_LOG | CMDFLAG_OPLOG));
+    if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_AUTH) && !(user->flags & USERFLAG_ISAUTHED)) {
         reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
         return;
     }
@@ -431,7 +431,7 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
             return;
         }
     }
-    if((cbind->func->flags & CMDFLAG_REGISTERED_CHAN)) {
+    if((BIND_FLAGS(cbind) & CMDFLAG_REGISTERED_CHAN)) {
         MYSQL_ROW defaults = NULL;
         char access_list[256];
         int access_pos = 0;
@@ -522,7 +522,7 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
             return;
         }
     }
-    if((cbind->func->flags & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
+    if((BIND_FLAGS(cbind) & CMDFLAG_REQUIRE_GOD) && !isGodMode(user)) {
         reply(tmp_text_client, user, "MODCMD_PRIVILEGED", cbind->cmd);
         return;
     }
@@ -905,6 +905,17 @@ void bind_botwise_set_channel_access(int botid, int clientid, char *cmd, char *c
     }
 }
 
+void bind_botwise_set_bind_flags(int botid, int clientid, char *cmd, unsigned int flags) {
+    int bind_index = get_binds_index(cmd[0]);
+    struct cmd_binding *cbind;
+    for(cbind = cmd_binds[bind_index]; cbind; cbind = cbind->next) {
+        if(cbind->botid == botid && (botid || clientid == cbind->clientid) && strcmp(cbind->cmd, cmd) == 0) {
+            cbind->flags |= flags;
+            return;
+        }
+    }
+}
+
 struct cmd_binding *find_botwise_cmd_binding(int botid, int clientid, char *cmd) {
     int bind_index = get_binds_index(cmd[0]);
     struct cmd_binding *cbind;