Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "services.h"
00011 #include "anope.h"
00012 #include "opertype.h"
00013 #include "config.h"
00014
00015 Oper *Oper::Find(const Anope::string &name)
00016 {
00017 for (unsigned i = 0; i < Config->Opers.size(); ++i)
00018 {
00019 Oper *o = Config->Opers[i];
00020
00021 if (o->name.equals_ci(name))
00022 return o;
00023 }
00024
00025 return NULL;
00026 }
00027
00028 OperType *OperType::Find(const Anope::string &name)
00029 {
00030 for (std::list<OperType *>::iterator it = Config->MyOperTypes.begin(), it_end = Config->MyOperTypes.end(); it != it_end; ++it)
00031 {
00032 OperType *ot = *it;
00033
00034 if (ot->GetName() == name)
00035 return ot;
00036 }
00037
00038 return NULL;
00039 }
00040
00041 OperType::OperType(const Anope::string &nname) : name(nname)
00042 {
00043 }
00044
00045 bool OperType::HasCommand(const Anope::string &cmdstr) const
00046 {
00047 for (std::list<Anope::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it)
00048 {
00049 if (Anope::Match(cmdstr, *it))
00050 return true;
00051 }
00052 for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit)
00053 {
00054 OperType *ot = *iit;
00055
00056 if (ot->HasCommand(cmdstr))
00057 return true;
00058 }
00059
00060 return false;
00061 }
00062
00063 bool OperType::HasPriv(const Anope::string &privstr) const
00064 {
00065 for (std::list<Anope::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it)
00066 {
00067 if (Anope::Match(privstr, *it))
00068 return true;
00069 }
00070 for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit)
00071 {
00072 OperType *ot = *iit;
00073
00074 if (ot->HasPriv(privstr))
00075 return true;
00076 }
00077
00078 return false;
00079 }
00080
00081 void OperType::AddCommand(const Anope::string &cmdstr)
00082 {
00083 this->commands.push_back(cmdstr);
00084 }
00085
00086 void OperType::AddPriv(const Anope::string &privstr)
00087 {
00088 this->privs.push_back(privstr);
00089 }
00090
00091 const Anope::string &OperType::GetName() const
00092 {
00093 return this->name;
00094 }
00095
00096 void OperType::Inherits(OperType *ot)
00097 {
00098 this->inheritances.insert(ot);
00099 }
00100
00101 const std::list<Anope::string> OperType::GetCommands() const
00102 {
00103 std::list<Anope::string> cmd_list = this->commands;
00104 for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it)
00105 {
00106 OperType *ot = *it;
00107 std::list<Anope::string> cmds = ot->GetPrivs();
00108 for (std::list<Anope::string>::const_iterator it2 = cmds.begin(), it2_end = cmds.end(); it2 != it2_end; ++it2)
00109 cmd_list.push_back(*it2);
00110 }
00111 return cmd_list;
00112 }
00113
00114 const std::list<Anope::string> OperType::GetPrivs() const
00115 {
00116 std::list<Anope::string> priv_list = this->privs;
00117 for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it)
00118 {
00119 OperType *ot = *it;
00120 std::list<Anope::string> priv = ot->GetPrivs();
00121 for (std::list<Anope::string>::const_iterator it2 = priv.begin(), it2_end = priv.end(); it2 != it2_end; ++it2)
00122 priv_list.push_back(*it2);
00123 }
00124 return priv_list;
00125 }
00126