1
0
mirror of https://github.com/anope/anope.git synced 2026-07-08 22:33:13 +02:00

Added cs_entrymsg

This commit is contained in:
Adam
2010-11-23 16:48:54 -06:00
parent 7d1cfe9514
commit 37e02a3594
14 changed files with 272 additions and 158 deletions
-3
View File
@@ -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);
-113
View File
@@ -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> &params)
{
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)
-4
View File
@@ -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())
+215
View File
@@ -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)
+3 -8
View File
@@ -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)
+1 -1
View File
@@ -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()