2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Written for InspIRCd-1.2 by Taros on the Tel'Laerad M&D Team
22 * <http://tellaerad.net>
27 /* $ModConfig: <ojoin prefix="!" notice="yes" op="yes">
28 * Specify the prefix that +Y will grant here, it should be unused.
29 * Leave prefix empty if you do not wish +Y to grant a prefix
30 * If notice is set to on, upon ojoin, the server will notice
31 * the channel saying that the oper is joining on network business
32 * If op is set to on, it will give them +o along with +Y */
33 /* $ModDesc: Provides the /ojoin command, which joins a user to a channel on network business, and gives them +Y, which makes them immune to kick / deop and so on. */
34 /* $ModAuthor: Taros */
35 /* $ModAuthorMail: taros34@hotmail.com */
37 /* A note: This will not protect against kicks from services,
38 * ulines, or operoverride. */
40 #define NETWORK_VALUE 9000000
48 class CommandOjoin : public Command
52 CommandOjoin(Module* parent) : Command(parent,"OJOIN", 1)
54 flags_needed = 'o'; Penalty = 0; syntax = "<channel>";
56 TRANSLATE3(TR_NICK, TR_TEXT, TR_END);
59 CmdResult Handle (const std::vector<std::string>& parameters, User *user)
61 // Make sure the channel name is allowable.
62 if (!ServerInstance->IsChannel(parameters[0].c_str(), ServerInstance->Config->Limits.ChanMax))
64 user->WriteServ("NOTICE "+user->nick+" :*** Invalid characters in channel name or name too long");
69 Channel* channel = Channel::JoinUser(user, parameters[0].c_str(), false, "", false);
74 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN to join "+channel->name);
78 channel = ServerInstance->FindChan(parameters[0]);
79 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s joined on official network business.",
80 parameters[0].c_str(), user->nick.c_str());
81 ServerInstance->PI->SendChannelNotice(channel, 0, user->nick + " joined on official network business.");
86 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN in "+parameters[0]);
87 // they're already in the channel
88 std::vector<std::string> modes;
89 modes.push_back(parameters[0]);
90 modes.push_back(op ? "+Yo" : "+Y");
91 modes.push_back(user->nick);
93 modes.push_back(user->nick);
94 ServerInstance->SendGlobalMode(modes, ServerInstance->FakeClient);
102 class NetworkPrefix : public ModeHandler
105 NetworkPrefix(Module* parent) : ModeHandler(parent, "official-join", 'Y', PARAM_ALWAYS, MODETYPE_CHANNEL)
109 levelrequired = INT_MAX;
110 m_paramtype = TR_NICK;
113 void RemoveMode(Channel* channel, irc::modestacker* stack)
115 const UserMembList* cl = channel->GetUsers();
116 std::vector<std::string> mode_junk;
117 mode_junk.push_back(channel->name);
118 irc::modestacker modestack(false);
119 std::vector<std::string> stackresult;
121 for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
123 if (i->second->hasMode('Y'))
126 stack->Push(this->GetModeChar(), i->first->nick);
128 modestack.Push(this->GetModeChar(), i->first->nick);
135 while (modestack.GetStackedLine(stackresult))
137 mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
138 ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
139 mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
143 unsigned int GetPrefixRank()
145 return NETWORK_VALUE;
148 void RemoveMode(User* user, irc::modestacker* stack)
152 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
154 User* theuser = ServerInstance->FindNick(parameter);
156 if (source == theuser && !adding)
157 return MOD_RES_ALLOW;
159 return MOD_RES_PASSTHRU;
162 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
164 return MODEACTION_ALLOW;
169 class ModuleOjoin : public Module
172 CommandOjoin mycommand;
177 : np(NULL), mycommand(this)
183 /* Load config stuff */
186 /* Initialise module variables */
187 np = new NetworkPrefix(this);
189 ServerInstance->Modules->AddService(*np);
190 ServerInstance->Modules->AddService(mycommand);
192 Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserPreKick, I_OnRehash };
193 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
196 ModResult OnUserPreJoin(User* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven)
198 if (mycommand.active)
203 return MOD_RES_ALLOW;
206 return MOD_RES_PASSTHRU;
209 void OnRehash(User* user)
211 ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
215 // This is done on module load only
216 std::string npre = Conf->getString("prefix");
217 NPrefix = npre.empty() ? 0 : npre[0];
219 if (NPrefix && ServerInstance->Modes->FindPrefix(NPrefix))
220 throw ModuleException("Looks like the +Y prefix you picked for m_ojoin is already in use. Pick another.");
223 notice = Conf->getBool("notice", true);
224 op = Conf->getBool("op", true);
227 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
229 // Don't do anything if they're not +Y
230 if (!memb->hasMode('Y'))
231 return MOD_RES_PASSTHRU;
233 // Let them do whatever they want to themselves.
234 if (source == memb->user)
235 return MOD_RES_PASSTHRU;
237 source->WriteNumeric(484, source->nick+" "+memb->chan->name+" :Can't kick "+memb->user->nick+" as they're on official network business.");
248 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
253 return Version("Network Business Join", VF_VENDOR);
257 MODULE_INIT(ModuleOjoin)