Просмотр исходного кода

* Begin work on new multi-bot queued cookie ops

svn: 1196
Bryan Drewery 22 лет назад
Родитель
Сommit
1141a0a9d2
5 измененных файлов с 114 добавлено и 26 удалено
  1. 4 0
      src/chan.h
  2. 3 1
      src/mod/channels.mod/channels.c
  3. 3 0
      src/mod/irc.mod/irc.c
  4. 3 1
      src/mod/irc.mod/irc.h
  5. 101 24
      src/mod/irc.mod/mode.c

+ 4 - 0
src/chan.h

@@ -133,6 +133,9 @@ struct chanset_t {
     char *op;
     int type;
   } cmode[MODES_PER_LINE_MAX];                 /* parameter-type mode changes -        */
+  struct {
+    char *op;
+  } ccmode[MODES_PER_LINE_MAX];                 /* parameter-type mode changes -        */
   /* detect floods */
   time_t floodtime[FLOOD_CHAN_MAX];
   uint32_t status;
@@ -174,6 +177,7 @@ struct chanset_t {
   /* queued mode changes: */
   int limit;			/* new limit to set			*/
   int bytes;			/* total bytes so far			*/
+  int cbytes;
   int compat;			/* to prevent mixing old/new modes	*/
   int floodnum[FLOOD_CHAN_MAX];
   int opreqtime[5];             /* remember when ops was requested */

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

@@ -711,8 +711,10 @@ void remove_channel(struct chanset_t *chan)
    user_del_chan(chan->dname);
    noshare = 0;
    free(chan->channel.key);
-   for (i = 0; i < 6 && chan->cmode[i].op; i++)
+   for (i = 0; i < MODES_PER_LINE_MAX && chan->cmode[i].op; i++)
      free(chan->cmode[i].op);
+   for (i = 0; i < (MODES_PER_LINE_MAX - 1) && chan->ccmode[i].op; i++)
+     free(chan->ccmode[i].op);
    if (chan->key)
      free(chan->key);
    if (chan->rmkey)

+ 3 - 0
src/mod/irc.mod/irc.c

@@ -1252,6 +1252,9 @@ flush_modes()
   struct chanset_t *chan = NULL;
   memberlist *m = NULL;
 
+  if (!modesperline)		/* Haven't received 005 yet :) */
+    return;
+
   if (modesperline > MODES_PER_LINE_MAX)
     modesperline = MODES_PER_LINE_MAX;
   for (chan = chanset; chan; chan = chan->next) {

+ 3 - 1
src/mod/irc.mod/irc.h

@@ -59,7 +59,9 @@ static int gotmode(char *, char *);
 
 #endif /* MAKING_IRC */
 
-void add_mode(struct chanset_t *, const char, const char, const char *);
+void real_add_mode(struct chanset_t *, const char, const char, const char *, int);
+#define add_mode(chan, pls, mode, nick) real_add_mode(chan, pls, mode, nick, 0)
+#define add_cookie(chan, nick) real_add_mode(chan, '+', 'o', nick, 1)
 int me_op(struct chanset_t *);
 void check_this_ban(struct chanset_t *, char *, int);
 void check_this_exempt(struct chanset_t *, char *, int);

+ 101 - 24
src/mod/irc.mod/mode.c

@@ -30,24 +30,85 @@ static int do_op(char *nick, struct chanset_t *chan, int delay, int force)
 
   if (channel_fastop(chan) || channel_take(chan)) {
     add_mode(chan, '+', 'o', nick);
+//    add_cookie(chan, nick);
   } else {
-    char *tmp = NULL;
-    
+    add_cookie(chan, nick);
+  }
+  return 1;
+}
+
+static void
+flush_cookies(struct chanset_t *chan, int pri)
+{
+  char *p = NULL, out[512] = "", post[512] = "";
+  size_t postsize = sizeof(post);
+  unsigned int i = 0;
+
+  p = out;
+  post[0] = 0, postsize--;
+
+  chan->cbytes = 0;
+
+  for (i = 0; i < (modesperline - 1); i++) {
+    if (chan->ccmode[i].op && postsize > strlen(chan->ccmode[i].op)) {
+
+      *p++ = '+';
+      *p++ = 'o';
+      postsize -= egg_strcatn(post, chan->ccmode[i].op, sizeof(post));
+      postsize -= egg_strcatn(post, " ", sizeof(post));
+
+      free(chan->ccmode[i].op), chan->ccmode[i].op = NULL;
+    }
+  }
+
+  /* remember to terminate the buffer ('out')... */
+  if (out[0]) {
+    *p++ = '-';
+    *p++ = 'b';
+  }
+  *p = 0;
+
+  if (post[0]) {
+    /* remove the trailing space... */
+    size_t myindex = (sizeof(post) - 1) - postsize;
+
+    if (myindex > 0 && post[myindex - 1] == ' ')
+      post[myindex - 1] = 0;
+
+    egg_strcatn(out, " ", sizeof(out));
+    egg_strcatn(out, post, sizeof(out));
+    egg_strcatn(out, " ", sizeof(out));
+    egg_strcatn(out, "*!*@NEW.MULTI.BOT.COOKIE.OPS.COMING.SOON", sizeof(out));
+/*    char *tmp = NULL;
+
     tmp = calloc(1, strlen(chan->name) + 200);
     makeopline(chan, nick, tmp);
     dprintf(DP_MODE, tmp);
     free(tmp);
+*/
+  }
+  if (out[0]) {
+    if (pri == QUICK) {
+      char outbuf[201] = "";
+ 
+      sprintf(outbuf, "MODE %s %s\n", chan->name, out);
+      tputs(serv, outbuf, strlen(outbuf));
+      /* dprintf(DP_MODE, "MODE %s %s\n", chan->name, out); */
+    } else
+      dprintf(DP_SERVER, "MODE %s %s\n", chan->name, out);
   }
-  return 1;
 }
 
-static void flush_mode(struct chanset_t *chan, int pri)
+static void 
+flush_mode(struct chanset_t *chan, int pri)
 {
   char *p = NULL, out[512] = "", post[512] = "";
   size_t postsize = sizeof(post);
   int plus = 2;              /* 0 = '-', 1 = '+', 2 = none */
   unsigned int i = 0;
 
+  flush_cookies(chan, pri);
+
 /* dequeue_op_deop(chan); */
   p = out;
   post[0] = 0, postsize--;
@@ -114,8 +175,7 @@ static void flush_mode(struct chanset_t *chan, int pri)
 
   /* Do -{b,e,I} before +{b,e,I} to avoid the server ignoring overlaps */
   for (i = 0; i < modesperline; i++) {
-    if ((chan->cmode[i].type & MINUS) && 
-        postsize > strlen(chan->cmode[i].op)) {
+    if ((chan->cmode[i].type & MINUS) && postsize > strlen(chan->cmode[i].op)) {
       if (plus) {
         *p++ = '-', plus = 0;
       }
@@ -135,8 +195,7 @@ static void flush_mode(struct chanset_t *chan, int pri)
 
   /* now do all the + modes... */
   for (i = 0; i < modesperline; i++) {
-    if ((chan->cmode[i].type & PLUS) && 
-        postsize > strlen(chan->cmode[i].op)) {
+    if ((chan->cmode[i].type & PLUS) && postsize > strlen(chan->cmode[i].op)) {
       if (plus != 1) {
         *p++ = '+', plus = 1;
       }
@@ -182,7 +241,8 @@ static void flush_mode(struct chanset_t *chan, int pri)
 
 /* Queue a channel mode change
  */
-void add_mode(struct chanset_t *chan, const char plus, const char mode, const char *op)
+void 
+real_add_mode(struct chanset_t *chan, const char plus, const char mode, const char *op, int cookie)
 {
   int type, modes, l;
   unsigned int i;
@@ -278,21 +338,38 @@ void add_mode(struct chanset_t *chan, const char plus, const char mode, const ch
     }
 
     /* op-type mode change */
-    for (i = 0; i < modesperline; i++)
-      if (chan->cmode[i].type == type && chan->cmode[i].op != NULL &&
-          !rfc_casecmp(chan->cmode[i].op, op))
-        return;                 /* Already in there :- duplicate */
-    l = strlen(op) + 1;
-    if (chan->bytes + l > mode_buf_len)
-      flush_mode(chan, NORMAL);
-    for (i = 0; i < modesperline; i++)
-      if (chan->cmode[i].type == 0) {
-        chan->cmode[i].type = type;
-        chan->cmode[i].op = (char *) calloc(1, l);
-        chan->bytes += l;       /* Add 1 for safety */
-        strcpy(chan->cmode[i].op, op);
-        break;
-      }
+
+    /* for cookie ops, use ccmode instead of cmode */
+    if (cookie) {
+      for (i = 0; i < (modesperline - 1); i++)
+        if (chan->ccmode[i].op != NULL && !rfc_casecmp(chan->ccmode[i].op, op))
+          return;                 /* Already in there :- duplicate */
+      l = strlen(op) + 1;
+      if (chan->cbytes + l > mode_buf_len)
+        flush_mode(chan, NORMAL);
+      for (i = 0; i < (modesperline - 1); i++)
+        if (!chan->ccmode[i].op) {
+          chan->ccmode[i].op = (char *) calloc(1, l);
+          chan->cbytes += l;       /* Add 1 for safety */
+          strcpy(chan->ccmode[i].op, op);
+          break;
+        }
+    } else {
+      for (i = 0; i < modesperline; i++)
+        if (chan->cmode[i].type == type && chan->cmode[i].op != NULL && !rfc_casecmp(chan->cmode[i].op, op))
+          return;                 /* Already in there :- duplicate */
+      l = strlen(op) + 1;
+      if (chan->bytes + l > mode_buf_len)
+        flush_mode(chan, NORMAL);
+      for (i = 0; i < modesperline; i++)
+        if (chan->cmode[i].type == 0) {
+          chan->cmode[i].type = type;
+          chan->cmode[i].op = (char *) calloc(1, l);
+          chan->bytes += l;       /* Add 1 for safety */
+          strcpy(chan->cmode[i].op, op);
+          break;
+        }
+    }
   }
 
   /* +k ? store key */