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

m_hideoper.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 #include "users.h"
00016 #include "channels.h"
00017 #include "modules.h"
00018 
00019 /* $ModDesc: Provides support for hiding oper status with user mode +H */
00020 
00023 class HideOper : public ModeHandler
00024 {
00025  public:
00026         HideOper(InspIRCd* Instance) : ModeHandler(Instance, 'H', 0, 0, false, MODETYPE_USER, true) { }
00027 
00028         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
00029         {
00030                 if (source != dest)
00031                         return MODEACTION_DENY;
00032 
00033                 if (adding)
00034                 {
00035                         if (!dest->IsModeSet('H'))
00036                         {
00037                                 dest->SetMode('H',true);
00038                                 return MODEACTION_ALLOW;
00039                         }
00040                 }
00041                 else
00042                 {
00043                         if (dest->IsModeSet('H'))
00044                         {
00045                                 dest->SetMode('H',false);
00046                                 return MODEACTION_ALLOW;
00047                         }
00048                 }
00049                 
00050                 return MODEACTION_DENY;
00051         }
00052 };
00053 
00054 class ModuleHideOper : public Module
00055 {
00056         
00057         HideOper* hm;
00058  public:
00059         ModuleHideOper(InspIRCd* Me)
00060                 : Module(Me)
00061         {
00062                 
00063                 hm = new HideOper(ServerInstance);
00064                 if (!ServerInstance->AddMode(hm, 'H'))
00065                         throw ModuleException("Could not add new modes!");
00066         }
00067 
00068         void Implements(char* List)
00069         {
00070                 List[I_OnWhoisLine] = 1;
00071         }
00072         
00073         virtual ~ModuleHideOper()
00074         {
00075                 ServerInstance->Modes->DelMode(hm);
00076                 DELETE(hm);
00077         }
00078         
00079         virtual Version GetVersion()
00080         {
00081                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
00082         }
00083 
00084         int OnWhoisLine(userrec* user, userrec* dest, int &numeric, std::string &text)
00085         {
00086                 /* Dont display numeric 313 (RPL_WHOISOPER) if they have +H set and the
00087                  * person doing the WHOIS is not an oper
00088                  */
00089                 return ((!IS_OPER(user)) && (numeric == 313) && dest->IsModeSet('H'));
00090         }
00091 };
00092 
00093 
00094 MODULE_INIT(ModuleHideOper)