anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
opertype.cpp (3501B)
1 /* 2 * 3 * (C) 2008-2011 Robin Burchell <w00t@inspircd.org> 4 * (C) 2008-2022 Anope Team <team@anope.org> 5 * 6 * Please read COPYING and README for further details. 7 */ 8 9 #include "services.h" 10 #include "anope.h" 11 #include "opertype.h" 12 #include "config.h" 13 14 std::vector<Oper *> Oper::opers; 15 16 Oper::Oper(const Anope::string &n, OperType *o) : name(n), ot(o), require_oper(true) 17 { 18 opers.push_back(this); 19 } 20 21 Oper::~Oper() 22 { 23 std::vector<Oper *>::iterator it = std::find(opers.begin(), opers.end(), this); 24 if (it != opers.end()) 25 opers.erase(it); 26 } 27 28 Oper *Oper::Find(const Anope::string &name) 29 { 30 for (unsigned i = 0; i < opers.size(); ++i) 31 { 32 Oper *o = opers[i]; 33 34 if (o->name.equals_ci(name)) 35 return o; 36 } 37 38 return NULL; 39 } 40 41 OperType *OperType::Find(const Anope::string &name) 42 { 43 for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i) 44 { 45 OperType *ot = Config->MyOperTypes[i]; 46 47 if (ot->GetName() == name) 48 return ot; 49 } 50 51 return NULL; 52 } 53 54 OperType::OperType(const Anope::string &nname) : name(nname) 55 { 56 } 57 58 bool OperType::HasCommand(const Anope::string &cmdstr) const 59 { 60 for (std::list<Anope::string>::const_iterator it = this->commands.begin(), it_end = this->commands.end(); it != it_end; ++it) 61 { 62 const Anope::string &s = *it; 63 64 if (!s.find('~') && Anope::Match(cmdstr, s.substr(1))) 65 return false; 66 else if (Anope::Match(cmdstr, s)) 67 return true; 68 } 69 for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit) 70 { 71 OperType *ot = *iit; 72 73 if (ot->HasCommand(cmdstr)) 74 return true; 75 } 76 77 return false; 78 } 79 80 bool OperType::HasPriv(const Anope::string &privstr) const 81 { 82 for (std::list<Anope::string>::const_iterator it = this->privs.begin(), it_end = this->privs.end(); it != it_end; ++it) 83 { 84 const Anope::string &s = *it; 85 86 if (!s.find('~') && Anope::Match(privstr, s.substr(1))) 87 return false; 88 else if (Anope::Match(privstr, s)) 89 return true; 90 } 91 for (std::set<OperType *>::const_iterator iit = this->inheritances.begin(), iit_end = this->inheritances.end(); iit != iit_end; ++iit) 92 { 93 OperType *ot = *iit; 94 95 if (ot->HasPriv(privstr)) 96 return true; 97 } 98 99 return false; 100 } 101 102 void OperType::AddCommand(const Anope::string &cmdstr) 103 { 104 this->commands.push_back(cmdstr); 105 } 106 107 void OperType::AddPriv(const Anope::string &privstr) 108 { 109 this->privs.push_back(privstr); 110 } 111 112 const Anope::string &OperType::GetName() const 113 { 114 return this->name; 115 } 116 117 void OperType::Inherits(OperType *ot) 118 { 119 if (ot != this) 120 this->inheritances.insert(ot); 121 } 122 123 const std::list<Anope::string> OperType::GetCommands() const 124 { 125 std::list<Anope::string> cmd_list = this->commands; 126 for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it) 127 { 128 OperType *ot = *it; 129 std::list<Anope::string> cmds = ot->GetCommands(); 130 for (std::list<Anope::string>::const_iterator it2 = cmds.begin(), it2_end = cmds.end(); it2 != it2_end; ++it2) 131 cmd_list.push_back(*it2); 132 } 133 return cmd_list; 134 } 135 136 const std::list<Anope::string> OperType::GetPrivs() const 137 { 138 std::list<Anope::string> priv_list = this->privs; 139 for (std::set<OperType *>::const_iterator it = this->inheritances.begin(), it_end = this->inheritances.end(); it != it_end; ++it) 140 { 141 OperType *ot = *it; 142 std::list<Anope::string> priv = ot->GetPrivs(); 143 for (std::list<Anope::string>::const_iterator it2 = priv.begin(), it2_end = priv.end(); it2 != it2_end; ++it2) 144 priv_list.push_back(*it2); 145 } 146 return priv_list; 147 }