]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_showfile.cpp
Fix the cloaking module on C++98 compilers.
[user/henk/code/inspircd.git] / src / modules / m_showfile.cpp
index 0f5d3ed1a00c8e556239edb9ed3d12934da6abad..ba3dc60e1a995d359bebc237f03adea76437a576 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * InspIRCd -- Internet Relay Chat Daemon
  *
- *   Copyright (C) 2013 Attila Molnar <attilamolnar@hush.com>
+ *   Copyright (C) 2018, 2020 Sadie Powell <sadie@witchery.services>
+ *   Copyright (C) 2013-2014, 2016, 2018 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
 
 #include "inspircd.h"
 
+enum
+{
+       // From UnrealIRCd.
+       RPL_RULES = 232,
+       RPL_RULESTART = 308,
+       RPL_RULESEND = 309,
+       ERR_NORULES = 434
+};
+
 class CommandShowFile : public Command
 {
        enum Method
@@ -42,25 +52,28 @@ class CommandShowFile : public Command
        {
        }
 
-       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
+       CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
        {
-               const std::string& sn = ServerInstance->Config->ServerName;
                if (method == SF_NUMERIC)
                {
-                       if (!introtext.empty())
-                               user->SendText(":%s %03d %s :%s %s", sn.c_str(), intronumeric, user->nick.c_str(), sn.c_str(), introtext.c_str());
+                       if (!introtext.empty() && intronumeric)
+                               user->WriteRemoteNumeric(intronumeric, introtext);
 
                        for (file_cache::const_iterator i = contents.begin(); i != contents.end(); ++i)
-                               user->SendText(":%s %03d %s :- %s", sn.c_str(), textnumeric, user->nick.c_str(), i->c_str());
+                               user->WriteRemoteNumeric(textnumeric, InspIRCd::Format(" %s", i->c_str()));
 
-                       user->SendText(":%s %03d %s :%s", sn.c_str(), endnumeric, user->nick.c_str(), endtext.c_str());
+                       if (!endtext.empty() && endnumeric)
+                               user->WriteRemoteNumeric(endnumeric, endtext.c_str());
                }
-               else
+               else if (IS_LOCAL(user))
                {
-                       const char* msgcmd = (method == SF_MSG ? "PRIVMSG" : "NOTICE");
-                       std::string header = InspIRCd::Format(":%s %s %s :", sn.c_str(), msgcmd, user->nick.c_str());
+                       LocalUser* const localuser = IS_LOCAL(user);
                        for (file_cache::const_iterator i = contents.begin(); i != contents.end(); ++i)
-                               user->SendText(header + *i);
+                       {
+                               const std::string& line = *i;
+                               ClientProtocol::Messages::Privmsg msg(ClientProtocol::Messages::Privmsg::nocopy, ServerInstance->FakeClient, localuser, line, ((method == SF_MSG) ? MSG_PRIVMSG : MSG_NOTICE));
+                               localuser->Send(ServerInstance->GetRFCEvents().privmsg, msg);
+                       }
                }
                return CMD_SUCCESS;
        }
@@ -69,9 +82,9 @@ class CommandShowFile : public Command
        {
                introtext = tag->getString("introtext", "Showing " + name);
                endtext = tag->getString("endtext", "End of " + name);
-               intronumeric = tag->getInt("intronumeric", RPL_RULESTART, 0, 999);
-               textnumeric = tag->getInt("numeric", RPL_RULES, 0, 999);
-               endnumeric = tag->getInt("endnumeric", RPL_RULESEND, 0, 999);
+               intronumeric = tag->getUInt("intronumeric", RPL_RULESTART, 0, 999);
+               textnumeric = tag->getUInt("numeric", RPL_RULES, 0, 999);
+               endnumeric = tag->getUInt("endnumeric", RPL_RULESEND, 0, 999);
                std::string smethod = tag->getString("method");
 
                method = SF_NUMERIC;
@@ -81,8 +94,7 @@ class CommandShowFile : public Command
                        method = SF_NOTICE;
 
                contents = filecontents;
-               if (tag->getBool("colors"))
-                       InspIRCd::ProcessColors(contents);
+               InspIRCd::ProcessColors(contents);
        }
 };
 
@@ -104,7 +116,7 @@ class ModuleShowFile : public Module
                FileReader reader(file);
 
                CommandShowFile* sfcmd;
-               Command* handler = ServerInstance->Parser->GetHandler(cmdname);
+               Command* handler = ServerInstance->Parser.GetHandler(cmdname);
                if (handler)
                {
                        // Command exists, check if it is ours
@@ -113,7 +125,7 @@ class ModuleShowFile : public Module
 
                        // This is our command, make sure we don't have the same entry twice
                        sfcmd = static_cast<CommandShowFile*>(handler);
-                       if (std::find(newcmds.begin(), newcmds.end(), sfcmd) != newcmds.end())
+                       if (stdalgo::isin(newcmds, sfcmd))
                                throw ModuleException("Command " + cmdname + " is already used in a <showfile> tag");
                }
                else
@@ -127,12 +139,6 @@ class ModuleShowFile : public Module
                newcmds.push_back(sfcmd);
        }
 
-       static void DelAll(const std::vector<CommandShowFile*>& list)
-       {
-               for (std::vector<CommandShowFile*>::const_iterator i = list.begin(); i != list.end(); ++i)
-                       delete *i;
-       }
-
  public:
        void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
        {
@@ -157,18 +163,18 @@ class ModuleShowFile : public Module
                std::sort(newcmds.begin(), newcmds.end());
                std::set_difference(cmds.begin(), cmds.end(), newcmds.begin(), newcmds.end(), removed.begin());
 
-               DelAll(removed);
+               stdalgo::delete_all(removed);
                cmds.swap(newcmds);
        }
 
        ~ModuleShowFile()
        {
-               DelAll(cmds);
+               stdalgo::delete_all(cmds);
        }
 
        Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("Provides support for showing text files to users", VF_VENDOR);
+               return Version("Adds support for showing the contents of files to users when they execute a command.", VF_VENDOR);
        }
 };