]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/channels.cpp
Normalise paths in the httpd module.
[user/henk/code/inspircd.git] / src / channels.cpp
index 780251f5f9c34bcb756a5275ffde9f48bc757d01..972efa92773865592db8b4c8703bb1ad09ee9c60 100644 (file)
-/*   +------------------------------------+
- *   | Inspire Internet Relay Chat Daemon |
- *   +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
+ *   Copyright (C) 2013-2014, 2016-2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013 Adam <Adam@anope.org>
+ *   Copyright (C) 2012-2016, 2018 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ *   Copyright (C) 2006-2008, 2010 Craig Edwards <brain@inspircd.org>
+ *
+ * This file is part of InspIRCd.  InspIRCd 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, version 2.
  *
- *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- *   E-mail:
- *       <brain@chatspike.net>
- *       <Craig@chatspike.net>
- * 
- * Written by Craig Edwards, Craig McLure, and others.
- * This program is free but copyrighted software; see
- *     the file COPYING for details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the 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, see <http://www.gnu.org/licenses/>.
  */
 
-using namespace std;
 
-#include <string>
-#include <map>
-#include <sstream>
-#include <vector>
-#include <deque>
-#include <stdarg.h>
-#include "configreader.h"
 #include "inspircd.h"
-#include "hash_map.h"
-#include "users.h"
-#include "ctables.h"
-#include "globals.h"
-#include "modules.h"
-#include "dynamic.h"
-#include "commands.h"
-#include "wildcard.h"
-#include "mode.h"
-#include "xline.h"
-#include "inspstring.h"
-
-#include "typedefs.h"
-
-chanrec::chanrec(InspIRCd* Instance) : ServerInstance(Instance)
-{
-       *name = *topic = *setby = *key = 0;
-       created = topicset = limit = 0;
-       internal_userlist.clear();
-       memset(&modes,0,64);
-}
+#include "listmode.h"
 
-void chanrec::SetMode(char mode,bool mode_on)
+namespace
 {
-       modes[mode-65] = mode_on;
-       if (!mode_on)
-               this->SetModeParam(mode,"",false);
+       ChanModeReference ban(NULL, "ban");
 }
 
-
-void chanrec::SetModeParam(char mode,const char* parameter,bool mode_on)
+Channel::Channel(const std::string &cname, time_t ts)
+       : name(cname), age(ts), topicset(0)
 {
-       ServerInstance->Log(DEBUG,"SetModeParam called");
-       
-       CustomModeList::iterator n = custom_mode_params.find(mode);     
-
-       if (mode_on)
-       {
-               if (n == custom_mode_params.end())
-               {
-                       custom_mode_params[mode] = strdup(parameter);
-                       ServerInstance->Log(DEBUG,"Custom mode parameter %c %s added",mode,parameter);
-               }
-               else
-               {
-                       ServerInstance->Log(DEBUG, "Tried to set custom mode parameter for %c '%s' when it was already '%s'", mode, parameter, n->second);
-               }
-       }
-       else
-       {
-               if (n != custom_mode_params.end())
-               {
-                       free(n->second);
-                       custom_mode_params.erase(n);
-               }
-       }
+       if (!ServerInstance->chanlist.insert(std::make_pair(cname, this)).second)
+               throw CoreException("Cannot create duplicate channel " + cname);
 }
 
-bool chanrec::IsModeSet(char mode)
+void Channel::SetMode(ModeHandler* mh, bool on)
 {
-       return modes[mode-65];
+       if (mh && mh->GetId() != ModeParser::MODEID_MAX)
+               modes[mh->GetId()] = on;
 }
 
-std::string chanrec::GetModeParameter(char mode)
+void Channel::SetTopic(User* u, const std::string& ntopic, time_t topicts, const std::string* setter)
 {
-       if (mode == 'k')
+       // Send a TOPIC message to the channel only if the new topic text differs
+       if (this->topic != ntopic)
        {
-               return this->key;
+               this->topic = ntopic;
+               ClientProtocol::Messages::Topic topicmsg(u, this, this->topic);
+               Write(ServerInstance->GetRFCEvents().topic, topicmsg);
        }
-       else if (mode == 'l')
-       {
-               return ConvToStr(this->limit);
-       }
-       else
-       {
-               CustomModeList::iterator n = custom_mode_params.find(mode);
-               if (n != custom_mode_params.end())
-               {
-                       return n->second;
-               }
-               return "";
-       }
-}
 
-long chanrec::GetUserCounter()
-{
-       return (this->internal_userlist.size());
-}
+       // Always update setter and set time
+       if (!setter)
+               setter = ServerInstance->Config->FullHostInTopic ? &u->GetFullHost() : &u->nick;
+       this->setby.assign(*setter, 0, ServerInstance->Config->Limits.GetMaxMask());
+       this->topicset = topicts;
 
-void chanrec::AddUser(userrec* user)
-{
-       internal_userlist[user] = user;
+       FOREACH_MOD(OnPostTopicChange, (u, this, this->topic));
 }
 
-unsigned long chanrec::DelUser(userrec* user)
+Membership* Channel::AddUser(User* user)
 {
-       CUListIter a = internal_userlist.find(user);
-       
-       if (a != internal_userlist.end())
-       {
-               internal_userlist.erase(a);
-               /* And tidy any others... */
-               DelOppedUser(user);
-               DelHalfoppedUser(user);
-               DelVoicedUser(user);
-       }
-       
-       return internal_userlist.size();
-}
+       std::pair<MemberMap::iterator, bool> ret = userlist.insert(std::make_pair(user, insp::aligned_storage<Membership>()));
+       if (!ret.second)
+               return NULL;
 
-bool chanrec::HasUser(userrec* user)
-{
-       return (internal_userlist.find(user) != internal_userlist.end());
+       Membership* memb = new(ret.first->second) Membership(user, this);
+       return memb;
 }
 
-void chanrec::AddOppedUser(userrec* user)
+void Channel::DelUser(User* user)
 {
-       internal_op_userlist[user] = user;
+       MemberMap::iterator it = userlist.find(user);
+       if (it != userlist.end())
+               DelUser(it);
 }
 
-void chanrec::DelOppedUser(userrec* user)
+void Channel::CheckDestroy()
 {
-       CUListIter a = internal_op_userlist.find(user);
-       if (a != internal_op_userlist.end())
-       {
-               internal_op_userlist.erase(a);
+       if (!userlist.empty())
                return;
-       }
-}
-
-void chanrec::AddHalfoppedUser(userrec* user)
-{
-       internal_halfop_userlist[user] = user;
-}
-
-void chanrec::DelHalfoppedUser(userrec* user)
-{
-       CUListIter a = internal_halfop_userlist.find(user);
-
-       if (a != internal_halfop_userlist.end())
-       {   
-               internal_halfop_userlist.erase(a);
-       }
-}
 
-void chanrec::AddVoicedUser(userrec* user)
-{
-       internal_voice_userlist[user] = user;
-}
+       ModResult res;
+       FIRST_MOD_RESULT(OnChannelPreDelete, res, (this));
+       if (res == MOD_RES_DENY)
+               return;
 
-void chanrec::DelVoicedUser(userrec* user)
-{
-       CUListIter a = internal_voice_userlist.find(user);
-       
-       if (a != internal_voice_userlist.end())
-       {
-               internal_voice_userlist.erase(a);
-       }
-}
+       // If the channel isn't in chanlist then it is already in the cull list, don't add it again
+       chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
+       if ((iter == ServerInstance->chanlist.end()) || (iter->second != this))
+               return;
 
-CUList* chanrec::GetUsers()
-{
-       return &internal_userlist;
+       FOREACH_MOD(OnChannelDelete, (this));
+       ServerInstance->chanlist.erase(iter);
+       ServerInstance->GlobalCulls.AddItem(this);
 }
 
-CUList* chanrec::GetOppedUsers()
+void Channel::DelUser(const MemberMap::iterator& membiter)
 {
-       return &internal_op_userlist;
-}
+       Membership* memb = membiter->second;
+       memb->cull();
+       memb->~Membership();
+       userlist.erase(membiter);
 
-CUList* chanrec::GetHalfoppedUsers()
-{
-       return &internal_halfop_userlist;
+       // If this channel became empty then it should be removed
+       CheckDestroy();
 }
 
-CUList* chanrec::GetVoicedUsers()
+Membership* Channel::GetUser(User* user)
 {
-       return &internal_voice_userlist;
+       MemberMap::iterator i = userlist.find(user);
+       if (i == userlist.end())
+               return NULL;
+       return i->second;
 }
 
-/* 
- * add a channel to a user, creating the record for it if needed and linking
- * it to the user record 
- */
-chanrec* chanrec::JoinUser(InspIRCd* Instance, userrec *user, const char* cn, bool override, const char* key)
+void Channel::SetDefaultModes()
 {
-       if (!user || !cn)
-               return NULL;
-
-       int created = 0;
-       char cname[MAXBUF];
-       int MOD_RESULT = 0;
-       strlcpy(cname,cn,CHANMAX);
+       ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "SetDefaultModes %s",
+               ServerInstance->Config->DefaultModes.c_str());
+       irc::spacesepstream list(ServerInstance->Config->DefaultModes);
+       std::string modeseq;
+       std::string parameter;
 
-       chanrec* Ptr = Instance->FindChan(cname);
+       list.GetToken(modeseq);
 
-       if (!Ptr)
+       for (std::string::iterator n = modeseq.begin(); n != modeseq.end(); ++n)
        {
-               if (IS_LOCAL(user))
+               ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
+               if (mode)
                {
-                       MOD_RESULT = 0;
-                       FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,NULL,cname));
-                       if (MOD_RESULT == 1)
-                               return NULL;
-               }
+                       if (mode->IsPrefixMode())
+                               continue;
 
-               /* create a new one */
-               Ptr = new chanrec(Instance);
-               Instance->chanlist[cname] = Ptr;
-
-               strlcpy(Ptr->name, cname,CHANMAX);
-               Ptr->modes[CM_TOPICLOCK] = Ptr->modes[CM_NOEXTERNAL] = 1;
-               Ptr->created = Instance->Time();
-               *Ptr->topic = 0;
-               strlcpy(Ptr->setby, user->nick,NICKMAX-1);
-               Ptr->topicset = 0;
-               Instance->Log(DEBUG,"chanrec::JoinUser(): created: %s",cname);
-               /*
-                * set created to 2 to indicate user
-                * is the first in the channel
-                * and should be given ops
-                */
-               created = 2;
-       }
-       else
-       {
-               /* Already on the channel */
-               if (Ptr->HasUser(user))
-                       return NULL;
-
-               /*
-                * remote users are allowed us to bypass channel modes
-                * and bans (used by servers)
-                */
-               if (IS_LOCAL(user)) /* was a check on fd > -1 */
-               {
-                       MOD_RESULT = 0;
-                       FOREACH_RESULT_I(Instance,I_OnUserPreJoin,OnUserPreJoin(user,Ptr,cname));
-                       if (MOD_RESULT == 1)
-                       {
-                               return NULL;
-                       }
-                       else if (MOD_RESULT == 0)
+                       if (mode->NeedsParam(true))
                        {
-                               if (*Ptr->key)
-                               {
-                                       MOD_RESULT = 0;
-                                       FOREACH_RESULT_I(Instance,I_OnCheckKey,OnCheckKey(user, Ptr, key ? key : ""));
-                                       if (!MOD_RESULT)
-                                       {
-                                               if (!key)
-                                               {
-                                                       Instance->Log(DEBUG,"chanrec::JoinUser(): no key given in JOIN");
-                                                       user->WriteServ("475 %s %s :Cannot join channel (Requires key)",user->nick, Ptr->name);
-                                                       return NULL;
-                                               }
-                                               else
-                                               {
-                                                       if (strcmp(key,Ptr->key))
-                                                       {
-                                                               Instance->Log(DEBUG,"chanrec::JoinUser(): bad key given in JOIN");
-                                                               user->WriteServ("475 %s %s :Cannot join channel (Incorrect key)",user->nick, Ptr->name);
-                                                               return NULL;
-                                                       }
-                                               }
-                                       }
-                               }
-                               if (Ptr->modes[CM_INVITEONLY])
-                               {
-                                       MOD_RESULT = 0;
-                                       irc::string xname(Ptr->name);
-                                       FOREACH_RESULT_I(Instance,I_OnCheckInvite,OnCheckInvite(user, Ptr));
-                                       if (!MOD_RESULT)
-                                       {
-                                               if (user->IsInvited(xname))
-                                               {
-                                                       /* user was invited to channel */
-                                                       /* there may be an optional channel NOTICE here */
-                                               }
-                                               else
-                                               {
-                                                       user->WriteServ("473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
-                                                       return NULL;
-                                               }
-                                       }
-                                       user->RemoveInvite(xname);
-                               }
-                               if (Ptr->limit)
-                               {
-                                       MOD_RESULT = 0;
-                                       FOREACH_RESULT_I(Instance,I_OnCheckLimit,OnCheckLimit(user, Ptr));
-                                       if (!MOD_RESULT)
-                                       {
-                                               if (Ptr->GetUserCounter() >= Ptr->limit)
-                                               {
-                                                       user->WriteServ("471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name);
-                                                       return NULL;
-                                               }
-                                       }
-                               }
-                               if (Ptr->bans.size())
-                               {
-                                       MOD_RESULT = 0;
-                                       FOREACH_RESULT_I(Instance,I_OnCheckBan,OnCheckBan(user, Ptr));
-                                       char mask[MAXBUF];
-                                       sprintf(mask,"%s!%s@%s",user->nick, user->ident, user->GetIPString());
-                                       if (!MOD_RESULT)
-                                       {
-                                               for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
-                                               {
-                                                       /* This allows CIDR ban matching
-                                                        * 
-                                                        *        Full masked host                      Full unmasked host                   IP with/without CIDR
-                                                        */
-                                                       if ((match(user->GetFullHost(),i->data)) || (match(user->GetFullRealHost(),i->data)) || (match(mask, i->data, true)))
-                                                       {
-                                                               user->WriteServ("474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
-                                                               return NULL;
-                                                       }
-                                               }
-                                       }
-                               }
+                               list.GetToken(parameter);
+                               // If the parameter begins with a ':' then it's invalid
+                               if (parameter.c_str()[0] == ':')
+                                       continue;
                        }
+                       else
+                               parameter.clear();
+
+                       if ((mode->NeedsParam(true)) && (parameter.empty()))
+                               continue;
+
+                       mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
                }
-               else
-               {
-                       Instance->Log(DEBUG,"chanrec::JoinUser(): Overridden checks");
-               }
-               created = 1;
        }
+}
 
-       for (UserChanList::const_iterator index = user->chans.begin(); index != user->chans.end(); index++)
+/*
+ * add a channel to a user, creating the record for it if needed and linking
+ * it to the user record
+ */
+Channel* Channel::JoinUser(LocalUser* user, std::string cname, bool override, const std::string& key)
+{
+       if (user->registered != REG_ALL)
        {
-               if ((*index)->channel == NULL)
-               {
-                       return chanrec::ForceChan(Instance, Ptr, *index, user, created);
-               }
+               ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join unregistered user " + user->uuid + " to channel " + cname);
+               return NULL;
        }
 
        /*
-        * XXX: If the user is an oper here, we can just extend their user->chans vector by one
-        * and put the channel in here. Same for remote users which are not bound by
-        * the channel limits. Otherwise, nope, youre boned.
+        * We don't restrict the number of channels that remote users or users that are override-joining may be in.
+        * We restrict local users to <connect:maxchans> channels.
+        * We restrict local operators to <oper:maxchans> channels.
+        * This is a lot more logical than how it was formerly. -- w00t
         */
-       if (!IS_LOCAL(user)) /* was a check on fd < 0 */
+       if (!override)
        {
-               ucrec* a = new ucrec();
-               chanrec* c = chanrec::ForceChan(Instance, Ptr,a,user,created);
-               user->chans.push_back(a);
-               return c;
-       }
-       else if (*user->oper)
-       {
-               /* Oper allows extension up to the OPERMAXCHANS value */
-               if (user->chans.size() < OPERMAXCHANS)
+               unsigned int maxchans = user->GetClass()->maxchans;
+               if (!maxchans)
+                       maxchans = ServerInstance->Config->MaxChans;
+               if (user->IsOper())
                {
-                       ucrec* a = new ucrec();
-                       chanrec* c = chanrec::ForceChan(Instance, Ptr,a,user,created);
-                       user->chans.push_back(a);
-                       return c;
+                       unsigned int opermaxchans = ConvToNum<unsigned int>(user->oper->getConfig("maxchans"));
+                       // If not set, use 2.0's <channels:opers>, if that's not set either, use limit from CC
+                       if (!opermaxchans && user->HasPrivPermission("channels/high-join-limit"))
+                               opermaxchans = ServerInstance->Config->OperMaxChans;
+                       if (opermaxchans)
+                               maxchans = opermaxchans;
                }
-       }
-
-       user->WriteServ("405 %s %s :You are on too many channels",user->nick, cname);
-
-       if (created == 2)
-       {
-               Instance->Log(DEBUG,"BLAMMO, Whacking channel.");
-               /* Things went seriously pear shaped, so take this away. bwahaha. */
-               chan_hash::iterator n = Instance->chanlist.find(cname);
-               if (n != Instance->chanlist.end())
+               if (user->chans.size() >= maxchans)
                {
-                       Ptr->DelUser(user);
-                       DELETE(Ptr);
-                       Instance->chanlist.erase(n);
-                       for (unsigned int index =0; index < user->chans.size(); index++)
-                       {
-                               if (user->chans[index]->channel == Ptr)
-                               {
-                                       user->chans[index]->channel = NULL;
-                                       user->chans[index]->uc_modes = 0;       
-                               }
-                       }
+                       user->WriteNumeric(ERR_TOOMANYCHANNELS, cname, "You are on too many channels");
+                       return NULL;
                }
        }
-       else
+
+       // Crop channel name if it's too long
+       if (cname.length() > ServerInstance->Config->Limits.ChanMax)
+               cname.resize(ServerInstance->Config->Limits.ChanMax);
+
+       Channel* chan = ServerInstance->FindChan(cname);
+       bool created_by_local = (chan == NULL); // Flag that will be passed to modules in the OnUserJoin() hook later
+       std::string privs; // Prefix mode(letter)s to give to the joining user
+
+       if (!chan)
        {
-               for (unsigned int index =0; index < user->chans.size(); index++)
+               privs = ServerInstance->Config->DefaultModes.substr(0, ServerInstance->Config->DefaultModes.find(' '));
+
+               if (override == false)
                {
-                       if (user->chans[index]->channel == Ptr)
-                       {
-                               user->chans[index]->channel = NULL;
-                               user->chans[index]->uc_modes = 0;
-                       }
+                       // Ask the modules whether they're ok with the join, pass NULL as Channel* as the channel is yet to be created
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, NULL, cname, privs, key));
+                       if (MOD_RESULT == MOD_RES_DENY)
+                               return NULL; // A module wasn't happy with the join, abort
                }
-       }
-       return NULL;
-}
 
-chanrec* chanrec::ForceChan(InspIRCd* Instance, chanrec* Ptr,ucrec *a,userrec* user, int created)
-{
-       if (created == 2)
-       {
-               /* first user in is given ops */
-               a->uc_modes = UCMODE_OP;
-               Ptr->AddOppedUser(user);
-               Ptr->SetPrefix(user, '@', OP_VALUE, true);
+               chan = new Channel(cname, ServerInstance->Time());
+               // Set the default modes on the channel (<options:defaultmodes>)
+               chan->SetDefaultModes();
        }
        else
        {
-               a->uc_modes = 0;
-       }
-
-       a->channel = Ptr;
-       Ptr->AddUser(user);
-       Ptr->WriteChannel(user,"JOIN :%s",Ptr->name);
+               /* Already on the channel */
+               if (chan->HasUser(user))
+                       return NULL;
 
-       /* Major improvement by Brain - we dont need to be calculating all this pointlessly for remote users */
-       if (IS_LOCAL(user))
-       {
-               if (Ptr->topicset)
+               if (override == false)
                {
-                       user->WriteServ("332 %s %s :%s", user->nick, Ptr->name, Ptr->topic);
-                       user->WriteServ("333 %s %s %s %lu", user->nick, Ptr->name, Ptr->setby, (unsigned long)Ptr->topicset);
-               }
-               Ptr->UserList(user);
-       }
-       FOREACH_MOD_I(Instance,I_OnUserJoin,OnUserJoin(user,Ptr));
-       return Ptr;
-}
+                       ModResult MOD_RESULT;
+                       FIRST_MOD_RESULT(OnUserPreJoin, MOD_RESULT, (user, chan, cname, privs, key));
 
-/* chanrec::PartUser
- * remove a channel from a users record, and remove the record from the hash
- * if the channel has become empty
- */
-long chanrec::PartUser(userrec *user, const char* reason)
-{
-       if (!user)
-               return this->GetUserCounter();
+                       // A module explicitly denied the join and (hopefully) generated a message
+                       // describing the situation, so we may stop here without sending anything
+                       if (MOD_RESULT == MOD_RES_DENY)
+                               return NULL;
 
-       for (unsigned int i =0; i < user->chans.size(); i++)
-       {
-               /* zap it from the channel list of the user */
-               if (user->chans[i]->channel == this)
-               {
-                       if (reason)
+                       // If no module returned MOD_RES_DENY or MOD_RES_ALLOW (which is the case
+                       // most of the time) then proceed to check channel bans.
+                       //
+                       // If a module explicitly allowed the join (by returning MOD_RES_ALLOW),
+                       // then this entire section is skipped
+                       if (MOD_RESULT == MOD_RES_PASSTHRU)
                        {
-                               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, reason));
-                               this->WriteChannel(user, "PART %s :%s", this->name, reason);
-                       }
-                       else
-                       {
-                               FOREACH_MOD(I_OnUserPart,OnUserPart(user, this, ""));
-                               this->WriteChannel(user, "PART :%s", this->name);
+                               if (chan->IsBanned(user))
+                               {
+                                       user->WriteNumeric(ERR_BANNEDFROMCHAN, chan->name, "Cannot join channel (you're banned)");
+                                       return NULL;
+                               }
                        }
-                       user->chans[i]->uc_modes = 0;
-                       user->chans[i]->channel = NULL;
-                       this->RemoveAllPrefixes(user);
-                       break;
-               }
-       }
-
-       if (!this->DelUser(user)) /* if there are no users left on the channel... */
-       {
-               chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
-               /* kill the record */
-               if (iter != ServerInstance->chanlist.end())
-               {
-                       ServerInstance->Log(DEBUG,"del_channel: destroyed: %s", this->name);
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
-                       ServerInstance->chanlist.erase(iter);
                }
-               return 0;
        }
 
-       return this->GetUserCounter();
+       // We figured that this join is allowed and also created the
+       // channel if it didn't exist before, now do the actual join
+       chan->ForceJoin(user, &privs, false, created_by_local);
+       return chan;
 }
 
-long chanrec::ServerKickUser(userrec* user, const char* reason, bool triggerevents)
+Membership* Channel::ForceJoin(User* user, const std::string* privs, bool bursting, bool created_by_local)
 {
-       if (!user || !reason)
-               return this->GetUserCounter();
-
-       if (IS_LOCAL(user))
+       if (IS_SERVER(user))
        {
-               if (!this->HasUser(user))
-               {
-                       /* Not on channel */
-                       return this->GetUserCounter();
-               }
+               ServerInstance->Logs->Log("CHANNELS", LOG_DEBUG, "Attempted to join server user " + user->uuid + " to channel " + this->name);
+               return NULL;
        }
 
-       if (triggerevents)
-       {
-               FOREACH_MOD(I_OnUserKick,OnUserKick(NULL,user,this,reason));
-       }
+       Membership* memb = this->AddUser(user);
+       if (!memb)
+               return NULL; // Already on the channel
 
-       for (unsigned int i =0; i < user->chans.size(); i++)
-       {
-               if (user->chans[i]->channel == this)
-               {
-                       this->WriteChannelWithServ(ServerInstance->Config->ServerName, "KICK %s %s :%s", this->name, user->nick, reason);
-                       user->chans[i]->uc_modes = 0;
-                       user->chans[i]->channel = NULL;
-                       this->RemoveAllPrefixes(user);
-                       break;
-               }
-       }
+       user->chans.push_front(memb);
 
-       if (!this->DelUser(user))
+       if (privs)
        {
-               chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
-               /* kill the record */
-               if (iter != ServerInstance->chanlist.end())
+               // If the user was granted prefix modes (in the OnUserPreJoin hook, or they're a
+               // remote user and their own server set the modes), then set them internally now
+               for (std::string::const_iterator i = privs->begin(); i != privs->end(); ++i)
                {
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
-                       ServerInstance->chanlist.erase(iter);
+                       PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
+                       if (mh)
+                       {
+                               std::string nick = user->nick;
+                               // Set the mode on the user
+                               mh->OnModeChange(ServerInstance->FakeClient, NULL, this, nick, true);
+                       }
                }
-               return 0;
        }
 
-       return this->GetUserCounter();
+       // Tell modules about this join, they have the chance now to populate except_list with users we won't send the JOIN (and possibly MODE) to
+       CUList except_list;
+       FOREACH_MOD(OnUserJoin, (memb, bursting, created_by_local, except_list));
+
+       ClientProtocol::Events::Join joinevent(memb);
+       this->Write(joinevent, 0, except_list);
+
+       FOREACH_MOD(OnPostJoin, (memb));
+       return memb;
 }
 
-long chanrec::KickUser(userrec *src, userrec *user, const char* reason)
+bool Channel::IsBanned(User* user)
 {
-       if (!src || !user || !reason)
-               return this->GetUserCounter();
+       ModResult result;
+       FIRST_MOD_RESULT(OnCheckChannelBan, result, (user, this));
 
-       if (IS_LOCAL(src))
-       {
-               if (!this->HasUser(user))
-               {
-                       src->WriteServ("441 %s %s %s :They are not on that channel",src->nick, user->nick, this->name);
-                       return this->GetUserCounter();
-               }
-               if ((ServerInstance->ULine(user->server)) && (!ServerInstance->ULine(src->server)))
-               {
-                       src->WriteServ("482 %s %s :Only a u-line may kick a u-line from a channel.",src->nick, this->name);
-                       return this->GetUserCounter();
-               }
-               int MOD_RESULT = 0;
-
-               if (!ServerInstance->ULine(src->server))
-               {
-                       MOD_RESULT = 0;
-                       FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,this,reason));
-                       if (MOD_RESULT == 1)
-                               return this->GetUserCounter();
-               }
-               /* Set to -1 by OnUserPreKick if explicit allow was set */
-               if (MOD_RESULT != -1)
-               {
-                       FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,this,AC_KICK));
-                       if ((MOD_RESULT == ACR_DENY) && (!ServerInstance->ULine(src->server)))
-                               return this->GetUserCounter();
-       
-                       if ((MOD_RESULT == ACR_DEFAULT) || (!ServerInstance->ULine(src->server)))
-                       {
-                               int them = this->GetStatus(src);
-                               int us = this->GetStatus(user);
-                               if ((them < STATUS_HOP) || (them < us))
-                               {
-                                       if (them == STATUS_HOP)
-                                       {
-                                               src->WriteServ("482 %s %s :You must be a channel operator",src->nick, this->name);
-                                       }
-                                       else
-                                       {
-                                               src->WriteServ("482 %s %s :You must be at least a half-operator",src->nick, this->name);
-                                       }
-                                       return this->GetUserCounter();
-                               }
-                       }
-               }
-       }
+       if (result != MOD_RES_PASSTHRU)
+               return (result == MOD_RES_DENY);
 
-       FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,this,reason));
-                       
-       for (UserChanList::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
-       {
-               /* zap it from the channel list of the user */
-               if ((*i)->channel == this)
-               {
-                       this->WriteChannel(src, "KICK %s %s :%s", this->name, user->nick, reason);
-                       (*i)->uc_modes = 0;
-                       (*i)->channel = NULL;
-                       this->RemoveAllPrefixes(user);
-                       break;
-               }
-       }
+       ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+       if (!banlm)
+               return false;
 
-       if (!this->DelUser(user))
-       /* if there are no users left on the channel */
+       const ListModeBase::ModeList* bans = banlm->GetList(this);
+       if (bans)
        {
-               chan_hash::iterator iter = ServerInstance->chanlist.find(this->name);
-
-               /* kill the record */
-               if (iter != ServerInstance->chanlist.end())
+               for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); it++)
                {
-                       FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(this));
-                       ServerInstance->chanlist.erase(iter);
+                       if (CheckBan(user, it->mask))
+                               return true;
                }
-               return 0;
        }
-
-       return this->GetUserCounter();
+       return false;
 }
 
-void chanrec::WriteChannel(userrec* user, char* text, ...)
+bool Channel::CheckBan(User* user, const std::string& mask)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
+       ModResult result;
+       FIRST_MOD_RESULT(OnCheckBan, result, (user, this, mask));
+       if (result != MOD_RES_PASSTHRU)
+               return (result == MOD_RES_DENY);
 
-       if (!user || !text)
-               return;
+       // extbans were handled above, if this is one it obviously didn't match
+       if ((mask.length() <= 2) || (mask[1] == ':'))
+               return false;
 
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
+       std::string::size_type at = mask.find('@');
+       if (at == std::string::npos)
+               return false;
 
-       this->WriteChannel(user, std::string(textbuffer));
+       const std::string nickIdent = user->nick + "!" + user->ident;
+       std::string prefix(mask, 0, at);
+       if (InspIRCd::Match(nickIdent, prefix, NULL))
+       {
+               std::string suffix(mask, at + 1);
+               if (InspIRCd::Match(user->GetRealHost(), suffix, NULL) ||
+                       InspIRCd::Match(user->GetDisplayedHost(), suffix, NULL) ||
+                       InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL))
+                       return true;
+       }
+       return false;
 }
 
-void chanrec::WriteChannel(userrec* user, const std::string &text)
+ModResult Channel::GetExtBanStatus(User *user, char type)
 {
-       CUList *ulist = this->GetUsers();
+       ModResult rv;
+       FIRST_MOD_RESULT(OnExtBanCheck, rv, (user, this, type));
+       if (rv != MOD_RES_PASSTHRU)
+               return rv;
 
-       if (!user)
-               return;
+       ListModeBase* banlm = static_cast<ListModeBase*>(*ban);
+       if (!banlm)
+               return MOD_RES_PASSTHRU;
 
-       for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+       const ListModeBase::ModeList* bans = banlm->GetList(this);
+       if (bans)
        {
-               if (IS_LOCAL(i->second))
-                       user->WriteTo(i->second,text);
+               for (ListModeBase::ModeList::const_iterator it = bans->begin(); it != bans->end(); ++it)
+               {
+                       if (it->mask.length() <= 2 || it->mask[0] != type || it->mask[1] != ':')
+                               continue;
+
+                       if (CheckBan(user, it->mask.substr(2)))
+                               return MOD_RES_DENY;
+               }
        }
+       return MOD_RES_PASSTHRU;
 }
 
-void chanrec::WriteChannelWithServ(const char* ServName, const char* text, ...)
+/* Channel::PartUser
+ * Remove a channel from a users record, remove the reference to the Membership object
+ * from the channel and destroy it.
+ */
+bool Channel::PartUser(User* user, std::string& reason)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
+       MemberMap::iterator membiter = userlist.find(user);
 
-       if (!text)
-               return;
+       if (membiter == userlist.end())
+               return false;
 
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
+       Membership* memb = membiter->second;
+       CUList except_list;
+       FOREACH_MOD(OnUserPart, (memb, reason, except_list));
 
-       this->WriteChannelWithServ(ServName, std::string(textbuffer));
-}
+       ClientProtocol::Messages::Part partmsg(memb, reason);
+       Write(ServerInstance->GetRFCEvents().part, partmsg, 0, except_list);
 
-void chanrec::WriteChannelWithServ(const char* ServName, const std::string &text)
-{
-       CUList *ulist = this->GetUsers();
+       // Remove this channel from the user's chanlist
+       user->chans.erase(memb);
+       // Remove the Membership from this channel's userlist and destroy it
+       this->DelUser(membiter);
 
-       for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
-       {
-               if (IS_LOCAL(i->second))
-                       i->second->WriteServ(text);
-       }
+       return true;
 }
 
-/* write formatted text from a source user to all users on a channel except
- * for the sender (for privmsg etc) */
-void chanrec::WriteAllExceptSender(userrec* user, char status, char* text, ...)
+void Channel::KickUser(User* src, const MemberMap::iterator& victimiter, const std::string& reason)
 {
-       char textbuffer[MAXBUF];
-       va_list argsPtr;
-
-       if (!user || !text)
-               return;
+       Membership* memb = victimiter->second;
+       CUList except_list;
+       FOREACH_MOD(OnUserKick, (src, memb, reason, except_list));
 
-       va_start(argsPtr, text);
-       vsnprintf(textbuffer, MAXBUF, text, argsPtr);
-       va_end(argsPtr);
+       ClientProtocol::Messages::Kick kickmsg(src, memb, reason);
+       Write(ServerInstance->GetRFCEvents().kick, kickmsg, 0, except_list);
 
-       this->WriteAllExceptSender(user, status, std::string(textbuffer));
+       memb->user->chans.erase(memb);
+       this->DelUser(victimiter);
 }
 
-void chanrec::WriteAllExceptSender(userrec* user, char status, const std::string& text)
+void Channel::Write(ClientProtocol::Event& protoev, char status, const CUList& except_list)
 {
-       CUList *ulist;
-
-       if (!user)
-               return;
-
-       switch (status)
+       unsigned int minrank = 0;
+       if (status)
        {
-               case '@':
-                       ulist = this->GetOppedUsers();
-                       break;
-               case '%':
-                       ulist = this->GetHalfoppedUsers();
-                       break;
-               case '+':
-                       ulist = this->GetVoicedUsers();
-                       break;
-               default:
-                       ulist = this->GetUsers();
-                       break;
+               PrefixMode* mh = ServerInstance->Modes->FindPrefix(status);
+               if (mh)
+                       minrank = mh->GetPrefixRank();
        }
-
-       for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+       for (MemberMap::iterator i = userlist.begin(); i != userlist.end(); i++)
        {
-               if ((IS_LOCAL(i->second)) && (user != i->second))
-                       i->second->WriteFrom(user,text);
-       }
-}
+               LocalUser* user = IS_LOCAL(i->first);
+               if ((user) && (!except_list.count(user)))
+               {
+                       /* User doesn't have the status we're after */
+                       if (minrank && i->second->getRank() < minrank)
+                               continue;
 
-/*
- * return a count of the users on a specific channel accounting for
- * invisible users who won't increase the count. e.g. for /LIST
- */
-int chanrec::CountInvisible()
-{
-       int count = 0;
-       CUList *ulist= this->GetUsers();
-       for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
-       {
-               if (!(i->second->modes[UM_INVISIBLE]))
-                       count++;
+                       user->Send(protoev);
+               }
        }
-
-       return count;
 }
 
-char* chanrec::ChanModes(bool showkey)
+const char* Channel::ChanModes(bool showsecret)
 {
-       static char scratch[MAXBUF];
-       static char sparam[MAXBUF];
-       char* offset = scratch;
-       std::string extparam = "";
+       static std::string scratch;
+       std::string sparam;
 
-       *scratch = '\0';
-       *sparam = '\0';
+       scratch.clear();
 
-       /* This was still iterating up to 190, chanrec::custom_modes is only 64 elements -- Om */
+       /* This was still iterating up to 190, Channel::modes is only 64 elements -- Om */
        for(int n = 0; n < 64; n++)
        {
-               if(this->modes[n])
+               ModeHandler* mh = ServerInstance->Modes->FindMode(n + 65, MODETYPE_CHANNEL);
+               if (mh && IsModeSet(mh))
                {
-                       *offset++ = n + 65;
-                       extparam = "";
-                       switch (n)
+                       scratch.push_back(n + 65);
+
+                       ParamModeBase* pm = mh->IsParameterMode();
+                       if (!pm)
+                               continue;
+
+                       if (pm->IsParameterSecret() && !showsecret)
                        {
-                               case CM_KEY:
-                                       extparam = (showkey ? this->key : "<key>");
-                               break;
-                               case CM_LIMIT:
-                                       extparam = ConvToStr(this->limit);
-                               break;
-                               case CM_NOEXTERNAL:
-                               case CM_TOPICLOCK:
-                               case CM_INVITEONLY:
-                               case CM_MODERATED:
-                               case CM_SECRET:
-                               case CM_PRIVATE:
-                                       /* We know these have no parameters */
-                               break;
-                               default:
-                                       extparam = this->GetModeParameter(n + 65);
-                               break;
+                               sparam += " <" + pm->name + ">";
                        }
-                       if (extparam != "")
+                       else
                        {
-                               charlcat(sparam,' ',MAXBUF);
-                               strlcat(sparam,extparam.c_str(),MAXBUF);
+                               sparam += ' ';
+                               pm->GetParameter(this, sparam);
                        }
                }
        }
 
-       /* Null terminate scratch */
-       *offset = '\0';
-       strlcat(scratch,sparam,MAXBUF);
-       return scratch;
+       scratch += sparam;
+       return scratch.c_str();
 }
 
-/* compile a userlist of a channel into a string, each nick seperated by
- * spaces and op, voice etc status shown as @ and +, and send it to 'user'
- */
-void chanrec::UserList(userrec *user)
+void Channel::WriteNotice(const std::string& text, char status)
 {
-       char list[MAXBUF];
-       size_t dlen, curlen;
-       int MOD_RESULT = 0;
-
-       FOREACH_RESULT(I_OnUserList,OnUserList(user, this));
-       ServerInstance->Log(DEBUG,"MOD_RESULT for UserList = %d",MOD_RESULT);
-       if (MOD_RESULT == 1)
-               return;
-
-       ServerInstance->Log(DEBUG,"Using builtin NAMES list generation");
-
-       dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
-
-       int numusers = 0;
-       char* ptr = list + dlen;
-
-       CUList *ulist= this->GetUsers();
-
-       /* Improvement by Brain - this doesnt change in value, so why was it inside
-        * the loop?
-        */
-       bool has_user = this->HasUser(user);
-
-       for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
-       {
-               if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
-               {
-                       /*
-                        * user is +i, and source not on the channel, does not show
-                        * nick in NAMES list
-                        */
-                       continue;
-               }
-
-               size_t ptrlen = snprintf(ptr, MAXBUF, "%s%s ", this->GetPrefixChar(i->second), i->second->nick);
-
-               curlen += ptrlen;
-               ptr += ptrlen;
-
-               numusers++;
-
-               if (curlen > (480-NICKMAX))
-               {
-                       /* list overflowed into multiple numerics */
-                       user->WriteServ(list);
-
-                       /* reset our lengths */
-                       dlen = curlen = snprintf(list,MAXBUF,"353 %s = %s :", user->nick, this->name);
-                       ptr = list + dlen;
-
-                       ptrlen = 0;
-                       numusers = 0;
-               }
-       }
-
-       /* if whats left in the list isnt empty, send it */
-       if (numusers)
-       {
-               user->WriteServ(list);
-       }
-
-       user->WriteServ("366 %s %s :End of /NAMES list.", user->nick, this->name);
+       ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, this, text, MSG_NOTICE, status);
+       Write(ServerInstance->GetRFCEvents().privmsg, privmsg);
 }
 
-long chanrec::GetMaxBans()
+void Channel::WriteRemoteNotice(const std::string& text, char status)
 {
-       std::string x;
-       for (std::map<std::string,int>::iterator n = ServerInstance->Config->maxbans.begin(); n != ServerInstance->Config->maxbans.end(); n++)
-       {
-               x = n->first;
-               if (match(this->name,x.c_str()))
-               {
-                       return n->second;
-               }
-       }
-       return 64;
+       WriteNotice(text, status);
+       ServerInstance->PI->SendMessage(this, status, text, MSG_NOTICE);
 }
 
-
 /* returns the status character for a given user on a channel, e.g. @ for op,
  * % for halfop etc. If the user has several modes set, the highest mode
  * the user has must be returned.
  */
-const char* chanrec::GetPrefixChar(userrec *user)
+char Membership::GetPrefixChar() const
 {
-       static char px[2];
-       unsigned int mx = 0;
+       char pf = 0;
+       unsigned int bestrank = 0;
 
-       *px = 0;
-       *(px+1) = 0;
-
-       prefixlist::iterator n = prefixes.find(user);
-       if (n != prefixes.end())
+       for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
        {
-               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
+               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
+               if (mh && mh->GetPrefixRank() > bestrank && mh->GetPrefix())
                {
-                       if (x->second > mx)
-                       {
-                               *px = x->first;
-                               mx  = x->second;
-                       }
+                       bestrank = mh->GetPrefixRank();
+                       pf = mh->GetPrefix();
                }
        }
-
-       return px;
+       return pf;
 }
 
-const char* chanrec::GetAllPrefixChars(userrec* user)
+unsigned int Membership::getRank()
 {
-       static char prefix[MAXBUF];
-       int ctr = 0;
-       *prefix = 0;
-
-       /* Cheat and always put the highest first.
-        * This fixes a NASTY ass-umption in xchat.
-        */
-       const char* first = this->GetPrefixChar(user);
-       if (*first)
-               prefix[ctr++] = *first;
-
-       prefixlist::iterator n = prefixes.find(user);
-       if (n != prefixes.end())
+       char mchar = modes.c_str()[0];
+       unsigned int rv = 0;
+       if (mchar)
        {
-               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
-               {
-                       if (x->first != *first)
-                               prefix[ctr++] = x->first;
-               }
+               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(mchar);
+               if (mh)
+                       rv = mh->GetPrefixRank();
        }
-
-       prefix[ctr] = 0;
-
-       return prefix;
+       return rv;
 }
 
-unsigned int chanrec::GetPrefixValue(userrec* user)
+std::string Membership::GetAllPrefixChars() const
 {
-       unsigned int mx = 0;
-
-       prefixlist::iterator n = prefixes.find(user);
-       if (n != prefixes.end())
+       std::string ret;
+       for (std::string::const_iterator i = modes.begin(); i != modes.end(); ++i)
        {
-               for (std::vector<prefixtype>::iterator x = n->second.begin(); x != n->second.end(); x++)
-               {
-                       if (x->second > mx)
-                               mx  = x->second;
-               }
+               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(*i);
+               if (mh && mh->GetPrefix())
+                       ret.push_back(mh->GetPrefix());
        }
 
-       return mx;
+       return ret;
 }
 
-
-int chanrec::GetStatusFlags(userrec *user)
+unsigned int Channel::GetPrefixValue(User* user)
 {
-       for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
-       {
-               if ((*i)->channel == this)
-               {
-                       return (*i)->uc_modes;
-               }
-       }
-       return 0;
+       MemberMap::iterator m = userlist.find(user);
+       if (m == userlist.end())
+               return 0;
+       return m->second->getRank();
 }
 
-
-int chanrec::GetStatus(userrec *user)
+bool Membership::SetPrefix(PrefixMode* delta_mh, bool adding)
 {
-       if (ServerInstance->ULine(user->server))
-               return STATUS_OP;
-
-       for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
+       char prefix = delta_mh->GetModeChar();
+       for (unsigned int i = 0; i < modes.length(); i++)
        {
-               if ((*i)->channel == this)
+               char mchar = modes[i];
+               PrefixMode* mh = ServerInstance->Modes->FindPrefixMode(mchar);
+               if (mh && mh->GetPrefixRank() <= delta_mh->GetPrefixRank())
                {
-                       if (((*i)->uc_modes & UCMODE_OP) > 0)
-                       {
-                               return STATUS_OP;
-                       }
-                       if (((*i)->uc_modes & UCMODE_HOP) > 0)
-                       {
-                               return STATUS_HOP;
-                       }
-                       if (((*i)->uc_modes & UCMODE_VOICE) > 0)
-                       {
-                               return STATUS_VOICE;
-                       }
-                       return STATUS_NORMAL;
+                       modes = modes.substr(0,i) +
+                               (adding ? std::string(1, prefix) : "") +
+                               modes.substr(mchar == prefix ? i+1 : i);
+                       return adding != (mchar == prefix);
                }
        }
-       return STATUS_NORMAL;
-}
-
-void chanrec::SetPrefix(userrec* user, char prefix, unsigned int prefix_value, bool adding)
-{
-       prefixlist::iterator n = prefixes.find(user);
-       prefixtype pfx = std::make_pair(prefix,prefix_value);
        if (adding)
-       {
-               if (n != prefixes.end())
-               {
-                       if (std::find(n->second.begin(), n->second.end(), pfx) == n->second.end())
-                       {
-                               n->second.push_back(pfx);
-                       }
-               }
-               else
-               {
-                       pfxcontainer one;
-                       one.push_back(pfx);
-                       prefixes.insert(std::make_pair<userrec*,pfxcontainer>(user, one));
-               }
-       }
-       else
-       {
-               if (n != prefixes.end())
-               {
-                       pfxcontainer::iterator x = std::find(n->second.begin(), n->second.end(), pfx);
-                       if (x != n->second.end())
-                               n->second.erase(x);
-               }
-       }
+               modes.push_back(prefix);
+       return adding;
 }
 
-void chanrec::RemoveAllPrefixes(userrec* user)
+
+void Membership::WriteNotice(const std::string& text) const
 {
-       prefixlist::iterator n = prefixes.find(user);
-       if (n != prefixes.end())
-               prefixes.erase(n);
-}
+       LocalUser* const localuser = IS_LOCAL(user);
+       if (!localuser)
+               return;
 
+       ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, this->chan, text, MSG_NOTICE);
+       localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg);
+}