Преглед изворни кода

* Fixed up cmd_chanset to work as intended
* Added alert when saving userfile when a cmd calls it


svn: 698

Bryan Drewery пре 22 година
родитељ
комит
a8b4b2ce28

+ 2 - 0
doc/UPDATES

@@ -12,6 +12,8 @@ This is a summary of ChangeLog basically.
 9.Bot is now much more portable.
 10.Fixed a bug in cmd_channels, was allowing to view higher flagged users.
 11.Added extort to CREDITS.
+12.Rewrote cmd_chanset to parse options correctly.
+13.Cmds that auto save userfile now alert you of that.
 
 1.0.15 (Non-Release Version)
 1.cmd_randstring is now limited to 300.

+ 1 - 1
src/botnet.c

@@ -91,7 +91,7 @@ void check_should_backup()
 
   for (chan = chanset; chan; chan = chan->next) {
     if (chan->channel.backup_time && (chan->channel.backup_time < now) && !channel_backup(chan)) {
-      do_chanset(chan, STR("+backup"), DO_LOCAL | DO_NET);
+      do_chanset(NULL, chan, STR("+backup"), DO_LOCAL | DO_NET);
       chan->channel.backup_time = 0;
     }
   }

+ 20 - 40
src/chanprog.c

@@ -706,8 +706,9 @@ int shouldjoin(struct chanset_t *chan)
 /* do_chanset() set (options) on (chan)
  * USES DO_LOCAL|DO_NET bits.
  */
-void do_chanset(struct chanset_t *chan, char *options, int local)
+int do_chanset(char *result, struct chanset_t *chan, char *options, int local)
 {
+  int ret = OK;
 
   if (local & DO_NET) {
     char *buf = NULL;
@@ -731,56 +732,35 @@ void do_chanset(struct chanset_t *chan, char *options, int local)
   }
 
   if (local & DO_LOCAL) {
-    char *buf2 = NULL, *bak = NULL; 
     struct chanset_t *ch = NULL;
-    int all = 0;
+    int all = chan ? 0 : 1;
 
-    if (!chan) {
-      ch = chanset;
-      all++;
-    } else
+    if (chan)
       ch = chan;
-
-    bak = options;
-    buf2 = malloc(strlen(options) + 1); 
+    else
+      ch = chanset;
 
     while (ch) {
-/* expiremental code 
-      const char **list = NULL;
+      const char **item = NULL;
       int items = 0;
-      char result[1024] = "";
-
-      if (SplitList(result, options, &items, &item) != OK) {
-        putlog(LOG_MISC, "*", "Error parsing channel options: %s", result);
-        return ERROR;
 
-      if ((channel_modify(result, chan, items, (char **) item) != OK) && !loading) {
+      if (SplitList(result, options, &items, &item) == OK) {
+        ret = channel_modify(result, ch, items, (char **) item);
+      } else 
         ret = ERROR;
-      }
 
-  free(item);
-*/
-      char *list[2] = { NULL, NULL };
-
-      strcpy(buf2, bak);
-      options = buf2;
-      list[0] = newsplit(&options);
-      while (list[0][0]) {
-        if (list[0][0] == '+' || list[0][0] == '-' || (!strcmp(list[0], "dont-idle-kick"))) {
-          channel_modify(NULL, ch, 1, list);
-          list[0] = newsplit(&options);
-          continue;
-        }
-        /* chanints */
-        list[1] = options;
-        channel_modify(NULL, ch, 2, list);
-        break;
-      }
-      if (all)
+
+      free(item);
+
+      if (all) {
+        if (ret == ERROR) /* just bail if there was an error, no sense in trying more */
+          return ret;
+
         ch = ch->next;
-      else
+      } else {
         ch = NULL;
+      }
     }
-    free(buf2);
   }
+  return ret;
 }

+ 1 - 1
src/chanprog.h

@@ -8,7 +8,7 @@
 extern struct chanset_t *chanset;
 extern char botname[];
 
-void do_chanset(struct chanset_t *, char *, int);
+int do_chanset(char *, struct chanset_t *, char *, int);
 void checkchans(int);
 void tell_verbose_uptime(int);
 void tell_verbose_status(int);

+ 4 - 4
src/mod/channels.mod/channels.c

@@ -93,7 +93,7 @@ static void check_should_lock()
   if ((hc >= H) && (lc <= L)) {
     for (chan = chanset; chan; chan = chan->next) {
       if (!channel_closed(chan)) {
-        do_chanset(chan, STR("+closed chanmode +stni"), DO_LOCAL | DO_NET);
+        do_chanset(NULL, chan, STR("+closed chanmode +stni"), DO_LOCAL | DO_NET);
 #ifdef G_BACKUP
         chan->channel.backup_time = now + 30;
 #endif /* G_BACKUP */
@@ -132,7 +132,7 @@ static void got_cset(char *botnick, char *code, char *par)
 
   while (chan) {
     chname = chan->dname;
-    do_chanset(chan, par, DO_LOCAL);
+    do_chanset(NULL, chan, par, DO_LOCAL);
     if (chan->status & CHAN_BITCH) {
       module_entry *me;
       if ((me = module_find("irc", 0, 0)))
@@ -200,7 +200,7 @@ static void got_cycle(char *botnick, char *code, char *par)
   if (par[0])
     delay = atoi(newsplit(&par));
   
-  do_chanset(chan, "+inactive", DO_LOCAL);
+  do_chanset(NULL, chan, "+inactive", DO_LOCAL);
   dprintf(DP_SERVER, "PART %s\n", chan->name);
   chan->channel.jointime = ((now + delay) - server_lag); 		/* rejoin in 10 seconds */
 }
@@ -242,7 +242,7 @@ void got_kl(char *botnick, char *code, char *par)
     struct chanset_t *ch = NULL;
 
     for (ch = chanset; ch; ch = ch->next)
-      do_chanset(ch, STR("+closed +backup +bitch"), DO_LOCAL | DO_NET);
+      do_chanset(NULL, ch, STR("+closed +backup +bitch"), DO_LOCAL | DO_NET);
   /* FIXME: we should randomize nick here ... */
   }
 #endif /* S_AUTOLOCK */

+ 52 - 106
src/mod/channels.mod/cmdschan.c

@@ -1353,7 +1353,7 @@ static void cmd_cycle(struct userrec *u, int idx, char *par)
   sprintf(buf2, "cycle %s %d", chname, delay); //this just makes the bot PART
   putallbots(buf2);
 #ifdef LEAF
-  do_chanset(chan, "+inactive", DO_LOCAL);
+  do_chanset(NULL, chan, "+inactive", DO_LOCAL);
   dprintf(DP_SERVER, "PART %s\n", chan->name);
   chan->channel.jointime = ((now + delay) - server_lag);
 #endif /* LEAF */
@@ -1427,12 +1427,12 @@ static void cmd_pls_chan(struct userrec *u, int idx, char *par)
 
       tmp = calloc(1, 7 + 1 + strlen(dcc[idx].nick) + 1);
       sprintf(tmp, "addedby %s", dcc[idx].nick);
-      do_chanset(chan, tmp, DO_LOCAL | DO_NET );
+      do_chanset(NULL, chan, tmp, DO_LOCAL | DO_NET );
       free(tmp);
 
       tmp = calloc(1, 7 + 1 + 10 + 1);
       sprintf(tmp, "addedts %lu", now);
-      do_chanset(chan, tmp, DO_LOCAL | DO_NET );
+      do_chanset(NULL, chan, tmp, DO_LOCAL | DO_NET );
       free(tmp);
     }
 #ifdef HUB
@@ -1711,123 +1711,69 @@ static void cmd_chaninfo(struct userrec *u, int idx, char *par)
 
 static void cmd_chanset(struct userrec *u, int idx, char *par)
 {
-  char *chname = NULL, answers[512] = "", *parcpy = NULL;
-  char *list[2] = { NULL, NULL }, *bak = NULL, *buf = NULL;
+  char *chname = NULL, result[1024] = "";
   struct chanset_t *chan = NULL;
   int all = 0;
 
   putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
 
-  if (!par[0])
+  if (!par[0]) {
     dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
-  else {
-    if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
-      all = 1;
-      get_user_flagrec(u, &user, chanset ? chanset->dname : "");
-      if (!glob_master(user)) {
-	dprintf(idx, "You need to be a global master to use %schanset *.\n", dcc_prefix);
+    return;
+  }
+
+  if (strlen(par) > 2 && par[0] == '*' && par[1] == ' ') {
+    all = 1;
+    get_user_flagrec(u, &user, chanset ? chanset->dname : "");
+    if (!glob_master(user)) {
+      dprintf(idx, "You need to be a global master to use %schanset *.\n", dcc_prefix);
+      return;
+    }
+    newsplit(&par);
+  } else {
+    if (strchr(CHANMETA, par[0])) {
+      chname = newsplit(&par);
+      get_user_flagrec(u, &user, chname);
+      if (!glob_master(user) && !chan_master(user)) {
+        dprintf(idx, "You don't have access to %s. \n", chname);
 	return;
-      }
-      newsplit(&par);
-    } else {
-      if (strchr(CHANMETA, par[0])) {
-        chname = newsplit(&par);
-        get_user_flagrec(u, &user, chname);
-        if (!glob_master(user) && !chan_master(user)) {
-	  dprintf(idx, "You don't have access to %s. \n", chname);
-	  return;
-	} else if (!(chan = findchan_by_dname(chname)) && (chname[0] != '+')) {
-	  dprintf(idx, "That channel doesn't exist!\n");
-	  return;
-	} else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
-	  dprintf(idx, "You don't have access to set +/-private on %s (halting command due to lazy coder).\n", chname);
-	  return;
-	} else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
-	  dprintf(idx, "You don't have access to set +/-inactive on %s (halting command due to lazy coder).\n", chname);
-	  return;
-        }
-	if (!chan) {
-	  if (par[0])
-	    *--par = ' ';
-	  par = chname;
-	}
-      }
-      if (!par[0] || par[0] == '*') {
-        dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
+      } else if (!(chan = findchan_by_dname(chname)) && (chname[0] != '+')) {
+        dprintf(idx, "That channel doesn't exist!\n");
+	return;
+      } else if ((strstr(par, "+private") || strstr(par, "-private")) && (!glob_owner(user))) {
+        dprintf(idx, "You don't have access to set +/-private on %s (halting command due to lazy coder).\n", chname);
+	return;
+      } else if ((strstr(par, "+inactive") || strstr(par, "-inactive")) && (!glob_owner(user))) {
+        dprintf(idx, "You don't have access to set +/-inactive on %s (halting command due to lazy coder).\n", chname);
         return;
       }
-      if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
-        dprintf(idx, "Invalid console channel.\n");
-        return;
+      if (!chan) {
+        if (par[0])
+	  *--par = ' ';
+	par = chname;
       }
     }
-    if (all)
-      chan = chanset;
-    bak = par;
-    buf = calloc(1, strlen(par) + 1);
-    while (chan) {
-      chname = chan->dname;
-      strcpy(buf, bak);
-      par = buf;
-      list[0] = newsplit(&par);
-      answers[0] = 0;
-      while (list[0][0]) {
-	if (list[0][0] == '+' || list[0][0] == '-' ||
-	    (!strcmp(list[0], "dont-idle-kick"))) {
-	  if (channel_modify(0, chan, 1, list) == OK) {
-	    strcat(answers, list[0]);
-	    strcat(answers, " ");
-	  } else if (!all || !chan->next)
-	    dprintf(idx, "Error trying to set %s for %s, invalid mode.\n",
-		    list[0], all ? "all channels" : chname);
-	  list[0] = newsplit(&par);
-	  continue;
-	}
-	/* The rest have an unknown amount of args, so assume the rest of the
-	 * 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.
-	 */
-	/* chanints */
-	list[1] = par;
-	/* Par gets modified in tcl channel_modify under some
-  	 * circumstances, so save it now.
-	 */
-        parcpy = strdup(par);
-        if (channel_modify(0, chan, 2, list) == 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);
-        free(parcpy);
-	break;
-      }
-      if (!all && answers[0]) {
-        struct chanset_t *my_chan = NULL;
-
-        if ((my_chan = findchan_by_dname(chname)))
-          do_chanset(my_chan, bak, DO_NET);
-	dprintf(idx, "Successfully set modes { %s } on %s.\n", answers, chname);
-#ifdef HUB
-        write_userfile(idx);
-#endif /* HUB */
-      }
-      if (!all)
-        chan = NULL;
-      else
-        chan = chan->next;
+    if (!par[0] || par[0] == '*') {
+      dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
+      return;
     }
-    if (all && answers[0]) {
-      do_chanset(NULL, bak, DO_NET);		
-      dprintf(idx, "Successfully set modes { %s } on all channels.\n", answers);
-#ifdef HUB
-        write_userfile(idx);
-#endif /* HUB */
-
+    if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
+      dprintf(idx, "Invalid console channel.\n");
+      return;
     }
-    free(buf);
   }
+  if (do_chanset(result, all ? chan : NULL, par, DO_LOCAL) == ERROR) {
+    dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
+    return;
+  }
+  if (all)
+    dprintf(idx, "Successfully set modes { %s } on all channels.\n", par);
+  else
+    dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);
+
+#ifdef HUB
+  write_userfile(idx);
+#endif /* HUB */
 }
 
 /* DCC CHAT COMMANDS

+ 3 - 1
src/mod/channels.mod/tclchan.c

@@ -410,7 +410,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
       strncpyz(chan->temp, item[i], sizeof(chan->temp));
       check_temp(chan);
  */
-    } else if (!strcmp(item[i], "topic")) { //this is here for compatability
+    } else if (!strcmp(item[i], "topic")) { /* this is here for compatability */
       i++;
       if (i >= items) {
         if (result)
@@ -418,6 +418,8 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item)
         return ERROR;
       }
     }
+
+
     else if (!strcmp(item[i], "+enforcebans"))
       chan->status |= CHAN_ENFORCEBANS;
     else if (!strcmp(item[i], "-enforcebans"))

+ 1 - 1
src/mod/irc.mod/cmdsirc.c

@@ -704,7 +704,7 @@ ContextNote("!mdop!");
   }
   if (bitch && !simul && chan) {
     chan->status |= CHAN_BITCH;
-    do_chanset(chan, STR("+bitch"), DO_LOCAL | DO_NET);
+    do_chanset(NULL, chan, STR("+bitch"), DO_LOCAL | DO_NET);
   }
   free(targets);
   free(chanbots);

+ 1 - 1
src/mod/irc.mod/irc.c

@@ -1097,7 +1097,7 @@ void check_netfight()
       if ((chan->channel.fighting) && (chan->channel.fighting > limit)) {
         if (!channel_bitch(chan) || !channel_closed(chan)) {
           putlog(LOG_WARN, "*", STR("Auto-closed %s - channel fight\n"), chan->dname);
-          do_chanset(chan, STR("+bitch +closed"), DO_LOCAL | DO_NET);
+          do_chanset(NULL, chan, STR("+bitch +closed"), DO_LOCAL | DO_NET);
           enforce_closed(chan);
           dprintf(DP_MODE, STR("TOPIC %s :Auto-closed - channel fight\n"), chan->name);
         }

+ 1 - 1
src/mod/module.h

@@ -239,7 +239,7 @@
 #define debug_output (*(int *)(global[106]))
 #define noshare (*(int *)(global[107]))
 /* 108 - 111 */
-#define do_chanset ((void (*)(struct chanset_t *, char *, int))global[108])
+#define do_chanset ((int (*)(char *, struct chanset_t *, char *, int))global[108])
 #define str_isdigit ((int (*) (const char *))global[109])
 #define default_flags (*(int*)global[110])
 #define dcc_total (*(int*)global[111])

+ 2 - 1
src/userrec.c

@@ -424,7 +424,8 @@ int write_userfile(int idx)
     free(new_userfile);
     return 2;
   }
-  /*  putlog(LOG_MISC, "*", USERF_WRITING); */
+  if (idx >= 0)
+    dprintf(idx, USERF_WRITING);
   if (sort_users)
     sort_userlist();
   tt = now;