summaryrefslogtreecommitdiff
path: root/modules/extra
diff options
context:
space:
mode:
Diffstat (limited to 'modules/extra')
-rw-r--r--modules/extra/cs_entrymsg.cpp215
-rw-r--r--modules/extra/db_mysql.cpp11
2 files changed, 218 insertions, 8 deletions
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> &params)
+ {
+ 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> &params)
+ {
+ 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)