diff options
author | Adam <Adam@anope.org> | 2013-01-21 22:31:16 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-01-21 22:31:16 -0500 |
commit | ddaa001dafb5122e6e363e4acbbe6ce045b7b104 (patch) | |
tree | 0364a76606ac6e2881ebd663601ce260f7c1101e /src/users.cpp | |
parent | 51c049e1a738e9124bab3961f35b830906517421 (diff) |
Merge usefulness of Flags and Extensible classes into Extensible, made most flags we have juse strings instead of defines/enums
Diffstat (limited to 'src/users.cpp')
-rw-r--r-- | src/users.cpp | 94 |
1 files changed, 45 insertions, 49 deletions
diff --git a/src/users.cpp b/src/users.cpp index b4c4e339d..972a39d56 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -140,7 +140,7 @@ const Anope::string &User::GetDisplayedHost() const { if (!this->vhost.empty()) return this->vhost; - else if (this->HasMode(UMODE_CLOAK) && !this->GetCloakedHost().empty()) + else if (this->HasMode("CLOAK") && !this->GetCloakedHost().empty()) return this->GetCloakedHost(); else return this->host; @@ -239,7 +239,7 @@ User::~User() ModeManager::StackerDel(this); this->Logout(); - if (this->HasMode(UMODE_OPER)) + if (this->HasMode("OPER")) --OperCount; while (!this->chans.empty()) @@ -280,7 +280,7 @@ void User::SendMessage(const BotInfo *source, const Anope::string &msg) Anope::string tok; while (sep.GetToken(tok)) { - if (Config->UsePrivmsg && ((!this->nc && Config->NSDefFlags.HasFlag(NI_MSG)) || (this->nc && this->nc->HasFlag(NI_MSG)))) + if (Config->UsePrivmsg && ((!this->nc && Config->NSDefFlags.count("msg")) || (this->nc && this->nc->HasExt("MSG")))) IRCD->SendPrivmsg(source, this->GetUID(), "%s", tok.c_str()); else IRCD->SendNotice(source, this->GetUID(), "%s", tok.c_str()); @@ -346,7 +346,7 @@ void User::SendMessage(const BotInfo *source, const Anope::string &msg) void User::Collide(NickAlias *na) { if (na) - na->SetFlag(NS_COLLIDED); + na->Extend("COLLIDED"); if (IRCD->CanSVSNick) { @@ -393,8 +393,8 @@ void User::Identify(NickAlias *na) IRCD->SendLogin(this); const NickAlias *this_na = NickAlias::Find(this->nick); - if (!Config->NoNicknameOwnership && this_na && this_na->nc == *na->nc && na->nc->HasFlag(NI_UNCONFIRMED) == false) - this->SetMode(NickServ, UMODE_REGISTERED); + if (!Config->NoNicknameOwnership && this_na && this_na->nc == *na->nc && na->nc->HasExt("UNCONFIRMED") == false) + this->SetMode(NickServ, "REGISTERED"); FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(this)); @@ -405,8 +405,8 @@ void User::Identify(NickAlias *na) this->SetModes(OperServ, "%s", this->nc->o->ot->modes.c_str()); if (OperServ) this->SendMessage(OperServ, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str()); - UserMode *um = ModeManager::FindUserModeByName(UMODE_OPER); - if (um && !this->HasMode(UMODE_OPER) && this->nc->o->ot->modes.find(um->mchar) != Anope::string::npos) + UserMode *um = ModeManager::FindUserModeByName("OPER"); + if (um && !this->HasMode("OPER") && this->nc->o->ot->modes.find(um->mchar) != Anope::string::npos) IRCD->SendOper(this); } if (IRCD->CanSetVHost && !this->nc->o->vhost.empty()) @@ -472,7 +472,7 @@ bool User::IsRecognized(bool CheckSecure) const { const NickAlias *na = NickAlias::Find(this->nick); - if (!na || na->nc->HasFlag(NI_SECURE)) + if (!na || na->nc->HasExt("SECURE")) return false; } @@ -484,7 +484,7 @@ bool User::IsServicesOper() if (!this->nc || !this->nc->IsServicesOper()) // No opertype. return false; - else if (this->nc->o->require_oper && !this->HasMode(UMODE_OPER)) + else if (this->nc->o->require_oper && !this->HasMode("OPER")) return false; else if (!this->nc->o->certfp.empty() && this->fingerprint != this->nc->o->certfp) // Certfp mismatch @@ -541,9 +541,9 @@ void User::UpdateHost() } } -bool User::HasMode(UserModeName Name) const +bool User::HasMode(const Anope::string &mname) const { - return this->modes.HasFlag(Name); + return this->modes.count(mname); } void User::SetModeInternal(UserMode *um, const Anope::string ¶m) @@ -551,9 +551,7 @@ void User::SetModeInternal(UserMode *um, const Anope::string ¶m) if (!um) return; - this->modes.SetFlag(um->name); - if (!param.empty()) - this->mode_params.insert(std::make_pair(um->name, param)); + this->modes[um->name] = param; FOREACH_MOD(I_OnUserModeSet, OnUserModeSet(this, um->name)); } @@ -563,10 +561,7 @@ void User::RemoveModeInternal(UserMode *um) if (!um) return; - this->modes.UnsetFlag(um->name); - std::map<UserModeName, Anope::string>::iterator it = this->mode_params.find(um->name); - if (it != this->mode_params.end()) - this->mode_params.erase(it); + this->modes.erase(um->name); FOREACH_MOD(I_OnUserModeUnset, OnUserModeUnset(this, um->name)); } @@ -580,9 +575,9 @@ void User::SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param) SetModeInternal(um, Param); } -void User::SetMode(const BotInfo *bi, UserModeName Name, const Anope::string &Param) +void User::SetMode(const BotInfo *bi, const Anope::string &uname, const Anope::string &Param) { - SetMode(bi, ModeManager::FindUserModeByName(Name), Param); + SetMode(bi, ModeManager::FindUserModeByName(uname), Param); } void User::RemoveMode(const BotInfo *bi, UserMode *um) @@ -594,9 +589,9 @@ void User::RemoveMode(const BotInfo *bi, UserMode *um) RemoveModeInternal(um); } -void User::RemoveMode(const BotInfo *bi, UserModeName Name) +void User::RemoveMode(const BotInfo *bi, const Anope::string &name) { - RemoveMode(bi, ModeManager::FindUserModeByName(Name)); + RemoveMode(bi, ModeManager::FindUserModeByName(name)); } void User::SetModes(const BotInfo *bi, const char *umodes, ...) @@ -687,39 +682,40 @@ void User::SetModesInternal(const char *umodes, ...) else this->RemoveModeInternal(um); - switch (um->name) + if (um->name == "OPER") { - case UMODE_OPER: - if (add) - ++OperCount; - else - --OperCount; - break; - case UMODE_CLOAK: - case UMODE_VHOST: - if (!add && !this->vhost.empty()) - this->vhost.clear(); - this->UpdateHost(); - default: - break; + if (add) + ++OperCount; + else + --OperCount; + } + else if (um->name == "CLOAK" || um->name == "VHOST") + { + if (!add && !this->vhost.empty()) + this->vhost.clear(); + this->UpdateHost(); } } } Anope::string User::GetModes() const { - Anope::string ret; + Anope::string m, params; - for (size_t i = UMODE_BEGIN + 1; i < UMODE_END; ++i) - if (this->modes.HasFlag(static_cast<UserModeName>(i))) - { - UserMode *um = ModeManager::FindUserModeByName(static_cast<UserModeName>(i)); - if (um == NULL) - continue; - ret += um->mchar; - } + typedef std::map<Anope::string, Anope::string> mode_map; + for (mode_map::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it) + { + UserMode *um = ModeManager::FindUserModeByName(it->first); + if (um == NULL) + continue; + + m += um->mchar; + + if (!it->second.empty()) + params += " " + it->second; + } - return ret; + return m + params; } ChanUserContainer *User::FindChannel(const Channel *c) const @@ -732,7 +728,7 @@ ChanUserContainer *User::FindChannel(const Channel *c) const bool User::IsProtected() const { - if (this->HasMode(UMODE_PROTECTED) || this->HasMode(UMODE_GOD)) + if (this->HasMode("PROTECTED") || this->HasMode("GOD")) return true; return false; @@ -757,7 +753,7 @@ void User::KillInternal(const Anope::string &source, const Anope::string &reason Log(this, "killed") << "was killed by " << source << " (Reason: " << reason << ")"; NickAlias *na = NickAlias::Find(this->nick); - if (na && !na->nc->HasFlag(NI_SUSPENDED) && (this->IsRecognized() || this->IsIdentified(true))) + if (na && !na->nc->HasExt("SUSPENDED") && (this->IsRecognized() || this->IsIdentified(true))) { na->last_seen = Anope::CurTime; na->last_quit = reason; |