00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "module.h"
00015
00016 struct MyOper : Oper, Serializable
00017 {
00018 MyOper(const Anope::string &n, OperType *o) : Oper(n, o), Serializable("Oper") { }
00019
00020 void Serialize(Serialize::Data &data) const anope_override
00021 {
00022 data["name"] << this->name;
00023 data["type"] << this->ot->GetName();
00024 }
00025
00026 static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
00027 {
00028 Anope::string stype, sname;
00029
00030 data["type"] >> stype;
00031 data["name"] >> sname;
00032
00033 OperType *ot = OperType::Find(stype);
00034 if (ot == NULL)
00035 return NULL;
00036 NickCore *nc = NickCore::Find(sname);
00037 if (nc == NULL)
00038 return NULL;
00039
00040 MyOper *myo;
00041 if (obj)
00042 myo = anope_dynamic_static_cast<MyOper *>(obj);
00043 else
00044 myo = new MyOper(nc->display, ot);
00045 nc->o = myo;
00046 Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName();
00047 return myo;
00048 }
00049 };
00050
00051 class CommandOSOper : public Command
00052 {
00053 public:
00054 CommandOSOper(Module *creator) : Command(creator, "operserv/oper", 1, 3)
00055 {
00056 this->SetDesc(_("View and change Services Operators"));
00057 this->SetSyntax(_("ADD \037oper\037 \037type\037"));
00058 this->SetSyntax(_("DEL \037oper\037"));
00059 this->SetSyntax(_("INFO \037type\037"));
00060 this->SetSyntax(_("LIST"));
00061 }
00062
00063 void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override
00064 {
00065 const Anope::string &subcommand = params[0];
00066
00067 if (subcommand.equals_ci("ADD") && params.size() > 2)
00068 {
00069 const Anope::string &oper = params[1];
00070 const Anope::string &otype = params[2];
00071
00072 const NickAlias *na = NickAlias::Find(oper);
00073 if (na == NULL)
00074 source.Reply(NICK_X_NOT_REGISTERED, oper.c_str());
00075 else if (na->nc->o)
00076 source.Reply(_("Nick \002%s\002 is already an operator."), na->nick.c_str());
00077 else
00078 {
00079 OperType *ot = OperType::Find(otype);
00080 if (ot == NULL)
00081 source.Reply(_("Oper type \002%s\002 has not been configured."), otype.c_str());
00082 else
00083 {
00084 na->nc->o = new MyOper(na->nc->display, ot);
00085
00086 Log(LOG_ADMIN, source, this) << "ADD " << na->nick << " as type " << ot->GetName();
00087 source.Reply("%s (%s) added to the \002%s\002 list.", na->nick.c_str(), na->nc->display.c_str(), ot->GetName().c_str());
00088 }
00089 }
00090 }
00091 else if (subcommand.equals_ci("DEL") && params.size() > 1)
00092 {
00093 const Anope::string &oper = params[1];
00094
00095 const NickAlias *na = NickAlias::Find(oper);
00096 if (na == NULL)
00097 source.Reply(NICK_X_NOT_REGISTERED, oper.c_str());
00098 else if (!na->nc || !na->nc->o)
00099 source.Reply(_("Nick \002%s\002 is not a Services Operator."), oper.c_str());
00100 else
00101 {
00102 delete na->nc->o;
00103 na->nc->o = NULL;
00104
00105 Log(LOG_ADMIN, source, this) << "DEL " << na->nick;
00106 source.Reply(_("Oper privileges removed from %s (%s)."), na->nick.c_str(), na->nc->display.c_str());
00107 }
00108 }
00109 else if (subcommand.equals_ci("LIST"))
00110 {
00111 source.Reply(_("Name Type"));
00112 for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
00113 {
00114 const NickCore *nc = it->second;
00115
00116 if (!nc->o)
00117 continue;
00118
00119 source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str());
00120 if (nc->o->config)
00121 source.Reply(_(" This oper is configured in the configuration file."));
00122 for (std::list<User *>::const_iterator uit = nc->users.begin(); uit != nc->users.end(); ++uit)
00123 {
00124 User *u = *uit;
00125 source.Reply(_(" %s is online using this oper block."), u->nick.c_str());
00126 }
00127 }
00128 }
00129 else if (subcommand.equals_ci("INFO") && params.size() > 1)
00130 {
00131 Anope::string fulltype = params[1];
00132 if (params.size() > 2)
00133 fulltype += " " + params[2];
00134 OperType *ot = OperType::Find(fulltype);
00135 if (ot == NULL)
00136 source.Reply(_("Oper type \002%s\002 has not been configured."), fulltype.c_str());
00137 else
00138 {
00139 if (ot->GetCommands().empty())
00140 source.Reply(_("Opertype \002%s\002 has no allowed commands."), ot->GetName().c_str());
00141 else
00142 {
00143 source.Reply(_("Available commands for \002%s\002:"), ot->GetName().c_str());
00144 Anope::string buf;
00145 std::list<Anope::string> cmds = ot->GetCommands();
00146 for (std::list<Anope::string>::const_iterator it = cmds.begin(), it_end = cmds.end(); it != it_end; ++it)
00147 {
00148 buf += *it + " ";
00149 if (buf.length() > 400)
00150 {
00151 source.Reply("%s", buf.c_str());
00152 buf.clear();
00153 }
00154 }
00155 if (!buf.empty())
00156 {
00157 source.Reply("%s", buf.c_str());
00158 buf.clear();
00159 }
00160 }
00161 if (ot->GetPrivs().empty())
00162 source.Reply(_("Opertype \002%s\002 has no allowed privileges."), ot->GetName().c_str());
00163 else
00164 {
00165 source.Reply(_("Available privileges for \002%s\002:"), ot->GetName().c_str());
00166 Anope::string buf;
00167 std::list<Anope::string> privs = ot->GetPrivs();
00168 for (std::list<Anope::string>::const_iterator it = privs.begin(), it_end = privs.end(); it != it_end; ++it)
00169 {
00170 buf += *it + " ";
00171 if (buf.length() > 400)
00172 {
00173 source.Reply("%s", buf.c_str());
00174 buf.clear();
00175 }
00176 }
00177 if (!buf.empty())
00178 {
00179 source.Reply("%s", buf.c_str());
00180 buf.clear();
00181 }
00182 }
00183 if (!ot->modes.empty())
00184 source.Reply(_("Opertype \002%s\002 receives modes \002%s\002 once identified."), ot->GetName().c_str(), ot->modes.c_str());
00185 }
00186 }
00187 else
00188 this->OnSyntaxError(source, subcommand);
00189
00190 return;
00191 }
00192
00193 bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
00194 {
00195 this->SendSyntax(source);
00196 source.Reply(" ");
00197 source.Reply(_("Allows you to change and view Services Operators.\n"
00198 "Note that operators removed by this command but are still set in\n"
00199 "the configuration file are not permanently affected by this."));
00200 return true;
00201 }
00202 };
00203
00204 class OSOper : public Module
00205 {
00206 Serialize::Type myoper_type;
00207 CommandOSOper commandosoper;
00208
00209 public:
00210 OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
00211 myoper_type("Oper", MyOper::Unserialize), commandosoper(this)
00212 {
00213 this->SetAuthor("Anope");
00214 }
00215
00216 ~OSOper()
00217 {
00218 for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
00219 {
00220 const NickCore *nc = it->second;
00221
00222 if (nc->o && !nc->o->config)
00223 delete nc->o;
00224 }
00225 }
00226 };
00227
00228 MODULE_INIT(OSOper)