2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2004-2006, 2008 Craig Edwards <craigedwards@brainbox.cc>
5 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /** Handles the /KNOCK command
26 class CommandKnock : public Command
28 SimpleChannelModeHandler& noknockmode;
29 ChanModeReference inviteonlymode;
34 CommandKnock(Module* Creator, SimpleChannelModeHandler& Noknockmode)
35 : Command(Creator,"KNOCK", 2, 2)
36 , noknockmode(Noknockmode)
37 , inviteonlymode(Creator, "inviteonly")
39 syntax = "<channel> <reason>";
43 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
45 Channel* c = ServerInstance->FindChan(parameters[0]);
48 user->WriteNumeric(401, "%s %s :No such channel",user->nick.c_str(), parameters[0].c_str());
54 user->WriteNumeric(480, "%s :Can't KNOCK on %s, you are already on that channel.", user->nick.c_str(), c->name.c_str());
58 if (c->IsModeSet(noknockmode))
60 user->WriteNumeric(480, "%s :Can't KNOCK on %s, +K is set.",user->nick.c_str(), c->name.c_str());
64 if (!c->IsModeSet(inviteonlymode))
66 user->WriteNumeric(480, "%s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick.c_str(), c->name.c_str());
71 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), parameters[1].c_str());
74 c->WriteChannelWithServ(ServerInstance->Config->ServerName, "710 %s %s %s :is KNOCKing: %s", c->name.c_str(), c->name.c_str(), user->GetFullHost().c_str(), parameters[1].c_str());
76 user->WriteNotice("KNOCKing on " + c->name);
80 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
82 return ROUTE_OPT_BCAST;
86 class ModuleKnock : public Module
88 SimpleChannelModeHandler kn;
93 : kn(this, "noknock", 'K')
98 void init() CXX11_OVERRIDE
100 ServerInstance->Modules->AddService(kn);
101 ServerInstance->Modules->AddService(cmd);
106 void OnRehash(User* user) CXX11_OVERRIDE
108 std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify");
109 irc::string notify(knocknotify.c_str());
111 if (notify == "numeric")
113 cmd.sendnotice = false;
114 cmd.sendnumeric = true;
116 else if (notify == "both")
118 cmd.sendnotice = true;
119 cmd.sendnumeric = true;
123 cmd.sendnotice = true;
124 cmd.sendnumeric = false;
128 Version GetVersion() CXX11_OVERRIDE
130 return Version("Provides support for /KNOCK and channel mode +K", VF_OPTCOMMON | VF_VENDOR);
134 MODULE_INIT(ModuleKnock)