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

* Port [3477] to 1.2.14
* Optimize request_(in|op) some
* Modify invite code to always attempt joining



svn: 3478

Bryan Drewery 19 лет назад
Родитель
Сommit
b64f4c8916
2 измененных файлов с 29 добавлено и 32 удалено
  1. 6 3
      src/mod/irc.mod/chan.c
  2. 23 29
      src/mod/irc.mod/irc.c

+ 6 - 3
src/mod/irc.mod/chan.c

@@ -2183,14 +2183,17 @@ static int gotinvite(char *from, char *msg)
 {
   char *nick = NULL;
   struct chanset_t *chan = NULL;
+  bool flood = 0;
 
   newsplit(&msg);
   fixcolon(msg);
   nick = splitnick(&from);
+  /* Two invites to the same channel in 10 seconds? */
   if (!rfc_casecmp(last_invchan, msg))
-    if (now - last_invtime < 30)
-      return 0;		/* Two invites to the same channel in 30 seconds? */
-  putlog(LOG_MISC, "*", "%s!%s invited me to %s", nick, from, msg);
+    if (now - last_invtime < 10)
+      flood = 1;
+  if (!flood)
+    putlog(LOG_MISC, "*", "%s!%s invited me to %s", nick, from, msg);
   strncpy(last_invchan, msg, 299);
   last_invchan[299] = 0;
   last_invtime = now;

+ 23 - 29
src/mod/irc.mod/irc.c

@@ -780,7 +780,8 @@ request_op(struct chanset_t *chan)
     return;
   }
 
-  char *l = (char *) my_calloc(1, cnt * 50);
+  char l[1024] = "";
+  size_t len = 0;
 
   /* first scan for bots on my server, ask first found for ops */
   simple_sprintf(s, "gi o %s %s", chan->dname, botname);
@@ -790,16 +791,13 @@ request_op(struct chanset_t *chan)
     if (botops[i2]->hops < 2) {
       putbot(botops[i2]->user->handle, s);
       chan->opreqtime[first] = n;
-      if (l[0]) {
-        strcat(l, ", ");
-        strcat(l, botops[i2]->user->handle);
-      } else {
-        strcpy(l, botops[i2]->user->handle);
-      }
-      strcat(l, "/");
-      strcat(l, botops[i2]->nick);
+      if (l[0])
+        len += strlcpy(l + len, ", ", sizeof(l) - len);
+      len += strlcpy(l + len, botops[i2]->user->handle, sizeof(l) - len);
+      len += strlcpy(l + len, "/", sizeof(l) - len);
+      len += strlcpy(l + len, botops[i2]->nick, sizeof(l) - len);
       botops[i2] = NULL;
-      cnt--;
+      --cnt;
       break;
     }
   }
@@ -810,23 +808,20 @@ request_op(struct chanset_t *chan)
     if (botops[i2]) {
       putbot(botops[i2]->user->handle, s);
       chan->opreqtime[first] = n;
-      if (l[0]) {
-        strcat(l, ", ");
-        strcat(l, botops[i2]->user->handle);
-      } else {
-        strcpy(l, botops[i2]->user->handle);
-      }
-      strcat(l, "/");
-      strcat(l, botops[i2]->nick);
-      cnt--;
+      if (l[0])
+        len += strlcpy(l + len, ", ", sizeof(l) - len);
+      len += strlcpy(l + len, botops[i2]->user->handle, sizeof(l) - len);
+      len += strlcpy(l + len, "/", sizeof(l) - len);
+      len += strlcpy(l + len, botops[i2]->nick, sizeof(l) - len);
+      --cnt;
       botops[i2] = NULL;
     } else {
       if (i < op_bots)
         cnt--;
     }
   }
+  l[len] = 0;
   putlog(LOG_GETIN, "*", "Requested ops on %s from %s", chan->dname, l);
-  free(l);
 }
 
 static void
@@ -858,12 +853,14 @@ request_in(struct chanset_t *chan)
   }
 
   if (!foundBots) {
-    putlog(LOG_GETIN, "*", "No bots linked, can't request help to join %s", chan->dname);
+    putlog(LOG_GETIN, "*", "No bots available, can't request help to join %s", chan->dname);
     return;
   }
 
   int cnt = foundBots < in_bots ? foundBots : in_bots;
-  char s[255] = "", *l = (char *) my_calloc(1, cnt * 30);
+  char s[255] = "";
+  char l[1024] = "";
+  size_t len = 0;
 
   simple_sprintf(s, "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
 
@@ -871,15 +868,12 @@ request_in(struct chanset_t *chan)
   for (int n = 0; n < cnt; ++n) {
     putbot(botops[n], s);
 
-    if (l[0]) {
-      strcat(l, ", ");
-      strcat(l, botops[n]);
-    } else {
-      strcpy(l, botops[n]);
-    }
+    if (l[0])
+      len += strlcpy(l + len, ", ", sizeof(l) - len);
+    len += strlcpy(l + len, botops[n], sizeof(l) - len);
   }
+  l[len] = 0;
   putlog(LOG_GETIN, "*", "Requested help to join %s from %s", chan->dname, l);
-  free(l);
 }