[eggheads-patches] PATCH1.5: channel_part_fix_1.5.patch

Fabian Knittel fknittel at gmx.de
Mon Oct 23 16:31:01 CST 2000


[ channel_part_fix_1.5.patch ]

This patch fixes the PART bind behaviour. PART is now triggered
as soon as a channel channel is removed as well.

Fabian

--
Fabian Knittel <fknittel at gmx.de> -- http://www.esc-web.de/fabian/
Signed or encrypted mail preferred.    PGP DSA key ID: 0x838B4D20
-------------- next part --------------
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/doc/UPDATES1.5 eggdrop1.5/doc/UPDATES1.5
--- eggdrop1.5~/doc/UPDATES1.5	Mon Oct 23 22:42:37 2000
+++ eggdrop1.5/doc/UPDATES1.5	Mon Oct 23 22:43:54 2000
@@ -4,6 +4,9 @@
 
 1.5.5
 Found by  Fixed by  What...
+Sup       Fabian    Properly call PART bind when removing channel and the bot
+                    will therefore leave the channel shortly. Also slightly
+                    reworked channel removal.
           Fabian    Move actual assert check back into macro, saving a
                     function call.
 NigtHuntr Fabian    Removed small compile warning about ambigious if/else.
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/channels.mod/channels.c eggdrop1.5/src/mod/channels.mod/channels.c
--- eggdrop1.5~/src/mod/channels.mod/channels.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/channels.mod/channels.c	Mon Oct 23 22:42:49 2000
@@ -246,26 +246,20 @@
   return 0;
 }
 
-/* Destroy a chanset in the list
- * 
- * Note: does NOT free up memory associated with channel data inside
- *       the chanset!
+/* Unlink chanset element from chanset list.
  */
-static int killchanset(struct chanset_t *chan)
+inline static int chanset_unlink(struct chanset_t *chan)
 {
-  struct chanset_t *c = chanset, *old = NULL;
+  struct chanset_t	*c, *c_old = NULL;
 
-  while (c) {
+  for (c = chanset; c; c_old = c, c = c->next) {
     if (c == chan) {
-      if (old)
-	old->next = c->next;
+      if (c_old)
+	c_old->next = c->next;
       else
 	chanset = c->next;
-      nfree(c);
       return 1;
     }
-    old = c;
-    c = c->next;
   }
   return 0;
 }
@@ -277,7 +271,15 @@
  */
 static void remove_channel(struct chanset_t *chan)
 {
-   int i;
+   int		 i;
+   module_entry	*me;
+   
+   /* Remove the channel from the list, so that noone can pull it
+      away from under our feet during the check_tcl_part() call. */
+   (void) chanset_unlink(chan);
+
+   if ((me = module_find("irc", 1, 3)) != NULL)
+     (me->funcs[IRC_DO_CHANNEL_PART])();
 
    clear_channel(chan, 0);
    noshare = 1;
@@ -300,7 +302,7 @@
      nfree(chan->key);
    if (chan->rmkey)
      nfree(chan->rmkey);
-   killchanset(chan);
+   nfree(chan);
 }
 
 /* Bind this to chon and *if* the users console channel == ***
@@ -463,7 +465,7 @@
 
 static void read_channels(int create)
 {
-  struct chanset_t *chan, *chan2;
+  struct chanset_t *chan, *chan_next;
 
   if (!chanfile[0])
     return;
@@ -484,17 +486,12 @@
       fclose(f);
   }
   chan_hack = 0;
-  chan = chanset;
-  while (chan != NULL) {
+  for (chan = chanset; chan; chan = chan_next) {
+    chan_next = chan->next;
     if (chan->status & CHAN_FLAGGED) {
       putlog(LOG_MISC, "*", "No longer supporting channel %s", chan->dname);
-      if (chan->name[0] && !channel_inactive(chan))
-        dprintf(DP_SERVER, "PART %s\n", chan->name);
-      chan2 = chan->next;
       remove_channel(chan);
-      chan = chan2;
-    } else
-      chan = chan->next;
+    }
   }
 }
 
@@ -522,11 +519,9 @@
   read_channels(1);
   /* Remove any extra channels, by checking the flag. */
   chan = chanset;
-  while (chan) {
+  for (chan = chanset; chan;) {
     if (chan->status & CHAN_FLAGGED) {
       putlog(LOG_MISC, "*", "No longer supporting channel %s", chan->dname);
-      if (chan->name[0] && !channel_inactive(chan))
-        dprintf(DP_SERVER, "PART %s\n", chan->name);
       remove_channel(chan);
       chan = chanset;
     } else
@@ -849,7 +844,7 @@
   /* 32 - 35 */
   (Function) NULL,/* [32] used to be u_sticky_exempt() <cybah> */
   (Function) NULL,
-  (Function) killchanset,
+  (Function) NULL,	/* [34] used to be killchanset().	*/
   (Function) u_delinvite,
   /* 36 - 39 */
   (Function) u_addinvite,
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/channels.mod/channels.h eggdrop1.5/src/mod/channels.mod/channels.h
--- eggdrop1.5~/src/mod/channels.mod/channels.h	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/channels.mod/channels.h	Mon Oct 23 22:42:49 2000
@@ -87,7 +87,6 @@
 static void check_expired_invites(void);
 static void write_channels(void);
 static void read_channels(int);
-static int killchanset(struct chanset_t *);
 static void clear_channel(struct chanset_t *, int);
 static void get_mode_protect(struct chanset_t *chan, char *s);
 static void set_mode_protect(struct chanset_t *chan, char *set);
@@ -106,6 +105,7 @@
 static void setudef(struct udef_struct *, char *, int);
 static void remove_channel(struct chanset_t *);
 static int ngetudef(char *, char *);
+inline static int chanset_unlink(struct chanset_t *chan);
 
 #else
 
@@ -147,7 +147,7 @@
 /* 32 - 35 */
 /* *HOLE* channels_funcs[32] used to be u_sticky_exempt() <cybah> */
 /* *HOLE* channels_funcs[33] used to be u_match_invite() <cybah> */
-#define killchanset ((int (*)(struct chanset_t *))channels_funcs[354)
+/* *HOLE* channels_funcs[34] used to be killchanset().			*/
 #define u_delinvite ((int (*)(struct chanset_t *, char *, int))channels_funcs[35])
 /* 36 - 39 */
 #define u_addinvite ((int (*)(struct chanset_t *, char *, char *, char *, time_t, int))channels_funcs[36])
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/channels.mod/cmdschan.c eggdrop1.5/src/mod/channels.mod/cmdschan.c
--- eggdrop1.5~/src/mod/channels.mod/cmdschan.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/channels.mod/cmdschan.c	Mon Oct 23 22:42:49 2000
@@ -1134,10 +1134,6 @@
     return;
   }
 
-  /* Using chan->name is important here, especially for !chans <cybah> */
-  if (!channel_inactive(chan) && chan->name[0])
-    dprintf(DP_SERVER, "PART %s\n", chan->name);
-
   remove_channel(chan);
   dprintf(idx, "Channel %s removed from the bot.\n", chname);
   dprintf(idx, "This includes any channel specific bans, invites, exemptions and user records that you set.\n");
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/channels.mod/tclchan.c eggdrop1.5/src/mod/channels.mod/tclchan.c
--- eggdrop1.5~/src/mod/channels.mod/tclchan.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/channels.mod/tclchan.c	Mon Oct 23 22:42:49 2000
@@ -917,8 +917,6 @@
       Tcl_AppendResult(irp, "no such channel record", NULL);
       return TCL_ERROR;
     }
-    if (!channel_inactive(chan))
-      dprintf(DP_SERVER, "PART %s\n", chan->name);
     remove_channel(chan);
     return TCL_OK;
   }
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/irc.mod/irc.c eggdrop1.5/src/mod/irc.mod/irc.c
--- eggdrop1.5~/src/mod/irc.mod/irc.c	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/irc.mod/irc.c	Mon Oct 23 22:42:49 2000
@@ -463,6 +463,21 @@
   }
 }
 
+/* Leave the specified channel and notify registered Tcl procs. This
+ * should not be called by itsself.
+ */
+static void do_channel_part(struct chanset_t *chan)
+{
+  if (!channel_inactive(chan) && chan->name[0]) {
+    /* Using chan->name is important here, especially for !chans <cybah> */
+    dprintf(DP_SERVER, "PART %s\n", chan->name);
+
+    /* As we don't know of this channel anymore when we receive the server's
+       ack for the above PART, we have to notify about it _now_. */
+    check_tcl_part(botname, botuserhost, NULL, chan->dname, NULL);
+  }
+}
+
 /* Report the channel status of every active channel to dcc chat every
  * 5 minutes.
  */
@@ -1186,6 +1201,8 @@
   (Function) me_op,
   (Function) recheck_channel_modes,
   (Function) & H_need,		/* p_tcl_bind_list		*/
+  (Function) do_channel_part,
+  /* 20 - 23 */
 };
 
 char *irc_start(Function * global_funcs)
@@ -1195,7 +1212,7 @@
   global = global_funcs;
 
   Context;
-  module_register(MODULE_NAME, irc_table, 1, 2);
+  module_register(MODULE_NAME, irc_table, 1, 3);
   if (!module_depend(MODULE_NAME, "eggdrop", 105, 3)) {
     module_undepend(MODULE_NAME);
     return "This module needs eggdrop1.5.3 or later";
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/irc.mod/irc.h eggdrop1.5/src/mod/irc.mod/irc.h
--- eggdrop1.5~/src/mod/irc.mod/irc.h	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/irc.mod/irc.h	Mon Oct 23 22:42:49 2000
@@ -104,6 +104,8 @@
 #define me_op ((int(*)(struct chanset_t *))irc_funcs[16])
 /* recheck_channel_modes is here */
 #define H_need (*(p_tcl_bind_list*)(irc_funcs[18]))
+/* do_channel_part is here. */
+/* 20 - 23 */
 
 #endif				/* MAKING_IRC */
 
diff -urN --exclude-from=/home/fabian/.diffex eggdrop1.5~/src/mod/modvals.h eggdrop1.5/src/mod/modvals.h
--- eggdrop1.5~/src/mod/modvals.h	Thu Oct 19 19:25:39 2000
+++ eggdrop1.5/src/mod/modvals.h	Mon Oct 23 22:42:49 2000
@@ -72,6 +72,7 @@
 /* IRC */
 #define IRC_RECHECK_CHANNEL	  15
 #define IRC_RECHECK_CHANNEL_MODES 17
+#define IRC_DO_CHANNEL_PART	  19
 /* Notes */
 #define NOTES_CMD_NOTE		  4
 /* Console */




More information about the Patches mailing list