diff options
Diffstat (limited to 'src/channels.cpp')
-rw-r--r-- | src/channels.cpp | 312 |
1 files changed, 173 insertions, 139 deletions
diff --git a/src/channels.cpp b/src/channels.cpp index 41755b9c8..51ceb324c 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -1,6 +1,6 @@ /* Channel-handling routines. * - * (C) 2003-2012 Anope Team + * (C) 2003-2013 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -23,13 +23,9 @@ #include "config.h" #include "access.h" #include "sockets.h" -#include "chanserv.h" channel_map ChannelList; -static const Anope::string ChannelFlagString[] = { "CH_INABIT", "CH_PERSIST", "CH_SYNCING", "" }; -template<> const Anope::string* Flags<ChannelFlag>::flags_strings = ChannelFlagString; - Channel::Channel(const Anope::string &nname, time_t ts) { if (nname.empty()) @@ -73,12 +69,12 @@ void Channel::Reset() { this->modes.clear(); - for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) + for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) { - UserContainer *uc = *it; + ChanUserContainer *uc = *it; - ChannelStatus flags = *uc->status; - uc->status->ClearFlags(); + ChannelStatus f = uc->status; + uc->status.modes.clear(); if (BotInfo::Find(uc->user->nick)) { @@ -86,7 +82,7 @@ void Channel::Reset() { ChannelMode *cm = ModeManager::ChannelModes[i]; - if (flags.HasFlag(cm->name)) + if (f.modes.count(cm->name)) this->SetMode(NULL, cm, uc->user->GetUID(), false); } } @@ -94,7 +90,7 @@ void Channel::Reset() this->CheckModes(); - for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) + for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) this->SetCorrectModes((*it)->user, true, false); if (this->ci && Me && Me->IsSynced()) @@ -103,7 +99,7 @@ void Channel::Reset() void Channel::Sync() { - if (!this->HasMode(CMODE_PERM) && (this->users.empty() || (this->users.size() == 1 && this->ci && this->ci->bi && *this->ci->bi == this->users.front()->user))) + if (!this->HasMode("PERM") && (this->users.empty() || (this->users.size() == 1 && this->ci && this->ci->bi && *this->ci->bi == this->users.front()->user))) { this->Hold(); } @@ -129,13 +125,6 @@ void Channel::CheckModes() return; } - if (this->chanserv_modetime != Anope::CurTime) - { - this->chanserv_modecount = 0; - this->chanserv_modetime = Anope::CurTime; - } - this->chanserv_modecount++; - EventReturn MOD_RESULT; FOREACH_RESULT(I_OnCheckModes, OnCheckModes(this)); if (MOD_RESULT == EVENT_STOP) @@ -184,20 +173,15 @@ void Channel::CheckModes() } } -UserContainer* Channel::JoinUser(User *user) +ChanUserContainer* Channel::JoinUser(User *user) { Log(user, this, "join"); - ChannelStatus *status = new ChannelStatus(); - ChannelContainer *cc = new ChannelContainer(this); - cc->status = status; - user->chans.push_back(cc); - - UserContainer *uc = new UserContainer(user); - uc->status = status; - this->users.push_back(uc); + ChanUserContainer *cuc = new ChanUserContainer(user, this); + user->chans.push_back(cuc); + this->users.push_back(cuc); - if (this->ci && this->ci->HasFlag(CI_PERSIST) && this->creation_time > this->ci->time_registered) + if (this->ci && this->ci->HasExt("PERSIST") && this->creation_time > this->ci->time_registered) { Log(LOG_DEBUG) << "Changing TS of " << this->name << " from " << this->creation_time << " to " << this->ci->time_registered; this->creation_time = this->ci->time_registered; @@ -205,7 +189,7 @@ UserContainer* Channel::JoinUser(User *user) this->Reset(); } - return uc; + return cuc; } void Channel::DeleteUser(User *user) @@ -213,49 +197,50 @@ void Channel::DeleteUser(User *user) Log(user, this, "leaves"); FOREACH_MOD(I_OnLeaveChannel, OnLeaveChannel(user, this)); - CUserList::iterator cit, cit_end = this->users.end(); - for (cit = this->users.begin(); (*cit)->user != user && cit != cit_end; ++cit); + ChanUserContainer *cul; + ChanUserList::iterator cit, cit_end; + for (cit = this->users.begin(), cit_end = this->users.end(); cit != cit_end && (*cit)->user != user; ++cit); if (cit == cit_end) { Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete nonexistant user " << user->nick << " from channel " << this->name; return; } - - delete (*cit)->status; - delete *cit; + cul = *cit; this->users.erase(cit); - UChannelList::iterator uit, uit_end = user->chans.end(); - for (uit = user->chans.begin(); (*uit)->chan != this && uit != uit_end; ++uit); + ChanUserList::iterator uit, uit_end; + for (uit = user->chans.begin(), uit_end = user->chans.end(); uit != uit_end && (*uit)->chan != this; ++uit); if (uit == uit_end) Log(LOG_DEBUG) << "Channel::DeleteUser() tried to delete nonexistant channel " << this->name << " from " << user->nick << "'s channel list"; else { - delete *uit; + if (cul != *uit) + Log(LOG_DEBUG) << "Channel::DeleteUser() mismatch between user and channel usre container objects"; user->chans.erase(uit); } + delete cul; /* Channel is persistent, it shouldn't be deleted and the service bot should stay */ - if (this->HasFlag(CH_PERSIST) || (this->ci && this->ci->HasFlag(CI_PERSIST))) + if (this->HasExt("PERSIST") || (this->ci && this->ci->HasExt("PERSIST"))) return; /* Channel is syncing from a netburst, don't destroy it as more users are probably wanting to join immediatly * We also don't part the bot here either, if necessary we will part it after the sync */ - if (this->HasFlag(CH_SYNCING)) + if (this->HasExt("SYNCING")) return; /* Additionally, do not delete this channel if ChanServ/a BotServ bot is inhabiting it */ - if (this->HasFlag(CH_INHABIT)) + if (this->HasExt("INHABIT")) return; if (this->users.empty()) delete this; } -UserContainer *Channel::FindUser(const User *u) const +ChanUserContainer *Channel::FindUser(const User *u) const { - for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) + for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) if ((*it)->user == u) return *it; return NULL; @@ -263,39 +248,67 @@ UserContainer *Channel::FindUser(const User *u) const bool Channel::HasUserStatus(const User *u, ChannelModeStatus *cms) const { - if (!u || (cms && cms->type != MODE_STATUS)) - throw CoreException("Channel::HasUserStatus got bad mode"); - /* Usually its more efficient to search the users channels than the channels users */ - ChannelContainer *cc = u->FindChannel(this); + ChanUserContainer *cc = u->FindChannel(this); if (cc) { if (cms) - return cc->status->HasFlag(cms->name); + return cc->status.modes.count(cms->name); else - return !cc->status->FlagCount(); + return cc->status.modes.empty(); } return false; } -bool Channel::HasUserStatus(const User *u, ChannelModeName Name) const +bool Channel::HasUserStatus(const User *u, const Anope::string &mname) const { - return HasUserStatus(u, anope_dynamic_static_cast<ChannelModeStatus *>(ModeManager::FindChannelModeByName(Name))); + return HasUserStatus(u, anope_dynamic_static_cast<ChannelModeStatus *>(ModeManager::FindChannelModeByName(mname))); } -size_t Channel::HasMode(ChannelModeName Name, const Anope::string ¶m) +size_t Channel::HasMode(const Anope::string &mname, const Anope::string ¶m) { if (param.empty()) - return modes.count(Name); - std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> its = this->GetModeList(Name); + return modes.count(mname); + std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> its = this->GetModeList(mname); for (; its.first != its.second; ++its.first) if (its.first->second == param) return 1; return 0; } -std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> Channel::GetModeList(ChannelModeName mname) +Anope::string Channel::GetModes(bool complete, bool plus) +{ + Anope::string res, params; + + for (std::multimap<Anope::string, Anope::string>::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) + { + ChannelMode *cm = ModeManager::FindChannelModeByName(it->first); + if (!cm || cm->type == MODE_LIST) + continue; + + res += cm->mchar; + + if (complete && !it->second.empty()) + { + ChannelModeParam *cmp = NULL; + if (cm->type == MODE_PARAM) + cmp = anope_dynamic_static_cast<ChannelModeParam *>(cm); + + if (plus || !cmp || !cmp->minus_no_arg) + params += " " + it->second; + } + } + + return res + params; +} + +const Channel::ModeList &Channel::GetModes() const +{ + return this->modes; +} + +std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> Channel::GetModeList(const Anope::string &mname) { Channel::ModeList::iterator it = this->modes.find(mname), it_end = it; if (it != this->modes.end()) @@ -309,7 +322,6 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop return; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnChannelModeSet, OnChannelModeSet(this, setter, cm->name, param)); /* Setting v/h/o/a/q etc */ if (cm->type == MODE_STATUS) @@ -331,12 +343,14 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop Log(LOG_DEBUG) << "Setting +" << cm->mchar << " on " << this->name << " for " << u->nick; /* Set the status on the user */ - ChannelContainer *cc = u->FindChannel(this); + ChanUserContainer *cc = u->FindChannel(this); if (cc) - cc->status->SetFlag(cm->name); + cc->status.modes.insert(cm->name); + + FOREACH_RESULT(I_OnChannelModeSet, OnChannelModeSet(this, setter, cm->name, param)); /* Enforce secureops, etc */ - if (enforce_mlock) + if (enforce_mlock && MOD_RESULT != EVENT_STOP) this->SetCorrectModes(u, false, false); return; } @@ -347,7 +361,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop if (param.empty() && cm->type != MODE_REGULAR) { - Log() << "Channel::SetModeInternal() mode " << cm->mchar << " for " << this->name << " with a paramater, but its not a param mode"; + Log() << "Channel::SetModeInternal() mode " << cm->mchar << " for " << this->name << " with no paramater, but is a param mode"; return; } @@ -358,13 +372,15 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop } /* Channel mode +P or so was set, mark this channel as persistent */ - if (cm->name == CMODE_PERM) + if (cm->name == "PERM") { - this->SetFlag(CH_PERSIST); + this->Extend("PERSIST"); if (this->ci) - this->ci->SetFlag(CI_PERSIST); + this->ci->ExtendMetadata("PERSIST"); } + FOREACH_RESULT(I_OnChannelModeSet, OnChannelModeSet(this, setter, cm->name, param)); + /* Check if we should enforce mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) return; @@ -378,7 +394,6 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A return; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnChannelModeUnset, OnChannelModeUnset(this, setter, cm->name, param)); /* Setting v/h/o/a/q etc */ if (cm->type == MODE_STATUS) @@ -401,16 +416,18 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A Log(LOG_DEBUG) << "Setting -" << cm->mchar << " on " << this->name << " for " << u->nick; /* Remove the status on the user */ - ChannelContainer *cc = u->FindChannel(this); + ChanUserContainer *cc = u->FindChannel(this); if (cc) - cc->status->UnsetFlag(cm->name); + cc->status.modes.erase(cm->name); + + FOREACH_RESULT(I_OnChannelModeUnset, OnChannelModeUnset(this, setter, cm->name, param)); if (enforce_mlock) { /* Reset modes on bots if we're supposed to */ if (this->ci && this->ci->bi && this->ci->bi == bi) { - if (ModeManager::DefaultBotModes.HasFlag(cm->name)) + if (ModeManager::DefaultBotModes.modes.count(cm->name)) this->SetMode(bi, cm, bi->GetUID()); } @@ -438,22 +455,23 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A cml->OnDel(this, param); } - if (cm->name == CMODE_PERM) + if (cm->name == "PERM") { - this->UnsetFlag(CH_PERSIST); + this->Shrink("PERSIST"); if (this->ci) - this->ci->UnsetFlag(CI_PERSIST); + this->ci->Shrink("PERSIST"); - if (this->users.empty()) + if (this->users.empty() && !this->HasExt("SYNCING") && !this->HasExt("INHABIT")) { delete this; return; } } - /* Check for mlock */ + FOREACH_RESULT(I_OnChannelModeUnset, OnChannelModeUnset(this, setter, cm->name, param)); + /* Check for mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) return; @@ -490,14 +508,25 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, return; } + if (Me->IsSynced()) + { + if (this->chanserv_modetime != Anope::CurTime) + { + this->chanserv_modecount = 0; + this->chanserv_modetime = Anope::CurTime; + } + + this->chanserv_modecount++; + } + ModeManager::StackerAdd(bi, this, cm, true, param); MessageSource ms(bi); SetModeInternal(ms, cm, param, enforce_mlock); } -void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool enforce_mlock) +void Channel::SetMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) { - SetMode(bi, ModeManager::FindChannelModeByName(Name), param, enforce_mlock); + SetMode(bi, ModeManager::FindChannelModeByName(mname), param, enforce_mlock); } void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) @@ -530,25 +559,36 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶ this->GetParam(cmp->name, realparam); } + if (Me->IsSynced()) + { + if (this->chanserv_modetime != Anope::CurTime) + { + this->chanserv_modecount = 0; + this->chanserv_modetime = Anope::CurTime; + } + + this->chanserv_modecount++; + } + ModeManager::StackerAdd(bi, this, cm, false, realparam); MessageSource ms(bi); RemoveModeInternal(ms, cm, realparam, enforce_mlock); } -void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string ¶m, bool enforce_mlock) +void Channel::RemoveMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) { - RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, enforce_mlock); + RemoveMode(bi, ModeManager::FindChannelModeByName(mname), param, enforce_mlock); } -bool Channel::GetParam(ChannelModeName Name, Anope::string &Target) const +bool Channel::GetParam(const Anope::string &mname, Anope::string &target) const { - std::multimap<ChannelModeName, Anope::string>::const_iterator it = this->modes.find(Name); + std::multimap<Anope::string, Anope::string>::const_iterator it = this->modes.find(mname); - Target.clear(); + target.clear(); if (it != this->modes.end()) { - Target = it->second; + target = it->second; return true; } @@ -622,7 +662,7 @@ void Channel::SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...) void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, time_t ts, bool enforce_mlock) { - if (source.GetServer()) + if (source.GetServer() && source.GetServer()->IsSynced()) { if (Anope::CurTime != this->server_modetime) { @@ -636,7 +676,10 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, if (!ts) ; else if (ts > this->creation_time) + { + Log(LOG_DEBUG) << "Dropping mode " << mode << " on " << this->name << ", " << ts << " > " << this->creation_time; return; + } else if (ts < this->creation_time) { Log(LOG_DEBUG) << "Changing TS of " << this->name << " from " << this->creation_time << " to " << ts; @@ -685,9 +728,9 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, if (cm->type == MODE_REGULAR) { if (add) - this->SetModeInternal(source, cm, "", enforce_mlock); + this->SetModeInternal(source, cm, "", false); else - this->RemoveModeInternal(source, cm, "", enforce_mlock); + this->RemoveModeInternal(source, cm, "", false); continue; } else if (cm->type == MODE_PARAM) @@ -696,7 +739,7 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, if (!add && cmp->minus_no_arg) { - this->RemoveModeInternal(source, cm, "", enforce_mlock); + this->RemoveModeInternal(source, cm, "", false); continue; } } @@ -710,9 +753,9 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, paramstring += " " + token; if (add) - this->SetModeInternal(source, cm, token, enforce_mlock); + this->SetModeInternal(source, cm, token, false); else - this->RemoveModeInternal(source, cm, token, enforce_mlock); + this->RemoveModeInternal(source, cm, token, false); } else Log() << "warning: Channel::SetModesInternal() recieved more modes requiring params than params, modes: " << mode; @@ -725,9 +768,12 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, Log(setter, this, "mode") << modestring << paramstring; else Log(LOG_DEBUG) << source.GetName() << " is setting " << this->name << " to " << modestring << paramstring; + + if (enforce_mlock) + this->CheckModes(); } -bool Channel::MatchesList(User *u, ChannelModeName mode) +bool Channel::MatchesList(User *u, const Anope::string &mode) { if (!this->HasMode(mode)) return false; @@ -769,7 +815,7 @@ void Channel::KickInternal(MessageSource &source, const Anope::string &nick, con { FOREACH_MOD(I_OnUserKicked, OnUserKicked(this, target, source, reason)); if (bi) - this->SetFlag(CH_INHABIT); + this->Extend("INHABIT"); this->DeleteUser(target); } else @@ -779,7 +825,7 @@ void Channel::KickInternal(MessageSource &source, const Anope::string &nick, con if (bi) { bi->Join(this, &ModeManager::DefaultBotModes); - this->UnsetFlag(CH_INHABIT); + this->Shrink("INHABIT"); } } @@ -812,30 +858,6 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) return true; } -Anope::string Channel::GetModes(bool complete, bool plus) -{ - Anope::string res, params; - - for (std::multimap<ChannelModeName, Anope::string>::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) - { - ChannelMode *cm = ModeManager::FindChannelModeByName(it->first); - if (!cm || cm->type == MODE_LIST) - continue; - - res += cm->mchar; - - if (complete && !it->second.empty()) - { - ChannelModeParam *cmp = anope_dynamic_static_cast<ChannelModeParam *>(cm); - - if (plus || !cmp->minus_no_arg) - params += " " + it->second; - } - } - - return res + params; -} - void Channel::ChangeTopicInternal(const Anope::string &user, const Anope::string &newtopic, time_t ts) { User *u = User::Find(user); @@ -890,7 +912,7 @@ void Channel::Hold() { if (!ChanServ || !c) return; - c->SetFlag(CH_INHABIT); + c->Extend("INHABIT"); if (!c->ci || !c->ci->bi) ChanServ->Join(c); else if (!c->FindUser(c->ci->bi)) @@ -905,7 +927,7 @@ void Channel::Hold() if (!c) return; - c->UnsetFlag(CH_INHABIT); + c->Shrink("INHABIT"); if (!c->ci || !c->ci->bi) { @@ -922,11 +944,12 @@ void Channel::Hold() void Channel::SetCorrectModes(User *user, bool give_modes, bool check_noop) { - ChannelMode *owner = ModeManager::FindChannelModeByName(CMODE_OWNER), - *admin = ModeManager::FindChannelModeByName(CMODE_PROTECT), - *op = ModeManager::FindChannelModeByName(CMODE_OP), - *halfop = ModeManager::FindChannelModeByName(CMODE_HALFOP), - *voice = ModeManager::FindChannelModeByName(CMODE_VOICE); + ChannelMode *owner = ModeManager::FindChannelModeByName("OWNER"), + *admin = ModeManager::FindChannelModeByName("PROTECT"), + *op = ModeManager::FindChannelModeByName("OP"), + *halfop = ModeManager::FindChannelModeByName("HALFOP"), + *voice = ModeManager::FindChannelModeByName("VOICE"), + *registered = ModeManager::FindChannelModeByName("REGISTERED"); if (user == NULL) return; @@ -938,34 +961,38 @@ void Channel::SetCorrectModes(User *user, bool give_modes, bool check_noop) AccessGroup u_access = ci->AccessFor(user); - if (give_modes && (!user->Account() || user->Account()->HasFlag(NI_AUTOOP)) && (!check_noop || !ci->HasFlag(CI_NOAUTOOP))) + if (give_modes && (!user->Account() || user->Account()->HasExt("AUTOOP")) && (!check_noop || !ci->HasExt("NOAUTOOP"))) { if (owner && u_access.HasPriv("AUTOOWNER")) - this->SetMode(NULL, CMODE_OWNER, user->GetUID()); + this->SetMode(NULL, "OWNER", user->GetUID()); else if (admin && u_access.HasPriv("AUTOPROTECT")) - this->SetMode(NULL, CMODE_PROTECT, user->GetUID()); + this->SetMode(NULL, "PROTECT", user->GetUID()); if (op && u_access.HasPriv("AUTOOP")) - this->SetMode(NULL, CMODE_OP, user->GetUID()); + this->SetMode(NULL, "OP", user->GetUID()); else if (halfop && u_access.HasPriv("AUTOHALFOP")) - this->SetMode(NULL, CMODE_HALFOP, user->GetUID()); + this->SetMode(NULL, "HALFOP", user->GetUID()); else if (voice && u_access.HasPriv("AUTOVOICE")) - this->SetMode(NULL, CMODE_VOICE, user->GetUID()); + this->SetMode(NULL, "VOICE", user->GetUID()); } - /* If this channel has secureops or the channel is syncing and they are not ulined, check to remove modes */ - if ((ci->HasFlag(CI_SECUREOPS) || (this->HasFlag(CH_SYNCING) && user->server->IsSynced())) && !user->server->IsULined()) + /* If this channel has secureops, or the registered channel mode exists and the channel does not have +r set (aka the channel + * was created just now or while we were off), or the registered channel mode does not exist and channel is syncing (aka just + * created *to us*) and the user's server is synced (aka this isn't us doing our initial uplink - without this we would be deopping all + * users with no access on a non-secureops channel on startup), and the user's server isn't ulined, then set negative modes. + */ + if ((ci->HasExt("SECUREOPS") || (registered && !this->HasMode("REGISTERED")) || (!registered && this->HasExt("SYNCING") && user->server->IsSynced())) && !user->server->IsULined()) { if (owner && !u_access.HasPriv("AUTOOWNER") && !u_access.HasPriv("OWNERME")) - this->RemoveMode(NULL, CMODE_OWNER, user->GetUID()); + this->RemoveMode(NULL, "OWNER", user->GetUID()); if (admin && !u_access.HasPriv("AUTOPROTECT") && !u_access.HasPriv("PROTECTME")) - this->RemoveMode(NULL, CMODE_PROTECT, user->GetUID()); + this->RemoveMode(NULL, "PROTECT", user->GetUID()); - if (op && this->HasUserStatus(user, CMODE_OP) && !u_access.HasPriv("AUTOOP") && !u_access.HasPriv("OPDEOPME")) - this->RemoveMode(NULL, CMODE_OP, user->GetUID()); + if (op && this->HasUserStatus(user, "OP") && !u_access.HasPriv("AUTOOP") && !u_access.HasPriv("OPDEOPME")) + this->RemoveMode(NULL, "OP", user->GetUID()); if (halfop && !u_access.HasPriv("AUTOHALFOP") && !u_access.HasPriv("HALFOPME")) - this->RemoveMode(NULL, CMODE_HALFOP, user->GetUID()); + this->RemoveMode(NULL, "HALFOP", user->GetUID()); } // Check mlock @@ -989,19 +1016,26 @@ void Channel::SetCorrectModes(User *user, bool give_modes, bool check_noop) } } -void Channel::Unban(const User *u, bool full) +bool Channel::Unban(const User *u, bool full) { - if (!this->HasMode(CMODE_BAN)) - return; + if (!this->HasMode("BAN")) + return false; + + bool ret = false; - std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = this->GetModeList(CMODE_BAN); + std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = this->GetModeList("BAN"); for (; bans.first != bans.second;) { - Entry ban(CMODE_BAN, bans.first->second); + Entry ban("BAN", bans.first->second); ++bans.first; if (ban.Matches(u, full)) - this->RemoveMode(NULL, CMODE_BAN, ban.GetMask()); + { + this->RemoveMode(NULL, "BAN", ban.GetMask()); + ret = true; + } } + + return ret; } Channel* Channel::Find(const Anope::string &name) |