2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 * Originally by Chernov-Phoenix Alexey (Phoenix@RusNet) mailto:phoenix /email address separator/ pravmail.ru
25 /* $ModDesc: Gives opers cmode +y which provides a staff prefix. */
29 #define OPERPREFIX_VALUE 1000000
31 class OperPrefixMode : public ModeHandler
34 OperPrefixMode(Module* Creator, char pfx) : ModeHandler(Creator, "operprefix", 'y', PARAM_ALWAYS, MODETYPE_CHANNEL)
38 levelrequired = OPERPREFIX_VALUE;
39 m_paramtype = TR_NICK;
42 unsigned int GetPrefixRank()
44 return OPERPREFIX_VALUE;
47 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
49 if (IS_SERVER(source) || (source && ServerInstance->ULine(source->server)))
50 return MODEACTION_ALLOW;
53 if (source && channel)
54 source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only servers are permitted to change channel mode '%c'", source->nick.c_str(), channel->name.c_str(), 'y');
55 return MODEACTION_DENY;
59 bool NeedsOper() { return true; }
62 class ModuleOperPrefixMode : public Module
67 ModuleOperPrefixMode() {
69 std::string pfx = Conf.ReadValue("operprefix", "prefix", "!", 0, false);
71 opm = new OperPrefixMode(this, pfx[0]);
72 if ((!ServerInstance->Modes->AddMode(opm)))
73 throw ModuleException("Could not add a new mode!");
75 Implementation eventlist[] = { I_OnPostJoin, I_OnUserQuit, I_OnUserKick, I_OnUserPart, I_OnOper };
76 ServerInstance->Modules->Attach(eventlist, this, 5);
79 void PushChanMode(Channel* channel, User* user)
81 char modeline[] = "+y";
82 std::vector<std::string> modechange;
83 modechange.push_back(channel->name);
84 modechange.push_back(modeline);
85 modechange.push_back(user->nick);
86 ServerInstance->SendMode(modechange,ServerInstance->FakeClient);
89 void OnPostJoin(Membership* memb)
91 if (IS_OPER(memb->user) && !memb->user->IsModeSet('H'))
92 PushChanMode(memb->chan, memb->user);
95 // XXX: is there a better way to do this?
96 ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string ¶m, bool adding, int pcnt)
98 /* force event propagation to its ModeHandler */
99 if (!IS_SERVER(user) && chan && (mode == 'y'))
100 return MOD_RES_ALLOW;
101 return MOD_RES_PASSTHRU;
104 void OnOper(User *user, const std::string&)
106 if (user && !user->IsModeSet('H'))
108 for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
110 PushChanMode(*v, user);
115 ~ModuleOperPrefixMode()
122 return Version("Gives opers cmode +y which provides a staff prefix.", VF_VENDOR);
126 MODULE_INIT(ModuleOperPrefixMode)