1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides support for /KNOCK and mode +K */
18 /** Handles the /KNOCK command
20 class CommandKnock : public Command
23 CommandKnock (InspIRCd* Instance) : Command(Instance,"KNOCK", 0, 2)
25 this->source = "m_knock.so";
26 syntax = "<channel> <reason>";
27 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
30 CmdResult Handle (const std::vector<std::string> ¶meters, User *user)
32 Channel* c = ServerInstance->FindChan(parameters[0]);
37 user->WriteNumeric(401, "%s %s :No such channel",user->nick.c_str(), parameters[0].c_str());
43 user->WriteNumeric(480, "%s :Can't KNOCK on %s, you are already on that channel.", user->nick.c_str(), c->name.c_str());
47 if (c->IsModeSet('K'))
49 user->WriteNumeric(480, "%s :Can't KNOCK on %s, +K is set.",user->nick.c_str(), c->name.c_str());
53 if (!c->modes[CM_INVITEONLY])
55 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());
59 for (int i = 1; i < (int)parameters.size() - 1; i++)
61 line = line + parameters[i] + " ";
63 line = line + parameters[parameters.size()-1];
65 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), line.c_str());
66 user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str());
71 /** Handles channel mode +K
73 class Knock : public SimpleChannelModeHandler
76 Knock(InspIRCd* Instance) : SimpleChannelModeHandler(Instance, 'K') { }
79 class ModuleKnock : public Module
81 CommandKnock* mycommand;
84 ModuleKnock(InspIRCd* Me) : Module(Me)
86 kn = new Knock(ServerInstance);
88 if (!ServerInstance->Modes->AddMode(kn))
89 throw ModuleException("Could not add new modes!");
91 mycommand = new CommandKnock(ServerInstance);
92 ServerInstance->AddCommand(mycommand);
97 virtual ~ModuleKnock()
99 ServerInstance->Modes->DelMode(kn);
103 virtual Version GetVersion()
105 return Version("$Id$", VF_COMMON | VF_VENDOR, API_VERSION);
109 MODULE_INIT(ModuleKnock)