Fix several bugs; make off-channel a per-channel option
[srvx.git] / src / hash.c
index 92067ed4132060b020251461e39eba15963e2de5..edd745421fca6e7cbd9fd2bf56a074943c1d9a15 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"
@@ -139,7 +141,7 @@ ReintroduceUser(struct userNode *user)
     unsigned int n;
        
     irc_user(user);
-    change.modes_set = change.modes_clear = 0;
+    mod_chanmode_init(&change);
     change.argc = 1;
     for (n = 0; n < user->channels.used; n++) {
         struct modeNode *mn = user->channels.list[n];
@@ -302,14 +304,13 @@ wipeout_channel(struct chanNode *cNode, time_t new_time, char **modes, unsigned
     /* deop anybody in the channel now, but count services to reop */
     for (nn=argc=0; nn<cNode->members.used; nn++) {
         struct modeNode *mn = cNode->members.list[nn];
-        if (mn->modes & MODE_CHANOP && IsService(mn->user) && IsLocal(mn->user))
+        if ((mn->modes & MODE_CHANOP) && IsService(mn->user) && IsLocal(mn->user))
             argc++;
     }
     if (argc) {
-        extern struct userNode *opserv;
         struct mod_chanmode *change;
 
-        change = mod_chanmode_alloc(nn);
+        change = mod_chanmode_alloc(argc);
         change->modes_clear = 0;
         change->modes_set = orig_modes;
         change->new_limit = orig_limit;
@@ -322,10 +323,9 @@ wipeout_channel(struct chanNode *cNode, time_t new_time, char **modes, unsigned
                 argc++;
             }
         }
-        if (change->argc > 0)
-            mod_chanmode_announce(change->args[0].member->user, cNode, change);
-        else
-            mod_chanmode_announce(opserv, cNode, change);
+        assert(argc == change->argc);
+        change->args[0].member->modes &= ~MODE_CHANOP;
+        mod_chanmode_announce(change->args[0].member->user, cNode, change);
         mod_chanmode_free(change);
     }
 }
@@ -532,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);
 
@@ -544,15 +543,15 @@ DelChannelUser(struct userNode* user, struct chanNode* channel, const char *reas
     if (!mNode)
         return;
 
+    for (n=0; n<pf_used; n++)
+       pf_list[n](mNode, reason);
+
     /* remove modeNode from channel and user */
     modeList_remove(&channel->members, mNode);
     modeList_remove(&user->channels, mNode);
     free(mNode);
 
-    for (n=0; n<pf_used; n++)
-        pf_list[n](user, channel, reason);
-
-    if (!deleting && !channel->members.used && !channel->locks)
+    if (!deleting && !channel->members.used && !channel->locks && !(channel->modes & MODE_REGISTERED))
         DelChannel(channel);
 }
 
@@ -708,7 +707,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);