summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-01-21 22:31:16 -0500
committerAdam <Adam@anope.org>2013-01-21 22:31:16 -0500
commitddaa001dafb5122e6e363e4acbbe6ce045b7b104 (patch)
tree0364a76606ac6e2881ebd663601ce260f7c1101e /src
parent51c049e1a738e9124bab3961f35b830906517421 (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')
-rw-r--r--src/bots.cpp29
-rw-r--r--src/channels.cpp127
-rw-r--r--src/command.cpp30
-rw-r--r--src/config.cpp82
-rw-r--r--src/extensible.cpp99
-rw-r--r--src/memos.cpp18
-rw-r--r--src/messages.cpp12
-rw-r--r--src/modes.cpp165
-rw-r--r--src/nickalias.cpp29
-rw-r--r--src/nickcore.cpp33
-rw-r--r--src/pipeengine.cpp14
-rw-r--r--src/protocol.cpp4
-rw-r--r--src/regchannel.cpp126
-rw-r--r--src/servers.cpp39
-rw-r--r--src/socket_clients.cpp16
-rw-r--r--src/socketengines/socketengine_epoll.cpp21
-rw-r--r--src/sockets.cpp28
-rw-r--r--src/threadengine.cpp4
-rw-r--r--src/uplink.cpp8
-rw-r--r--src/users.cpp94
20 files changed, 460 insertions, 518 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index ef8514c87..a81332ad6 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -21,23 +21,13 @@
Serialize::Checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo");
-static const Anope::string BotFlagString[] = { "BEGIN", "CORE", "PRIVATE", "CONF", "" };
-template<> const Anope::string* Flags<BotFlag>::flags_strings = BotFlagString;
-
-static const Anope::string BotServFlagStrings[] = {
- "BEGIN", "DONTKICKOPS", "DONTKICKVOICES", "FANTASY", "GREET", "NOBOT",
- "KICK_BOLDs", "KICK_COLORS", "KICK_REVERSES", "KICK_UNDERLINES", "KICK_BADWORDS", "KICK_CAPS",
- "KICK_FLOOD", "KICK_REPEAT", "KICK_ITALICS", "KICK_AMSGS", "MSG_PRIVMSG", "MSG_NOTICE",
- "MSG_NOTICEOPS", ""
-};
-template<> const Anope::string* Flags<BotServFlag>::flags_strings = BotServFlagStrings;
-
BotInfo *BotServ = NULL, *ChanServ = NULL, *Global = NULL, *HostServ = NULL, *MemoServ = NULL, *NickServ = NULL, *OperServ = NULL;
BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve()), Serializable("BotInfo"), botmodes(bmodes)
{
this->lastmsg = this->created = Anope::CurTime;
this->introduced = false;
+ this->oper_only = this->conf = false;
(*BotListByNick)[this->nick] = this;
if (!this->uid.empty())
@@ -91,7 +81,7 @@ void BotInfo::Serialize(Serialize::Data &data) const
data["host"] << this->host;
data["realname"] << this->realname;
data["created"] << this->created;
- data["flags"] << this->ToString();
+ data["oper_only"] << this->oper_only;
}
Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data)
@@ -102,15 +92,16 @@ Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data)
data["user"] >> user;
data["host"] >> host;
data["realname"] >> realname;
- data["flags"] >> flags;
BotInfo *bi;
if (obj)
bi = anope_dynamic_static_cast<BotInfo *>(obj);
else if (!(bi = BotInfo::Find(nick)))
bi = new BotInfo(nick, user, host, realname);
+
data["created"] >> bi->created;
- bi->FromString(flags);
+ data["oper_only"] >> bi->oper_only;
+
return bi;
}
@@ -198,23 +189,23 @@ void BotInfo::Join(Channel *c, ChannelStatus *status)
if (Config && IRCD && Config->BSSmartJoin)
{
- std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = c->GetModeList(CMODE_BAN);
+ std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> bans = c->GetModeList("BAN");
/* We check for bans */
for (; bans.first != bans.second; ++bans.first)
{
- Entry ban(CMODE_BAN, bans.first->second);
+ Entry ban("BAN", bans.first->second);
if (ban.Matches(this))
- c->RemoveMode(NULL, CMODE_BAN, ban.GetMask());
+ c->RemoveMode(NULL, "BAN", ban.GetMask());
}
Anope::string Limit;
unsigned limit = 0;
- if (c->GetParam(CMODE_LIMIT, Limit) && Limit.is_pos_number_only())
+ if (c->GetParam("LIMIT", Limit) && Limit.is_pos_number_only())
limit = convertTo<unsigned>(Limit);
/* Should we be invited? */
- if (c->HasMode(CMODE_INVITE) || (limit && c->users.size() >= limit))
+ if (c->HasMode("INVITE") || (limit && c->users.size() >= limit))
IRCD->SendNotice(this, "@" + c->name, "%s invited %s into the channel.", this->nick.c_str(), this->nick.c_str());
ModeManager::ProcessModes();
diff --git a/src/channels.cpp b/src/channels.cpp
index 43c4283c1..32fb5aea7 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -26,9 +26,6 @@
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())
@@ -76,8 +73,8 @@ void Channel::Reset()
{
ChanUserContainer *uc = *it;
- ChannelStatus flags = uc->status;
- uc->status.ClearFlags();
+ ChannelStatus f = uc->status;
+ uc->status.modes.clear();
if (BotInfo::Find(uc->user->nick))
{
@@ -85,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);
}
}
@@ -102,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();
}
@@ -191,7 +188,7 @@ ChanUserContainer* Channel::JoinUser(User *user)
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;
@@ -231,17 +228,17 @@ void Channel::DeleteUser(User *user)
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())
@@ -258,39 +255,39 @@ ChanUserContainer *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");
+ if (!cms)
+ return false;
/* Usually its more efficient to search the users channels than the channels users */
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 &param)
+size_t Channel::HasMode(const Anope::string &mname, const Anope::string &param)
{
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)
+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())
@@ -328,7 +325,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop
/* Set the status on the user */
ChanUserContainer *cc = u->FindChannel(this);
if (cc)
- cc->status.SetFlag(cm->name);
+ cc->status.modes.insert(cm->name);
/* Enforce secureops, etc */
if (enforce_mlock)
@@ -353,11 +350,11 @@ 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");
}
/* Check if we should enforce mlock */
@@ -398,14 +395,14 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A
/* Remove the status on the user */
ChanUserContainer *cc = u->FindChannel(this);
if (cc)
- cc->status.UnsetFlag(cm->name);
+ cc->status.modes.erase(cm->name);
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());
}
@@ -433,12 +430,12 @@ 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())
{
@@ -490,9 +487,9 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param,
SetModeInternal(ms, cm, param, enforce_mlock);
}
-void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param, bool enforce_mlock)
+void Channel::SetMode(BotInfo *bi, const Anope::string &mname, const Anope::string &param, 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 &param, bool enforce_mlock)
@@ -530,20 +527,20 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &para
RemoveModeInternal(ms, cm, realparam, enforce_mlock);
}
-void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param, bool enforce_mlock)
+void Channel::RemoveMode(BotInfo *bi, const Anope::string &mname, const Anope::string &param, 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;
}
@@ -728,7 +725,7 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode,
this->CheckModes();
}
-bool Channel::MatchesList(User *u, ChannelModeName mode)
+bool Channel::MatchesList(User *u, const Anope::string &mode)
{
if (!this->HasMode(mode))
return false;
@@ -770,7 +767,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
@@ -780,7 +777,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");
}
}
@@ -817,7 +814,7 @@ 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)
+ 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)
@@ -893,7 +890,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))
@@ -908,7 +905,7 @@ void Channel::Hold()
if (!c)
return;
- c->UnsetFlag(CH_INHABIT);
+ c->Shrink("INHABIT");
if (!c->ci || !c->ci->bi)
{
@@ -925,11 +922,11 @@ 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");
if (user == NULL)
return;
@@ -941,34 +938,34 @@ 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 ((ci->HasExt("SECUREOPS") || (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
@@ -994,16 +991,16 @@ void Channel::SetCorrectModes(User *user, bool give_modes, bool check_noop)
void Channel::Unban(const User *u, bool full)
{
- if (!this->HasMode(CMODE_BAN))
+ if (!this->HasMode("BAN"))
return;
- 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());
}
}
diff --git a/src/command.cpp b/src/command.cpp
index 11913ffd2..36bab658f 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -18,9 +18,6 @@
#include "regchannel.h"
#include "channels.h"
-static const Anope::string CommandFlagString[] = { "CFLAG_ALLOW_UNREGISTERED", "CFLAG_STRIP_CHANNEL", "CFLAG_REQUIRE_USER", "" };
-template<> const Anope::string* Flags<CommandFlag>::flags_strings = CommandFlagString;
-
CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r),
c(NULL), service(bi)
{
@@ -90,7 +87,7 @@ bool CommandSource::IsServicesOper()
bool CommandSource::IsOper()
{
if (this->u)
- return this->u->HasMode(UMODE_OPER);
+ return this->u->HasMode("OPER");
else if (this->nc)
return this->nc->IsServicesOper();
return false;
@@ -123,6 +120,7 @@ void CommandSource::Reply(const Anope::string &message)
Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(owner)
{
+ allow_unregistered = require_user = false;
}
Command::~Command()
@@ -160,6 +158,26 @@ void Command::SendSyntax(CommandSource &source, const Anope::string &syn)
source.Reply(MORE_INFO, Config->UseStrictPrivMsgString.c_str(), source.service->nick.c_str(), source.command.c_str());
}
+bool Command::AllowUnregistered() const
+{
+ return this->allow_unregistered;
+}
+
+void Command::AllowUnregistered(bool b)
+{
+ this->allow_unregistered = b;
+}
+
+bool Command::RequireUser() const
+{
+ return this->require_user;
+}
+
+void Command::RequireUser(bool b)
+{
+ this->require_user = b;
+}
+
const Anope::string &Command::GetDesc() const
{
return this->desc;
@@ -218,11 +236,11 @@ void RunCommand(CommandSource &source, const Anope::string &message)
return;
}
- if (c->HasFlag(CFLAG_REQUIRE_USER) && !source.GetUser())
+ if (c->RequireUser() && !source.GetUser())
return;
// Command requires registered users only
- if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !source.nc)
+ if (!c->AllowUnregistered() && !source.nc)
{
source.Reply(NICK_IDENTIFY_REQUIRED);
if (source.GetUser())
diff --git a/src/config.cpp b/src/config.cpp
index bdd7180da..968d6fd73 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -43,9 +43,9 @@ ServerConfig::ServerConfig()
if (NSDefaults.empty())
{
- this->NSDefFlags.SetFlag(NI_SECURE);
- this->NSDefFlags.SetFlag(NI_MEMO_SIGNON);
- this->NSDefFlags.SetFlag(NI_MEMO_RECEIVE);
+ this->NSDefFlags.insert("SECURE");
+ this->NSDefFlags.insert("MEMOSIGNON");
+ this->NSDefFlags.insert("MEMORECEIVE");
}
else if (!NSDefaults.equals_ci("none"))
{
@@ -53,33 +53,15 @@ ServerConfig::ServerConfig()
Anope::string option;
while (options.GetToken(option))
{
- if (option.equals_ci("kill"))
- this->NSDefFlags.SetFlag(NI_KILLPROTECT);
- else if (option.equals_ci("killquick"))
- this->NSDefFlags.SetFlag(NI_KILL_QUICK);
- else if (option.equals_ci("secure"))
- this->NSDefFlags.SetFlag(NI_SECURE);
- else if (option.equals_ci("private"))
- this->NSDefFlags.SetFlag(NI_PRIVATE);
- else if (option.equals_ci("msg"))
+ if (option.equals_ci("msg"))
{
if (!this->UsePrivmsg)
Log() << "msg in <nickserv:defaults> can only be used when UsePrivmsg is set";
else
- this->NSDefFlags.SetFlag(NI_MSG);
+ this->NSDefFlags.insert(option.upper());
}
- else if (option.equals_ci("hideemail"))
- this->NSDefFlags.SetFlag(NI_HIDE_EMAIL);
- else if (option.equals_ci("hideusermask"))
- this->NSDefFlags.SetFlag(NI_HIDE_MASK);
- else if (option.equals_ci("hidequit"))
- this->NSDefFlags.SetFlag(NI_HIDE_QUIT);
- else if (option.equals_ci("memosignon"))
- this->NSDefFlags.SetFlag(NI_MEMO_SIGNON);
- else if (option.equals_ci("memoreceive"))
- this->NSDefFlags.SetFlag(NI_MEMO_RECEIVE);
- else if (option.equals_ci("autoop"))
- this->NSDefFlags.SetFlag(NI_AUTOOP);
+ else
+ this->NSDefFlags.insert(option.upper());
}
}
@@ -90,42 +72,17 @@ ServerConfig::ServerConfig()
if (CSDefaults.empty())
{
- this->CSDefFlags.SetFlag(CI_KEEPTOPIC);
- this->CSDefFlags.SetFlag(CI_SECURE);
- this->CSDefFlags.SetFlag(CI_SECUREFOUNDER);
- this->CSDefFlags.SetFlag(CI_SIGNKICK);
+ this->CSDefFlags.insert("KEEPTOPIC");
+ this->CSDefFlags.insert("SECURE");
+ this->CSDefFlags.insert("SECUREFOUNDER");
+ this->CSDefFlags.insert("SIGNKICK");
}
else if (!CSDefaults.equals_ci("none"))
{
spacesepstream options(CSDefaults);
Anope::string option;
while (options.GetToken(option))
- {
- if (option.equals_ci("keeptopic"))
- this->CSDefFlags.SetFlag(CI_KEEPTOPIC);
- else if (option.equals_ci("topiclock"))
- this->CSDefFlags.SetFlag(CI_TOPICLOCK);
- else if (option.equals_ci("private"))
- this->CSDefFlags.SetFlag(CI_PRIVATE);
- else if (option.equals_ci("restricted"))
- this->CSDefFlags.SetFlag(CI_RESTRICTED);
- else if (option.equals_ci("secure"))
- this->CSDefFlags.SetFlag(CI_SECURE);
- else if (option.equals_ci("secureops"))
- this->CSDefFlags.SetFlag(CI_SECUREOPS);
- else if (option.equals_ci("securefounder"))
- this->CSDefFlags.SetFlag(CI_SECUREFOUNDER);
- else if (option.equals_ci("signkick"))
- this->CSDefFlags.SetFlag(CI_SIGNKICK);
- else if (option.equals_ci("signkicklevel"))
- this->CSDefFlags.SetFlag(CI_SIGNKICK_LEVEL);
- else if (option.equals_ci("peace"))
- this->CSDefFlags.SetFlag(CI_PEACE);
- else if (option.equals_ci("persist"))
- this->CSDefFlags.SetFlag(CI_PERSIST);
- else if (option.equals_ci("noautoop"))
- this->CSDefFlags.SetFlag(CI_NOAUTOOP);
- }
+ this->CSDefFlags.insert(option.upper());
}
if (UseStrictPrivMsg)
@@ -139,16 +96,7 @@ ServerConfig::ServerConfig()
spacesepstream options(BSDefaults);
Anope::string option;
while (options.GetToken(option))
- {
- if (option.equals_ci("dontkickops"))
- this->BSDefFlags.SetFlag(BS_DONTKICKOPS);
- else if (option.equals_ci("dontkickvoices"))
- this->BSDefFlags.SetFlag(BS_DONTKICKVOICES);
- else if (option.equals_ci("greet"))
- this->BSDefFlags.SetFlag(BS_GREET);
- else if (option.equals_ci("fantasy"))
- this->BSDefFlags.SetFlag(BS_FANTASY);
- }
+ this->BSDefFlags.insert(option.upper());
}
/* Ulines */
@@ -922,7 +870,7 @@ static bool DoServices(ServerConfig *config, const Anope::string &, const Anope:
BotInfo* bi = BotInfo::Find(nick);
if (!bi)
bi = new BotInfo(nick, user, host, gecos, modes);
- bi->SetFlag(BI_CONF);
+ bi->conf = true;
Anope::string token;
commasepstream sep(channels);
@@ -995,7 +943,7 @@ static bool DoneServices(ServerConfig *config, const Anope::string &)
BotInfo *bi = it->second;
++it;
- if (bi->HasFlag(BI_CONF) && services.count(bi->nick) == 0)
+ if (bi->conf && services.count(bi->nick) == 0)
bi->Destroy();
}
services.clear();
diff --git a/src/extensible.cpp b/src/extensible.cpp
new file mode 100644
index 000000000..66f603e21
--- /dev/null
+++ b/src/extensible.cpp
@@ -0,0 +1,99 @@
+/*
+ *
+ * (C) 2003-2013 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ *
+ */
+
+#include "extensible.h"
+
+Extensible::Extensible() : extension_items(NULL)
+{
+}
+
+Extensible::~Extensible()
+{
+ if (extension_items)
+ {
+ for (extensible_map::iterator it = extension_items->begin(), it_end = extension_items->end(); it != it_end; ++it)
+ delete it->second;
+ delete extension_items;
+ }
+}
+
+void Extensible::Extend(const Anope::string &key, ExtensibleItem *p)
+{
+ this->Shrink(key);
+ if (!extension_items)
+ extension_items = new extensible_map();
+ (*this->extension_items)[key] = p;
+}
+
+void Extensible::ExtendMetadata(const Anope::string &key, const Anope::string &value)
+{
+ this->Extend(key, new ExtensibleMetadata(value));
+}
+
+bool Extensible::Shrink(const Anope::string &key)
+{
+ if (!extension_items)
+ return false;
+
+ extensible_map::iterator it = this->extension_items->find(key);
+ if (it != this->extension_items->end())
+ {
+ delete it->second;
+ /* map::size_type map::erase( const key_type& key );
+ * returns the number of elements removed, std::map
+ * is single-associative so this should only be 0 or 1
+ */
+ return this->extension_items->erase(key) > 0;
+ }
+
+ return false;
+}
+
+bool Extensible::HasExt(const Anope::string &key) const
+{
+ return this->extension_items != NULL && this->extension_items->count(key) > 0;
+}
+
+void Extensible::GetExtList(std::deque<Anope::string> &list) const
+{
+ if (extension_items)
+ for (extensible_map::const_iterator it = extension_items->begin(), it_end = extension_items->end(); it != it_end; ++it)
+ list.push_back(it->first);
+}
+
+void Extensible::ExtensibleSerialize(Serialize::Data &data) const
+{
+ if (extension_items)
+ for (extensible_map::const_iterator it = extension_items->begin(), it_end = extension_items->end(); it != it_end; ++it)
+ if (it->second && it->second->Serialize())
+ data["extensible:" + it->first] << *it->second->Serialize();
+}
+
+void Extensible::ExtensibleUnserialize(Serialize::Data &data)
+{
+ /* Shrink existing extensible items */
+ if (extension_items)
+ for (extensible_map::iterator it = extension_items->begin(), it_end = extension_items->end(); it != it_end; ++it)
+ this->Shrink(it->first);
+
+ std::set<Anope::string> keys = data.KeySet();
+ for (std::set<Anope::string>::iterator it = keys.begin(), it_end = keys.end(); it != it_end; ++it)
+ if (it->find("extensible:") == 0)
+ {
+ if (!extension_items)
+ extension_items = new extensible_map();
+
+ Anope::string str;
+ data[*it] >> str;
+
+ this->ExtendMetadata(it->substr(11), str);
+ }
+}
+
diff --git a/src/memos.cpp b/src/memos.cpp
index d3bb7afce..eb4d22107 100644
--- a/src/memos.cpp
+++ b/src/memos.cpp
@@ -19,10 +19,10 @@
#include "account.h"
#include "regchannel.h"
-static const Anope::string MemoFlagString[] = { "MF_UNREAD", "MF_RECEIPT", "" };
-template<> const Anope::string* Flags<MemoFlag>::flags_strings = MemoFlagString;
-
-Memo::Memo() : Serializable("Memo") { }
+Memo::Memo() : Serializable("Memo")
+{
+ unread = receipt = false;
+}
void Memo::Serialize(Serialize::Data &data) const
{
@@ -30,7 +30,8 @@ void Memo::Serialize(Serialize::Data &data) const
data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time;
data["sender"] << this->sender;
data["text"] << this->text;
- data["flags"] << this->ToString();
+ data["unread"] << this->unread;
+ data["receipt"] << this->receipt;
}
Serializable* Memo::Unserialize(Serializable *obj, Serialize::Data &data)
@@ -39,10 +40,9 @@ Serializable* Memo::Unserialize(Serializable *obj, Serialize::Data &data)
if (!MemoServService)
return NULL;
- Anope::string owner, flags;
+ Anope::string owner;
data["owner"] >> owner;
- data["flags"] >> flags;
bool ischan;
MemoInfo *mi = MemoServService->GetMemoInfo(owner, ischan);
@@ -54,11 +54,13 @@ Serializable* Memo::Unserialize(Serializable *obj, Serialize::Data &data)
m = anope_dynamic_static_cast<Memo *>(obj);
else
m = new Memo();
+
data["owner"] >> m->owner;
data["time"] >> m->time;
data["sender"] >> m->sender;
data["text"] >> m->text;
- m->FromString(flags);
+ data["unread"] >> m->unread;
+ data["receipt"] >> m->receipt;
if (obj == NULL)
mi->memos->push_back(m);
diff --git a/src/messages.cpp b/src/messages.cpp
index 1317b5e46..6a60d9cd9 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -90,7 +90,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
if (!c)
{
c = new Channel(chan, ts ? ts : Anope::CurTime);
- c->SetFlag(CH_SYNCING);
+ c->Extend("SYNCING");
}
/* Some IRCds do not include a TS */
else if (!ts)
@@ -139,9 +139,9 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co
}
/* Channel is done syncing */
- if (c->HasFlag(CH_SYNCING))
+ if (c->HasExt("SYNCING"))
{
- c->UnsetFlag(CH_SYNCING);
+ c->Shrink("SYNCING");
/* Sync the channel (mode lock, topic, etc) */
c->Sync();
}
@@ -345,7 +345,7 @@ void Quit::Run(MessageSource &source, const std::vector<Anope::string> &params)
Log(user, "quit") << "quit (Reason: " << (!reason.empty() ? reason : "no reason") << ")";
NickAlias *na = NickAlias::Find(user->nick);
- if (na && !na->nc->HasFlag(NI_SUSPENDED) && (user->IsRecognized() || user->IsIdentified(true)))
+ if (na && !na->nc->HasExt("SUSPENDED") && (user->IsRecognized() || user->IsIdentified(true)))
{
na->last_seen = Anope::CurTime;
na->last_quit = reason;
@@ -380,7 +380,7 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
switch (params[0][0])
{
case 'l':
- if (u->HasMode(UMODE_OPER))
+ if (u->HasMode("OPER"))
{
IRCD->SendNumeric(211, source.GetSource(), "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
IRCD->SendNumeric(211, source.GetSource(), "%s %d %d %d %d %d %d %ld", Config->Uplinks[Anope::CurrentUplink]->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - Anope::StartTime));
@@ -391,7 +391,7 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params)
case 'o':
case 'O':
/* Check whether the user is an operator */
- if (!u->HasMode(UMODE_OPER) && Config->HideStatsO)
+ if (!u->HasMode("OPER") && Config->HideStatsO)
IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
else
{
diff --git a/src/modes.cpp b/src/modes.cpp
index a3d2cd041..4f77a044b 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -26,51 +26,12 @@ std::vector<UserMode *> ModeManager::UserModes;
unsigned ModeManager::GenericChannelModes = 0, ModeManager::GenericUserModes = 0;
/* Default channel mode lock */
-std::list<std::pair<ChannelModeName, Anope::string> > ModeManager::ModeLockOn;
-std::list<ChannelModeName> ModeManager::ModeLockOff;
+std::list<std::pair<Anope::string, Anope::string> > ModeManager::ModeLockOn;
+std::list<Anope::string> ModeManager::ModeLockOff;
/* Default modes bots have on channels */
ChannelStatus ModeManager::DefaultBotModes;
-static const Anope::string UserModeNameStrings[] = {
- "UMODE_BEGIN",
-
- "UMODE_SERV_ADMIN", "UMODE_BOT", "UMODE_CO_ADMIN", "UMODE_FILTER", "UMODE_HIDEOPER", "UMODE_NETADMIN",
- "UMODE_REGPRIV", "UMODE_PROTECTED", "UMODE_NOCTCP", "UMODE_WEBTV", "UMODE_WEBIRC", "UMODE_WHOIS", "UMODE_ADMIN", "UMODE_DEAF",
- "UMODE_GLOBOPS", "UMODE_HELPOP", "UMODE_INVIS", "UMODE_OPER", "UMODE_PRIV", "UMODE_GOD", "UMODE_REGISTERED",
- "UMODE_SNOMASK", "UMODE_VHOST", "UMODE_WALLOPS", "UMODE_CLOAK", "UMODE_SSL", "UMODE_SOFTCALLERID", "UMODE_CALLERID",
- "UMODE_COMMONCHANS", "UMODE_HIDDEN", "UMODE_STRIPCOLOR", "UMODE_INVISIBLE_OPER", "UMODE_RESTRICTED", "UMODE_HIDEIDLE",
-
- ""
-};
-template<> const Anope::string* Flags<UserModeName>::flags_strings = UserModeNameStrings;
-
-static const Anope::string ChannelModeNameStrings[] = {
- "CMODE_BEGIN",
-
- /* Channel modes */
- "CMODE_BLOCKCOLOR", "CMODE_FLOOD", "CMODE_INVITE", "CMODE_KEY", "CMODE_LIMIT", "CMODE_MODERATED", "CMODE_NOEXTERNAL",
- "CMODE_PRIVATE", "CMODE_REGISTERED", "CMODE_SECRET", "CMODE_TOPIC", "CMODE_AUDITORIUM", "CMODE_SSL", "CMODE_ADMINONLY",
- "CMODE_NOCTCP", "CMODE_FILTER", "CMODE_NOKNOCK", "CMODE_REDIRECT", "CMODE_REGMODERATED", "CMODE_NONICK", "CMODE_OPERONLY",
- "CMODE_NOKICK", "CMODE_REGISTEREDONLY", "CMODE_STRIPCOLOR", "CMODE_NONOTICE", "CMODE_NOINVITE", "CMODE_ALLINVITE",
- "CMODE_BLOCKCAPS", "CMODE_PERM", "CMODE_NICKFLOOD", "CMODE_JOINFLOOD", "CMODE_DELAYEDJOIN", "CMODE_NOREJOIN",
- "CMODE_BANDWIDTH",
-
- /* b/e/I */
- "CMODE_BAN", "CMODE_EXCEPT",
- "CMODE_INVITEOVERRIDE",
-
- /* v/h/o/a/q */
- "CMODE_VOICE", "CMODE_HALFOP", "CMODE_OP",
- "CMODE_PROTECT", "CMODE_OWNER",
-
- ""
-};
-template<> const Anope::string* Flags<ChannelModeName>::flags_strings = ChannelModeNameStrings;
-
-static const Anope::string EntryFlagString[] = { "ENTRYTYPE_NONE", "ENTRYTYPE_CIDR", "ENTRYTYPE_NICK_WILD", "ENTRYTYPE_NICK", "ENTRYTYPE_USER_WILD", "ENTRYTYPE_USER", "ENTRYTYPE_HOST_WILD", "ENTRYTYPE_HOST", "" };
-template<> const Anope::string* Flags<EntryType>::flags_strings = EntryFlagString;
-
Anope::string ChannelStatus::BuildCharPrefixList() const
{
Anope::string ret;
@@ -79,7 +40,7 @@ Anope::string ChannelStatus::BuildCharPrefixList() const
{
ChannelMode *cm = ModeManager::ChannelModes[i];
- if (this->HasFlag(cm->name))
+ if (this->modes.count(cm->name))
ret += cm->mchar;
}
@@ -94,7 +55,7 @@ Anope::string ChannelStatus::BuildModePrefixList() const
{
ChannelMode *cm = ModeManager::ChannelModes[i];
- if (this->HasFlag(cm->name))
+ if (this->modes.count(cm->name))
{
ChannelModeStatus *cms = anope_dynamic_static_cast<ChannelModeStatus *>(cm);
ret += cms->Symbol;
@@ -104,7 +65,7 @@ Anope::string ChannelStatus::BuildModePrefixList() const
return ret;
}
-Mode::Mode(ModeClass mcl, char mch, ModeType mt) : mclass(mcl), mchar(mch), type(mt)
+Mode::Mode(const Anope::string &mname, ModeClass mcl, char mch, ModeType mt) : name(mname), mclass(mcl), mchar(mch), type(mt)
{
}
@@ -112,7 +73,7 @@ Mode::~Mode()
{
}
-UserMode::UserMode(UserModeName un, char mch) : Mode(MC_USER, mch, MODE_REGULAR), name(un)
+UserMode::UserMode(const Anope::string &un, char mch) : Mode(un, MC_USER, mch, MODE_REGULAR)
{
}
@@ -120,19 +81,12 @@ UserMode::~UserMode()
{
}
-const Anope::string UserMode::NameAsString()
-{
- if (this->name >= UMODE_END)
- return this->mchar;
- return UserModeNameStrings[this->name];
-}
-
-UserModeParam::UserModeParam(UserModeName un, char mch) : UserMode(un, mch)
+UserModeParam::UserModeParam(const Anope::string &un, char mch) : UserMode(un, mch)
{
this->type = MODE_PARAM;
}
-ChannelMode::ChannelMode(ChannelModeName cm, char mch) : Mode(MC_CHANNEL, mch, MODE_REGULAR), name(cm)
+ChannelMode::ChannelMode(const Anope::string &cm, char mch) : Mode(cm, MC_CHANNEL, mch, MODE_REGULAR)
{
}
@@ -147,14 +101,7 @@ bool ChannelMode::CanSet(User *u) const
return true;
}
-const Anope::string ChannelMode::NameAsString()
-{
- if (this->name >= CMODE_END)
- return this->mchar;
- return ChannelModeNameStrings[this->name];
-}
-
-ChannelModeList::ChannelModeList(ChannelModeName cm, char mch) : ChannelMode(cm, mch)
+ChannelModeList::ChannelModeList(const Anope::string &cm, char mch) : ChannelMode(cm, mch)
{
this->type = MODE_LIST;
}
@@ -163,7 +110,7 @@ ChannelModeList::~ChannelModeList()
{
}
-ChannelModeParam::ChannelModeParam(ChannelModeName cm, char mch, bool ma) : ChannelMode(cm, mch), minus_no_arg(ma)
+ChannelModeParam::ChannelModeParam(const Anope::string &cm, char mch, bool ma) : ChannelMode(cm, mch), minus_no_arg(ma)
{
this->type = MODE_PARAM;
}
@@ -172,7 +119,7 @@ ChannelModeParam::~ChannelModeParam()
{
}
-ChannelModeStatus::ChannelModeStatus(ChannelModeName mName, char modeChar, char mSymbol, unsigned short mLevel) : ChannelMode(mName, modeChar), Symbol(mSymbol), Level(mLevel)
+ChannelModeStatus::ChannelModeStatus(const Anope::string &mname, char modeChar, char mSymbol, unsigned short mLevel) : ChannelMode(mname, modeChar), Symbol(mSymbol), Level(mLevel)
{
this->type = MODE_STATUS;
}
@@ -191,7 +138,7 @@ bool ChannelModeKey::IsValid(const Anope::string &value) const
bool ChannelModeAdmin::CanSet(User *u) const
{
- if (u && u->HasMode(UMODE_OPER))
+ if (u && u->HasMode("OPER"))
return true;
return false;
@@ -199,7 +146,7 @@ bool ChannelModeAdmin::CanSet(User *u) const
bool ChannelModeOper::CanSet(User *u) const
{
- if (u && u->HasMode(UMODE_OPER))
+ if (u && u->HasMode("OPER"))
return true;
return false;
@@ -343,11 +290,12 @@ bool ModeManager::AddUserMode(UserMode *um)
if (ModeManager::FindUserModeByChar(um->mchar) != NULL)
return false;
- if (um->name == UMODE_END)
+ if (um->name.empty())
{
- um->name = static_cast<UserModeName>(UMODE_END + ++GenericUserModes);
+ um->name = stringify(++GenericUserModes);
Log() << "ModeManager: Added generic support for user mode " << um->mchar;
}
+
ModeManager::UserModes.push_back(um);
FOREACH_MOD(I_OnUserModeAdd, OnUserModeAdd(um));
@@ -360,11 +308,12 @@ bool ModeManager::AddChannelMode(ChannelMode *cm)
if (ModeManager::FindChannelModeByChar(cm->mchar) != NULL)
return false;
- if (cm->name == CMODE_END)
+ if (cm->name.empty())
{
- cm->name = static_cast<ChannelModeName>(CMODE_END + ++GenericChannelModes);
+ cm->name = stringify(++GenericChannelModes);
Log() << "ModeManager: Added generic support for channel mode " << cm->mchar;
}
+
ModeManager::ChannelModes.push_back(cm);
/* Apply this mode to the new default mlock if its used */
@@ -429,48 +378,24 @@ UserMode *ModeManager::FindUserModeByChar(char Mode)
return NULL;
}
-ChannelMode *ModeManager::FindChannelModeByName(ChannelModeName Name)
+ChannelMode *ModeManager::FindChannelModeByName(const Anope::string &name)
{
for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
{
ChannelMode *cm = ModeManager::ChannelModes[i];
- if (cm->name == Name)
+ if (cm->name == name)
return cm;
}
return NULL;
}
-UserMode *ModeManager::FindUserModeByName(UserModeName Name)
+UserMode *ModeManager::FindUserModeByName(const Anope::string &name)
{
for (unsigned i = 0; i < ModeManager::UserModes.size(); ++i)
{
UserMode *um = ModeManager::UserModes[i];
- if (um->name == Name)
- return um;
- }
-
- return NULL;
-}
-
-ChannelMode *ModeManager::FindChannelModeByString(const Anope::string &name)
-{
- for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
- {
- ChannelMode *cm = ModeManager::ChannelModes[i];
- if (cm->NameAsString() == name || Anope::string(cm->mchar) == name)
- return cm;
- }
-
- return NULL;
-}
-
-UserMode *ModeManager::FindUserModeByString(const Anope::string &name)
-{
- for (size_t i = UMODE_BEGIN + 1; i != UMODE_END; ++i)
- {
- UserMode *um = ModeManager::FindUserModeByName(static_cast<UserModeName>(i));
- if (um != NULL && (um->NameAsString() == name || Anope::string(um->mchar) == name))
+ if (um->name == name)
return um;
}
@@ -643,14 +568,14 @@ void ModeManager::UpdateDefaultMLock(ServerConfig *config)
if (cm->type != MODE_LIST) // Only MODE_LIST can have duplicates
{
- for (std::list<std::pair<ChannelModeName, Anope::string> >::iterator it = ModeLockOn.begin(), it_end = ModeLockOn.end(); it != it_end; ++it)
+ for (std::list<std::pair<Anope::string, Anope::string> >::iterator it = ModeLockOn.begin(), it_end = ModeLockOn.end(); it != it_end; ++it)
if (it->first == cm->name)
{
ModeLockOn.erase(it);
break;
}
- for (std::list<ChannelModeName>::iterator it = ModeLockOff.begin(), it_end = ModeLockOff.end(); it != it_end; ++it)
+ for (std::list<Anope::string>::iterator it = ModeLockOff.begin(), it_end = ModeLockOff.end(); it != it_end; ++it)
if (*it == cm->name)
{
ModeLockOff.erase(it);
@@ -667,19 +592,18 @@ void ModeManager::UpdateDefaultMLock(ServerConfig *config)
}
/* Set Bot Modes */
- DefaultBotModes.ClearFlags();
+ DefaultBotModes.modes.clear();
for (unsigned i = 0; i < config->BotModes.length(); ++i)
{
ChannelMode *cm = ModeManager::FindChannelModeByChar(config->BotModes[i]);
if (cm && cm->type == MODE_STATUS)
- DefaultBotModes.SetFlag(cm->name);
+ DefaultBotModes.modes.insert(cm->name);
}
}
-Entry::Entry(ChannelModeName mode, const Anope::string &_host) : modename(mode)
+Entry::Entry(const Anope::string &m, const Anope::string &_host) : name(m)
{
- this->SetFlag(ENTRYTYPE_NONE);
this->cidr_len = 0;
this->mask = _host;
@@ -706,18 +630,18 @@ Entry::Entry(ChannelModeName mode, const Anope::string &_host) : modename(mode)
{
this->nick = _nick;
if (_nick.find_first_of("*?") != Anope::string::npos)
- this->SetFlag(ENTRYTYPE_NICK_WILD);
+ this->types.insert(ENTRYTYPE_NICK_WILD);
else
- this->SetFlag(ENTRYTYPE_NICK);
+ this->types.insert(ENTRYTYPE_NICK);
}
if (!_user.empty() && _user.find_first_not_of("*") != Anope::string::npos)
{
this->user = _user;
if (_user.find_first_of("*?") != Anope::string::npos)
- this->SetFlag(ENTRYTYPE_USER_WILD);
+ this->types.insert(ENTRYTYPE_USER_WILD);
else
- this->SetFlag(ENTRYTYPE_USER);
+ this->types.insert(ENTRYTYPE_USER);
}
if (!_realhost.empty() && _realhost.find_first_not_of("*") != Anope::string::npos)
@@ -735,21 +659,22 @@ Entry::Entry(ChannelModeName mode, const Anope::string &_host) : modename(mode)
{
_realhost = _realhost.substr(0, sl);
this->cidr_len = convertTo<unsigned int>(cidr_range);
- this->SetFlag(ENTRYTYPE_CIDR);
+ this->types.insert(ENTRYTYPE_CIDR);
Log(LOG_DEBUG) << "Ban " << _realhost << " has cidr " << static_cast<unsigned int>(this->cidr_len);
}
}
catch (const SocketException &) { }
+ catch (const ConvertException &) { }
}
this->host = _realhost;
- if (!this->HasFlag(ENTRYTYPE_CIDR))
+ if (!this->types.count(ENTRYTYPE_CIDR))
{
if (_realhost.find_first_of("*?") != Anope::string::npos)
- this->SetFlag(ENTRYTYPE_HOST_WILD);
+ this->types.insert(ENTRYTYPE_HOST_WILD);
else
- this->SetFlag(ENTRYTYPE_HOST);
+ this->types.insert(ENTRYTYPE_HOST);
}
}
}
@@ -763,7 +688,7 @@ bool Entry::Matches(const User *u, bool full) const
{
bool ret = true;
- if (this->HasFlag(ENTRYTYPE_CIDR))
+ if (this->types.count(ENTRYTYPE_CIDR))
{
try
{
@@ -783,26 +708,26 @@ bool Entry::Matches(const User *u, bool full) const
ret = false;
}
}
- if (this->HasFlag(ENTRYTYPE_NICK) && !this->nick.equals_ci(u->nick))
+ if (this->types.count(ENTRYTYPE_NICK) && !this->nick.equals_ci(u->nick))
ret = false;
- if (this->HasFlag(ENTRYTYPE_USER) && !this->user.equals_ci(u->GetVIdent()) && (!full ||
+ if (this->types.count(ENTRYTYPE_USER) && !this->user.equals_ci(u->GetVIdent()) && (!full ||
!this->user.equals_ci(u->GetIdent())))
ret = false;
- if (this->HasFlag(ENTRYTYPE_HOST) && !this->host.equals_ci(u->GetDisplayedHost()) && (!full ||
+ if (this->types.count(ENTRYTYPE_HOST) && !this->host.equals_ci(u->GetDisplayedHost()) && (!full ||
(!this->host.equals_ci(u->host) && !this->host.equals_ci(u->chost) && !this->host.equals_ci(u->vhost) &&
!this->host.equals_ci(u->ip))))
ret = false;
- if (this->HasFlag(ENTRYTYPE_NICK_WILD) && !Anope::Match(u->nick, this->nick))
+ if (this->types.count(ENTRYTYPE_NICK_WILD) && !Anope::Match(u->nick, this->nick))
ret = false;
- if (this->HasFlag(ENTRYTYPE_USER_WILD) && !Anope::Match(u->GetVIdent(), this->user) && (!full ||
+ if (this->types.count(ENTRYTYPE_USER_WILD) && !Anope::Match(u->GetVIdent(), this->user) && (!full ||
!Anope::Match(u->GetIdent(), this->user)))
ret = false;
- if (this->HasFlag(ENTRYTYPE_HOST_WILD) && !Anope::Match(u->GetDisplayedHost(), this->host) && (!full ||
+ if (this->types.count(ENTRYTYPE_HOST_WILD) && !Anope::Match(u->GetDisplayedHost(), this->host) && (!full ||
(!Anope::Match(u->host, this->host) && !Anope::Match(u->chost, this->host) &&
!Anope::Match(u->vhost, this->host) && !Anope::Match(u->ip, this->host))))
ret = false;
- ChannelMode *cm = ModeManager::FindChannelModeByName(this->modename);
+ ChannelMode *cm = ModeManager::FindChannelModeByName(this->name);
if (cm != NULL && cm->type == MODE_LIST)
{
ChannelModeList *cml = anope_dynamic_static_cast<ChannelModeList *>(cm);
diff --git a/src/nickalias.cpp b/src/nickalias.cpp
index 61061e031..9c09c1c0a 100644
--- a/src/nickalias.cpp
+++ b/src/nickalias.cpp
@@ -79,7 +79,7 @@ NickAlias::~NickAlias()
void NickAlias::Release()
{
- if (this->HasFlag(NS_HELD))
+ if (this->HasExt("HELD"))
{
if (IRCD->CanSVSHold)
IRCD->SendSVSHoldDel(this->nick);
@@ -92,7 +92,7 @@ void NickAlias::Release()
}
}
- this->UnsetFlag(NS_HELD);
+ this->Shrink("HELD");
}
}
@@ -122,7 +122,7 @@ class NickServHeld : public Timer
void Tick(time_t)
{
if (na)
- na->UnsetFlag(NS_HELD);
+ na->Shrink("HELD");
}
};
std::map<Anope::string, NickServHeld *> NickServHeld::NickServHelds;
@@ -171,10 +171,10 @@ std::map<Anope::string, NickServRelease *> NickServRelease::NickServReleases;
void NickAlias::OnCancel(User *)
{
- if (this->HasFlag(NS_COLLIDED))
+ if (this->HasExt("COLLIDED"))
{
- this->SetFlag(NS_HELD);
- this->UnsetFlag(NS_COLLIDED);
+ this->Extend("HELD");
+ this->Shrink("COLLIDED");
new NickServHeld(this, Config->NSReleaseTimeout);
@@ -248,7 +248,7 @@ void NickAlias::Serialize(Serialize::Data &data) const
data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered;
data.SetType("time_registered", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen;
data["nc"] << this->nc->display;
- data["flags"] << this->ToString();
+ this->ExtensibleSerialize(data);
if (this->HasVhost())
{
@@ -297,10 +297,7 @@ Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data)
data["last_realhost"] >> na->last_realhost;
data["time_registered"] >> na->time_registered;
data["last_seen"] >> na->last_seen;
-
- Anope::string flags;
- data["flags"] >> flags;
- na->FromString(flags);
+ na->ExtensibleUnserialize(data);
Anope::string vhost_ident, vhost_host, vhost_creator;
time_t vhost_time;
@@ -311,6 +308,16 @@ Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data)
data["vhost_time"] >> vhost_time;
na->SetVhost(vhost_ident, vhost_host, vhost_creator, vhost_time);
+
+ /* Compat */
+ Anope::string sflags;
+ data["flags"] >> sflags;
+ spacesepstream sep(sflags);
+ Anope::string tok;
+ while (sep.GetToken(tok))
+ na->ExtendMetadata(tok);
+ /* End compat */
+
return na;
}
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index ef98a7bef..c906f5999 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -17,18 +17,6 @@
Serialize::Checker<nickcore_map> NickCoreList("NickCore");
-static const Anope::string NickNameFlagStrings[] = {
- "BEGIN", "NO_EXPIRE", "HELD", "COLLIDED", ""
-};
-template<> const Anope::string* Flags<NickNameFlag>::flags_strings = NickNameFlagStrings;
-
-static const Anope::string NickCoreFlagStrings[] = {
- "BEGIN", "KILLPROTECT", "SECURE", "MSG", "MEMO_HARDMAX", "MEMO_SIGNON", "MEMO_RECEIVE",
- "PRIVATE", "HIDE_EMAIL", "HIDE_MASK", "HIDE_QUIT", "KILL_QUICK", "KILL_IMMED",
- "MEMO_MAIL", "HIDE_STATUS", "SUSPENDED", "AUTOOP", "UNCONFIRMED", "STATS", ""
-};
-template<> const Anope::string* Flags<NickCoreFlag>::flags_strings = NickCoreFlagStrings;
-
NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore")
{
if (coredisplay.empty())
@@ -43,9 +31,8 @@ NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore")
this->display = coredisplay;
/* Set default nick core flags */
- for (size_t t = NI_BEGIN + 1; t != NI_END; ++t)
- if (Config->NSDefFlags.HasFlag(static_cast<NickCoreFlag>(t)))
- this->SetFlag(static_cast<NickCoreFlag>(t));
+ for (std::set<Anope::string>::const_iterator it = Config->NSDefFlags.begin(), it_end = Config->NSDefFlags.end(); it != it_end; ++it)
+ this->ExtendMetadata(*it);
size_t old = NickCoreList->size();
(*NickCoreList)[this->display] = this;
@@ -85,7 +72,7 @@ void NickCore::Serialize(Serialize::Data &data) const
data["email"] << this->email;
data["greet"] << this->greet;
data["language"] << this->language;
- data["flags"] << this->ToString();
+ this->ExtensibleSerialize(data);
for (unsigned i = 0; i < this->access.size(); ++i)
data["access"] << this->access[i] << " ";
for (unsigned i = 0; i < this->cert.size(); ++i)
@@ -99,10 +86,9 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data)
{
NickCore *nc;
- Anope::string sdisplay, sflags;
+ Anope::string sdisplay;
data["display"] >> sdisplay;
- data["flags"] >> sflags;
if (obj)
nc = anope_dynamic_static_cast<NickCore *>(obj);
@@ -113,7 +99,7 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data)
data["email"] >> nc->email;
data["greet"] >> nc->greet;
data["language"] >> nc->language;
- nc->FromString(sflags);
+ nc->ExtensibleUnserialize(data);
{
Anope::string buf;
data["access"] >> buf;
@@ -140,6 +126,15 @@ Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data)
nc->memos.ignores.push_back(buf);
}
+ /* Compat */
+ Anope::string sflags;
+ data["flags"] >> sflags;
+ spacesepstream sep(sflags);
+ Anope::string tok;
+ while (sep.GetToken(tok))
+ nc->ExtendMetadata(tok);
+ /* End compat */
+
return nc;
}
diff --git a/src/pipeengine.cpp b/src/pipeengine.cpp
index 5071db9d0..3219a0e05 100644
--- a/src/pipeengine.cpp
+++ b/src/pipeengine.cpp
@@ -22,10 +22,10 @@ Pipe::Pipe() : Socket(-1), write_pipe(-1)
int fds[2];
if (pipe(fds))
throw CoreException("Could not create pipe: " + Anope::LastError());
- int flags = fcntl(fds[0], F_GETFL, 0);
- fcntl(fds[0], F_SETFL, flags | O_NONBLOCK);
- flags = fcntl(fds[1], F_GETFL, 0);
- fcntl(fds[1], F_SETFL, flags | O_NONBLOCK);
+ int sflags = fcntl(fds[0], F_GETFL, 0);
+ fcntl(fds[0], F_SETFL, sflags | O_NONBLOCK);
+ sflags = fcntl(fds[1], F_GETFL, 0);
+ fcntl(fds[1], F_SETFL, sflags | O_NONBLOCK);
SocketEngine::Change(this, false, SF_READABLE);
SocketEngine::Change(this, false, SF_WRITABLE);
@@ -67,11 +67,11 @@ int Pipe::Read(char *data, size_t sz)
bool Pipe::SetWriteBlocking(bool state)
{
- int flags = fcntl(this->write_pipe, F_GETFL, 0);
+ int f = fcntl(this->write_pipe, F_GETFL, 0);
if (state)
- return !fcntl(this->write_pipe, F_SETFL, flags & ~O_NONBLOCK);
+ return !fcntl(this->write_pipe, F_SETFL, f & ~O_NONBLOCK);
else
- return !fcntl(this->write_pipe, F_SETFL, flags | O_NONBLOCK);
+ return !fcntl(this->write_pipe, F_SETFL, f | O_NONBLOCK);
}
void Pipe::Notify()
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 9082295b3..c14f1ee68 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -64,7 +64,7 @@ void IRCDProto::SendKickInternal(const BotInfo *bi, const Channel *c, const User
void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf)
{
- if (Config->NSDefFlags.HasFlag(NI_MSG))
+ if (Config->NSDefFlags.count("msg"))
SendPrivmsgInternal(bi, dest, buf);
else
SendNoticeInternal(bi, dest, buf);
@@ -382,7 +382,7 @@ bool IRCDProto::IsHostValid(const Anope::string &host)
void IRCDProto::SendOper(User *u)
{
SendNumericInternal(381, u->GetUID(), ":You are now an IRC operator (set by services)");
- u->SetMode(OperServ, UMODE_OPER);
+ u->SetMode(OperServ, "OPER");
}
MessageSource::MessageSource(const Anope::string &src) : source(src), u(NULL), s(NULL)
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 6f2581703..38fe73ff9 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -23,16 +23,6 @@
Serialize::Checker<registered_channel_map> RegisteredChannelList("ChannelInfo");
-static const Anope::string ChannelInfoFlagStrings[] = {
- "BEGIN", "KEEPTOPIC", "SECUREOPS", "PRIVATE", "TOPICLOCK", "RESTRICTED",
- "PEACE", "SECURE", "NO_EXPIRE", "MEMO_HARDMAX", "SECUREFOUNDER",
- "SIGNKICK", "SIGNKICK_LEVEL", "SUSPENDED", "PERSIST", "STATS", "NOAUTOOP", ""
-};
-template<> const Anope::string* Flags<ChannelInfoFlag>::flags_strings = ChannelInfoFlagStrings;
-
-static const Anope::string AutoKickFlagString[] = { "AK_ISNICK", "" };
-template<> const Anope::string* Flags<AutoKickFlag>::flags_strings = AutoKickFlagString;
-
BadWord::BadWord() : Serializable("BadWord")
{
}
@@ -90,7 +80,7 @@ AutoKick::~AutoKick()
void AutoKick::Serialize(Serialize::Data &data) const
{
data["ci"] << this->ci->name;
- if (this->HasFlag(AK_ISNICK) && this->nc)
+ if (this->nc)
data["nc"] << this->nc->display;
else
data["mask"] << this->mask;
@@ -98,7 +88,6 @@ void AutoKick::Serialize(Serialize::Data &data) const
data["creator"] << this->creator;
data.SetType("addtime", Serialize::Data::DT_INT); data["addtime"] << this->addtime;
data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used;
- data["flags"] << this->ToString();
}
Serializable* AutoKick::Unserialize(Serializable *obj, Serialize::Data &data)
@@ -142,14 +131,10 @@ Serializable* AutoKick::Unserialize(Serializable *obj, Serialize::Data &data)
ak = ci->AddAkick(screator, smask, sreason, addtime, lastused);
}
- Anope::string sflags;
- data["flags"] >> sflags;
- ak->FromString(sflags);
-
return ak;
}
-ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se, time_t c) : Serializable("ModeLock"), ci(ch), set(s), name(n), param(p), setter(se), created(c)
+ModeLock::ModeLock(ChannelInfo *ch, bool s, const Anope::string &n, const Anope::string &p, const Anope::string &se, time_t c) : Serializable("ModeLock"), ci(ch), set(s), name(n), param(p), setter(se), created(c)
{
}
@@ -164,13 +149,9 @@ void ModeLock::Serialize(Serialize::Data &data) const
if (!this->ci)
return;
- const Anope::string* ChannelModeNameStrings = Flags<ChannelModeName>::GetFlagStrings();
data["ci"] << this->ci->name;
data["set"] << this->set;
- if (this->name < CMODE_END)
- data["name"] << ChannelModeNameStrings[this->name];
- else
- data["name"] << this->name - CMODE_END;
+ data["name"] << this->name;
data["param"] << this->param;
data["setter"] << this->setter;
data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created;
@@ -178,37 +159,13 @@ void ModeLock::Serialize(Serialize::Data &data) const
Serializable* ModeLock::Unserialize(Serializable *obj, Serialize::Data &data)
{
- Anope::string sci, sname;
+ Anope::string sci;
data["ci"] >> sci;
- data["name"] >> sname;
ChannelInfo *ci = ChannelInfo::Find(sci);
if (!ci)
return NULL;
-
- ChannelModeName name = CMODE_END;
-
- if (sname.is_pos_number_only())
- {
- try
- {
- name = static_cast<ChannelModeName>(CMODE_END + convertTo<unsigned>(sname));
- }
- catch (const ConvertException &) { }
- }
- else
- {
- const Anope::string* ChannelModeNameStrings = Flags<ChannelModeName>::GetFlagStrings();
- for (unsigned i = 0; !ChannelModeNameStrings[i].empty(); ++i)
- if (ChannelModeNameStrings[i] == sname)
- {
- name = static_cast<ChannelModeName>(i);
- break;
- }
- }
- if (name == CMODE_END)
- return NULL;
ModeLock *ml;
if (obj)
@@ -216,7 +173,7 @@ Serializable* ModeLock::Unserialize(Serializable *obj, Serialize::Data &data)
ml = anope_dynamic_static_cast<ModeLock *>(obj);
data["set"] >> ml->set;
- ml->name = name;
+ data["name"] >> ml->name;
data["param"] >> ml->param;
data["setter"] >> ml->setter;
data["created"] >> ml->created;
@@ -233,7 +190,10 @@ Serializable* ModeLock::Unserialize(Serializable *obj, Serialize::Data &data)
Anope::string setter;
data["setter"] >> setter;
- ml = new ModeLock(ci, set, name, "", setter, created);
+ Anope::string sname;
+ data["name"] >> sname;
+
+ ml = new ModeLock(ci, set, sname, "", setter, created);
data["param"] >> ml->param;
ci->mode_locks->insert(std::make_pair(ml->name, ml));
@@ -309,16 +269,13 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf
this->name = chname;
- size_t t;
/* Set default channel flags */
- for (t = CI_BEGIN + 1; t != CI_END; ++t)
- if (Config->CSDefFlags.HasFlag(static_cast<ChannelInfoFlag>(t)))
- this->SetFlag(static_cast<ChannelInfoFlag>(t));
+ for (std::set<Anope::string>::const_iterator it = Config->CSDefFlags.begin(), it_end = Config->CSDefFlags.end(); it != it_end; ++it)
+ this->ExtendMetadata(*it);
/* Set default bot flags */
- for (t = BS_BEGIN + 1; t != BS_END; ++t)
- if (Config->BSDefFlags.HasFlag(static_cast<BotServFlag>(t)))
- this->botflags.SetFlag(static_cast<BotServFlag>(t));
+ for (std::set<Anope::string>::const_iterator it = Config->BSDefFlags.begin(), it_end = Config->BSDefFlags.end(); it != it_end; ++it)
+ this->ExtendMetadata(*it);
this->bantype = Config->CSDefBantype;
this->memos.memomax = Config->MSMaxMemos;
@@ -370,7 +327,7 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"),
for (unsigned i = 0; i < ci.GetAkickCount(); ++i)
{
const AutoKick *takick = ci.GetAkick(i);
- if (takick->HasFlag(AK_ISNICK))
+ if (takick->nc)
this->AddAkick(takick->creator, takick->nc, takick->reason, takick->addtime, takick->last_used);
else
this->AddAkick(takick->creator, takick->mask, takick->reason, takick->addtime, takick->last_used);
@@ -440,8 +397,7 @@ void ChannelInfo::Serialize(Serialize::Data &data) const
data["last_topic_setter"] << this->last_topic_setter;
data.SetType("last_topic_time", Serialize::Data::DT_INT); data["last_topic_time"] << this->last_topic_time;
data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype;
- data["flags"] << this->ToString();
- data["botflags"] << this->botflags.ToString();
+ this->ExtensibleSerialize(data);
{
Anope::string levels_buffer;
for (std::map<Anope::string, int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
@@ -464,13 +420,11 @@ void ChannelInfo::Serialize(Serialize::Data &data) const
Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
{
- Anope::string sname, sfounder, ssuccessor, sflags, sbotflags, slevels, sbi;
+ Anope::string sname, sfounder, ssuccessor, slevels, sbi;
data["name"] >> sname;
data["founder"] >> sfounder;
data["successor"] >> ssuccessor;
- data["flags"] >> sflags;
- data["botflags"] >> sbotflags;
data["levels"] >> slevels;
data["bi"] >> sbi;
@@ -480,6 +434,8 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
else
ci = new ChannelInfo(sname);
+ ci->ExtensibleUnserialize(data);
+
if (ci->founder)
--ci->founder->channelcount;
ci->founder = NickCore::Find(sfounder);
@@ -497,8 +453,6 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
data["last_topic_setter"] >> ci->last_topic_setter;
data["last_topic_time"] >> ci->last_topic_time;
data["bantype"] >> ci->bantype;
- ci->FromString(sflags);
- ci->botflags.FromString(sbotflags);
{
std::vector<Anope::string> v;
spacesepstream(slevels).GetTokens(v);
@@ -529,6 +483,19 @@ Serializable* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data)
ci->memos.ignores.push_back(buf);
}
+ /* Compat */
+ Anope::string sflags, sbotflags;
+ data["flags"] >> sflags;
+ data["botflags"] >> sbotflags;
+ spacesepstream sep(sflags);
+ Anope::string tok;
+ while (sep.GetToken(tok))
+ ci->ExtendMetadata(tok);
+ spacesepstream sep2(sbotflags);
+ while (sep2.GetToken(tok))
+ ci->ExtendMetadata(tok);
+ /* End compat */
+
return ci;
}
@@ -663,7 +630,6 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, co
{
AutoKick *autokick = new AutoKick();
autokick->ci = this;
- autokick->SetFlag(AK_ISNICK);
autokick->nc = akicknc;
autokick->reason = reason;
autokick->creator = user;
@@ -781,13 +747,13 @@ void ChannelInfo::ClearBadWords()
bool ChannelInfo::HasMLock(ChannelMode *mode, const Anope::string &param, bool status) const
{
- std::multimap<ChannelModeName, ModeLock *>::const_iterator it = this->mode_locks->find(mode->name);
+ std::multimap<Anope::string, ModeLock *>::const_iterator it = this->mode_locks->find(mode->name);
if (it != this->mode_locks->end())
{
if (mode->type != MODE_REGULAR)
{
- std::multimap<ChannelModeName, ModeLock *>::const_iterator it_end = this->mode_locks->upper_bound(mode->name);
+ std::multimap<Anope::string, ModeLock *>::const_iterator it_end = this->mode_locks->upper_bound(mode->name);
for (; it != it_end; ++it)
{
@@ -806,7 +772,7 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
{
if (setter.empty())
setter = this->founder ? this->founder->display : "Unknown";
- std::pair<ChannelModeName, ModeLock *> ml = std::make_pair(mode->name, new ModeLock(this, status, mode->name, param, setter, created));
+ std::pair<Anope::string, ModeLock *> ml = std::make_pair(mode->name, new ModeLock(this, status, mode->name, param, setter, created));
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnMLock, OnMLock(this, ml.second));
@@ -918,15 +884,15 @@ const ChannelInfo::ModeList &ChannelInfo::GetMLock() const
return this->mode_locks;
}
-std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> ChannelInfo::GetModeList(ChannelModeName Name)
+std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> ChannelInfo::GetModeList(const Anope::string &mname)
{
- ChannelInfo::ModeList::iterator it = this->mode_locks->find(Name), it_end = it;
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mname), it_end = it;
if (it != this->mode_locks->end())
- it_end = this->mode_locks->upper_bound(Name);
+ it_end = this->mode_locks->upper_bound(mname);
return std::make_pair(it, it_end);
}
-const ModeLock *ChannelInfo::GetMLock(ChannelModeName mname, const Anope::string &param)
+const ModeLock *ChannelInfo::GetMLock(const Anope::string &mname, const Anope::string &param)
{
ChannelInfo::ModeList::iterator it = this->mode_locks->find(mname);
if (it != this->mode_locks->end())
@@ -1010,19 +976,19 @@ bool ChannelInfo::CheckKick(User *user)
* ChanServ always enforces channels like this to keep people from deleting bots etc
* that are holding channels.
*/
- if (this->c->users.size() == (this->bi && this->c->FindUser(this->bi) ? 2 : 1) && !this->c->HasFlag(CH_INHABIT) && !this->c->HasFlag(CH_SYNCING))
+ if (this->c->users.size() == (this->bi && this->c->FindUser(this->bi) ? 2 : 1) && !this->c->HasExt("INHABIT") && !this->c->HasExt("SYNCING"))
{
/* Set +ntsi to prevent rejoin */
- c->SetMode(NULL, CMODE_NOEXTERNAL);
- c->SetMode(NULL, CMODE_TOPIC);
- c->SetMode(NULL, CMODE_SECRET);
- c->SetMode(NULL, CMODE_INVITE);
+ c->SetMode(NULL, "NOEXTERNAL");
+ c->SetMode(NULL, "TOPIC");
+ c->SetMode(NULL, "SECRET");
+ c->SetMode(NULL, "INVITE");
/* Join ChanServ and set a timer for this channel to part ChanServ later */
this->c->Hold();
}
- this->c->SetMode(NULL, CMODE_BAN, mask);
+ this->c->SetMode(NULL, "BAN", mask);
this->c->Kick(NULL, user, "%s", reason.c_str());
return true;
@@ -1038,7 +1004,7 @@ void ChannelInfo::CheckTopic()
* This desyncs what is really set with what we have stored, and we end up resetting the topic often when
* it is not required
*/
- if (this->HasFlag(CI_TOPICLOCK) && this->last_topic != this->c->topic)
+ if (this->HasExt("TOPICLOCK") && this->last_topic != this->c->topic)
{
this->c->ChangeTopic(this->last_topic_setter, this->last_topic, this->last_topic_time);
}
@@ -1055,7 +1021,7 @@ void ChannelInfo::RestoreTopic()
if (!this->c)
return;
- if ((this->HasFlag(CI_KEEPTOPIC) || this->HasFlag(CI_TOPICLOCK)) && this->last_topic != this->c->topic)
+ if ((this->HasExt("KEEPTOPIC") || this->HasExt("TOPICLOCK")) && this->last_topic != this->c->topic)
{
this->c->ChangeTopic(!this->last_topic_setter.empty() ? this->last_topic_setter : this->WhoSends()->nick, this->last_topic, this->last_topic_time ? this->last_topic_time : Anope::CurTime);
}
diff --git a/src/servers.cpp b/src/servers.cpp
index d1301af80..bbb7a1596 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -20,18 +20,15 @@
#include "config.h"
#include "channels.h"
-const Anope::string ServerFlagStrings[] = { "SERVER_NONE", "SERVER_SYNCING", "SERVER_JUPED", "" };
-template<> const Anope::string* Flags<ServerFlag>::flags_strings = ServerFlagStrings;
-
/* Anope */
Server *Me = NULL;
std::set<Anope::string> Servers::Capab;
-Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Anope::string &desc, const Anope::string &ssid, ServerFlag flag) : name(sname), hops(shops), description(desc), sid(ssid), uplink(up)
+Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Anope::string &desc, const Anope::string &ssid, bool jupe) : name(sname), hops(shops), description(desc), sid(ssid), uplink(up)
{
- this->SetFlag(SERVER_SYNCING);
- this->SetFlag(flag);
+ syncing = true;
+ juped = jupe;
Log(this, "connect") << "uplinked to " << (this->uplink ? this->uplink->GetName() : "no uplink") << " connected to the network";
@@ -41,7 +38,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
this->uplink->AddLink(this);
/* Check to be sure this isn't a juped server */
- if (Me == this->uplink && !this->HasFlag(SERVER_JUPED))
+ if (Me == this->uplink && !juped)
{
/* Now do mode related stuff as we know what modes exist .. */
for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
@@ -81,7 +78,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano
{
Server *s = Me->GetLinks()[i];
- if (s->HasFlag(SERVER_JUPED))
+ if (s->juped)
IRCD->SendServer(s);
}
@@ -131,7 +128,7 @@ Server::~Server()
if (u->server == this)
{
NickAlias *na = NickAlias::Find(u->nick);
- if (na && !na->nc->HasFlag(NI_SUSPENDED) && (u->IsRecognized() || u->IsIdentified()))
+ if (na && !na->nc->HasExt("SUSPENDED") && (u->IsRecognized() || u->IsIdentified()))
{
na->last_seen = Anope::CurTime;
na->last_quit = this->quit_reason;
@@ -231,7 +228,7 @@ void Server::Sync(bool sync_links)
if (this->IsSynced())
return;
- this->UnsetFlag(SERVER_SYNCING);
+ syncing = false;
Log(this, "sync") << "is done syncing";
@@ -248,7 +245,7 @@ void Server::Sync(bool sync_links)
for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
ChannelInfo *ci = it->second;
- if (ci->HasFlag(CI_PERSIST))
+ if (ci->HasExt("PERSIST"))
{
bool created = false;
if (!ci->c)
@@ -256,9 +253,9 @@ void Server::Sync(bool sync_links)
ci->c = new Channel(ci->name, ci->time_registered);
created = true;
}
- if (ModeManager::FindChannelModeByName(CMODE_PERM) != NULL)
+ if (ModeManager::FindChannelModeByName("PERM") != NULL)
{
- ci->c->SetMode(NULL, CMODE_PERM);
+ ci->c->SetMode(NULL, "PERM");
if (created)
IRCD->SendChannel(ci->c);
}
@@ -297,7 +294,12 @@ void Server::Sync(bool sync_links)
bool Server::IsSynced() const
{
- return !this->HasFlag(SERVER_SYNCING);
+ return !syncing;
+}
+
+void Server::Unsync()
+{
+ syncing = true;
}
bool Server::IsULined() const
@@ -311,9 +313,14 @@ bool Server::IsULined() const
return false;
}
+bool Server::IsJuped() const
+{
+ return juped;
+}
+
void Server::Notice(const BotInfo *source, const Anope::string &message)
{
- if (Config->NSDefFlags.HasFlag(NI_MSG))
+ if (Config->NSDefFlags.count("MSG"))
IRCD->SendGlobalPrivmsg(source, this, message);
else
IRCD->SendGlobalNotice(source, this, message);
@@ -400,7 +407,7 @@ const Anope::string Servers::TS6_SID_Retrieve()
Server* Servers::GetUplink()
{
for (unsigned i = 0; Me && i < Me->GetLinks().size(); ++i)
- if (!Me->GetLinks()[i]->HasFlag(SERVER_JUPED))
+ if (!Me->GetLinks()[i]->IsJuped())
return Me->GetLinks()[i];
return NULL;
}
diff --git a/src/socket_clients.cpp b/src/socket_clients.cpp
index 32f9c1ff6..3686b2c0a 100644
--- a/src/socket_clients.cpp
+++ b/src/socket_clients.cpp
@@ -30,12 +30,12 @@ bool ConnectionSocket::Process()
{
try
{
- if (this->HasFlag(SF_CONNECTED))
+ if (this->flags[SF_CONNECTED])
return true;
- else if (this->HasFlag(SF_CONNECTING))
- this->SetFlag(this->io->FinishConnect(this));
+ else if (this->flags[SF_CONNECTING])
+ this->flags[this->io->FinishConnect(this)] = true;
else
- this->SetFlag(SF_DEAD);
+ this->flags[SF_DEAD] = true;
}
catch (const SocketException &ex)
{
@@ -70,12 +70,12 @@ bool ClientSocket::Process()
{
try
{
- if (this->HasFlag(SF_ACCEPTED))
+ if (this->flags[SF_ACCEPTED])
return true;
- else if (this->HasFlag(SF_ACCEPTING))
- this->SetFlag(this->io->FinishAccept(this));
+ else if (this->flags[SF_ACCEPTING])
+ this->flags[this->io->FinishAccept(this)] = true;
else
- this->SetFlag(SF_DEAD);
+ this->flags[SF_DEAD] = true;
}
catch (const SocketException &ex)
{
diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp
index 87430b798..52cc3d784 100644
--- a/src/socketengines/socketengine_epoll.cpp
+++ b/src/socketengines/socketengine_epoll.cpp
@@ -40,23 +40,20 @@ void SocketEngine::Shutdown()
void SocketEngine::Change(Socket *s, bool set, SocketFlag flag)
{
- if (set == s->HasFlag(flag))
+ if (set == s->flags[flag])
return;
- bool before_registered = s->HasFlag(SF_READABLE) || s->HasFlag(SF_WRITABLE);
+ bool before_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE];
- if (set)
- s->SetFlag(flag);
- else
- s->UnsetFlag(flag);
+ s->flags[flag] = set;
- bool now_registered = s->HasFlag(SF_READABLE) || s->HasFlag(SF_WRITABLE);
+ bool now_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE];
epoll_event ev;
memset(&ev, 0, sizeof(ev));
- ev.events = (s->HasFlag(SF_READABLE) ? EPOLLIN : 0) | (s->HasFlag(SF_WRITABLE) ? EPOLLOUT : 0);
+ ev.events = (s->flags[SF_READABLE] ? EPOLLIN : 0) | (s->flags[SF_WRITABLE] ? EPOLLOUT : 0);
ev.data.fd = s->GetFD();
int mod;
@@ -107,18 +104,18 @@ void SocketEngine::Process()
if (!s->Process())
{
- if (s->HasFlag(SF_DEAD))
+ if (s->flags[SF_DEAD])
delete s;
continue;
}
if ((ev.events & EPOLLIN) && !s->ProcessRead())
- s->SetFlag(SF_DEAD);
+ s->flags[SF_DEAD] = true;
if ((ev.events & EPOLLOUT) && !s->ProcessWrite())
- s->SetFlag(SF_DEAD);
+ s->flags[SF_DEAD] = true;
- if (s->HasFlag(SF_DEAD))
+ if (s->flags[SF_DEAD])
delete s;
}
}
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 03dada807..1049d0b7f 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -21,11 +21,6 @@
#include <fcntl.h>
#endif
-static const Anope::string SocketFlagStrings[] = {
- "SF_DEAD", "SF_WRITABLE", "SF_CONNECTING", "SF_CONNECTED", "SF_ACCEPTING", "SF_ACCEPTED", ""
-};
-template<> const Anope::string* Flags<SocketFlag>::flags_strings = SocketFlagStrings;
-
std::map<int, Socket *> SocketEngine::Sockets;
uint32_t TotalRead = 0;
@@ -339,7 +334,7 @@ ClientSocket *SocketIO::Accept(ListenSocket *s)
if (newsock >= 0)
{
ClientSocket *ns = s->OnAccept(newsock, conaddr);
- ns->SetFlag(SF_ACCEPTED);
+ ns->flags[SF_ACCEPTED] = true;
ns->OnAccept();
return ns;
}
@@ -361,8 +356,7 @@ void SocketIO::Bind(Socket *s, const Anope::string &ip, int port)
void SocketIO::Connect(ConnectionSocket *s, const Anope::string &target, int port)
{
- s->UnsetFlag(SF_CONNECTING);
- s->UnsetFlag(SF_CONNECTED);
+ s->flags[SF_CONNECTING] = s->flags[SF_CONNECTED] = false;
s->conaddr.pton(s->IsIPv6() ? AF_INET6 : AF_INET, target, port);
int c = connect(s->GetFD(), &s->conaddr.sa, s->conaddr.size());
if (c == -1)
@@ -372,29 +366,29 @@ void SocketIO::Connect(ConnectionSocket *s, const Anope::string &target, int por
else
{
SocketEngine::Change(s, true, SF_WRITABLE);
- s->SetFlag(SF_CONNECTING);
+ s->flags[SF_CONNECTING] = true;
}
}
else
{
- s->SetFlag(SF_CONNECTED);
+ s->flags[SF_CONNECTED] = true;
s->OnConnect();
}
}
SocketFlag SocketIO::FinishConnect(ConnectionSocket *s)
{
- if (s->HasFlag(SF_CONNECTED))
+ if (s->flags[SF_CONNECTED])
return SF_CONNECTED;
- else if (!s->HasFlag(SF_CONNECTING))
+ else if (!s->flags[SF_CONNECTING])
throw SocketException("SocketIO::FinishConnect called for a socket not connected nor connecting?");
int optval = 0;
socklen_t optlen = sizeof(optval);
if (!getsockopt(s->GetFD(), SOL_SOCKET, SO_ERROR, reinterpret_cast<char *>(&optval), &optlen) && !optval)
{
- s->SetFlag(SF_CONNECTED);
- s->UnsetFlag(SF_CONNECTING);
+ s->flags[SF_CONNECTED] = true;
+ s->flags[SF_CONNECTING] = false;
s->OnConnect();
return SF_CONNECTED;
}
@@ -445,11 +439,11 @@ bool Socket::IsIPv6() const
bool Socket::SetBlocking(bool state)
{
- int flags = fcntl(this->GetFD(), F_GETFL, 0);
+ int f = fcntl(this->GetFD(), F_GETFL, 0);
if (state)
- return !fcntl(this->GetFD(), F_SETFL, flags & ~O_NONBLOCK);
+ return !fcntl(this->GetFD(), F_SETFL, f & ~O_NONBLOCK);
else
- return !fcntl(this->GetFD(), F_SETFL, flags | O_NONBLOCK);
+ return !fcntl(this->GetFD(), F_SETFL, f | O_NONBLOCK);
}
void Socket::Bind(const Anope::string &ip, int port)
diff --git a/src/threadengine.cpp b/src/threadengine.cpp
index 1f4d23b68..421f6d94f 100644
--- a/src/threadengine.cpp
+++ b/src/threadengine.cpp
@@ -75,7 +75,7 @@ void Thread::Start()
{
if (pthread_create(&this->handle, get_engine_attr(), entry_point, this))
{
- this->SetFlag(SF_DEAD);
+ this->flags[SF_DEAD] = true;
throw CoreException("Unable to create thread: " + Anope::LastError());
}
}
@@ -88,7 +88,7 @@ bool Thread::GetExitState() const
void Thread::OnNotify()
{
this->Join();
- this->SetFlag(SF_DEAD);
+ this->flags[SF_DEAD] = true;
}
Mutex::Mutex()
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 70023c987..085ef889b 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -85,12 +85,12 @@ UplinkSocket::~UplinkSocket()
if (Me)
for (unsigned i = Me->GetLinks().size(); i > 0; --i)
- if (!Me->GetLinks()[i - 1]->HasFlag(SERVER_JUPED))
+ if (!Me->GetLinks()[i - 1]->IsJuped())
Me->GetLinks()[i - 1]->Delete(Me->GetName() + " " + Me->GetLinks()[i - 1]->GetName());
UplinkSock = NULL;
- Me->SetFlag(SERVER_SYNCING);
+ Me->Unsync();
if (Anope::AtTerm())
{
@@ -159,7 +159,7 @@ UplinkSocket::Message::~Message()
if (this->server != NULL)
{
- if (this->server != Me && !this->server->HasFlag(SERVER_JUPED))
+ if (this->server != Me && !this->server->IsJuped())
{
Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->server->GetName() << " who is not from me?";
return;
@@ -169,7 +169,7 @@ UplinkSocket::Message::~Message()
}
else if (this->user != NULL)
{
- if (this->user->server != Me && !this->user->server->HasFlag(SERVER_JUPED))
+ if (this->user->server != Me && !this->user->server->IsJuped())
{
Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->user->nick << " who is not from me?";
return;
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 &param)
@@ -551,9 +551,7 @@ void User::SetModeInternal(UserMode *um, const Anope::string &param)
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;