The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

m_opermotd.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #include "inspircd.h"
00015 
00016 /* $ModDesc: Shows a message to opers after oper-up, adds /opermotd */
00017 
00018 static FileReader* opermotd;
00019 
00020 CmdResult ShowOperMOTD(User* user)
00021 {
00022         if(!opermotd->FileSize())
00023         {
00024                 user->WriteServ(std::string("425 ") + user->nick + std::string(" :OPERMOTD file is missing"));
00025                 return CMD_FAILURE;
00026         }
00027 
00028         user->WriteServ(std::string("375 ") + user->nick + std::string(" :- IRC Operators Message of the Day"));
00029 
00030         for(int i=0; i != opermotd->FileSize(); i++)
00031         {
00032                 user->WriteServ(std::string("372 ") + user->nick + std::string(" :- ") + opermotd->GetLine(i));
00033         }
00034 
00035         user->WriteServ(std::string("376 ") + user->nick + std::string(" :- End of OPERMOTD"));
00036 
00037         /* don't route me */
00038         return CMD_LOCALONLY;
00039 }
00040 
00043 class CommandOpermotd : public Command
00044 {
00045  public:
00046         CommandOpermotd (InspIRCd* Instance) : Command(Instance,"OPERMOTD", "o", 0)
00047         {
00048                 this->source = "m_opermotd.so";
00049                 syntax = "[<servername>]";
00050         }
00051 
00052         CmdResult Handle (const std::vector<std::string>& parameters, User* user)
00053         {
00054                 return ShowOperMOTD(user);
00055         }
00056 };
00057 
00058 
00059 class ModuleOpermotd : public Module
00060 {
00061         CommandOpermotd* mycommand;
00062  public:
00063 
00064         void LoadOperMOTD()
00065         {
00066                 ConfigReader* conf = new ConfigReader(ServerInstance);
00067                 std::string filename;
00068                 filename = conf->ReadValue("opermotd","file",0);
00069                 if (opermotd)
00070                 {
00071                         delete opermotd;
00072                         opermotd = NULL;
00073                 }
00074                 opermotd = new FileReader(ServerInstance, filename);
00075                 delete conf;
00076         }
00077 
00078         ModuleOpermotd(InspIRCd* Me)
00079                 : Module(Me)
00080         {
00081                 opermotd = NULL;
00082                 mycommand = new CommandOpermotd(ServerInstance);
00083                 ServerInstance->AddCommand(mycommand);
00084                 opermotd = new FileReader(ServerInstance);
00085                 LoadOperMOTD();
00086                 Implementation eventlist[] = { I_OnRehash, I_OnOper };
00087                 ServerInstance->Modules->Attach(eventlist, this, 2);
00088         }
00089 
00090         virtual ~ModuleOpermotd()
00091         {
00092         }
00093 
00094         virtual Version GetVersion()
00095         {
00096                 return Version("$Id: m_opermotd.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR, API_VERSION);
00097         }
00098 
00099 
00100         virtual void OnOper(User* user, const std::string &opertype)
00101         {
00102                 ShowOperMOTD(user);
00103         }
00104 
00105         virtual void OnRehash(User* user, const std::string &parameter)
00106         {
00107                 LoadOperMOTD();
00108         }
00109 };
00110 
00111 MODULE_INIT(ModuleOpermotd)