Selaa lähdekoodia

* Add channel_to_string()

Bryan Drewery 16 vuotta sitten
vanhempi
commit
4baf17002e

+ 1 - 0
src/mod/channels.mod/channels.c

@@ -47,6 +47,7 @@
 #include "src/net.h"
 #include "src/binds.h"
 #include "src/cmds.h"
+#include <bdlib/src/String.h>
 
 
 #include <sys/stat.h>

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

@@ -26,6 +26,7 @@ static int count_mask(maskrec *);
 
 namespace bd {
   class Stream;
+  class String;
 }
 
 void remove_channel(struct chanset_t *);
@@ -39,6 +40,7 @@ void write_bans(bd::Stream&, int);
 void write_exempts(bd::Stream&, int);
 void write_chans(bd::Stream&, int, bool = 0);
 void write_chans_compat(bd::Stream&, int);
+bd::String channel_to_string(struct chanset_t* chan, bool force_inactive = 0);
 void write_invites(bd::Stream&, int);
 bool expired_mask(struct chanset_t *, char *);
 void set_handle_laston(char *, struct userrec *, time_t);

+ 19 - 16
src/mod/channels.mod/userchan.c

@@ -704,23 +704,28 @@ void write_invites(bd::Stream& stream, int idx)
 static void write_chan(bd::Stream& stream, int idx, struct chanset_t* chan)
 {
   bd::String buf;
-  char w[1024] = "";
-
-  char inactive = 0;
 
   putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
-  get_mode_protect(chan, w, sizeof(w));
 
+  bool force_inactive = 0;
   /* 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));
+    force_inactive = 1;
 
-  stream << buf.printf("\
-+ channel add %s { chanmode { %s } addedby %s addedts %li \
-bad-cookie %d manop %d mdop %d mop %d limit %d ban-type %d \
+  stream << buf.printf("+ channel add %s { ", chan->dname);
+  if (chan != chanset_default)
+    stream << buf.printf("addedby %s addedts %li ", chan->added_by, (long)chan->added_ts);
+  stream << channel_to_string(chan, force_inactive);
+  stream << buf.printf("}\n");
+}
+
+bd::String channel_to_string(struct chanset_t* chan, bool force_inactive) {
+  bd::String buf;
+  char w[1024] = "";
+
+  get_mode_protect(chan, w, sizeof(w));
+  buf.printf("\
+chanmode { %s } bad-cookie %d manop %d mdop %d mop %d limit %d  ban-type %d \
 flood-chan %d:%d flood-ctcp %d:%d flood-join %d:%d \
 flood-kick %d:%d flood-deop %d:%d flood-nick %d:%d flood-mjoin %d:%d \
 closed-ban %d closed-invite %d closed-private %d ban-time %d \
@@ -729,11 +734,8 @@ flood-exempt %d flood-lock-time %d knock %d \
 %cmeankicks %cenforcebans %cdynamicbans %cuserbans %cbitch \
 %cprivate %ccycle %cinactive %cdynamicexempts %cuserexempts \
 %cdynamicinvites %cuserinvites %cnodesynch %cclosed %cvoice \
-%cfastop %cautoop %cbotbitch %cbackup %cnomassjoin %crbl %c%s}\n",
-	chan->dname,
+%cfastop %cautoop %cbotbitch %cbackup %cnomassjoin %crbl %c%s",
 	w,
-        chan->added_by,
-        (long)chan->added_ts,
 /* Chanchar template
  *      temp,
  * also include temp %s in dprintf.
@@ -773,7 +775,7 @@ flood-exempt %d flood-lock-time %d knock %d \
 	PLSMNS(channel_bitch(chan)),
 	PLSMNS(channel_privchan(chan)),
 	PLSMNS(channel_cycle(chan)),
-        inactive,
+        force_inactive ? '+' : PLSMNS(channel_inactive(chan)),
 	PLSMNS(channel_dynamicexempts(chan)),
 	PLSMNS(!channel_nouserexempts(chan)),
  	PLSMNS(channel_dynamicinvites(chan)),
@@ -794,6 +796,7 @@ flood-exempt %d flood-lock-time %d knock %d \
  *      PLSMNS(channel_temp(chan)),
  */
   );
+  return buf;
 }
 
 /* Write the channels to the userfile