fixed botwar detection for bot deops
[NeonServV5.git] / src / modcmd.c
index 18483ed63887f77cc09cebe55dfc735940c2b1ab..8846d900197bc75b53c1e0181a04b062a093058a 100644 (file)
@@ -128,7 +128,8 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
 static USERAUTH_CALLBACK(command_checked_auth) {
     struct command_check_user_cache *cache = data;
     tmp_text_client = cache->textclient;
-    handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc);
+    if(user)
+        handle_command_async(cache->client, user, cache->chan, cache->sent_chan, cache->cbind, cache->argv, cache->argc);
     free(cache->message);
     if(cache->args_buffer)
         free(cache->args_buffer);
@@ -159,7 +160,7 @@ static struct cmd_binding *modcmd_linker_command(struct ClientSocket *client, st
                 break;
         }
         *args_ptr = args;
-        if(cbind->func->func == modcmd_linker) {
+        if(cbind && cbind->func->func == modcmd_linker) {
             return modcmd_linker_command(client, user, cbind, bind_index, args_ptr);
         }
         return cbind;
@@ -391,7 +392,7 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
         reply(tmp_text_client, user, "MODCMD_AUTH_REQUIRED");
         return;
     }
-    if(chan && sent_chan != chan && !isUserOnChan(user, chan)) {
+    if(chan && sent_chan != chan && (BIND_FLAGS(cbind) & CMDFLAG_NO_CROSSCHAN) && !isUserOnChan(user, chan)) {
         char user_in_chan = 0;
         if((user->flags & USERFLAG_ISAUTHED)) {
             //maybe there's another user authed to user->auth on the channel...
@@ -456,6 +457,7 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
             str_b = cbind->channel_access;
         access_list[0] = '\0';
         if(str_b) {
+            struct ChanUser *chanuser = getChanUser(user, chan);
             str_c = strdup(str_b);
             str_b = str_c;
             while((str_a = str_b)) {
@@ -464,6 +466,15 @@ static void handle_command_async(struct ClientSocket *client, struct UserNode *u
                     *str_b = '\0';
                     str_b++;
                 }
+                if(*str_a == '@' || *str_a == '+') {
+                    //privs can override this access requirement
+                    int priv = 0;
+                    if(*str_a == '@') priv = CHANUSERFLAG_OPPED;
+                    else if(*str_a == '%') priv = CHANUSERFLAG_HALFOPPED;
+                    else if(*str_a == '+') priv = CHANUSERFLAG_VOICED;
+                    if(chanuser && (chanuser->flags & priv)) continue;
+                    str_a++;
+                }
                 if(*str_a == '#') {
                     str_a++;
                     access_pos += sprintf(access_list+access_pos, ", `%s`", str_a);