summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-28 15:46:15 -0400
committerAdam <Adam@anope.org>2011-09-10 02:05:00 -0400
commit700a585b1bb38a9dc0ac3e749083250d405488f8 (patch)
tree8af306bd60778815fe5a137590d3b888213ad231 /src
parent62752db4c49a8679b51d5996003fd3a23c2a3f2d (diff)
Allow modules to add their own channel levels
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp141
-rw-r--r--src/botserv.cpp4
-rw-r--r--src/channels.cpp18
-rw-r--r--src/init.cpp1
-rw-r--r--src/regchannel.cpp28
5 files changed, 151 insertions, 41 deletions
diff --git a/src/access.cpp b/src/access.cpp
index b9b3e1e9a..49636cd04 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -19,6 +19,84 @@ enum
ACCESS_FOUNDER = 10001
};
+Privilege::Privilege(const Anope::string &n, const Anope::string &d) : name(n), desc(d)
+{
+}
+
+bool Privilege::operator==(const Privilege &other)
+{
+ return this->name == other.name;
+}
+
+std::vector<Privilege> PrivilegeManager::privs;
+
+void PrivilegeManager::AddPrivilege(Privilege p, int pos, int def)
+{
+ if (pos < 0 || static_cast<size_t>(pos) > privs.size())
+ pos = privs.size();
+ privs.insert(privs.begin() + pos, p);
+ for (registered_channel_map::const_iterator cit = RegisteredChannelList.begin(), cit_end = RegisteredChannelList.end(); cit != cit_end; ++cit)
+ cit->second->SetLevel(p.name, def);
+}
+
+void PrivilegeManager::RemovePrivilege(Privilege &p)
+{
+ std::vector<Privilege>::iterator it = std::find(privs.begin(), privs.end(), p);
+ if (it != privs.end())
+ privs.erase(it);
+ for (registered_channel_map::const_iterator cit = RegisteredChannelList.begin(), cit_end = RegisteredChannelList.end(); cit != cit_end; ++cit)
+ cit->second->RemoveLevel(p.name);
+}
+
+Privilege *PrivilegeManager::FindPrivilege(const Anope::string &name)
+{
+ for (unsigned i = privs.size(); i > 0; --i)
+ if (privs[i - 1].name == name)
+ return &privs[i - 1];
+ return NULL;
+}
+
+void PrivilegeManager::Init()
+{
+ AddPrivilege(Privilege("ACCESS_LIST", _("Allowed to view the access list")));
+ AddPrivilege(Privilege("NOKICK", _("Prevents users being kicked by Services")));
+ AddPrivilege(Privilege("FANTASIA", _("Allowed to use fantasy commands")));
+ AddPrivilege(Privilege("FOUNDER", _("Allowed to issue commands restricted to channel founders")));
+ AddPrivilege(Privilege("GREET", _("Greet message displayed")));
+ AddPrivilege(Privilege("AUTOVOICE", _("Automatic mode +v")));
+ AddPrivilege(Privilege("VOICEME", _("Allowed to (de)voice him/herself")));
+ AddPrivilege(Privilege("VOICE", _("Allowed to (de)voice users")));
+ AddPrivilege(Privilege("INFO", _("Allowed to use INFO command with ALL option")));
+ AddPrivilege(Privilege("SAY", _("Allowed to use SAY and ACT commands")));
+ AddPrivilege(Privilege("AUTOHALFOP", _("Automatic mode +h")));
+ AddPrivilege(Privilege("HALFOPME", _("Allowed to (de)halfop him/herself")));
+ AddPrivilege(Privilege("HALFOP", _("Allowed to (de)halfop users")));
+ AddPrivilege(Privilege("KICK", _("Allowed to use the KICK command")));
+ AddPrivilege(Privilege("SIGNKICK", _("No signed kick when SIGNKICK LEVEL is used")));
+ AddPrivilege(Privilege("BAN", _("Allowed to use ban users")));
+ AddPrivilege(Privilege("TOPIC", _("Allowed to change channel topics")));
+ AddPrivilege(Privilege("MODE", _("Allowed to change channel modes")));
+ AddPrivilege(Privilege("GETKEY", _("Allowed to use GETKEY command")));
+ AddPrivilege(Privilege("INVITE", _("Allowed to use the INVITE command")));
+ AddPrivilege(Privilege("UNBAN", _("Allowed to unban users")));
+ AddPrivilege(Privilege("AUTOOP", _("Automatic channel operator status")));
+ AddPrivilege(Privilege("AUTOOWNER", _("Automatic mode +q")));
+ AddPrivilege(Privilege("OPDEOPME", _("Allowed to (de)op him/herself")));
+ AddPrivilege(Privilege("OPDEOP", _("Allowed to (de)op users")));
+ AddPrivilege(Privilege("AUTOPROTECT", _("Automatic mode +a")));
+ AddPrivilege(Privilege("AKICK", _("Allowed to use AKICK command")));
+ AddPrivilege(Privilege("BADWORDS", _("Allowed to modify channel badwords list")));
+ AddPrivilege(Privilege("ASSIGN", _("Allowed to assign/unassign a bot")));
+ AddPrivilege(Privilege("MEMO", _("Allowed to read channel memos")));
+ AddPrivilege(Privilege("ACCESS_CHANGE", _("Allowed to modify the access list")));
+ AddPrivilege(Privilege("PROTECTME", _("Allowed to (de)protect him/herself")));
+}
+
+std::vector<Privilege> &PrivilegeManager::GetPrivileges()
+{
+ return privs;
+}
+
AccessProvider::AccessProvider(Module *o, const Anope::string &n) : Service<AccessProvider>(o, n)
{
}
@@ -37,26 +115,29 @@ ChanAccess::~ChanAccess()
bool ChanAccess::operator>(ChanAccess &other)
{
- for (size_t i = CA_SIZE; i > 0; --i)
- if (this->HasPriv(static_cast<ChannelAccess>(i - 1)) && !other.HasPriv(static_cast<ChannelAccess>(i - 1)))
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ if (this->HasPriv(privs[i - 1].name) && !other.HasPriv(privs[i - 1].name))
return true;
return false;
}
bool ChanAccess::operator<(ChanAccess &other)
{
- for (size_t i = CA_SIZE; i > 0; --i)
- if (!this->HasPriv(static_cast<ChannelAccess>(i - 1)) && other.HasPriv(static_cast<ChannelAccess>(i - 1)))
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ if (!this->HasPriv(privs[i - 1].name) && other.HasPriv(privs[i - 1].name))
return true;
return false;
}
bool ChanAccess::operator>=(ChanAccess &other)
{
- for (size_t i = CA_SIZE; i > 0; --i)
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
{
- bool this_p = this->HasPriv(static_cast<ChannelAccess>(i - 1)),
- other_p = other.HasPriv(static_cast<ChannelAccess>(i - 1));
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
if ((this_p && !other_p) || (this_p && other_p))
return true;
@@ -67,10 +148,11 @@ bool ChanAccess::operator>=(ChanAccess &other)
bool ChanAccess::operator<=(ChanAccess &other)
{
- for (size_t i = CA_SIZE; i > 0; --i)
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
{
- bool this_p = this->HasPriv(static_cast<ChannelAccess>(i - 1)),
- other_p = other.HasPriv(static_cast<ChannelAccess>(i - 1));
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
if ((!this_p && other_p) || (this_p && other_p))
return true;
@@ -86,23 +168,23 @@ AccessGroup::AccessGroup() : std::vector<ChanAccess *>()
this->SuperAdmin = this->Founder = false;
}
-bool AccessGroup::HasPriv(ChannelAccess priv) const
+bool AccessGroup::HasPriv(const Anope::string &name) const
{
if (this->SuperAdmin)
return true;
- else if (ci->levels[priv] == ACCESS_INVALID)
+ else if (ci->GetLevel(name) == ACCESS_INVALID)
return false;
else if (this->Founder)
return true;
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnGroupCheckPriv, OnGroupCheckPriv(this, priv));
+ FOREACH_RESULT(I_OnGroupCheckPriv, OnGroupCheckPriv(this, name));
if (MOD_RESULT != EVENT_CONTINUE)
return MOD_RESULT == EVENT_ALLOW;
for (unsigned i = this->size(); i > 0; --i)
{
ChanAccess *access = this->at(i - 1);
- FOREACH_RESULT(I_OnCheckPriv, OnCheckPriv(access, priv));
- if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(priv))
+ FOREACH_RESULT(I_OnCheckPriv, OnCheckPriv(access, name));
+ if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name))
return true;
}
return false;
@@ -110,9 +192,10 @@ bool AccessGroup::HasPriv(ChannelAccess priv) const
ChanAccess *AccessGroup::Highest() const
{
- for (size_t i = CA_SIZE; i > 0; --i)
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
for (unsigned j = this->size(); j > 0; --j)
- if (this->at(j - 1)->HasPriv(static_cast<ChannelAccess>(i - 1)))
+ if (this->at(j - 1)->HasPriv(privs[ - 1].name))
return this->at(j - 1);
return NULL;
}
@@ -127,8 +210,9 @@ bool AccessGroup::operator>(const AccessGroup &other) const
return true;
else if (!this->Founder && other.Founder)
return false;
- for (size_t i = CA_SIZE; i > 0; --i)
- if (this->HasPriv(static_cast<ChannelAccess>(i - 1)) && !other.HasPriv(static_cast<ChannelAccess>(i - 1)))
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ if (this->HasPriv(privs[i - 1].name) && !other.HasPriv(privs[i - 1].name))
return true;
return false;
}
@@ -143,8 +227,9 @@ bool AccessGroup::operator<(const AccessGroup &other) const
return true;
else if (this->Founder && !other.Founder)
return false;
- for (size_t i = CA_SIZE; i > 0; --i)
- if (!this->HasPriv(static_cast<ChannelAccess>(i - 1)) && other.HasPriv(static_cast<ChannelAccess>(i - 1)))
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ if (!this->HasPriv(privs[i - 1].name) && other.HasPriv(privs[i - 1].name))
return true;
return false;
}
@@ -159,10 +244,11 @@ bool AccessGroup::operator>=(const AccessGroup &other) const
return true;
else if (other.Founder)
return false;
- for (size_t i = CA_SIZE; i > 0; --i)
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
{
- bool this_p = this->HasPriv(static_cast<ChannelAccess>(i - 1)),
- other_p = other.HasPriv(static_cast<ChannelAccess>(i - 1));
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
if ((this_p && !other_p) || (this_p && other_p))
return true;
@@ -181,10 +267,11 @@ bool AccessGroup::operator<=(const AccessGroup &other) const
return true;
else if (this->Founder)
return false;
- for (size_t i = CA_SIZE; i > 0; --i)
+ const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
{
- bool this_p = this->HasPriv(static_cast<ChannelAccess>(i - 1)),
- other_p = other.HasPriv(static_cast<ChannelAccess>(i - 1));
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
if ((!this_p && other_p) || (this_p && other_p))
return true;
diff --git a/src/botserv.cpp b/src/botserv.cpp
index 1670283be..c388b8a94 100644
--- a/src/botserv.cpp
+++ b/src/botserv.cpp
@@ -71,7 +71,7 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, User *u, const Anope::string
ci->c->SetMode(NULL, CMODE_BAN, mask);
/* Check if we need to do a signkick or not -GD */
- if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv(CA_SIGNKICK)))
+ if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv("SIGNKICK")))
ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str());
else
ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str());
@@ -100,7 +100,7 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, User *u, const Anope::string
if (ci->HasFlag(CI_PEACE) && requester != u && u_access >= req_access)
return;
- if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv(CA_SIGNKICK)))
+ if (ci->HasFlag(CI_SIGNKICK) || (ci->HasFlag(CI_SIGNKICK_LEVEL) && !req_access.HasPriv("SIGNKICK")))
ci->c->Kick(ci->bi, u, "%s (%s)", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str(), requester->nick.c_str());
else
ci->c->Kick(ci->bi, u, "%s", !reason.empty() ? reason.c_str() : ci->bi->nick.c_str());
diff --git a/src/channels.cpp b/src/channels.cpp
index 52b0b86c5..1778b9f01 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -1091,31 +1091,31 @@ void chan_set_correct_modes(User *user, Channel *c, int give_modes)
if (give_modes && (!user->Account() || user->Account()->HasFlag(NI_AUTOOP)))
{
- if (owner && u_access.HasPriv(CA_AUTOOWNER))
+ if (owner && u_access.HasPriv("AUTOOWNER"))
c->SetMode(NULL, CMODE_OWNER, user->nick);
- else if (admin && u_access.HasPriv(CA_AUTOPROTECT))
+ else if (admin && u_access.HasPriv("AUTOPROTECT"))
c->SetMode(NULL, CMODE_PROTECT, user->nick);
- if (op && u_access.HasPriv(CA_AUTOOP))
+ if (op && u_access.HasPriv("AUTOOP"))
c->SetMode(NULL, CMODE_OP, user->nick);
- else if (halfop && u_access.HasPriv(CA_AUTOHALFOP))
+ else if (halfop && u_access.HasPriv("AUTOHALFOP"))
c->SetMode(NULL, CMODE_HALFOP, user->nick);
- else if (voice && u_access.HasPriv(CA_AUTOVOICE))
+ else if (voice && u_access.HasPriv("AUTOVOICE"))
c->SetMode(NULL, CMODE_VOICE, user->nick);
}
/* If this channel has secureops or the channel is syncing and they are not ulined, check to remove modes */
if ((ci->HasFlag(CI_SECUREOPS) || (c->HasFlag(CH_SYNCING) && user->server->IsSynced())) && !user->server->IsULined())
{
- if (owner && !u_access.HasPriv(CA_AUTOOWNER) && !u_access.HasPriv(CA_OWNERME))
+ if (owner && !u_access.HasPriv("AUTOOWNER") && !u_access.HasPriv("OWNERME"))
c->RemoveMode(NULL, CMODE_OWNER, user->nick);
- if (admin && !u_access.HasPriv(CA_AUTOPROTECT) && !u_access.HasPriv(CA_PROTECTME))
+ if (admin && !u_access.HasPriv("AUTOPROTECT") && !u_access.HasPriv("PROTECTME"))
c->RemoveMode(NULL, CMODE_PROTECT, user->nick);
- if (op && c->HasUserStatus(user, CMODE_OP) && !u_access.HasPriv(CA_AUTOOP) && !u_access.HasPriv(CA_OPDEOPME))
+ if (op && c->HasUserStatus(user, CMODE_OP) && !u_access.HasPriv("AUTOOP") && !u_access.HasPriv("OPDEOPME"))
c->RemoveMode(NULL, CMODE_OP, user->nick);
- if (halfop && !u_access.HasPriv(CA_AUTOHALFOP) && !u_access.HasPriv(CA_HALFOPME))
+ if (halfop && !u_access.HasPriv("AUTOHALFOP") && !u_access.HasPriv("HALFOPME"))
c->RemoveMode(NULL, CMODE_HALFOP, user->nick);
}
diff --git a/src/init.cpp b/src/init.cpp
index 4cff3fc91..76ba350bb 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -355,6 +355,7 @@ void Init(int ac, char **av)
/* Initialize the socket engine */
SocketEngine::Init();
+ PrivilegeManager::Init();
/* Create me */
Me = new Server(NULL, Config->ServerName, 0, Config->ServerDesc, Config->Numeric);
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 882649d54..7eceb5942 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -49,9 +49,6 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, C
this->memos.memomax = Config->MSMaxMemos;
this->last_used = this->time_registered = Anope::CurTime;
- for (int i = 0; i < CA_SIZE; ++i)
- this->levels[i] = 0;
-
for (int i = 0; i < TTB_SIZE; ++i)
this->ttb[i] = 0;
@@ -781,3 +778,28 @@ void ChannelInfo::RestoreTopic()
}
}
+int16 ChannelInfo::GetLevel(const Anope::string &priv)
+{
+ if (PrivilegeManager::FindPrivilege(priv) == NULL)
+ throw CoreException("Unknown privilege " + priv);
+
+ if (this->levels.count(priv) == 0)
+ this->levels[priv] = 0;
+ return this->levels[priv];
+}
+
+void ChannelInfo::SetLevel(const Anope::string &priv, int16 level)
+{
+ this->levels[priv] = level;
+}
+
+void ChannelInfo::RemoveLevel(const Anope::string &priv)
+{
+ this->levels.erase(priv);
+}
+
+void ChannelInfo::ClearLevels()
+{
+ this->levels.clear();
+}
+