2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Taros <taros34@hotmail.com>
5 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
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 #define NETWORK_VALUE 9000000
26 class CommandOjoin : public SplitCommand
33 CommandOjoin(Module* parent) :
34 SplitCommand(parent, "OJOIN", 1)
36 flags_needed = 'o'; Penalty = 0; syntax = "<channel>";
40 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
42 // Make sure the channel name is allowable.
43 if (!ServerInstance->IsChannel(parameters[0]))
45 user->WriteNotice("*** Invalid characters in channel name or name too long");
50 // override is false because we want OnUserPreJoin to run
51 Channel* channel = Channel::JoinUser(user, parameters[0], false);
56 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN to join "+channel->name);
60 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s joined on official network business.",
61 parameters[0].c_str(), user->nick.c_str());
62 ServerInstance->PI->SendChannelNotice(channel, 0, user->nick + " joined on official network business.");
67 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN in "+parameters[0]);
68 // they're already in the channel
69 std::vector<std::string> modes;
70 modes.push_back(parameters[0]);
71 modes.push_back(std::string("+") + npmh->GetModeChar());
74 modes[1].push_back('o');
75 modes.push_back(user->nick);
77 modes.push_back(user->nick);
78 ServerInstance->Modes->Process(modes, ServerInstance->FakeClient);
86 class NetworkPrefix : public PrefixMode
89 NetworkPrefix(Module* parent, char NPrefix)
90 : PrefixMode(parent, "official-join", 'Y', NETWORK_VALUE, NPrefix)
92 levelrequired = INT_MAX;
95 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
97 User* theuser = ServerInstance->FindNick(parameter);
99 if (source == theuser && !adding)
100 return MOD_RES_ALLOW;
102 return MOD_RES_PASSTHRU;
106 class ModuleOjoin : public Module
109 CommandOjoin mycommand;
114 : np(NULL), mycommand(this)
118 void init() CXX11_OVERRIDE
120 std::string npre = ServerInstance->Config->ConfValue("ojoin")->getString("prefix");
121 char NPrefix = npre.empty() ? 0 : npre[0];
123 /* Initialise module variables */
124 np = new NetworkPrefix(this, NPrefix);
127 ServerInstance->Modules->AddService(*np);
130 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
132 if (mycommand.active)
134 privs += np->GetModeChar();
137 return MOD_RES_ALLOW;
140 return MOD_RES_PASSTHRU;
143 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
145 ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
146 mycommand.notice = Conf->getBool("notice", true);
147 mycommand.op = Conf->getBool("op", true);
150 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
152 // Don't do anything if they're not +Y
153 if (!memb->hasMode(np->GetModeChar()))
154 return MOD_RES_PASSTHRU;
156 // Let them do whatever they want to themselves.
157 if (source == memb->user)
158 return MOD_RES_PASSTHRU;
160 source->WriteNumeric(ERR_RESTRICTED, memb->chan->name+" :Can't kick "+memb->user->nick+" as they're on official network business.");
171 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
174 Version GetVersion() CXX11_OVERRIDE
176 return Version("Network Business Join", VF_VENDOR);
180 MODULE_INIT(ModuleOjoin)