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
30 class CommandOjoin : public SplitCommand
34 CommandOjoin(Module* parent) :
35 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 = ServerInstance->FindChan(parameters[0]);
62 channel->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s joined on official network business.",
63 parameters[0].c_str(), user->nick.c_str());
64 ServerInstance->PI->SendChannelNotice(channel, 0, user->nick + " joined on official network business.");
69 ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used OJOIN in "+parameters[0]);
70 // they're already in the channel
71 std::vector<std::string> modes;
72 modes.push_back(parameters[0]);
73 modes.push_back(op ? "+Yo" : "+Y");
74 modes.push_back(user->nick);
76 modes.push_back(user->nick);
77 ServerInstance->Modes->Process(modes, ServerInstance->FakeClient);
85 class NetworkPrefix : public ModeHandler
88 NetworkPrefix(Module* parent) : ModeHandler(parent, "official-join", 'Y', PARAM_ALWAYS, MODETYPE_CHANNEL)
92 levelrequired = INT_MAX;
93 m_paramtype = TR_NICK;
94 prefixrank = NETWORK_VALUE;
97 ModResult AccessCheck(User* source, Channel* channel, std::string ¶meter, bool adding)
99 User* theuser = ServerInstance->FindNick(parameter);
101 if (source == theuser && !adding)
102 return MOD_RES_ALLOW;
104 return MOD_RES_PASSTHRU;
107 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
109 return MODEACTION_ALLOW;
114 class ModuleOjoin : public Module
117 CommandOjoin mycommand;
122 : np(NULL), mycommand(this)
126 void init() CXX11_OVERRIDE
128 /* Load config stuff */
131 /* Initialise module variables */
132 np = new NetworkPrefix(this);
134 ServerInstance->Modules->AddService(*np);
135 ServerInstance->Modules->AddService(mycommand);
137 Implementation eventlist[] = { I_OnUserPreJoin, I_OnUserPreKick, I_OnRehash };
138 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
141 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
143 if (mycommand.active)
148 return MOD_RES_ALLOW;
151 return MOD_RES_PASSTHRU;
154 void OnRehash(User* user) CXX11_OVERRIDE
156 ConfigTag* Conf = ServerInstance->Config->ConfValue("ojoin");
160 // This is done on module load only
161 std::string npre = Conf->getString("prefix");
162 NPrefix = npre.empty() ? 0 : npre[0];
164 if (NPrefix && ServerInstance->Modes->FindPrefix(NPrefix))
165 throw ModuleException("Looks like the +Y prefix you picked for m_ojoin is already in use. Pick another.");
168 notice = Conf->getBool("notice", true);
169 op = Conf->getBool("op", true);
172 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
174 // Don't do anything if they're not +Y
175 if (!memb->hasMode('Y'))
176 return MOD_RES_PASSTHRU;
178 // Let them do whatever they want to themselves.
179 if (source == memb->user)
180 return MOD_RES_PASSTHRU;
182 source->WriteNumeric(484, source->nick+" "+memb->chan->name+" :Can't kick "+memb->user->nick+" as they're on official network business.");
193 ServerInstance->Modules->SetPriority(this, I_OnUserPreJoin, PRIORITY_FIRST);
196 Version GetVersion() CXX11_OVERRIDE
198 return Version("Network Business Join", VF_VENDOR);
202 MODULE_INIT(ModuleOjoin)