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 "+std::string(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', std::string(user->nick)+" used OJOIN to join "+channel->name);
78 channel = ServerInstance->FindChan(parameters[0]);
79 channel->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s joined on official network business.",
80 parameters[0].c_str(), user->nick.c_str());
81 ServerInstance->PI->SendChannelNotice(channel, 0, std::string(user->nick) + " joined on official network business.");
86 ServerInstance->SNO->WriteGlobalSno('a', std::string(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("+Y");
91 modes.push_back(user->nick);
92 ServerInstance->SendGlobalMode(modes, ServerInstance->FakeClient);
100 class NetworkPrefix : public ModeHandler
103 NetworkPrefix(Module* parent) : ModeHandler(parent, "official-join", 'Y', PARAM_ALWAYS, MODETYPE_CHANNEL)
107 levelrequired = INT_MAX;
108 m_paramtype = TR_NICK;
111 void RemoveMode(Channel* channel, irc::modestacker* stack)
113 const UserMembList* cl = channel->GetUsers();
114 std::vector<std::string> mode_junk;
115 mode_junk.push_back(channel->name);
116 irc::modestacker modestack(false);
117 std::deque<std::string> stackresult;
119 for (UserMembCIter i = cl->begin(); i != cl->end(); i++)
121 if (i->second->hasMode('Y'))
124 stack->Push(this->GetModeChar(), i->first->nick);
126 modestack.Push(this->GetModeChar(), i->first->nick);
133 while (modestack.GetStackedLine(stackresult))
135 mode_junk.insert(mode_junk.end(), stackresult.begin(), stackresult.end());
136 ServerInstance->SendMode(mode_junk, ServerInstance->FakeClient);
137 mode_junk.erase(mode_junk.begin() + 1, mode_junk.end());
141 unsigned int GetPrefixRank()
143 return NETWORK_VALUE;
146 void RemoveMode(User* user, irc::modestacker* stack)
150 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
152 User* theuser = ServerInstance->FindNick(parameter);
154 if (source == theuser && !adding)
155 return MOD_RES_ALLOW;
157 return MOD_RES_PASSTHRU;
160 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
162 return MODEACTION_ALLOW;
167 class ModuleOjoin : public Module
170 CommandOjoin mycommand;
175 : np(NULL), mycommand(this)
181 /* Load config stuff */
184 /* Initialise module variables */
185 np = new NetworkPrefix(this);
187 ServerInstance->Modules->AddService(*np);
188 ServerInstance->Modules->AddService(mycommand);
190 Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserPreKick, I_OnRehash };
191 ServerInstance->Modules->Attach(eventlist, this, 3);
194 ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
196 if (mycommand.active)
201 return MOD_RES_ALLOW;
204 return MOD_RES_PASSTHRU;
207 void OnRehash(User* user)
209 ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
213 // This is done on module load only
214 std::string npre = Conf->getString("prefix");
215 NPrefix = npre.empty() ? 0 : npre[0];
217 if (NPrefix && ServerInstance->Modes->FindPrefix(NPrefix))
218 throw ModuleException("Looks like the +Y prefix you picked for m_ojoin is already in use. Pick another.");
221 notice = Conf->getBool("notice", true);
222 op = Conf->getBool("op", true);
225 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
227 // Don't do anything if they're not +Y
228 if (!memb->hasMode('Y'))
229 return MOD_RES_PASSTHRU;
231 // Let them do whatever they want to themselves.
232 if (source == memb->user)
233 return MOD_RES_PASSTHRU;
235 source->WriteNumeric(484, source->nick+" "+memb->chan->name+" :Can't kick "+memb->user->nick+" as they're on official network business.");
246 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
251 return Version("Network Business Join", VF_VENDOR);
255 MODULE_INIT(ModuleOjoin)