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, ModeHandler& mode)
34 : SplitCommand(parent, "OJOIN", 1)
37 flags_needed = 'o'; Penalty = 0; syntax = "<channel>";
41 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
43 // Make sure the channel name is allowable.
44 if (!ServerInstance->IsChannel(parameters[0]))
46 user->WriteNotice("*** Invalid characters in channel name or name too long");
51 // override is false because we want OnUserPreJoin to run
52 Channel* channel = Channel::JoinUser(user, parameters[0], false);
57 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN to join "+channel->name);
61 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s joined on official network business.",
62 parameters[0].c_str(), user->nick.c_str());
63 ServerInstance->PI->SendChannelNotice(channel, 0, user->nick + " joined on official network business.");
68 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN in "+parameters[0]);
69 // they're already in the channel
70 std::vector<std::string> modes;
71 modes.push_back(parameters[0]);
72 modes.push_back(std::string("+") + npmh->GetModeChar());
75 modes[1].push_back('o');
76 modes.push_back(user->nick);
78 modes.push_back(user->nick);
79 ServerInstance->Modes->Process(modes, ServerInstance->FakeClient);
87 class NetworkPrefix : public PrefixMode
90 NetworkPrefix(Module* parent, char NPrefix)
91 : PrefixMode(parent, "official-join", 'Y', NETWORK_VALUE, NPrefix)
93 levelrequired = INT_MAX;
96 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
98 User* theuser = ServerInstance->FindNick(parameter);
100 if (source == theuser && !adding)
101 return MOD_RES_ALLOW;
103 return MOD_RES_PASSTHRU;
107 class ModuleOjoin : public Module
110 CommandOjoin mycommand;
115 : np(this, ServerInstance->Config->ConfValue("ojoin")->getString("prefix").c_str()[0])
116 , mycommand(this, np)
120 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
122 if (mycommand.active)
124 privs += np.GetModeChar();
127 return MOD_RES_ALLOW;
130 return MOD_RES_PASSTHRU;
133 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
135 ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
136 mycommand.notice = Conf->getBool("notice", true);
137 mycommand.op = Conf->getBool("op", true);
140 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
142 // Don't do anything if they're not +Y
143 if (!memb->hasMode(np.GetModeChar()))
144 return MOD_RES_PASSTHRU;
146 // Let them do whatever they want to themselves.
147 if (source == memb->user)
148 return MOD_RES_PASSTHRU;
150 source->WriteNumeric(ERR_RESTRICTED, memb->chan->name+" :Can't kick "+memb->user->nick+" as they're on official network business.");
156 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
159 Version GetVersion() CXX11_OVERRIDE
161 return Version("Network Business Join", VF_VENDOR);
165 MODULE_INIT(ModuleOjoin)