2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5 * Copyright (C) 2005, 2007 Robin Burchell <robin+git@viroteck.net>
6 * Copyright (C) 2005-2006 Craig Edwards <craigedwards@brainbox.cc>
7 * Copyright (C) 2004 Christopher Hall <typobox43@gmail.com>
9 * This file is part of InspIRCd. InspIRCd is free software: you can
10 * redistribute it and/or modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation, version 2.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
29 class CommandOpermotd : public Command
34 CommandOpermotd(Module* Creator) : Command(Creator,"OPERMOTD", 0, 1)
36 flags_needed = 'o'; syntax = "[<servername>]";
39 CmdResult Handle (const std::vector<std::string>& parameters, User* user)
41 if ((parameters.empty()) || (parameters[0] == ServerInstance->Config->ServerName))
46 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
48 if (!parameters.empty())
49 return ROUTE_OPT_UCAST(parameters[0]);
50 return ROUTE_LOCALONLY;
53 void ShowOperMOTD(User* user)
55 const std::string& servername = ServerInstance->Config->ServerName;
58 user->SendText(":%s 455 %s :OPERMOTD file is missing", servername.c_str(), user->nick.c_str());
62 user->SendText(":%s 375 %s :- IRC Operators Message of the Day", servername.c_str(), user->nick.c_str());
64 for (file_cache::const_iterator i = opermotd.begin(); i != opermotd.end(); ++i)
66 user->SendText(":%s 372 %s :- %s", servername.c_str(), user->nick.c_str(), i->c_str());
69 user->SendText(":%s 376 %s :- End of OPERMOTD", servername.c_str(), user->nick.c_str());
74 class ModuleOpermotd : public Module
87 ServerInstance->Modules->AddService(cmd);
89 Implementation eventlist[] = { I_OnRehash, I_OnOper };
90 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
93 virtual Version GetVersion()
95 return Version("Shows a message to opers after oper-up, adds /opermotd", VF_VENDOR | VF_OPTCOMMON);
98 virtual void OnOper(User* user, const std::string &opertype)
100 if (onoper && IS_LOCAL(user))
101 cmd.ShowOperMOTD(user);
104 virtual void OnRehash(User* user)
106 cmd.opermotd.clear();
107 ConfigTag* conf = ServerInstance->Config->ConfValue("opermotd");
108 onoper = conf->getBool("onoper", true);
110 FileReader f(conf->getString("file", "opermotd"));
111 for (int i=0, filesize = f.FileSize(); i < filesize; i++)
112 cmd.opermotd.push_back(f.GetLine(i));
114 if (conf->getBool("processcolors"))
115 InspIRCd::ProcessColors(cmd.opermotd);
119 MODULE_INIT(ModuleOpermotd)