[eggheads-patches] PATCH: cmall.patch

Peter 'Rattacresh' Backes rtc at rhrk.uni-kl.de
Fri Oct 15 16:24:40 CST 1999


* fixes for modeless + channels
* strcasecmp for ircnick, rfc_casecmp for botnetnick in tcl_chnick. 
Should be vice versa
* Let tcl_chnick change any nick to our current irc nick as cmd_nick 
and cmd_chnick allow it, too...
* Someone replaced the invalid prefixes string in 1.3.28 by a 
BADNICKCHARS variable, but only in cmds.c. Someone else added two 
chars to BADNICKHARS which of course didn't take any effect in 
tcluser.c... So I moved it to eggdrop.h and replaced the prefix char 
string in tclusers.h by BADNICKCHARS, too.
* renamed BADNICKCHARS to BADHANDCHARS to avoid confusion.
* renamed variable 'nick' to 'newnick' in tcl_chnick to be more like 
cmd_chnick.
* .chattr shouldn't reset the channel if no changes have been made.
* You get the correct error message if you .chattr lamer |xyz and 
lamer has an invalid console channel.
* .botattr bot +s #test was changing global +s.
* .botattr bot |+s with conchan = '*' complained about invalid 
channel.
* userrec.c:change_chandle didn't check for some illegal prefix 
chars, now uses BADHANDCHARS.
* probably more...

All-in-one bugfixing only patch.


-- Peter 'Rattacresh' Backes, rtc at rhrk.uni-kl.de

-------------- next part --------------
diff -urN eggdrop1.3.29/doc/UPDATES1.3 eggdrop1.3.29+cmall/doc/UPDATES1.3
--- eggdrop1.3.29/doc/UPDATES1.3	Fri Oct 15 17:09:39 1999
+++ eggdrop1.3.29+cmall/doc/UPDATES1.3	Fri Oct 15 17:09:03 1999
@@ -4,6 +4,16 @@
 
 1.3.29
 Foundby   Fixedby   What....
+          rtc       modeless +channels should work better now
+          rtc       .chattr shouldn't reset the channel if not changes
+                    have been made
+          rtc       fixed .botattr +s #test not to set global +s
+          rtc       .botattr |+s with conchan * complained about invalid 
+                    channel
+          rtc       tcl_chnick should allow change to orignick like .chnick
+          rtc       several funcs in tcluser.c and userrec.c didn't check 
+                    for some illegal prefix chars.
+          rtc       fixed tcl_chnick not to use rfc_casecmp on botnetnick
           Cybah	    strncpy() being used on buffers without terminating them.
 Tothwolf  Fabian    stopped userfile parsing funcs from messing with ~ and `
           rtc       language files were being installed twice
diff -urN eggdrop1.3.29/src/cmds.c eggdrop1.3.29+cmall/src/cmds.c
--- eggdrop1.3.29/src/cmds.c	Fri Oct 15 17:09:39 1999
+++ eggdrop1.3.29+cmall/src/cmds.c	Fri Oct 15 16:38:24 1999
@@ -30,8 +30,6 @@
 extern char network[], owner[], spaces[];
 extern time_t now, online_since;
 
-#define BADNICKCHARS "-,+*=:!.@#;$%&"
-
 /* add hostmask to a bot's record if possible */
 static int add_bot_hostmask(int idx, char *nick)
 {
@@ -635,7 +633,9 @@
   get_user_flagrec(u, &fr, dcc[idx].u.chat->con_chan);
   strcpy(s1, par);
   nick = newsplit(&par);
-  if (nick[0] && !strchr("#&+-*", nick[0]) && glob_master(fr)) {
+  /* don't remove '+' as someone couldn't have '+' in CHANMETA cause 
+   * he doesn't use br0ken IRCnet ++rtc */
+  if (nick[0] && !strchr(CHANMETA "+-*", nick[0]) && glob_master(fr)) {
     for (i = 0; i < dcc_total; i++)
       if (!strcasecmp(nick, dcc[i].nick) &&
 	  (dcc[i].type == &DCC_CHAT) && (!ok)) {
@@ -651,7 +651,9 @@
     dest = idx;
   if (!nick[0])
     nick = newsplit(&par);
-  if (strchr("#&*", nick[0])) {
+  /* ugly hack for stupid modeless channels ++rtc */
+  if ((nick [0] == '+' && findchan(nick)) || 
+      (nick [0] != '+' && strchr(CHANMETA "*", nick[0]))) {
     if (strcmp(nick, "*") && !findchan(nick)) {
       dprintf(idx, "Invalid console channel: %s\n", nick);
       return;
@@ -744,7 +746,7 @@
       handle[HANDLEN] = 0;	/* max len = XX .. for the moment :) */
     if (get_user_by_handle(userlist, handle))
       dprintf(idx, "Someone already exists by that name.\n");
-    else if (strchr(BADNICKCHARS, handle[0]) != NULL)
+    else if (strchr(BADHANDCHARS, handle[0]) != NULL)
       dprintf(idx, "You can't start a botnick with '%c'.\n", handle[0]);
     else {
       if (strlen(addr) > 60)
@@ -804,7 +806,7 @@
   for (i = 0; i < strlen(newhand); i++)
     if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
       newhand[i] = '?';
-  if (strchr(BADNICKCHARS, newhand[0]) != NULL)
+  if (strchr(BADHANDCHARS, newhand[0]) != NULL)
     dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with %c\n",
            newhand[0]);
   else if (get_user_by_handle(userlist, newhand) &&
@@ -849,7 +851,7 @@
   for (i = 0; i < strlen(newnick); i++)
     if ((newnick[i] <= 32) || (newnick[i] >= 127) || (newnick[i] == '@'))
       newnick[i] = '?';
-  if (strchr(BADNICKCHARS, newnick[0]) != NULL) {
+  if (strchr(BADHANDCHARS, newnick[0]) != NULL) {
     dprintf(idx, "Bizarre quantum forces prevent nicknames from starting with '%c'\n",
 	    newnick[0]);
   } else if (get_user_by_handle(userlist, newnick) &&
@@ -1409,7 +1411,7 @@
 
 static void cmd_chattr(struct userrec *u, int idx, char *par)
 {
-  char *hand, *tmpchg = NULL, *chg = NULL, work[1024];
+  char *hand, *arg = NULL, *tmpchg = NULL, *chg = NULL, work[1024];
   struct chanset_t *chan = NULL;
   struct userrec *u2;
   struct flag_record pls = {0, 0, 0, 0, 0, 0},
@@ -1424,47 +1426,75 @@
   }
   hand = newsplit(&par);
   u2 = get_user_by_handle(userlist, hand);
-  if ((hand[0] == '*') || !u2) {
+  if (!u2) {
     dprintf(idx, "No such user!\n");
     return;
   }
-  if (par[0] && ((strchr(CHANMETA, par[0]) == NULL) || par[0]=='+')) {
-    chg = newsplit(&par);
-    if (!par[0] && strpbrk(chg, "&|"))
-      par = dcc[idx].u.chat->con_chan;
-     else if (par[0] && !strpbrk(chg, "&|")) {
-       context;
-       tmpchg = nmalloc(sizeof(chg)+1);
-       sprintf(tmpchg,"|%s",chg);
-       chg = nmalloc(sizeof(tmpchg));
-       strcpy(chg,tmpchg);
-     }
+
+  /* Parse args */
+  if (par[0]) {
+    arg = newsplit (&par);
+    if (par[0]) {
+      /* .chattr <handle> <changes> <channel> */
+      chg = arg;
+      arg = newsplit (&par);
+      chan = findchan (arg);
+    } else {
+      chan = findchan (arg);
+      /* ugly hack for stupid modeless channels ++rtc */
+      if (!(arg[0] == '+' && chan) &&
+          !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
+	/* .chattr <handle> <changes> */
+        chg = arg;
+        chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
+	arg = NULL;
+      }
+      /* .chattr <handle> <channel>: nothing to do... */
+    }
+  }
+  /* arg:  pointer to channel name, NULL if none specified
+   * chan: pointer to channel structure, NULL if none found or none specified
+   * chg:  pointer to changes, NULL if none specified
+   */
+  ASSERT (!(arg == NULL && chan != NULL));
+  if (arg && !chan) {
+    dprintf(idx, "No channel record for %s.\n", arg);
+    return;
   }
-  chan = findchan(par);
-  if (!chan && par[0] && (par[0] != '*')) {
-    dprintf(idx, "No channel record for %s.\n", par);
-    if (tmpchg) {
-      nfree(chg); nfree(tmpchg);
+  if (chg) {
+    if (!arg && strpbrk(chg, "&|")) {
+      /* .chattr <handle> *[&|]*: use console channel if found... */
+      if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
+        arg = NULL;
+      else
+        chan = findchan (arg);
+      if (arg && !chan) {
+        dprintf (idx, "Invalid console channel %s.\n", arg);
+	return;
+      }
+    } else if (arg && !strpbrk(chg, "&|")) {
+      context;
+      tmpchg = nmalloc(sizeof(chg)+1);
+      sprintf(tmpchg,"|%s",chg);
+      chg = tmpchg;
     }
-    return;
   }
+  par = arg;
   user.match = FR_GLOBAL;
   if (chan)
     user.match |= FR_CHAN;
   get_user_flagrec(u, &user, chan ? chan->name : 0);
   if (!chan && !glob_botmast(user)) {
     dprintf(idx, "You do not have Bot Master privileges.\n");
-    if (tmpchg) {
-      nfree(chg); nfree(tmpchg);
-    }
+    if (tmpchg)
+      nfree(tmpchg);
     return;
   }
   if (chan && !glob_master(user) && !chan_master(user)) {
     dprintf(idx, "You do not have channel master privileges for channel %s\n",
 	    par);
-    if (tmpchg) {
-      nfree(chg); nfree(tmpchg);
-    }
+    if (tmpchg)
+      nfree(tmpchg);
     return;
   }
   user.match &= fl;
@@ -1472,24 +1502,24 @@
     pls.match = user.match;
     break_down_flags(chg, &pls, &mns);
     /* no-one can change these flags on-the-fly */
-    pls.global &=~(USER_BOT);
-    mns.global &=~(USER_BOT);
+    pls.global &= ~(USER_BOT);
+    mns.global &= ~(USER_BOT);
 
     if (chan) {
       pls.chan &= ~(BOT_SHARE);
       mns.chan &= ~(BOT_SHARE);
     }
     if (!glob_owner(user)) {
-      pls.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
-      mns.global &=~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
+      pls.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
+      mns.global &= ~(USER_OWNER | USER_MASTER | USER_BOTMAST | USER_UNSHARED);
 
       if (chan) {
 	pls.chan &= ~USER_OWNER;
 	mns.chan &= ~USER_OWNER;
       }
       if (!glob_master(user)) {
-	pls.global &=USER_PARTY | USER_XFER;
-	mns.global &=USER_PARTY | USER_XFER;
+	pls.global &= USER_PARTY | USER_XFER;
+	mns.global &= USER_PARTY | USER_XFER;
 
 	if (!glob_botmast(user)) {
 	  pls.global = 0;
@@ -1552,21 +1582,20 @@
 	      chan->name, work);
     else
       dprintf(idx, "No flags for %s on %s.\n", hand, chan->name);
-    if ((me = module_find("irc", 0, 0))) {
+    if (chg && (me = module_find("irc", 0, 0))) {
       Function *func = me->funcs;
 
       if (chan)
 	(func[IRC_RECHECK_CHANNEL]) (chan, 0);
     }
   }
-  if (tmpchg) {
-      nfree(chg); nfree(tmpchg);
-    }
+  if (tmpchg)
+    nfree(tmpchg);
 }
 
 static void cmd_botattr(struct userrec *u, int idx, char *par)
 {
-  char *hand, *chg = NULL, work[1024];
+  char *hand, *chg = NULL, *arg = NULL, *tmpchg = NULL, work[1024];
   struct chanset_t *chan = NULL;
   struct userrec *u2;
   struct flag_record pls =
@@ -1581,7 +1610,7 @@
   }
   hand = newsplit(&par);
   u2 = get_user_by_handle(userlist, hand);
-  if ((hand[0] == '*') || !u2 || !(u2->flags & USER_BOT)) {
+  if (!u2 || !(u2->flags & USER_BOT)) {
     dprintf(idx, "No such bot!\n");
     return;
   }
@@ -1589,22 +1618,67 @@
     if (!strcasecmp(dcc[idx2].nick, hand))
       break;
   if (idx2 != dcc_total) {
-    dprintf(idx, "You may not change the attributes of a linked bot.\n");
+    dprintf(idx, "You may not change the attributes of a directly linked bot.\n");
     return;
   }
-  if (par[0] && ((strchr(CHANMETA, par[0]) == NULL) || par[0]=='+')) {
-    chg = newsplit(&par);
-    if (!par[0] && strpbrk(chg, "|&"))
-      par = dcc[idx].u.chat->con_chan;
-  }
-  if (!(chan = findchan(par)) && par[0]) {
-    dprintf(idx, "No channel record for %s.\n", par);
+  /* Parse args */
+  if (par[0]) {
+    arg = newsplit (&par);
+    if (par[0]) {
+      /* .botattr <handle> <changes> <channel> */
+      chg = arg;
+      arg = newsplit (&par);
+      chan = findchan (arg);
+    } else {
+      chan = findchan (arg);
+      /* ugly hack for stupid modeless channels ++rtc */
+      if (!(arg[0] == '+' && chan) &&
+          !(arg[0] != '+' && strchr (CHANMETA, arg[0]))) {
+	/* .botattr <handle> <changes> */
+        chg = arg;
+        chan = NULL; /* uh, !strchr (CHANMETA, channel[0]) && channel found?? */
+	arg = NULL;
+      }
+      /* .botattr <handle> <channel>: nothing to do... */
+    }
+  }
+  /* arg:  pointer to channel name, NULL if none specified
+   * chan: pointer to channel structure, NULL if none found or none specified
+   * chg:  pointer to changes, NULL if none specified
+   */
+  ASSERT (!(arg == NULL && chan != NULL));
+
+  if (arg && !chan) {
+    dprintf(idx, "No channel record for %s.\n", arg);
     return;
   }
+
+  if (chg) {
+    if (!arg && strpbrk(chg, "&|")) {
+      /* botattr <handle> *[&|]*: use console channel if found... */
+      if (!strcmp ((arg = dcc[idx].u.chat->con_chan), "*"))
+        arg = NULL;
+      else
+        chan = findchan (arg);
+      if (arg && !chan) {
+        dprintf (idx, "Invalid console channel %s.\n", arg);
+	return;
+      }
+    } else if (arg && !strpbrk(chg, "&|")) {
+      context;
+      tmpchg = nmalloc(sizeof(chg)+1);
+      sprintf(tmpchg,"|%s",chg);
+      chg = tmpchg;
+    }
+  }
+  par = arg;
+  
   user.match = FR_GLOBAL;
   get_user_flagrec(u, &user, chan ? chan->name : 0);
   if (!glob_botmast(user)) {
     dprintf(idx, "You do not have Bot Master privileges.\n");
+    if (tmpchg)
+      nfree(tmpchg);
     return;
   }
   if (chg) {
@@ -1662,6 +1736,8 @@
     else
       dprintf(idx, "No bot flags for %s on %s.\n", hand, chan->name);
   }
+  if (tmpchg)
+    nfree(tmpchg);
 }
 
 static void cmd_chat(struct userrec *u, int idx, char *par)
@@ -2280,7 +2356,7 @@
     handle[HANDLEN] = 0;	/* max len = XX */
   if (get_user_by_handle(userlist, handle)) {
     dprintf(idx, "Someone already exists by that name.\n");
-  } else if (strchr(BADNICKCHARS, handle[0]) != NULL) {
+  } else if (strchr(BADHANDCHARS, handle[0]) != NULL) {
     dprintf(idx, "You can't start a nick with '%c'.\n", handle[0]);
   } else {
     putlog(LOG_CMDS, "*", "#%s# +user %s %s", dcc[idx].nick, handle, host);
diff -urN eggdrop1.3.29/src/eggdrop.h eggdrop1.3.29+cmall/src/eggdrop.h
--- eggdrop1.3.29/src/eggdrop.h	Fri Oct 15 17:09:39 1999
+++ eggdrop1.3.29+cmall/src/eggdrop.h	Fri Oct 15 16:41:15 1999
@@ -33,6 +33,7 @@
 /* handy string lengths */
 
 #define HANDLEN		9	/* valid values 9->NICKMAX */
+#define BADHANDCHARS  "-,+*=:!.@#;$%&"
 #define NICKMAX       15	/* valid values HANDLEN->32 */
 #define UHOSTLEN     161	/* reasonable, i think? */
 #define DIRLEN       256	/* paranoia */
diff -urN eggdrop1.3.29/src/mod/irc.mod/chan.c eggdrop1.3.29+cmall/src/mod/irc.mod/chan.c
--- eggdrop1.3.29/src/mod/irc.mod/chan.c	Fri Oct 15 17:09:39 1999
+++ eggdrop1.3.29+cmall/src/mod/irc.mod/chan.c	Fri Oct 15 16:38:08 1999
@@ -1891,7 +1891,7 @@
   {FR_GLOBAL | FR_CHAN, 0, 0, 0, 0, 0};
   int ignoring;
 
-  if (!strchr("#&+@", *msg))
+  if (!strchr(CHANMETA "@", *msg))
     return 0;
   ignoring = match_ignore(from);
   to = newsplit(&msg);
diff -urN eggdrop1.3.29/src/tcluser.c eggdrop1.3.29+cmall/src/tcluser.c
--- eggdrop1.3.29/src/tcluser.c	Fri Oct 15 17:09:39 1999
+++ eggdrop1.3.29+cmall/src/tcluser.c	Fri Oct 15 16:42:28 1999
@@ -361,7 +361,7 @@
 
 static int tcl_chnick STDVAR {
   struct userrec *u;
-  char hand[HANDLEN + 1];
+  char newhand[HANDLEN + 1];
   int x = 1, i;
 
   context;
@@ -370,24 +370,24 @@
   if (!u)
      x = 0;
   else {
-    strncpy(hand, argv[2], HANDLEN);
-    hand[HANDLEN] = 0;
-    for (i = 0; i < strlen(hand); i++)
-      if ((hand[i] <= 32) || (hand[i] >= 127) || (hand[i] == '@'))
-	hand[i] = '?';
-    if (strchr("-,+*=:!.@#;$", hand[0]) != NULL)
+    strncpy(newhand, argv[2], HANDLEN);
+    newhand[HANDLEN] = 0;
+    for (i = 0; i < strlen(newhand); i++)
+      if ((newhand[i] <= 32) || (newhand[i] >= 127) || (newhand[i] == '@'))
+	newhand[i] = '?';
+    if (strchr(BADHANDCHARS, newhand[0]) != NULL)
       x = 0;
-    else if (strlen(hand) < 1)
+    else if (strlen(newhand) < 1)
       x = 0;
-    else if (get_user_by_handle(userlist, hand))
+    else if (get_user_by_handle(userlist, newhand))
       x = 0;
-    else if (!strcasecmp(origbotname, hand) || !rfc_casecmp(botnetnick, hand))
+    else if (!strcasecmp(botnetnick, newhand))
       x = 0;
-    else if (hand[0] == '*')
+    else if (newhand[0] == '*')
       x = 0;
   }
   if (x)
-     x = change_handle(u, hand);
+     x = change_handle(u, newhand);
 
   Tcl_AppendResult(irp, x ? "1" : "0", NULL);
   return TCL_OK;
diff -urN eggdrop1.3.29/src/userrec.c eggdrop1.3.29+cmall/src/userrec.c
--- eggdrop1.3.29/src/userrec.c	Fri Oct 15 17:09:39 1999
+++ eggdrop1.3.29+cmall/src/userrec.c	Fri Oct 15 16:38:08 1999
@@ -543,7 +543,7 @@
   if (!u)
     return 0;
   /* nothing that will confuse the userfile */
-  if ((newh[1] == 0) && strchr("+*:=.-#&", newh[0]))
+  if ((newh[1] == 0) && strchr(BADHANDCHARS, newh[0]))
     return 0;
   check_tcl_nkch(u->handle, newh);
   /* yes, even send bot nick changes now: */


More information about the Patches mailing list