[eggheads-patches] $server problems

Sven Trenkel Sven.Trenkel at tu-clausthal.de
Tue Mar 4 19:01:07 CST 2003


This patch should fix the bug that causes the bot to reset the $server
Tcl variable during a rehash.
The bot doesn't crash any more if a script tries to access $server after
too many servers have been removed from the serverlist.

CU
   Sven
-- 
Today's experiment ..... failed!
-------------- next part --------------
diff -urN eggdrop1.6.original/src/mod/server.mod/cmdsserv.c eggdrop1.6.modified/src/mod/server.mod/cmdsserv.c
--- eggdrop1.6.original/src/mod/server.mod/cmdsserv.c   Fri Jan 31 06:00:06 2003
+++ eggdrop1.6.modified/src/mod/server.mod/cmdsserv.c   Wed Mar  5 01:24:20 2003
@@ -36,9 +36,10 @@
     dprintf(idx, "Server list:\n");
     i = 0;
     for (; x; x = x->next) {
-      if (x->realname)
+      if (x->realname || ((i == curserv) && realservername))
         egg_snprintf(s, sizeof s, "  %s:%d (%s) %s", x->name,
-                     x->port ? x->port : default_port, x->realname,
+                     x->port ? x->port : default_port,
+                     ((i == curserv) && realservername) ? realservername : x->realname,
                      (i == curserv) ? "<- I am here" : "");
       else
         egg_snprintf(s, sizeof s, "  %s:%d %s", x->name,
diff -urN eggdrop1.6.original/src/mod/server.mod/server.c eggdrop1.6.modified/src/mod/server.mod/server.c
--- eggdrop1.6.original/src/mod/server.mod/server.c     Fri Feb 28 06:00:06 2003
+++ eggdrop1.6.modified/src/mod/server.mod/server.c     Wed Mar  5 01:23:03 2003
@@ -110,6 +110,7 @@
 static int deq_kick(int);
 static void msgq_clear(struct msgq_head *qh);
 static int stack_limit;
+static char *realservername;
 
 #include "servmsg.c"
 
@@ -1203,15 +1204,11 @@
 {
   char s[1024];
 
-  if (server_online) {
+  if (server_online && realservername) {
     int servidx = findanyidx(serv);
-    register int i;
-    struct server_list *x = serverlist;
 
-    for (i = 0; i < curserv; x = x->next)
-      i++;
     /* return real server name */
-    simple_sprintf(s, "%s:%u", x->realname, dcc[servidx].port);
+    simple_sprintf(s, "%s:%u", realservername, dcc[servidx].port);
   } else
     s[0] = 0;
   Tcl_SetVar2(interp, name1, name2, s, TCL_GLOBAL_ONLY);
@@ -1867,6 +1864,7 @@
   kick_method = 1;
   optimize_kicks = 0;
   stack_limit = 4;
+  realservername = 0;
 
   server_table[4] = (Function) botname;
   module_register(MODULE_NAME, server_table, 1, 2);
diff -urN eggdrop1.6.original/src/mod/server.mod/servmsg.c eggdrop1.6.modified/src/mod/server.mod/servmsg.c
--- eggdrop1.6.original/src/mod/server.mod/servmsg.c    Wed Feb  5 06:00:09 2003
+++ eggdrop1.6.modified/src/mod/server.mod/servmsg.c    Wed Mar  5 01:21:37 2003
@@ -235,6 +235,10 @@
       nfree(x->realname);
     x->realname = nmalloc(strlen(from) + 1);
     strcpy(x->realname, from);
+    if (realservername)
+      nfree(realservername);
+    realservername = nmalloc(strlen(from) + 1);
+    strcpy(realservername, from);
   } else
     putlog(LOG_MISC, "*", "No server list!");
 
@@ -269,15 +273,9 @@
 {
   char *chname;
   struct chanset_t *chan;
-  struct server_list *x;
-  int i;
 
-  for (x = serverlist, i = 0; x; x = x->next, i++)
-    if (i == curserv) {
-      if (egg_strcasecmp(from, x->realname ? x->realname : x->name))
-        return 0;
-      break;
-    }
+  if (!realservername || egg_strcasecmp(from, realservername))
+    return 0;
   newsplit(&msg);
   chname = newsplit(&msg);
   chan = findchan(chname);
@@ -952,6 +950,8 @@
   if (server_online > 0)
     check_tcl_event("disconnect-server");
   server_online = 0;
+  nfree(realservername);
+  realservername = 0;
   if (dcc[idx].sock >= 0)
     killsock(dcc[idx].sock);
   dcc[idx].sock = -1;
@@ -1063,14 +1063,8 @@
  */
 static int whoispenalty(char *from, char *msg)
 {
-  struct server_list *x = serverlist;
-  int i;
-
-  if (x && use_penalties) {
-    i = 0;
-    for (; x && i < curserv; x = x->next)
-      i++;
-    if (strcmp(x->realname, from)) {
+  if (realservername && use_penalties) {
+    if (strcmp(realservername, from)) {
       last_time += 1;
       if (raw_log)
         putlog(LOG_SRVOUT, "*", "adding 1sec penalty (remote whois)");


More information about the Patches mailing list