2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 Robby <robby@chatbelgie.be>
5 * Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012-2014, 2016 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
10 * This file is part of InspIRCd. InspIRCd is free software: you can
11 * redistribute it and/or modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation, version 2.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #define NETWORK_VALUE 9000000
29 class CommandOjoin : public SplitCommand
36 CommandOjoin(Module* parent, ModeHandler& mode)
37 : SplitCommand(parent, "OJOIN", 1)
45 CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE
47 // Make sure the channel name is allowable.
48 if (!ServerInstance->IsChannel(parameters[0]))
50 user->WriteNotice("*** Invalid characters in channel name or name too long");
55 // override is false because we want OnUserPreJoin to run
56 Channel* channel = Channel::JoinUser(user, parameters[0], false);
61 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN to join "+channel->name);
64 channel->WriteRemoteNotice(user->nick + " joined on official network business.");
68 channel = ServerInstance->FindChan(parameters[0]);
72 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN in "+parameters[0]);
73 // they're already in the channel
74 Modes::ChangeList changelist;
75 changelist.push_add(npmh, user->nick);
77 changelist.push_add(ServerInstance->Modes->FindMode('o', MODETYPE_CHANNEL), user->nick);
78 ServerInstance->Modes->Process(ServerInstance->FakeClient, channel, NULL, changelist);
86 class NetworkPrefix : public PrefixMode
89 NetworkPrefix(Module* parent, char NPrefix)
90 : PrefixMode(parent, "official-join", 'Y', NETWORK_VALUE, NPrefix)
92 ranktoset = ranktounset = UINT_MAX;
95 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding) CXX11_OVERRIDE
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(this, ServerInstance->Config->ConfValue("ojoin")->getString("prefix").c_str()[0])
115 , mycommand(this, np)
119 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
121 if (mycommand.active)
123 privs += np.GetModeChar();
126 return MOD_RES_ALLOW;
129 return MOD_RES_PASSTHRU;
132 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
134 ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
135 mycommand.notice = Conf->getBool("notice", true);
136 mycommand.op = Conf->getBool("op", true);
139 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
141 // Don't do anything if they're not +Y
142 if (!memb->HasMode(&np))
143 return MOD_RES_PASSTHRU;
145 // Let them do whatever they want to themselves.
146 if (source == memb->user)
147 return MOD_RES_PASSTHRU;
149 source->WriteNumeric(ERR_RESTRICTED, memb->chan->name, "Can't kick "+memb->user->nick+" as they're on official network business.");
153 void Prioritize() CXX11_OVERRIDE
155 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
158 Version GetVersion() CXX11_OVERRIDE
160 return Version("Provides the OJOIN command, allows an oper to join a channel and be immune to kicks", VF_VENDOR);
164 MODULE_INIT(ModuleOjoin)