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 /* $ModDesc: Provides support for /KNOCK and channel mode +K */
26 /** Handles the /KNOCK command
28 class CommandKnock : public Command
31 CommandKnock(Module* Creator) : Command(Creator,"KNOCK", 2)
33 syntax = "<channel> <reason>";
35 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
38 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
40 Channel* c = ServerInstance->FindChan(parameters[0]);
45 user->WriteNumeric(401, "%s %s :No such channel",user->nick.c_str(), parameters[0].c_str());
51 user->WriteNumeric(480, "%s :Can't KNOCK on %s, you are already on that channel.", user->nick.c_str(), c->name.c_str());
55 if (c->IsModeSet('K'))
57 user->WriteNumeric(480, "%s :Can't KNOCK on %s, +K is set.",user->nick.c_str(), c->name.c_str());
61 if (!c->IsModeSet('i'))
63 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());
67 for (int i = 1; i < (int)parameters.size() - 1; i++)
69 line = line + parameters[i] + " ";
71 line = line + parameters[parameters.size()-1];
73 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), line.c_str());
74 user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str());
78 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
80 return ROUTE_OPT_BCAST;
84 /** Handles channel mode +K
86 class Knock : public SimpleChannelModeHandler
89 Knock(Module* Creator) : SimpleChannelModeHandler(Creator, "noknock", 'K') { }
92 class ModuleKnock : public Module
97 ModuleKnock() : cmd(this), kn(this)
99 if (!ServerInstance->Modes->AddMode(&kn))
100 throw ModuleException("Could not add new modes!");
101 ServerInstance->AddCommand(&cmd);
106 virtual ~ModuleKnock()
110 virtual Version GetVersion()
112 return Version("Provides support for /KNOCK and channel mode +K", VF_OPTCOMMON | VF_VENDOR);
116 MODULE_INIT(ModuleKnock)