فهرست منبع

* Port [3426] to 1.2.14
* Cleaned up (and optimized) request_in a bit
* Made shuffleArray char*[] again.



svn: 3427

Bryan Drewery 19 سال پیش
والد
کامیت
d9ce55f647
8فایلهای تغییر یافته به همراه31 افزوده شده و 38 حذف شده
  1. 4 4
      src/botmsg.c
  2. 2 2
      src/botmsg.h
  3. 3 3
      src/botnet.c
  4. 3 3
      src/botnet.h
  5. 2 3
      src/misc.c
  6. 1 2
      src/misc.h
  7. 14 19
      src/mod/irc.mod/irc.c
  8. 2 2
      src/tandem.h

+ 4 - 4
src/botmsg.c

@@ -274,14 +274,14 @@ void botnet_send_reject(int idx, char *fromp, char *frombot, char *top, char *to
   tputs(dcc[idx].sock, OBUF, len);
 }
 
-void putallbots(char *par)
+void putallbots(const char *par)
 { 
   botnet_send_zapf_broad(-1, conf.bot->nick, NULL, par);
 
   return;
 }
 
-void putbot(char *bot, char *par)
+void putbot(const char *bot, char *par)
 {
   if (!bot || !par || !bot[0] || !par[0])
     return;
@@ -310,14 +310,14 @@ void botnet_send_log(int idx, const char *from, int type, const char *msg)
   }
 }
 
-void botnet_send_zapf(int idx, char *a, char *b, char *c)
+void botnet_send_zapf(int idx, const char *a, const char *b, const char *c)
 {
   const size_t len = simple_snprintf(OBUF, sizeof(OBUF), "z %s %s %s\n", a, b, c);
 
   tputs(dcc[idx].sock, OBUF, len);
 }
 
-void botnet_send_zapf_broad(int idx, char *a, char *b, char *c)
+void botnet_send_zapf_broad(int idx, const char *a, const char *b, const char *c)
 {
   if (tands > 0) {
     const size_t len = simple_snprintf(OBUF, sizeof(OBUF), "zb %s %s%s%s\n", a, b ? b : "", b ? " " : "", c);

+ 2 - 2
src/botmsg.h

@@ -10,8 +10,8 @@
 
 void botnet_send_var(int idx, variable_t *);
 void botnet_send_var_broad(int idx, variable_t *);
-void putbot(char *, char *);
-void putallbots(char *);
+void putbot(const char *, char *);
+void putallbots(const char *);
 int add_note(char *, char *, char *, int, int);
 
 #endif /* !_BOTMSG_H */

+ 3 - 3
src/botnet.c

@@ -44,7 +44,7 @@ void init_party()
   party = (party_t *) my_calloc(1, maxparty * sizeof(party_t));
 }
 
-tand_t *findbot(char *who)
+tand_t *findbot(const char *who)
 {
   for (tand_t* ptr = tandbot; ptr; ptr = ptr->next)
     if (!egg_strcasecmp(ptr->bot, who))
@@ -373,7 +373,7 @@ void besthub(char *hub)
 
 /* Return index into dcc list of the bot that connects us to bot <x>
  */
-int nextbot(char *who)
+int nextbot(const char *who)
 {
   tand_t *bot = findbot(who);
 
@@ -390,7 +390,7 @@ int nextbot(char *who)
 
 /* Return name of the bot that is directly connected to bot X
  */
-char *lastbot(char *who)
+char *lastbot(const char *who)
 {
   tand_t *bot = findbot(who);
 

+ 3 - 3
src/botnet.h

@@ -13,8 +13,8 @@ extern int		tands;
 
 void lower_bot_linked(int idx);
 void answer_local_whom(int, int);
-char *lastbot(char *);
-int nextbot(char *);
+char *lastbot(const char *);
+int nextbot(const char *);
 int in_chain(char *);
 void tell_bots(int, int, const char *);
 void tell_bottree(int);
@@ -24,7 +24,7 @@ int botunlink(int, char *, char *);
 void addbot(char *, char *, char *, char, int, time_t, char *);
 void updatebot(int, char *, char, int, time_t, char *);
 void rembot(const char *);
-struct tand_t_struct *findbot(char *);
+tand_t *findbot(const char *);
 void unvia(int, struct tand_t_struct *);
 void check_botnet_pings();
 int addparty(char *, char *, int, char, int, char *, int *);

+ 2 - 3
src/misc.c

@@ -1091,12 +1091,11 @@ void showhelp(int idx, struct flag_record *flags, char *string)
 }
 
 /* Arrange the N elements of ARRAY in random order. */
-template <class T>
-void shuffleArray(T array[], size_t n)
+void shuffleArray(char* array[], size_t n)
 {
   for (size_t i = 0; i < n; i++) {
     const size_t j = randint(n);
-    T temp = array[j];
+    char* temp = array[j];
     array[j] = array[i];
     array[i] = temp;
   }

+ 1 - 2
src/misc.h

@@ -17,8 +17,7 @@ void restart(int);
 int coloridx(int);
 const char *color(int, int, int);
 void shuffle(char *, char *);
-template <class T>
-void shuffleArray(T [], size_t);
+void shuffleArray(char **, size_t);
 void showhelp(int, struct flag_record *, char *);
 char *replace(const char *, const char *, const char *);
 int goodpass(char *, int, char *);

+ 14 - 19
src/mod/irc.mod/irc.c

@@ -604,7 +604,7 @@ getin_request(char *botnick, char *code, char *par)
     }
 
     if (!me_op(chan)) {
-      putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - I haven't got ops", botnick, nick, chan->dname);
+      putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I haven't got ops", botnick, nick, chan->dname);
       return;
     }
 
@@ -846,7 +846,7 @@ request_in(struct chanset_t *chan)
   }
 
   int foundBots = 0;
-  struct userrec *botops[MAX_BOTS];
+  char* botops[MAX_BOTS];
 
   for (tand_t* bot = tandbot; bot && (foundBots < MAX_BOTS); bot = bot->next) {
     if (bot->hub || !bot->u)
@@ -854,7 +854,7 @@ request_in(struct chanset_t *chan)
 
     get_user_flagrec(bot->u, &fr, chan->dname);
     if (bot_shouldjoin(bot->u, &fr, chan) && chk_op(fr, chan))
-      botops[foundBots++] = bot->u;
+      botops[foundBots++] = bot->bot;
   }
 
   if (!foundBots) {
@@ -862,28 +862,23 @@ request_in(struct chanset_t *chan)
     return;
   }
 
-  int cnt = in_bots, n;
+  int cnt = foundBots < in_bots ? foundBots : in_bots;
   char s[255] = "", *l = (char *) my_calloc(1, cnt * 30);
 
   simple_sprintf(s, "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
-  while (cnt) {
-    n = randint(foundBots);
-    if (botops[n]) {
-      putbot(botops[n]->handle, s);
-      if (l[0]) {
-        strcat(l, ", ");
-        strcat(l, botops[n]->handle);
-      } else {
-        strcpy(l, botops[n]->handle);
-      }
-      botops[n] = NULL;
-      cnt--;
+
+  shuffleArray(botops, foundBots);
+  for (int n = 0; n < cnt; ++n) {
+    putbot(botops[n], s);
+
+    if (l[0]) {
+      strcat(l, ", ");
+      strcat(l, botops[n]);
     } else {
-      if (foundBots < in_bots)
-        cnt--;
+      strcpy(l, botops[n]);
     }
   }
-  putlog(LOG_GETIN, "*", "Requesting help to join %s from %s", chan->dname, l);
+  putlog(LOG_GETIN, "*", "Requested help to join %s from %s", chan->dname, l);
   free(l);
 }
 

+ 2 - 2
src/tandem.h

@@ -61,8 +61,8 @@ void botnet_send_update(int, tand_t *);
 void botnet_send_nlinked(int, char *, char *, char, int, time_t, char *);
 void botnet_send_reject(int, char *, char *, char *, char *, char *);
 void botnet_send_log(int, const char *, int, const char *);
-void botnet_send_zapf(int, char *, char *, char *);
-void botnet_send_zapf_broad(int, char *, char *, char *);
+void botnet_send_zapf(int, const char *, const char *, const char *);
+void botnet_send_zapf_broad(int, const char *, const char *, const char *);
 void botnet_send_away(int, char *, int, char *, int);
 void botnet_send_idle(int, char *, int, int, char *);
 void botnet_send_join_idx(int);