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

* Port [3379] to 1.2.14
* Don't send new 'flood-' chansets to old bots
* Add forward compatible code in for 'flood-'* in channel options



svn: 3380

Bryan Drewery пре 19 година
родитељ
комит
871f9d7836

+ 2 - 1
src/mod/channels.mod/channels.h

@@ -34,6 +34,7 @@ void del_chanrec(struct userrec *, char *);
 bool write_bans(FILE *, int);
 bool write_bans(FILE *, int);
 bool write_exempts (FILE *, int);
 bool write_exempts (FILE *, int);
 bool write_chans (FILE *, int);
 bool write_chans (FILE *, int);
+bool write_chans_compat (FILE *, int);
 bool write_invites (FILE *, int);
 bool write_invites (FILE *, int);
 bool expired_mask(struct chanset_t *, char *);
 bool expired_mask(struct chanset_t *, char *);
 void set_handle_laston(char *, struct userrec *, time_t);
 void set_handle_laston(char *, struct userrec *, time_t);
@@ -50,7 +51,7 @@ bool u_match_mask(struct maskrec *, char *);
 bool ismasked(masklist *, const char *);
 bool ismasked(masklist *, const char *);
 bool ismodeline(masklist *, const char *);
 bool ismodeline(masklist *, const char *);
 void channels_report(int, int);
 void channels_report(int, int);
-void channels_writeuserfile();
+void channels_writeuserfile(bool = 0);
 void rcmd_chans(char *, char *, char *);
 void rcmd_chans(char *, char *, char *);
 
 
 extern char		glob_chanset[512];
 extern char		glob_chanset[512];

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

@@ -700,10 +700,9 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       } else if (!strcmp(item[i] + 6, "mjoin")) {
       } else if (!strcmp(item[i] + 6, "mjoin")) {
 	pthr = &chan->flood_mjoin_thr;
 	pthr = &chan->flood_mjoin_thr;
 	ptime = &chan->flood_mjoin_time;
 	ptime = &chan->flood_mjoin_time;
-      } else {
-	if (result)
-	  simple_snprintf(result, RESULT_LEN, "illegal channel flood type: %s", item[i]);
-	return ERROR;
+      } else { /* Ignore for optimal forward compatibility */
+        i++;
+        continue;
       }
       }
 
 
       if (pthr && ptime) { //Ignore flood-*
       if (pthr && ptime) { //Ignore flood-*

+ 103 - 2
src/mod/channels.mod/userchan.c

@@ -802,7 +802,105 @@ flood-exempt %d flood-lock-time %d \
   return 1;
   return 1;
 }
 }
 
 
-void channels_writeuserfile()
+/* FIXME: remove after 1.2.14 */
+/* Write the channels to the userfile
+ */
+bool write_chans_compat(FILE *f, int idx)
+{
+  putlog(LOG_DEBUG, "*", "Writing channels..");
+
+  if (lfprintf(f, CHANS_NAME " - -\n") == EOF) /* Daemus */
+    return 0;
+
+  char w[1024] = "";
+
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
+    char inactive = 0;
+
+    putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
+    get_mode_protect(chan, w);
+
+    /* if a bot should explicitly NOT join, just set it +inactive ... */
+    if (idx >= 0 && !botshouldjoin(dcc[idx].user, chan))
+      inactive = '+';
+    /* ... otherwise give the bot the *actual* setting */
+    else
+      inactive = PLSMNS(channel_inactive(chan));
+
+    if (lfprintf(f, "\
++ channel add %s { chanmode { %s } addedby %s addedts %lu idle-kick %d \
+bad-cookie %d manop %d mdop %d mop %d limit %d \
+flood-chan %d:%lu flood-ctcp %d:%lu flood-join %d:%lu \
+flood-kick %d:%lu flood-deop %d:%lu flood-nick %d:%lu \
+closed-ban %d closed-invite %d closed-private %d ban-time %lu \
+exempt-time %lu invite-time %lu voice-non-ident %d \
+%cenforcebans %cdynamicbans %cuserbans %cbitch \
+%cprivate %ccycle %cinactive %cdynamicexempts %cuserexempts \
+%cdynamicinvites %cuserinvites %cnodesynch %cclosed %cvoice \
+%cfastop %cautoop %cbotbitch %cbackup %cnomassjoin %c%s}\n",
+	chan->dname,
+	w,
+        chan->added_by,
+        chan->added_ts,
+/* Chanchar template
+ *      temp,
+ * also include temp %s in dprintf.
+ */
+	chan->idle_kick, /* idle-kick 0 is same as dont-idle-kick (lcode)*/
+	chan->bad_cookie,
+	chan->manop,
+	chan->mdop,
+	chan->mop,
+        chan->limitraise,
+	chan->flood_pub_thr, chan->flood_pub_time,
+        chan->flood_ctcp_thr, chan->flood_ctcp_time,
+        chan->flood_join_thr, chan->flood_join_time,
+        chan->flood_kick_thr, chan->flood_kick_time,
+        chan->flood_deop_thr, chan->flood_deop_time,
+	chan->flood_nick_thr, chan->flood_nick_time,
+        chan->closed_ban,
+/* Chanint template
+ *      chan->temp,
+ * also include temp %d in dprintf
+ */
+        chan->closed_invite,
+        chan->closed_private,
+        chan->ban_time,
+        chan->exempt_time,
+        chan->invite_time,
+        chan->voice_non_ident,
+ 	PLSMNS(channel_enforcebans(chan)),
+	PLSMNS(channel_dynamicbans(chan)),
+	PLSMNS(!channel_nouserbans(chan)),
+	PLSMNS(channel_bitch(chan)),
+	PLSMNS(channel_privchan(chan)),
+	PLSMNS(channel_cycle(chan)),
+        inactive,
+	PLSMNS(channel_dynamicexempts(chan)),
+	PLSMNS(!channel_nouserexempts(chan)),
+ 	PLSMNS(channel_dynamicinvites(chan)),
+	PLSMNS(!channel_nouserinvites(chan)),
+	PLSMNS(channel_nodesynch(chan)),
+	PLSMNS(channel_closed(chan)),
+	PLSMNS(channel_voice(chan)),
+	PLSMNS(channel_fastop(chan)),
+        PLSMNS(channel_autoop(chan)),
+        PLSMNS(channel_botbitch(chan)),
+        PLSMNS(channel_backup(chan)),
+        PLSMNS(channel_nomassjoin(chan)),
+	HAVE_TAKE ? PLSMNS(channel_take(chan)) : 0,
+        HAVE_TAKE ? "take " : " "
+/* Chanflag template
+ * also include a %ctemp above.
+ *      PLSMNS(channel_temp(chan)),
+ */
+        ) == EOF)
+          return 0;
+  }
+  return 1;
+}
+
+void channels_writeuserfile(bool old)
 {
 {
   char s[1024] = "";
   char s[1024] = "";
   FILE *f = NULL;
   FILE *f = NULL;
@@ -812,7 +910,10 @@ void channels_writeuserfile()
   simple_sprintf(s, "%s~new", userfile);
   simple_sprintf(s, "%s~new", userfile);
   f = fopen(s, "a");
   f = fopen(s, "a");
   if (f) {
   if (f) {
-    ret  = write_chans(f, -1);
+    if (!old)
+      ret  = write_chans(f, -1);
+    else
+      ret  = write_chans_compat(f, -1);
     ret += write_vars_and_cmdpass(f, -1);
     ret += write_vars_and_cmdpass(f, -1);
     ret += write_bans(f, -1);
     ret += write_bans(f, -1);
     ret += write_exempts(f, -1);
     ret += write_exempts(f, -1);

+ 11 - 1
src/mod/share.mod/share.c

@@ -1159,6 +1159,13 @@ write_tmp_userfile(char *fn, const struct userrec *bu, int idx)
   int ok = 0;
   int ok = 0;
 
 
   if ((f = fopen(fn, "wb"))) {
   if ((f = fopen(fn, "wb"))) {
+/* FIXME: REMOVE AFTER 1.2.14 */
+    bool old = 0;
+
+    tand_t* bot = findbot(dcc[idx].nick);
+    if (bot && bot->buildts < 1175102242) /* flood-* hacks */
+      old = 1;
+
     time_t tt = now;
     time_t tt = now;
     char s1[81] = "";
     char s1[81] = "";
 
 
@@ -1166,7 +1173,10 @@ write_tmp_userfile(char *fn, const struct userrec *bu, int idx)
     strcpy(s1, ctime(&tt));
     strcpy(s1, ctime(&tt));
     lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
     lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
 
 
-    ok += write_chans(f, idx);
+    if (!old)
+      ok += write_chans(f, idx);
+    else
+      ok += write_chans_compat(f, idx);
     ok += write_vars_and_cmdpass(f, idx);
     ok += write_vars_and_cmdpass(f, idx);
     ok += write_bans(f, idx);
     ok += write_bans(f, idx);
     ok += write_exempts(f, idx);
     ok += write_exempts(f, idx);

+ 10 - 1
src/userrec.c

@@ -475,7 +475,16 @@ int write_userfile(int idx)
   strcpy(s1, ctime(&tt));
   strcpy(s1, ctime(&tt));
   lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
   lfprintf(f, "#4v: %s -- %s -- written %s", ver, conf.bot->nick, s1);
   fclose(f);
   fclose(f);
-  channels_writeuserfile();
+
+
+/* FIXME: REMOVE AFTER 1.2.14 */
+  bool old = 0;
+
+  tand_t* bot = findbot(dcc[idx].nick);
+  if (bot && bot->buildts < 1175102242) /* flood-* hacks */
+    old = 1;
+  channels_writeuserfile(old);
+
   f = fopen(new_userfile, "a");
   f = fopen(new_userfile, "a");
   putlog(LOG_DEBUG, "@", "Writing user entries.");
   putlog(LOG_DEBUG, "@", "Writing user entries.");
   for (struct userrec *u = userlist; u && ok; u = u->next)
   for (struct userrec *u = userlist; u && ok; u = u->next)