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) : ModeHandler(Creator, "operprefix", 'y', PARAM_ALWAYS, MODETYPE_CHANNEL)
36 std::string pfx = ServerInstance->Config->ConfValue("operprefix")->getString("prefix", "!");
38 prefix = pfx.empty() ? '!' : pfx[0];
39 levelrequired = OPERPREFIX_VALUE;
40 m_paramtype = TR_NICK;
43 unsigned int GetPrefixRank()
45 return OPERPREFIX_VALUE;
48 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
50 if (IS_SERVER(source) || (source && ServerInstance->ULine(source->server)))
51 return MODEACTION_ALLOW;
54 if (source && channel)
55 source->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :Only servers are permitted to change channel mode '%c'", source->nick.c_str(), channel->name.c_str(), 'y');
56 return MODEACTION_DENY;
60 bool NeedsOper() { return true; }
63 class ModuleOperPrefixMode : public Module
68 ModuleOperPrefixMode()
75 ServerInstance->Modules->AddService(opm);
77 Implementation eventlist[] = { I_OnPostJoin, I_OnOper };
78 ServerInstance->Modules->Attach(eventlist, this, 2);
81 void PushChanMode(Channel* channel, User* user)
83 char modeline[] = "+y";
84 std::vector<std::string> modechange;
85 modechange.push_back(channel->name);
86 modechange.push_back(modeline);
87 modechange.push_back(user->nick);
88 ServerInstance->SendMode(modechange,ServerInstance->FakeClient);
91 void OnPostJoin(Membership* memb)
93 if (IS_OPER(memb->user) && !memb->user->IsModeSet('H'))
94 PushChanMode(memb->chan, memb->user);
97 // XXX: is there a better way to do this?
98 ModResult OnRawMode(User* user, Channel* chan, const char mode, const std::string ¶m, bool adding, int pcnt)
100 /* force event propagation to its ModeHandler */
101 if (!IS_SERVER(user) && chan && (mode == 'y'))
102 return MOD_RES_ALLOW;
103 return MOD_RES_PASSTHRU;
106 void OnOper(User *user, const std::string&)
108 if (user && !user->IsModeSet('H'))
110 for (UCListIter v = user->chans.begin(); v != user->chans.end(); v++)
112 PushChanMode(*v, user);
117 ~ModuleOperPrefixMode()
123 return Version("Gives opers cmode +y which provides a staff prefix.", VF_VENDOR);
127 MODULE_INIT(ModuleOperPrefixMode)