summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@drink-coca-cola.info>2010-05-07 15:29:41 -0400
committerAdam <Adam@anope.org>2010-06-18 20:58:55 -0400
commitebfff71599fbedb72009d71cd40c264713b43b5a (patch)
treedd687cc4fd7e77866c91fc7f48646762dee3983d /src
parent9439cac6b126254bc488c2375b9e7ff5fd4fce74 (diff)
Made opertypes inheritable
Diffstat (limited to 'src')
-rw-r--r--src/config.c28
-rw-r--r--src/opertype.cpp27
2 files changed, 48 insertions, 7 deletions
diff --git a/src/config.c b/src/config.c
index 9c486b7e3..82a2fcac6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -425,8 +425,9 @@ static bool InitOperTypes(ServerConfig *, const char *, bool)
static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueList &values, int *, bool)
{
const char *name = values[0].GetString();
- const char *commands = values[1].GetString();
- const char *privs = values[2].GetString();
+ const char *inherits = values[1].GetString();
+ const char *commands = values[2].GetString();
+ const char *privs = values[3].GetString();
ValueItem vi(name);
if (!ValidateNotEmpty(conf, "opertype", "name", vi))
@@ -442,6 +443,23 @@ static bool DoOperType(ServerConfig *conf, const char *, const char **, ValueLis
spacesepstream privstr(privs);
while (privstr.GetToken(tok))
ot->AddPriv(tok);
+
+ commasepstream inheritstr(inherits);
+ while (inheritstr.GetToken(tok))
+ {
+ /* Strip leading ' ' after , */
+ if (tok.size() > 1 && tok[0] == ' ')
+ tok.erase(tok.begin());
+ for (std::list<OperType *>::iterator it = Config.MyOperTypes.begin(); it != Config.MyOperTypes.end(); ++it)
+ {
+ if ((*it)->GetName() == tok)
+ {
+ Alog() << "Inheriting commands and privs from " << (*it)->GetName() << " to " << ot->GetName();
+ ot->Inherits(*it);
+ break;
+ }
+ }
+ }
Config.MyOperTypes.push_back(ot);
return true;
@@ -772,9 +790,9 @@ int ServerConfig::Read(bool bail)
{DT_CHARPTR},
InitModules, DoModule, DoneModules},
{"opertype",
- {"name", "commands", "privs", NULL},
- {"", "", "", NULL},
- {DT_CHARPTR, DT_CHARPTR, DT_CHARPTR},
+ {"name", "inherits", "commands", "privs", NULL},
+ {"", "", "", "", NULL},
+ {DT_CHARPTR, DT_CHARPTR, DT_CHARPTR, DT_CHARPTR},
InitOperTypes, DoOperType, DoneOperTypes},
{"oper",
{"name", "type", NULL},
diff --git a/src/opertype.cpp b/src/opertype.cpp
index fb0689add..0ee6d000f 100644
--- a/src/opertype.cpp
+++ b/src/opertype.cpp
@@ -16,26 +16,44 @@ OperType::OperType(const ci::string &nname) : name(nname)
bool OperType::HasCommand(const std::string &cmdstr) const
{
- for (std::list<std::string>::const_iterator it = this->commands.begin(); it != this->commands.end(); it++)
+ for (std::list<std::string>::const_iterator it = this->commands.begin(); it != this->commands.end(); ++it)
{
if (Anope::Match(cmdstr, *it))
{
return true;
}
}
+ for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(); iit != this->inheritances.end(); ++iit)
+ {
+ OperType *ot = *iit;
+
+ if (ot->HasCommand(cmdstr))
+ {
+ return true;
+ }
+ }
return false;
}
bool OperType::HasPriv(const std::string &privstr) const
{
- for (std::list<std::string>::const_iterator it = this->privs.begin(); it != this->privs.end(); it++)
+ for (std::list<std::string>::const_iterator it = this->privs.begin(); it != this->privs.end(); ++it)
{
if (Anope::Match(privstr, *it))
{
return true;
}
}
+ for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(); iit != this->inheritances.end(); ++iit)
+ {
+ OperType *ot = *iit;
+
+ if (ot->HasPriv(privstr))
+ {
+ return true;
+ }
+ }
return false;
}
@@ -55,3 +73,8 @@ const ci::string &OperType::GetName() const
return this->name;
}
+void OperType::Inherits(OperType *ot)
+{
+ this->inheritances.insert(ot);
+}
+