/* * OS_swhois * * * Many thanks to the anope team. This code is based heavily on the os_info * module's code. * * Update the SWhois entry if your ircd supoprts it. * Syntax: * /os swhois ADD * --or-- * /os swhois CLEAR * * There are no extra configuration options for this module. * * Add the following to your services config file (operserv.conf normally) module { name = "os_swhois"; } command { service ="OperServ"; name="SWHOIS"; command="operserv/swhois"; permission = "operserv/swhois"; } */ #include "module.h" struct SWhoisMsg : Serializable { Anope::string nick; Anope::string swhois; Anope::string creator; time_t when; SWhoisMsg() : Serializable("SWhoisMsg"), when(0) { } SWhoisMsg(const Anope::string &un, const Anope::string &sw, const Anope::string &c, time_t w) : Serializable("SWhoisMsg"), nick(un), swhois(sw), creator(c), when(w) { } ~SWhoisMsg(); void Serialize(Serialize::Data &data) const anope_override { data["nick"] << nick; data["swhois"] << swhois; data["creator"] << creator; data["when"] << when; } static Serializable *Unserialize(Serializable *obj, Serialize::Data &data); }; struct SWhoisMsgs : Serialize::Checker > { SWhoisMsgs(Extensible *) : Serialize::Checker >("SWhoisMsg") { } ~SWhoisMsgs() { for (unsigned i = (*this)->size(); i > 0; --i) delete (*this)->at(i - 1); } static Extensible *Find(const Anope::string &nick) { NickAlias *na = NickAlias::Find(nick); if (na) return na->nc; return NULL; } }; SWhoisMsg::~SWhoisMsg() { Extensible *e = SWhoisMsgs::Find(nick); if (e) { SWhoisMsgs *op = e->GetExt("swhoismsg"); if (op) { std::vector::iterator it = std::find((*op)->begin(), (*op)->end(), this); if (it != (*op)->end()) (*op)->erase(it); } } } Serializable *SWhoisMsg::Unserialize(Serializable *obj, Serialize::Data &data) { Anope::string snick; data["nick"] >> snick; Extensible *e = SWhoisMsgs::Find(snick); if (!e) return NULL; SWhoisMsgs *oi = e->Require("swhoismsg"); SWhoisMsg *o; if (obj) o = anope_dynamic_static_cast(obj); else { o = new SWhoisMsg(); o->nick = snick; } data["swhois"] >> o->swhois; data["creator"] >> o->creator; data["when"] >> o->when; if (!obj) (*oi)->push_back(o); return o; } class CommandSWhois : public Command { public: CommandSWhois(Module *creator) : Command(creator, "operserv/swhois",2,3) { this->SetDesc(_("Modify the Swhois value for a nick")); this->SetSyntax(_("\037nick\037 ADD \037swhois message\037")); this->SetSyntax(_("\037nick\037 CLEAR")); } void Execute(CommandSource &source, const std::vector ¶ms) anope_override { const Anope::string &unick = params[0]; const Anope::string &subcmd = params[1]; const Anope::string &message = params.size() > 2 ? params[2] : ""; Extensible *e; NickAlias *na = NickAlias::Find(unick); if (!na) { source.Reply(NICK_X_NOT_REGISTERED, unick.c_str()); return; } e = na->nc; if (subcmd.equals_ci("add")) { if (message.empty()) { this->OnSyntaxError(source, subcmd); return; } SWhoisMsgs *oi = e->Require("swhoismsg"); (*oi)->push_back(new SWhoisMsg(unick, message, source.GetNick(), Anope::CurTime)); source.Reply(_("Added Swhois to \002%s\002."), unick.c_str()); Log(LOG_ADMIN, source, this) << "to add SWHOIS info to " << unick; if (User::Find(unick)) { IRCD->SendSWhois(Config->GetClient("OperServ"),unick,message); } if (Anope::ReadOnly) source.Reply(READ_ONLY_MODE); } else if (subcmd.equals_ci("clear")) { SWhoisMsgs *oi = e->Require("swhoismsg"); if (!oi) { return; } e->Shrink("swhoismsg"); source.Reply(_("Cleared SWhois info for \002%s\002."), unick.c_str()); Log(LOG_ADMIN, source, this) << "to clear SWHOIS info on " << unick; if (User::Find(unick)) { IRCD->SendSWhois(Config->GetClient("OperServ"),unick,""); } if (Anope::ReadOnly) source.Reply(READ_ONLY_MODE); } else { this->SendSyntax(source); return; } } bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override { this->SendSyntax(source); source.Reply(" "); source.Reply(_("Allows you to assign or remove the supplimental \n" "whois (called swhois) for a nick.")); source.Reply(" "); return true; } }; class OSSWhois : public Module { CommandSWhois commandswhois; ExtensibleItem eml; Serialize::Type swhoismsg_type; void OnSwhois(User *u) { Extensible *e = SWhoisMsgs::Find(u->nick); if(!e) { return; } SWhoisMsgs *oi = eml.Get(e); if (!oi) return; for (unsigned i = 0; i < (*oi)->size(); ++i) { SWhoisMsg *o = (*oi)->at(i); //SendSWhois(const MessageSource &source, const Anope::string &who, const Anope::string &mask IRCD->SendSWhois(Config->GetClient("OperServ"),o->nick,o->swhois); } } public: OSSWhois(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA), commandswhois(this), eml(this, "swhoismsg"), swhoismsg_type("SWhoisMsg", SWhoisMsg::Unserialize) { this->SetAuthor("Azander"); this->SetVersion("1.0.1"); } void OnUserLogin(User *u) anope_override { OnSwhois(u); } }; MODULE_INIT(OSSWhois)