1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides support for oper-only chans via the +O channel mode */
18 class OperChans : public ModeHandler
21 /* This is an oper-only mode */
22 OperChans(InspIRCd* Instance, Module* Creator) : ModeHandler(Creator, 'O', PARAM_NONE, MODETYPE_CHANNEL) { oper = true; }
24 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
28 if (!channel->IsModeSet('O'))
30 channel->SetMode('O',true);
31 return MODEACTION_ALLOW;
36 if (channel->IsModeSet('O'))
38 channel->SetMode('O',false);
39 return MODEACTION_ALLOW;
43 return MODEACTION_DENY;
47 class ModuleOperChans : public Module
51 ModuleOperChans(InspIRCd* Me)
52 : Module(Me), oc(Me, this)
54 if (!ServerInstance->Modes->AddMode(&oc))
55 throw ModuleException("Could not add new modes!");
56 ServerInstance->Modules->Attach(I_OnUserPreJoin, this);
59 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
61 if (chan && chan->IsModeSet('O') && !IS_OPER(user))
63 user->WriteNumeric(ERR_CANTJOINOPERSONLY, "%s %s :Only IRC operators may join %s (+O is set)",
64 user->nick.c_str(), chan->name.c_str(), chan->name.c_str());
67 return MOD_RES_PASSTHRU;
72 ServerInstance->Modes->DelMode(&oc);
77 return Version("$Id$", VF_VENDOR | VF_COMMON, API_VERSION);
81 MODULE_INIT(ModuleOperChans)