summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/numericbuilder.h68
-rw-r--r--src/modules/m_namedmodes.cpp25
2 files changed, 81 insertions, 12 deletions
diff --git a/include/numericbuilder.h b/include/numericbuilder.h
index b09958986..17aa9e0c8 100644
--- a/include/numericbuilder.h
+++ b/include/numericbuilder.h
@@ -1,7 +1,7 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
- * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
+ * Copyright (C) 2015-2016 Attila Molnar <attilamolnar@hush.com>
*
* This file is part of InspIRCd. InspIRCd is free software: you can
* redistribute it and/or modify it under the terms of the GNU General Public
@@ -29,6 +29,12 @@ namespace Numeric
template <char Sep = ',', bool SendEmpty = false>
class Builder;
+
+ template <unsigned int NumStaticParams, bool SendEmpty, typename Sink>
+ class GenericParamBuilder;
+
+ template <unsigned int NumStaticParams, bool SendEmpty = false>
+ class ParamBuilder;
}
class Numeric::WriteNumericSink
@@ -130,3 +136,63 @@ class Numeric::Builder : public GenericBuilder<Sep, SendEmpty, WriteNumericSink>
{
}
};
+
+template <unsigned int NumStaticParams, bool SendEmpty, typename Sink>
+class Numeric::GenericParamBuilder
+{
+ Sink sink;
+ Numeric numeric;
+ std::string::size_type currlen;
+ std::string::size_type max;
+
+ bool HasRoom(const std::string::size_type additional) const
+ {
+ return (currlen + additional <= max);
+ }
+
+ public:
+ GenericParamBuilder(Sink s, unsigned int num, size_t additionalsize)
+ : sink(s)
+ , numeric(num)
+ , currlen(0)
+ , max(ServerInstance->Config->Limits.MaxLine - ServerInstance->Config->ServerName.size() - additionalsize - 10)
+ {
+ }
+
+ void AddStatic(const std::string& entry)
+ {
+ max -= (entry.length() + 1);
+ numeric.GetParams().push_back(entry);
+ }
+
+ void Add(const std::string& entry)
+ {
+ if (!HasRoom(entry.size()))
+ Flush();
+
+ currlen += entry.size() + 1;
+ numeric.GetParams().push_back(entry);
+ }
+
+ void Flush()
+ {
+ if ((!SendEmpty) && (IsEmpty()))
+ return;
+
+ sink(numeric);
+ currlen = 0;
+ numeric.GetParams().erase(numeric.GetParams().begin() + NumStaticParams, numeric.GetParams().end());
+ }
+
+ bool IsEmpty() const { return (numeric.GetParams().size() <= NumStaticParams); }
+};
+
+template <unsigned int NumStaticParams, bool SendEmpty>
+class Numeric::ParamBuilder : public GenericParamBuilder<NumStaticParams, SendEmpty, WriteNumericSink>
+{
+ public:
+ ParamBuilder(LocalUser* user, unsigned int num)
+ : ::Numeric::GenericParamBuilder<NumStaticParams, SendEmpty, WriteNumericSink>(WriteNumericSink(user), num, user->nick.size())
+ {
+ }
+};
diff --git a/src/modules/m_namedmodes.cpp b/src/modules/m_namedmodes.cpp
index 10bef981a..d4263d899 100644
--- a/src/modules/m_namedmodes.cpp
+++ b/src/modules/m_namedmodes.cpp
@@ -19,38 +19,40 @@
#include "inspircd.h"
-static void DisplayList(User* user, Channel* channel)
+static void DisplayList(LocalUser* user, Channel* channel)
{
- std::stringstream items;
+ Numeric::ParamBuilder<1> numeric(user, 961);
+ numeric.AddStatic(channel->name);
+
const ModeParser::ModeHandlerMap& mhs = ServerInstance->Modes->GetModes(MODETYPE_CHANNEL);
for (ModeParser::ModeHandlerMap::const_iterator i = mhs.begin(); i != mhs.end(); ++i)
{
ModeHandler* mh = i->second;
if (!channel->IsModeSet(mh))
continue;
- items << " +" << mh->name;
+ numeric.Add("+" + mh->name);
if (mh->GetNumParams(true))
{
if ((mh->name == "key") && (!channel->HasUser(user)) && (!user->HasPrivPermission("channels/auspex")))
- items << " <key>";
+ numeric.Add("<key>");
else
- items << " " << channel->GetModeParameter(mh);
+ numeric.Add(channel->GetModeParameter(mh));
}
}
- const std::string line = ":" + ServerInstance->Config->ServerName + " 961 " + user->nick + " " + channel->name;
- user->SendText(line, items);
+ numeric.Flush();
user->WriteNumeric(960, channel->name, "End of mode list");
}
-class CommandProp : public Command
+class CommandProp : public SplitCommand
{
public:
- CommandProp(Module* parent) : Command(parent, "PROP", 1)
+ CommandProp(Module* parent)
+ : SplitCommand(parent, "PROP", 1)
{
syntax = "<user|channel> {[+-]<mode> [<value>]}*";
}
- CmdResult Handle(const std::vector<std::string> &parameters, User *src)
+ CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* src)
{
Channel* const chan = ServerInstance->FindChan(parameters[0]);
if (!chan)
@@ -103,7 +105,8 @@ class DummyZ : public ModeHandler
// Handle /MODE #chan Z
void DisplayList(User* user, Channel* chan)
{
- ::DisplayList(user, chan);
+ if (IS_LOCAL(user))
+ ::DisplayList(static_cast<LocalUser*>(user), chan);
}
};