X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_chanhistory.cpp;h=08f4291c916c73b452a484a342a69b219c7d2e76;hb=db5610a5640749ab7dafab82c1ef1553f3d78615;hp=0817311260e7a990f53c1562bff6bcb967133e57;hpb=124c17e14134a4999afc1a5e981ab7c75b3694b9;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index 081731126..08f4291c9 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -18,12 +18,22 @@ #include "inspircd.h" +#include "modules/ircv3_servertime.h" +#include "modules/ircv3_batch.h" +#include "modules/server.h" struct HistoryItem { time_t ts; - std::string line; - HistoryItem(const std::string& Line) : ts(ServerInstance->Time()), line(Line) {} + std::string text; + std::string sourcemask; + + HistoryItem(User* source, const std::string& Text) + : ts(ServerInstance->Time()) + , text(Text) + , sourcemask(source->GetFullHost()) + { + } }; struct HistoryList @@ -38,20 +48,6 @@ struct HistoryList class HistoryMode : public ParamMode > { - bool IsValidDuration(const std::string& duration) - { - for (std::string::const_iterator i = duration.begin(); i != duration.end(); ++i) - { - unsigned char c = *i; - if (((c >= '0') && (c <= '9')) || (c == 's') || (c == 'S')) - continue; - - if (duration_multi[c] == 1) - return false; - } - return true; - } - public: unsigned int maxlines; HistoryMode(Module* Creator) @@ -69,7 +65,7 @@ class HistoryMode : public ParamMode > } std::string duration(parameter, colon+1); - if ((IS_LOCAL(source)) && ((duration.length() > 10) || (!IsValidDuration(duration)))) + if ((IS_LOCAL(source)) && ((duration.length() > 10) || (!InspIRCd::IsValidDuration(duration)))) { source->WriteNumeric(Numerics::InvalidModeParameter(channel, this, parameter)); return MODEACTION_DENY; @@ -109,14 +105,28 @@ class HistoryMode : public ParamMode > } }; -class ModuleChanHistory : public Module +class ModuleChanHistory + : public Module + , public ServerEventListener { HistoryMode m; bool sendnotice; UserModeReference botmode; bool dobots; + IRCv3::Batch::CapReference batchcap; + IRCv3::Batch::API batchmanager; + IRCv3::Batch::Batch batch; + IRCv3::ServerTime::API servertimemanager; + public: - ModuleChanHistory() : m(this), botmode(this, "bot") + ModuleChanHistory() + : ServerEventListener(this) + , m(this) + , botmode(this, "bot") + , batchcap(this) + , batchmanager(this) + , batch("chathistory") + , servertimemanager(this) { } @@ -128,6 +138,11 @@ class ModuleChanHistory : public Module dobots = tag->getBool("bots", true); } + ModResult OnBroadcastMessage(Channel* channel, const Server* server) CXX11_OVERRIDE + { + return channel->IsModeSet(m) ? MOD_RES_ALLOW : MOD_RES_PASSTHRU; + } + void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE { if ((target.type == MessageTarget::TYPE_CHANNEL) && (target.status == 0) && (details.type == MSG_PRIVMSG)) @@ -136,8 +151,7 @@ class ModuleChanHistory : public Module HistoryList* list = m.ext.get(c); if (list) { - const std::string line = ":" + user->GetFullHost() + " PRIVMSG " + c->name + " :" + details.text; - list->lines.push_back(HistoryItem(line)); + list->lines.push_back(HistoryItem(user, details.text)); if (list->lines.size() > list->maxlen) list->lines.pop_front(); } @@ -146,7 +160,8 @@ class ModuleChanHistory : public Module void OnPostJoin(Membership* memb) CXX11_OVERRIDE { - if (IS_REMOTE(memb->user)) + LocalUser* localuser = IS_LOCAL(memb->user); + if (!localuser) return; if (memb->user->IsModeSet(botmode) && !dobots) @@ -159,7 +174,7 @@ class ModuleChanHistory : public Module if (list->maxtime) mintime = ServerInstance->Time() - list->maxtime; - if (sendnotice) + if ((sendnotice) && (!batchcap.get(localuser))) { std::string message("Replaying up to " + ConvToStr(list->maxlen) + " lines of pre-join history"); if (list->maxtime > 0) @@ -167,11 +182,27 @@ class ModuleChanHistory : public Module memb->WriteNotice(message); } + if (batchmanager) + { + batchmanager->Start(batch); + batch.GetBatchStartMessage().PushParamRef(memb->chan->name); + } + for(std::deque::iterator i = list->lines.begin(); i != list->lines.end(); ++i) { - if (i->ts >= mintime) - memb->user->Write(i->line); + const HistoryItem& item = *i; + if (item.ts >= mintime) + { + ClientProtocol::Messages::Privmsg msg(ClientProtocol::Messages::Privmsg::nocopy, item.sourcemask, memb->chan, item.text); + if (servertimemanager) + servertimemanager->Set(msg, item.ts); + batch.AddToBatch(msg); + localuser->Send(ServerInstance->GetRFCEvents().privmsg, msg); + } } + + if (batchmanager) + batchmanager->End(batch); } Version GetVersion() CXX11_OVERRIDE