]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Merge branches 'master+check' and 'master+namedmodes'
authorAttila Molnar <attilamolnar@hush.com>
Tue, 22 Mar 2016 17:38:17 +0000 (18:38 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Tue, 22 Mar 2016 17:38:17 +0000 (18:38 +0100)
include/numericbuilder.h
src/modules/m_namedmodes.cpp

index b0995898699b9123576bffe116189d0eeb74e561..17aa9e0c866bb1ceafe1bae03a30e24fd482157c 100644 (file)
@@ -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())
+       {
+       }
+};
index 10bef981a3bee03425bbce9dfca8671103d1a277..d4263d899d46a741ee20482736043b904f18577c 100644 (file)
 
 #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);
        }
 };