basic off-channel support; restructuring how part functions are handled
[srvx.git] / src / hash.c
index b63da6d7458a916c3260df09cd01abc506ee265b..cbe43ceaa9c1dc5627ff2f176e1eaf624ce7eb00 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);
     }
 }
@@ -465,6 +465,9 @@ AddChannelUser(struct userNode *user, struct chanNode* channel)
        modeList_append(&channel->members, mNode);
        modeList_append(&user->channels, mNode);
 
+        if (channel->members.used == 1)
+            mNode->modes |= MODE_CHANOP;
+
         for (n=0; n<jf_used; n++) {
             /* Callbacks return true if they kick or kill the user,
              * and we can continue without removing mNode. */
@@ -518,8 +521,7 @@ LockChannel(struct chanNode* channel)
 void
 UnlockChannel(struct chanNode *channel)
 {
-    if (!channel->locks)
-        return;
+    assert(channel->locks > 0);
     if (!--channel->locks && !channel->members.used)
         DelChannel(channel);
 }
@@ -542,14 +544,14 @@ 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)
         DelChannel(channel);
 }