1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 * ---------------------------------------------------
15 * Originally by Chernov-Phoenix Alexey (Phoenix@RusNet) mailto:phoenix /email address separator/ pravmail.ru
18 /* $ModDesc: Gives opers cmode +y which provides a staff prefix. */
22 #define OPERPREFIX_VALUE 1000000
24 class OperPrefixMode : public ModeHandler
27 OperPrefixMode(Module* Creator, char pfx) : ModeHandler(Creator, "operprefix", 'y', PARAM_ALWAYS, MODETYPE_CHANNEL)
31 levelrequired = OPERPREFIX_VALUE;
32 m_paramtype = TR_NICK;
35 unsigned int GetPrefixRank()
37 return OPERPREFIX_VALUE;
40 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
42 if (IS_SERVER(source) || (source && ServerInstance->ULine(source->server)))
43 return MODEACTION_ALLOW;
46 if (source && channel)
47 source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only servers are permitted to change channel mode '%c'", source->nick.c_str(), channel->name.c_str(), 'y');
48 return MODEACTION_DENY;
52 bool NeedsOper() { return true; }
55 class ModuleOperPrefixMode : public Module
60 ModuleOperPrefixMode() {
62 std::string pfx = Conf.ReadValue("operprefix", "prefix", "!", 0, false);
64 opm = new OperPrefixMode(this, pfx[0]);
65 if ((!ServerInstance->Modes->AddMode(opm)))
66 throw ModuleException("Could not add a new mode!");
68 Implementation eventlist[] = { I_OnPostJoin, I_OnUserQuit, I_OnUserKick, I_OnUserPart, I_OnOper };
69 ServerInstance->Modules->Attach(eventlist, this, 5);
72 void PushChanMode(Channel* channel, User* user)
74 char modeline[] = "+y";
75 std::vector<std::string> modechange;
76 modechange.push_back(channel->name);
77 modechange.push_back(modeline);
78 modechange.push_back(user->nick);
79 ServerInstance->SendMode(modechange,ServerInstance->FakeClient);
82 void OnPostJoin(Membership* memb)
84 if (IS_OPER(memb->user) && !memb->user->IsModeSet('H'))
85 PushChanMode(memb->chan, memb->user);
88 // XXX: is there a better way to do this?
89 ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string ¶m, bool adding, int pcnt)
91 /* force event propagation to its ModeHandler */
92 if (!IS_SERVER(user) && chan && (mode == 'y'))
94 return MOD_RES_PASSTHRU;
97 void OnOper(User *user, const std::string&)
99 if (user && !user->IsModeSet('H'))
101 for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
103 PushChanMode(*v, user);
108 ~ModuleOperPrefixMode()
115 return Version("Gives opers cmode +y which provides a staff prefix.", VF_VENDOR);
119 MODULE_INIT(ModuleOperPrefixMode)