diff options
author | Adam <Adam@anope.org> | 2010-11-23 16:48:54 -0600 |
---|---|---|
committer | Adam <Adam@anope.org> | 2010-12-12 19:36:19 -0500 |
commit | 37e02a3594fdddc3d5a3df0501c528f42db6c4da (patch) | |
tree | 2b26a003def3b3ecdd7f46aa67d172a3b04a7369 /modules | |
parent | 7d1cfe9514062a451b480783fe8df6e63f2954ab (diff) |
Added cs_entrymsg
Diffstat (limited to 'modules')
-rw-r--r-- | modules/core/cs_info.cpp | 3 | ||||
-rw-r--r-- | modules/core/cs_set_entrymsg.cpp | 113 | ||||
-rw-r--r-- | modules/core/db_plain.cpp | 4 | ||||
-rw-r--r-- | modules/extra/cs_entrymsg.cpp | 215 | ||||
-rw-r--r-- | modules/extra/db_mysql.cpp | 11 | ||||
-rw-r--r-- | modules/protocol/plexus.cpp | 2 |
6 files changed, 219 insertions, 129 deletions
diff --git a/modules/core/cs_info.cpp b/modules/core/cs_info.cpp index 0df02ff43..bae7e118c 100644 --- a/modules/core/cs_info.cpp +++ b/modules/core/cs_info.cpp @@ -73,9 +73,6 @@ class CommandCSInfo : public Command u->SendMessage(ChanServ, CHAN_INFO_TOPIC_SET_BY, ci->last_topic_setter.c_str()); } - if (!ci->entry_message.empty() && show_all) - u->SendMessage(ChanServ, CHAN_INFO_ENTRYMSG, ci->entry_message.c_str()); - if (show_all) { u->SendMessage(ChanServ, CHAN_INFO_BANTYPE, ci->bantype); diff --git a/modules/core/cs_set_entrymsg.cpp b/modules/core/cs_set_entrymsg.cpp deleted file mode 100644 index 263e37d91..000000000 --- a/modules/core/cs_set_entrymsg.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* ChanServ core functions - * - * (C) 2003-2010 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - */ - -/*************************************************************************/ - -#include "module.h" - -class CommandCSSetEntryMsg : public Command -{ - public: - CommandCSSetEntryMsg(const Anope::string &cpermission = "") : Command("ENTRYMSG", 1, 2, cpermission) - { - } - - CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) - { - ChannelInfo *ci = cs_findchan(params[0]); - if (!ci) - throw CoreException("NULL ci in CommandCSSetEntryMsg"); - - if (params.size() > 1) - { - ci->entry_message = params[1]; - u->SendMessage(ChanServ, CHAN_ENTRY_MSG_CHANGED, ci->name.c_str(), ci->entry_message.c_str()); - } - else - { - ci->entry_message.clear(); - u->SendMessage(ChanServ, CHAN_ENTRY_MSG_UNSET, ci->name.c_str()); - } - - return MOD_CONT; - } - - bool OnHelp(User *u, const Anope::string &) - { - u->SendMessage(ChanServ, CHAN_HELP_SET_ENTRYMSG, "SET"); - return true; - } - - void OnSyntaxError(User *u, const Anope::string &) - { - // XXX - SyntaxError(ChanServ, u, "SET", CHAN_SET_SYNTAX); - } - - void OnServHelp(User *u) - { - u->SendMessage(ChanServ, CHAN_HELP_CMD_SET_ENTRYMSG); - } -}; - -class CommandCSSASetEntryMsg : public CommandCSSetEntryMsg -{ - public: - CommandCSSASetEntryMsg() : CommandCSSetEntryMsg("chanserv/saset/entrymsg") - { - } - - bool OnHelp(User *u, const Anope::string &) - { - u->SendMessage(ChanServ, CHAN_HELP_SET_ENTRYMSG, "SASET"); - return true; - } - - void OnSyntaxError(User *u, const Anope::string &) - { - // XXX - SyntaxError(ChanServ, u, "SASET", CHAN_SASET_SYNTAX); - } -}; - -class CSSetEntryMsg : public Module -{ - CommandCSSetEntryMsg commandcssetentrymsg; - CommandCSSASetEntryMsg commandcssasetentrymsg; - - public: - CSSetEntryMsg(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator) - { - this->SetAuthor("Anope"); - this->SetType(CORE); - - Command *c = FindCommand(ChanServ, "SET"); - if (c) - c->AddSubcommand(&commandcssetentrymsg); - - c = FindCommand(ChanServ, "SASET"); - if (c) - c->AddSubcommand(&commandcssasetentrymsg); - } - - ~CSSetEntryMsg() - { - Command *c = FindCommand(ChanServ, "SET"); - if (c) - c->DelSubcommand(&commandcssetentrymsg); - - c = FindCommand(ChanServ, "SASET"); - if (c) - c->DelSubcommand(&commandcssasetentrymsg); - } -}; - -MODULE_INIT(CSSetEntryMsg) diff --git a/modules/core/db_plain.cpp b/modules/core/db_plain.cpp index 3fa235710..953f35b4a 100644 --- a/modules/core/db_plain.cpp +++ b/modules/core/db_plain.cpp @@ -776,8 +776,6 @@ class DBPlain : public Module } else if (key.equals_ci("MIG")) ci->memos.ignores.push_back(params[0].ci_str()); - else if (key.equals_ci("ENTRYMSG")) - ci->entry_message = params[0]; else if (key.equals_ci("BI")) { if (params[0].equals_ci("NAME")) @@ -1061,8 +1059,6 @@ class DBPlain : public Module } for (unsigned k = 0, end = memos->ignores.size(); k < end; ++k) db << "MD MIG " << Anope::string(memos->ignores[k]) << endl; - if (!ci->entry_message.empty()) - db << "MD ENTRYMSG :" << ci->entry_message << endl; if (ci->bi) db << "MD BI NAME " << ci->bi->nick << endl; if (ci->botflags.FlagCount()) diff --git a/modules/extra/cs_entrymsg.cpp b/modules/extra/cs_entrymsg.cpp new file mode 100644 index 000000000..e2143f7d1 --- /dev/null +++ b/modules/extra/cs_entrymsg.cpp @@ -0,0 +1,215 @@ +/* ChanServ core functions + * + * (C) 2003-2010 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + * Based on the original code of Epona by Lara. + * Based on the original code of Services by Andy Church. + */ + +/*************************************************************************/ + +#include "module.h" + +struct EntryMsg +{ + static unsigned MaxEntries; + + EntryMsg(const Anope::string &cname, const Anope::string &cmessage, time_t ct = Anope::CurTime) + { + this->creator = cname; + this->message = cmessage; + this->when = ct; + } + + Anope::string creator; + Anope::string message; + time_t when; +}; +unsigned EntryMsg::MaxEntries = 0; + +class CommandEntryMessage : public Command +{ + private: + void DoList(User *u, ChannelInfo *ci) + { + std::vector<EntryMsg> messages; + if (ci->GetExtRegular("cs_entrymsg", messages)) + { + u->SendMessage(ChanServ, CHAN_ENTRYMSG_LIST_HEADER, ci->name.c_str()); + for (unsigned i = 0; i < messages.size(); ++i) + u->SendMessage(ChanServ, CHAN_ENTRYMSG_LIST_ENTRY, i + 1, messages[i].message.c_str(), messages[i].creator.c_str(), do_strftime(messages[i].when).c_str()); + u->SendMessage(ChanServ, CHAN_ENTRYMSG_LIST_END); + } + else + u->SendMessage(ChanServ, CHAN_ENTRYMSG_LIST_EMPTY, ci->name.c_str()); + } + + void DoAdd(User *u, ChannelInfo *ci, const Anope::string &message) + { + std::vector<EntryMsg> messages; + ci->GetExtRegular("cs_entrymsg", messages); + + if (EntryMsg::MaxEntries && messages.size() >= EntryMsg::MaxEntries) + u->SendMessage(ChanServ, CHAN_ENTRYMSG_LIST_FULL, ci->name.c_str()); + else + { + messages.push_back(EntryMsg(u->nick, message)); + ci->Extend("cs_entrymsg", new ExtensibleItemRegular<std::vector<EntryMsg> >(messages)); + u->SendMessage(ChanServ, CHAN_ENTRYMSG_ADDED, ci->name.c_str()); + } + } + + void DoDel(User *u, ChannelInfo *ci, const Anope::string &message) + { + std::vector<EntryMsg> messages; + if (!message.is_pos_number_only()) + u->SendMessage(ChanServ, CHAN_ENTRYMSG_NOT_FOUND, message.c_str(), ci->name.c_str()); + else if (ci->GetExtRegular("cs_entrymsg", messages)) + { + unsigned i = convertTo<unsigned>(message); + if (i > 0 && i <= messages.size()) + { + messages.erase(messages.begin() + i - 1); + ci->Extend("cs_entrymsg", new ExtensibleItemRegular<std::vector<EntryMsg> >(messages)); + u->SendMessage(ChanServ, CHAN_ENTRYMSG_DELETED, i, ci->name.c_str()); + } + else + u->SendMessage(ChanServ, CHAN_ENTRYMSG_NOT_FOUND, message.c_str(), ci->name.c_str()); + } + else + u->SendMessage(ChanServ, CHAN_ENTRYMSG_LIST_EMPTY, ci->name.c_str()); + } + + void DoClear(User *u, ChannelInfo *ci) + { + ci->Shrink("cs_entrymsg"); + u->SendMessage(ChanServ, CHAN_ENTRYMSG_CLEARED, ci->name.c_str()); + } + + public: + CommandEntryMessage(const Anope::string &cname) : Command(cname, 2, 3) + { + } + + CommandReturn Execute(User *u, const std::vector<Anope::string> ¶ms) + { + ChannelInfo *ci = cs_findchan(params[0]); + if (ci && (IsFounder(u, ci) || u->Account()->HasCommand("chanserv/entrymsg"))) + { + bool success = true; + if (params[1].equals_ci("LIST")) + this->DoList(u, ci); + else if (params[1].equals_ci("CLEAR")) + this->DoClear(u, ci); + else if (params.size() < 3) + { + success = false; + this->OnSyntaxError(u, ""); + } + else if (params[1].equals_ci("ADD")) + this->DoAdd(u, ci, params[2]); + else if (params[1].equals_ci("DEL")) + this->DoDel(u, ci, params[2]); + else + { + success = false; + this->OnSyntaxError(u, ""); + } + if (success) + Log(IsFounder(u, ci) ? LOG_COMMAND : LOG_OVERRIDE, u, this, ci) << params[1]; + } + else + { + u->SendMessage(ChanServ, ACCESS_DENIED); + } + + return MOD_CONT; + } + + void OnSyntaxError(User *u, const Anope::string &) + { + SyntaxError(ChanServ, u, "ENTRYMSG", CHAN_ENTRYMSG_SYNTAX); + } + + bool OnHelp(User *u, const Anope::string &subcommand) + { + u->SendMessage(ChanServ, CHAN_HELP_ENTRYMSG); + return true; + } + + void OnServHelp(User *u) + { + u->SendMessage(ChanServ, CHAN_HELP_CMD_ENTRYMSG); + } +}; + +class CSEntryMessage : public Module +{ + CommandEntryMessage commandentrymsg; + + public: + CSEntryMessage(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator), commandentrymsg("ENTRYMSG") + { + this->SetAuthor("Anope"); + this->SetType(CORE); + + Implementation i[] = { I_OnJoinChannel, I_OnReload, I_OnDatabaseReadMetadata, I_OnDatabaseWriteMetadata }; + ModuleManager::Attach(i, this, 4); + + this->AddCommand(ChanServ, &commandentrymsg); + + this->OnReload(false); + } + + void OnJoinChannel(User *u, Channel *c) + { + if (u && c && c->ci && u->server->IsSynced()) + { + std::vector<EntryMsg> messages; + + if (c->ci->GetExtRegular("cs_entrymsg", messages)) + for (unsigned i = 0; i < messages.size(); ++i) + this->SendMessage(whosends(c->ci), u, "[%s] %s", c->ci->name.c_str(), messages[i].message.c_str()); + } + } + + void OnReload(bool) + { + ConfigReader config; + EntryMsg::MaxEntries = config.ReadInteger("cs_entrymsg", "maxentries", "5", 0, true); + } + + EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, const std::vector<Anope::string> ¶ms) + { + if (key.find("CS_ENTRYMSG_") == 0 && params.size() > 2) + { + Anope::string creator = params[0]; + time_t t = params[1].is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; + Anope::string message = params[2]; + for (unsigned j = 3; j < params.size(); ++j) + message += " " + params[j]; + + std::vector<EntryMsg> messages; + ci->GetExtRegular("cs_entrymsg", messages); + messages.push_back(EntryMsg(creator, message, t)); + ci->Extend("cs_entrymsg", new ExtensibleItemRegular<std::vector<EntryMsg> >(messages)); + + return EVENT_STOP; + } + + return EVENT_CONTINUE; + } + + void OnDatabaseWriteMetadata(void (*WriteMetadata)(const Anope::string &, const Anope::string &), ChannelInfo *ci) + { + std::vector<EntryMsg> messages; + if (ci->GetExtRegular("cs_entrymsg", messages)) + for (unsigned i = 0; i < messages.size(); ++i) + WriteMetadata("CS_ENTRYMSG_" + stringify(i), messages[i].creator + " " + stringify(messages[i].when) + " " + messages[i].message); + } +}; + +MODULE_INIT(CSEntryMessage) diff --git a/modules/extra/db_mysql.cpp b/modules/extra/db_mysql.cpp index 8b90fa59e..bd1810f94 100644 --- a/modules/extra/db_mysql.cpp +++ b/modules/extra/db_mysql.cpp @@ -615,7 +615,6 @@ class DBMySQL : public Module ci->forbidby = r.Get(i, "forbidby"); ci->forbidreason = r.Get(i, "forbidreason"); ci->bantype = r.Get(i, "bantype").is_number_only() ? convertTo<int>(r.Get(i, "bantype")) : 2; - ci->entry_message = r.Get(i, "entry_message"); ci->memos.memomax = r.Get(i, "memomax").is_number_only() ? convertTo<int>(r.Get(i, "memomax")) : 20; ci->capsmin = r.Get(i, "capsmin").is_number_only() ? convertTo<int>(r.Get(i, "capsmin")) : 0; ci->capspercent = r.Get(i, "capspercent").is_number_only() ? convertTo<int>(r.Get(i, "capspercent")) : 0; @@ -1033,10 +1032,6 @@ class DBMySQL : public Module { this->RunQuery("UPDATE `anope_cs_info` SET `descr` = '" + this->Escape(ci->desc) + "' WHERE `name` = '" + this->Escape(ci->name) + "'"); } - else if (params[1].equals_ci("ENTRYMSG")) - { - this->RunQuery("UPDATE `anope_cs_info` SET `entry_message` = '" + this->Escape(ci->entry_message) + "' WHERE `name` = '" + this->Escape(ci->name) + "'"); - } else if (params[1].equals_ci("MLOCK")) { this->RunQuery("UPDATE `anope_cs_info` SET `mlock_on` = '" + GetMLockOn(ci) + "' WHERE `name` = '" + this->Escape(ci->name) + "'"); @@ -1261,16 +1256,16 @@ class DBMySQL : public Module void OnChanRegistered(ChannelInfo *ci) { Anope::string flags = BuildFlagsList(ci), mlockon = GetMLockOn(ci), mlockoff = GetMLockOff(ci), mlockparams = GetMLockParams(ci, true), mlockparams_off = GetMLockParams(ci, false); - this->RunQuery("INSERT INTO `anope_cs_info` (name, founder, successor, descr, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, mlock_on, mlock_off, mlock_params, mlock_params_off, entry_message, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES('" + + this->RunQuery("INSERT INTO `anope_cs_info` (name, founder, successor, descr, time_registered, last_used, last_topic, last_topic_setter, last_topic_time, flags, forbidby, forbidreason, bantype, mlock_on, mlock_off, mlock_params, mlock_params_off, memomax, botnick, botflags, capsmin, capspercent, floodlines, floodsecs, repeattimes) VALUES('" + this->Escape(ci->name) + "', '" + this->Escape(ci->founder ? ci->founder->display : "") + "', '" + this->Escape(ci->successor ? ci->successor->display : "") + "', '" + this->Escape(ci->desc) + "', " + stringify(ci->time_registered) + ", " + stringify(ci->last_used) + ", '" + this->Escape(ci->last_topic) + "', '" + this->Escape(ci->last_topic_setter) + "', " + stringify(ci->last_topic_time) + ", '" + flags + "', '" + this->Escape(ci->forbidby) + "', '" + this->Escape(ci->forbidreason) + "', " + stringify(ci->bantype) + ", '" + - mlockon + "', '" + mlockoff + "', '" + mlockparams + "', '" + mlockparams_off + "', '" + this->Escape(ci->entry_message) + "', " + + mlockon + "', '" + mlockoff + "', '" + mlockparams + "', '" + mlockparams_off + "', " + stringify(ci->memos.memomax) + ", '" + this->Escape(ci->bi ? ci->bi->nick : "") + "', '" + GetBotFlags(ci->botflags) + "', " + stringify(ci->capsmin) + ", " + stringify(ci->capspercent) + ", " + stringify(ci->floodlines) + ", " + stringify(ci->floodsecs) + ", " + stringify(ci->repeattimes) + ") " + - "ON DUPLICATE KEY UPDATE founder=VALUES(founder), successor=VALUES(successor), descr=VALUES(descr), time_registered=VALUES(time_registered), last_used=VALUES(last_used), last_topic=VALUES(last_topic), last_topic_setter=VALUES(last_topic_setter), last_topic_time=VALUES(last_topic_time), flags=VALUES(flags), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), bantype=VALUES(bantype), mlock_on=VALUES(mlock_on), mlock_off=VALUES(mlock_off), mlock_params=VALUES(mlock_params), entry_message=VALUES(entry_message), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(repeattimes)"); + "ON DUPLICATE KEY UPDATE founder=VALUES(founder), successor=VALUES(successor), descr=VALUES(descr), time_registered=VALUES(time_registered), last_used=VALUES(last_used), last_topic=VALUES(last_topic), last_topic_setter=VALUES(last_topic_setter), last_topic_time=VALUES(last_topic_time), flags=VALUES(flags), forbidby=VALUES(forbidby), forbidreason=VALUES(forbidreason), bantype=VALUES(bantype), mlock_on=VALUES(mlock_on), mlock_off=VALUES(mlock_off), mlock_params=VALUES(mlock_params), memomax=VALUES(memomax), botnick=VALUES(botnick), botflags=VALUES(botflags), capsmin=VALUES(capsmin), capspercent=VALUES(capspercent), floodlines=VALUES(floodlines), floodsecs=VALUES(floodsecs), repeattimes=VALUES(repeattimes)"); } void OnChanSuspend(ChannelInfo *ci) diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 0f37963c5..551c025ae 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -157,7 +157,7 @@ class RatboxProto : public IRCDProto void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when) { - send_cmd(Config->Numeric, "ENCAP %s SVSNICK %s %ld %s %ld", u->server->GetName().c_str(), u->nick, static_cast<long>(u->timestamp), newnick, static_cast<long>(when)); + send_cmd(Config->Numeric, "ENCAP %s SVSNICK %s %ld %s %ld", u->server->GetName().c_str(), u->nick.c_str(), static_cast<long>(u->timestamp), newnick.c_str(), static_cast<long>(when)); } void SendConnect() |