Fix helpserv whine when helpers leave the channel; fix ?devoiceall
[srvx.git] / src / hash.c
index bf2633d261a075515f6149a4b51b793ebcf858a5..21bfa5f1bccc35c5534255f3203e50bf8a535ea8 100644 (file)
@@ -1,11 +1,12 @@
 /* hash.c - IRC network state database
  * Copyright 2000-2004 srvx Development Team
  *
- * This program is free software; you can redistribute it and/or modify
+ * This file is part of srvx.
+ *
+ * srvx is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.  Important limitations are
- * listed in the COPYING file that accompanies this software.
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,7 +14,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, email srvx-maintainers@srvx.net.
+ * along with srvx; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
  */
 
 #include "conf.h"
@@ -306,7 +308,6 @@ wipeout_channel(struct chanNode *cNode, time_t new_time, char **modes, unsigned
             argc++;
     }
     if (argc) {
-        extern struct userNode *opserv;
         struct mod_chanmode *change;
 
         change = mod_chanmode_alloc(argc);
@@ -323,10 +324,8 @@ wipeout_channel(struct chanNode *cNode, time_t new_time, char **modes, unsigned
             }
         }
         assert(argc == change->argc);
-        if (change->argc > 0)
-            mod_chanmode_announce(change->args[0].member->user, cNode, change);
-        else
-            mod_chanmode_announce(opserv, cNode, change);
+        change->args[0].member->modes &= ~MODE_CHANOP;
+        mod_chanmode_announce(change->args[0].member->user, cNode, change);
         mod_chanmode_free(change);
     }
 }
@@ -533,9 +532,8 @@ DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reas
     struct modeNode* mNode;
     unsigned int n;
 
-    if (reason) {
+    if (reason)
         irc_part(user, channel, reason);
-    }
 
     mNode = GetUserMode(channel, user);
 
@@ -548,12 +546,15 @@ DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reas
     /* remove modeNode from channel and user */
     modeList_remove(&channel->members, mNode);
     modeList_remove(&user->channels, mNode);
-    free(mNode);
 
+    /* make callbacks */
     for (n=0; n<pf_used; n++)
-        pf_list[n](user, channel, reason);
+       pf_list[n](mNode, reason);
 
-    if (!deleting && !channel->members.used && !channel->locks)
+    /* free memory */
+    free(mNode);
+
+    if (!deleting && !channel->members.used && !channel->locks && !(channel->modes & MODE_REGISTERED))
         DelChannel(channel);
 }
 
@@ -709,7 +710,13 @@ DEFINE_LIST(serverList, struct server*)
 static void
 hash_cleanup(void)
 {
+    dict_iterator_t it, next;
+
     DelServer(self, 0, NULL);
+    for (it = dict_first(channels); it; it = next) {
+        next = iter_next(it);
+        DelChannel(iter_data(it));
+    }
     dict_delete(channels);
     dict_delete(clients);
     dict_delete(servers);