瀏覽代碼

* Fixed chanset *

svn: 322
Bryan Drewery 22 年之前
父節點
當前提交
62bf10312a
共有 3 個文件被更改,包括 36 次插入77 次删除
  1. 13 10
      src/chanprog.c
  2. 3 32
      src/mod/channels.mod/channels.c
  3. 20 35
      src/mod/channels.mod/cmdschan.c

+ 13 - 10
src/chanprog.c

@@ -867,6 +867,11 @@ int shouldjoin(struct chanset_t *chan)
 #endif /* G_BACKUP */
 #endif /* G_BACKUP */
 }
 }
 
 
+/* do_chanset() set (options) on (chan)
+ * local: 0 - send out over botnet only
+ * local: 1 - ALSO set locally
+ * local: 2 - ONLY set locally
+ */
 void do_chanset(struct chanset_t *chan, char *options, int local)
 void do_chanset(struct chanset_t *chan, char *options, int local)
 {
 {
   char *buf;
   char *buf;
@@ -913,19 +918,17 @@ Context;
       options = buf2;
       options = buf2;
       list[0] = newsplit(&options);
       list[0] = newsplit(&options);
       while (list[0][0]) {
       while (list[0][0]) {
-        if (list[0][0] == '+' || list[0][0] == '-' ||
-           (!strcmp(list[0], "dont-idle-kick"))) {
-          (func[38]) (0, ch, 1, list);
+        if (list[0][0] == '+' || list[0][0] == '-' || (!strcmp(list[0], "dont-idle-kick"))) {
+          (func[38]) (0, ch, 1, list);			/* tcl_channel_modify() */
           list[0] = newsplit(&options);
           list[0] = newsplit(&options);
           continue;
           continue;
         }
         }
-        if (strncmp(list[0], "need-", 5)) {
-          list[1] = options;
-          /* Par gets modified in tcl channel_modify under some
-           * circumstances, so save it now.
-           */
-           (func[38]) (0, ch, 2, list);			/* tcl_channel_modify() */
-        }
+	/* chanints */
+        list[1] = options;
+        /* Par gets modified in tcl channel_modify under some
+         * circumstances, so save it now.
+         */
+         (func[38]) (0, ch, 2, list);			/* tcl_channel_modify() */
       }
       }
       if (all)
       if (all)
         ch = ch->next;
         ch = ch->next;

+ 3 - 32
src/mod/channels.mod/channels.c

@@ -107,54 +107,27 @@ static void check_should_lock()
 static void got_cset(char *botnick, char *code, char *par)
 static void got_cset(char *botnick, char *code, char *par)
 {
 {
   int all = 0;
   int all = 0;
-  char *chname = NULL, *list[2], *buf, *bak;
+  char *chname = NULL;
   struct chanset_t *chan = NULL;
   struct chanset_t *chan = NULL;
 
 
   if (!par[0])
   if (!par[0])
    return;
    return;
   else {
   else {
    if (par[0] == '*' && par[1] == ' ') {
    if (par[0] == '*' && par[1] == ' ') {
-    return;
     all = 1;
     all = 1;
     newsplit(&par);
     newsplit(&par);
    } else {
    } else {
     chname = newsplit(&par);
     chname = newsplit(&par);
-    chan = findchan_by_dname(chname);
-    if (!chan)
+    if (!(chan = findchan_by_dname(chname)))
       return;
       return;
    }
    }
   }
   }
   if (all)
   if (all)
    chan = chanset;
    chan = chanset;
 
 
-  /* copied from cmd_chanset */
-  bak = par;
-  buf = nmalloc(strlen(par) + 1);
   while (chan) {
   while (chan) {
     chname = chan->dname;
     chname = chan->dname;
-    strcpy(buf, bak);
-    par = buf;
-    list[0] = newsplit(&par);
-    while (list[0][0]) {
-      if (list[0][0] == '+' || list[0][0] == '-' ||
-          (!strcmp(list[0], "dont-idle-kick"))) {
-        if (tcl_channel_modify(0, chan, 1, list) == TCL_OK) {
-        } else if (!all || !chan->next)
-          putlog(LOG_BOTS, "@", "Error trying to set %s for %s, invalid mode.", list[0], all ? "all channels" : chname);
-        list[0] = newsplit(&par);
-        continue;
-      }
-      if (strncmp(list[0], "need-", 5)) {
-        list[1] = par;
-        /* Par gets modified in tcl channel_modify under some
-         * circumstances, so save it now.
-         */
-        if (tcl_channel_modify(0, chan, 2, list) == TCL_OK) {
-        } else if (!all || !chan->next)
-          putlog(LOG_BOTS, "@", "Error trying to set %s for %s, invalid option\n", list[0], all ? "all channels" : chname);
-      }
-      break;
-    }
+    do_chanset(chan, par, 2);
     if (chan->status & CHAN_BITCH) {
     if (chan->status & CHAN_BITCH) {
       module_entry *me;
       module_entry *me;
       if ((me = module_find("irc", 0, 0)))
       if ((me = module_find("irc", 0, 0)))
@@ -165,8 +138,6 @@ static void got_cset(char *botnick, char *code, char *par)
     else
     else
       chan = chan->next;
       chan = chan->next;
   }
   }
-  if (buf)
-    nfree(buf);
 }
 }
 
 
 static void got_cpart(char *botnick, char *code, char *par)
 static void got_cpart(char *botnick, char *code, char *par)

+ 20 - 35
src/mod/channels.mod/cmdschan.c

@@ -1680,17 +1680,14 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
   char *chname = NULL, answers[512], *parcpy;
   char *chname = NULL, answers[512], *parcpy;
   char *list[2], *bak, *buf;
   char *list[2], *bak, *buf;
   struct chanset_t *chan = NULL;
   struct chanset_t *chan = NULL;
-  int all = 0, items = 0;
+  int all = 0;
 
 
   putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
   putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
 
 
   if (!par[0])
   if (!par[0])
-    dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
+    dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
   else {
   else {
     if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
     if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
-      dprintf(idx, "currently chanset * does not work. use %stcl foreach chan [channels] { channel set $chan +mode }\n", dcc_prefix);
-      return;
-
       all = 1;
       all = 1;
       get_user_flagrec(u, &user, chanset ? chanset->dname : "");
       get_user_flagrec(u, &user, chanset ? chanset->dname : "");
       if (!glob_master(user)) {
       if (!glob_master(user)) {
@@ -1744,7 +1741,6 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
 	  if (tcl_channel_modify(0, chan, 1, list) == TCL_OK) {
 	  if (tcl_channel_modify(0, chan, 1, list) == TCL_OK) {
 	    strcat(answers, list[0]);
 	    strcat(answers, list[0]);
 	    strcat(answers, " ");
 	    strcat(answers, " ");
-            items++;
 	  } else if (!all || !chan->next)
 	  } else if (!all || !chan->next)
 	    dprintf(idx, "Error trying to set %s for %s, invalid mode.\n",
 	    dprintf(idx, "Error trying to set %s for %s, invalid mode.\n",
 		    list[0], all ? "all channels" : chname);
 		    list[0], all ? "all channels" : chname);
@@ -1755,35 +1751,28 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
 	 * line is args. Woops nearly made a nasty little hole here :) we'll
 	 * line is args. Woops nearly made a nasty little hole here :) we'll
 	 * just ignore any non global +n's trying to set the need-commands.
 	 * just ignore any non global +n's trying to set the need-commands.
 	 */
 	 */
-	if (strncmp(list[0], "need-", 5) || (u->flags & USER_OWNER)) {
-	  list[1] = par;
-	  /* Par gets modified in tcl channel_modify under some
-  	   * circumstances, so save it now.
-	   */
-	  parcpy = nmalloc(strlen(par) + 1);
-	  strcpy(parcpy, par);
-          if (tcl_channel_modify(0, chan, 2, list) == TCL_OK) {
-	    strcat(answers, list[0]);
-	    strcat(answers, " { ");
-	    strcat(answers, parcpy);
-	    strcat(answers, " }");
-	  } else if (!all || !chan->next)
-	    dprintf(idx, "Error trying to set %s for %s, invalid option\n",
-		    list[0], all ? "all channels" : chname);
-          nfree(parcpy);
-	}
+	/* chanints */
+	list[1] = par;
+	/* Par gets modified in tcl channel_modify under some
+  	 * circumstances, so save it now.
+	 */
+	parcpy = nmalloc(strlen(par) + 1);
+	strcpy(parcpy, par);
+        if (tcl_channel_modify(0, chan, 2, list) == TCL_OK) {
+	  strcat(answers, list[0]);
+	  strcat(answers, " { ");
+	  strcat(answers, parcpy);
+	  strcat(answers, " }");
+	} else if (!all || !chan->next)
+	  dprintf(idx, "Error trying to set %s for %s, invalid option\n", list[0], all ? "all channels" : chname);
+        nfree(parcpy);
 	break;
 	break;
       }
       }
       if (!all && answers[0]) {
       if (!all && answers[0]) {
         struct chanset_t *my_chan;
         struct chanset_t *my_chan;
-        my_chan = findchan_by_dname(chname);
-        if (my_chan)
+        if ((my_chan = findchan_by_dname(chname)))
           do_chanset(my_chan, bak, 0);
           do_chanset(my_chan, bak, 0);
-	dprintf(idx, "Successfully set modes { %s } on %s.\n",
-		answers, chname);
-#ifdef HUB
-        write_userfile(-1);
-#endif /* HUB */
+	dprintf(idx, "Successfully set modes { %s } on %s.\n", answers, chname);
       }
       }
       if (!all)
       if (!all)
         chan = NULL;
         chan = NULL;
@@ -1792,11 +1781,7 @@ static void cmd_chanset(struct userrec *u, int idx, char *par)
     }
     }
     if (all && answers[0]) {
     if (all && answers[0]) {
       do_chanset(NULL, bak, 0);		/* NULL does all */
       do_chanset(NULL, bak, 0);		/* NULL does all */
-      dprintf(idx, "Successfully set modes { %s } on all channels.\n",
-	      answers);
-#ifdef HUB
-      write_userfile(-1);
-#endif /* HUB */
+      dprintf(idx, "Successfully set modes { %s } on all channels.\n", answers);
     }
     }
     nfree(buf);
     nfree(buf);
   }
   }