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

* Port [3458] to 1.2.14
* Cleaned up some of the replace() code to allow multiple calls (static buffer problems)
* Added ticket # to UPDATES for realname $n support



svn: 3459

Bryan Drewery 19 лет назад
Родитель
Сommit
16476cfc37
5 измененных файлов с 17 добавлено и 5 удалено
  1. 1 1
      doc/UPDATES
  2. 13 2
      src/misc.c
  3. 1 0
      src/misc.h
  4. 1 1
      src/mod/server.mod/cmdsserv.c
  5. 1 1
      src/mod/server.mod/servmsg.c

+ 1 - 1
doc/UPDATES

@@ -45,7 +45,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fix authing on non-chathubs (fixes #356)
 * Fix segfault with cmd_set and adding to empty lists.
 * Cleaned up some bugs in the 'getin' system.
-* Add '$n' expansion into realname.
+* Add '$n' expansion into realname. (fixes #361)
 * Reformat CTCP logging. (fixes #358)
 * Cleanup cmd_userlist to list hubs/leafs/backups (fixes #363)
 * Bots will now cycle nicks on servers which claim their nick is invalid. (fixes #311)

+ 13 - 2
src/misc.c

@@ -983,13 +983,12 @@ int goodpass(char *pass, int idx, char *nick)
   return 1;
 }
 
+#define REPLACES 10
 char *replace(const char *string, const char *oldie, const char *newbie)
 {
   if (string == NULL || !string[0])
     return (char *) string;
 
-  static char newstring[1024] = "";
-
   if (oldie == NULL || !oldie[0])
     return (char *) string;
 
@@ -998,6 +997,14 @@ char *replace(const char *string, const char *oldie, const char *newbie)
   if ((c = (char *) strstr(string, oldie)) == NULL) 
     return (char *) string;
 
+  static int n = 0;
+  static char newstring_buf[REPLACES][1024];
+  char *newstring = newstring_buf[n++];
+
+  egg_memset(newstring, 0, 1024);
+  if (n == REPLACES)
+    n = 0;
+
   const size_t new_len = strlen(newbie), old_len = strlen(oldie), end = (strlen(string) - old_len);
   size_t str_index = 0, newstr_index = 0, oldie_index = c - string, cpy_len;
 
@@ -1016,6 +1023,10 @@ char *replace(const char *string, const char *oldie, const char *newbie)
   return (newstring);
 }
 
+char* replace_vars(char *buf) {
+  return replace(buf, "$n", botname);
+}
+
 void showhelp(int idx, struct flag_record *flags, char *string)
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };

+ 1 - 0
src/misc.h

@@ -20,6 +20,7 @@ void shuffle(char *, char *);
 void shuffleArray(char **, size_t);
 void showhelp(int, struct flag_record *, char *);
 char *replace(const char *, const char *, const char *);
+char *replace_vars(char*);
 int goodpass(char *, int, char *);
 int bot_aggressive_to(struct userrec *);
 void readsocks(const char *);

+ 1 - 1
src/mod/server.mod/cmdsserv.c

@@ -42,7 +42,7 @@ static void cmd_dump(int idx, char *par)
     return;
   }
 
-  dprintf(DP_DUMP, "%s\n", replace(par, "$n", botname));
+  dprintf(DP_DUMP, "%s\n", replace_vars(par));
 }
 
 static void cmd_umode(int idx, char *par)

+ 1 - 1
src/mod/server.mod/servmsg.c

@@ -1601,7 +1601,7 @@ static void server_dns_callback(int id, void *client_data, const char *host, cha
     if (serverpass[0])
       dprintf(DP_MODE, "PASS %s\n", serverpass);
     dprintf(DP_MODE, "NICK %s\n", botname);
-    dprintf(DP_MODE, "USER %s localhost %s :%s\n", botuser, dcc[idx].host, replace(botrealname, "$n", botname));
+    dprintf(DP_MODE, "USER %s localhost %s :%s\n", botuser, dcc[idx].host, replace_vars(botrealname));
     /* Wait for async result now */
   }
 }