m_operchans.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015
00016
00017
00018 class OperChans : public ModeHandler
00019 {
00020 public:
00021
00022 OperChans(InspIRCd* Instance) : ModeHandler(Instance, 'O', 0, 0, false, MODETYPE_CHANNEL, true) { }
00023
00024 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
00025 {
00026 if (adding)
00027 {
00028 if (!channel->IsModeSet('O'))
00029 {
00030 channel->SetMode('O',true);
00031 return MODEACTION_ALLOW;
00032 }
00033 }
00034 else
00035 {
00036 if (channel->IsModeSet('O'))
00037 {
00038 channel->SetMode('O',false);
00039 return MODEACTION_ALLOW;
00040 }
00041 }
00042
00043 return MODEACTION_DENY;
00044 }
00045 };
00046
00047 class ModuleOperChans : public Module
00048 {
00049
00050 OperChans* oc;
00051 public:
00052 ModuleOperChans(InspIRCd* Me)
00053 : Module(Me)
00054 {
00055
00056 oc = new OperChans(ServerInstance);
00057 if (!ServerInstance->Modes->AddMode(oc))
00058 throw ModuleException("Could not add new modes!");
00059 Implementation eventlist[] = { I_OnUserPreJoin };
00060 ServerInstance->Modules->Attach(eventlist, this, 1);
00061 }
00062
00063
00064 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
00065 {
00066 if (!IS_OPER(user))
00067 {
00068 if (chan)
00069 {
00070 if (chan->IsModeSet('O'))
00071 {
00072 user->WriteNumeric(ERR_CANTJOINOPERSONLY, "%s %s :Only IRC operators may join the channel %s (+O is set)",user->nick.c_str(), chan->name.c_str(), chan->name.c_str());
00073 return 1;
00074 }
00075 }
00076 }
00077 else
00078 {
00079 if (chan && chan->IsExtBanned(user->oper, 'O'))
00080 {
00081 user->WriteNumeric(ERR_BANNEDFROMCHAN, "%s %s :Cannot join channel (You're banned)", user->nick.c_str(), chan->name.c_str());
00082 return 1;
00083 }
00084 }
00085
00086 return 0;
00087 }
00088
00089 virtual ~ModuleOperChans()
00090 {
00091 ServerInstance->Modes->DelMode(oc);
00092 delete oc;
00093 }
00094
00095 virtual Version GetVersion()
00096 {
00097 return Version("$Id: m_operchans.cpp 10291 2008-08-25 20:35:51Z w00t $", VF_VENDOR | VF_COMMON, API_VERSION);
00098 }
00099 };
00100
00101 MODULE_INIT(ModuleOperChans)