X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_opermotd.cpp;h=e0120c4dd04c29df04099fc0ff2154ae73fb15b3;hb=8df3d792bc99d9dd73db7a601ebe8d4a397c3522;hp=5f9dafa655917a22101d62592dbd95b27e19b289;hpb=5d407fb44c759524881712a80febb86b4506ddbf;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_opermotd.cpp b/src/modules/m_opermotd.cpp index 5f9dafa65..e0120c4dd 100644 --- a/src/modules/m_opermotd.cpp +++ b/src/modules/m_opermotd.cpp @@ -1,121 +1,127 @@ -// opermotd module by typobox43 - -using namespace std; - -#include -#include "users.h" -#include "channels.h" -#include "modules.h" -#include "helperfuncs.h" - -/* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */ - -static FileReader* opermotd; -static Server* Srv; - -void LoadOperMOTD() +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2013, 2018-2019 Sadie Powell + * Copyright (C) 2012-2013, 2016 Attila Molnar + * Copyright (C) 2012, 2019 Robby + * Copyright (C) 2009 Uli Schlachter + * Copyright (C) 2009 Daniel De Graaf + * Copyright (C) 2007, 2009 Dennis Friis + * Copyright (C) 2006 Craig Edwards + * + * 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 + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include "inspircd.h" + +enum { - ConfigReader* conf = new ConfigReader; - std::string filename; - - filename = conf->ReadValue("opermotd","file",0); + // From UnrealIRCd. + ERR_NOOPERMOTD = 425, - opermotd->LoadFile(filename); - DELETE(conf); -} + // From ircd-ratbox. + RPL_OMOTDSTART = 720, + RPL_OMOTD = 721, + RPL_ENDOFOMOTD = 722 +}; -void ShowOperMOTD(userrec* user) +/** Handle /OPERMOTD + */ +class CommandOpermotd : public Command { - if(!opermotd->FileSize()) - { - Srv->SendServ(user->fd,std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing")); - return; - } - - Srv->SendServ(user->fd,std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day")); + public: + file_cache opermotd; - for(int i=0; i != opermotd->FileSize(); i++) + CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0, 1) { - Srv->SendServ(user->fd,std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i)); + flags_needed = 'o'; syntax = "[]"; } - Srv->SendServ(user->fd,std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD")); - -} - -class cmd_opermotd : public command_t -{ - public: - cmd_opermotd () : command_t("OPERMOTD", 'o', 0) + CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE { - this->source = "m_opermotd.so"; + if ((parameters.empty()) || (irc::equals(parameters[0], ServerInstance->Config->ServerName))) + ShowOperMOTD(user, true); + return CMD_SUCCESS; } - void Handle (char** parameters, int pcnt, userrec* user) + RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE { - ShowOperMOTD(user); + if ((!parameters.empty()) && (parameters[0].find('.') != std::string::npos)) + return ROUTE_OPT_UCAST(parameters[0]); + return ROUTE_LOCALONLY; } -}; -class ModuleOpermotd : public Module -{ - cmd_opermotd* mycommand; - public: - ModuleOpermotd(Server* Me) - : Module::Module(Me) + void ShowOperMOTD(User* user, bool show_missing) + { + if (opermotd.empty()) { - Srv = Me; - mycommand = new cmd_opermotd(); - Srv->AddCommand(mycommand); - opermotd = new FileReader(); - LoadOperMOTD(); + if (show_missing) + user->WriteRemoteNumeric(ERR_NOOPERMOTD, "OPERMOTD file is missing."); + return; } - virtual ~ModuleOpermotd() - { - } + user->WriteRemoteNumeric(RPL_OMOTDSTART, "Server operators message of the day"); - virtual Version GetVersion() + for (file_cache::const_iterator i = opermotd.begin(); i != opermotd.end(); ++i) { - return Version(1,0,0,1,VF_VENDOR); + user->WriteRemoteNumeric(RPL_OMOTD, InspIRCd::Format("- %s", i->c_str())); } - void Implements(char* List) - { - List[I_OnRehash] = List[I_OnOper] = 1; - } + user->WriteRemoteNumeric(RPL_ENDOFOMOTD, "End of OPERMOTD"); + } +}; - virtual void OnOper(userrec* user, const std::string &opertype) - { - ShowOperMOTD(user); - } - virtual void OnRehash(const std::string ¶meter) - { - LoadOperMOTD(); - } +class ModuleOpermotd : public Module +{ + CommandOpermotd cmd; + bool onoper; + public: -}; + ModuleOpermotd() + : cmd(this) + { + } -class ModuleOpermotdFactory : public ModuleFactory -{ - public: - ModuleOpermotdFactory() - { - } + Version GetVersion() CXX11_OVERRIDE + { + return Version("Shows a message to opers after oper-up and adds the OPERMOTD command", VF_VENDOR | VF_OPTCOMMON); + } + + void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE + { + if (onoper && IS_LOCAL(user)) + cmd.ShowOperMOTD(user, false); + } - ~ModuleOpermotdFactory() + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE + { + cmd.opermotd.clear(); + ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd"); + onoper = conf->getBool("onoper", true); + + try { + FileReader reader(conf->getString("file", "opermotd")); + cmd.opermotd = reader.GetVector(); + InspIRCd::ProcessColors(cmd.opermotd); } - - virtual Module* CreateModule(Server* Me) + catch (CoreException&) { - return new ModuleOpermotd(Me); + // Nothing happens here as we do the error handling in ShowOperMOTD. } - + } }; -extern "C" void* init_module(void) -{ - return new ModuleOpermotdFactory; -} +MODULE_INIT(ModuleOpermotd)