1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/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 cmd_knock : public command_t
23 cmd_knock (InspIRCd* Instance) : command_t(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 char** parameters, int pcnt, userrec *user)
32 chanrec* c = ServerInstance->FindChan(parameters[0]);
36 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
42 if (c->IsModeSet('K'))
44 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
48 for (int i = 1; i < pcnt - 1; i++)
50 line = line + std::string(parameters[i]) + " ";
52 line = line + std::string(parameters[pcnt-1]);
54 if (!c->modes[CM_INVITEONLY])
56 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
60 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
61 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
66 /** Handles channel mode +K
68 class Knock : public ModeHandler
71 Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
73 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
77 if (!channel->IsModeSet('K'))
79 channel->SetMode('K',true);
80 return MODEACTION_ALLOW;
85 if (channel->IsModeSet('K'))
87 channel->SetMode('K',false);
88 return MODEACTION_ALLOW;
92 return MODEACTION_DENY;
96 class ModuleKnock : public Module
101 ModuleKnock(InspIRCd* Me) : Module(Me)
103 kn = new Knock(ServerInstance);
105 if (!ServerInstance->AddMode(kn, 'K'))
106 throw ModuleException("Could not add new modes!");
108 mycommand = new cmd_knock(ServerInstance);
109 ServerInstance->AddCommand(mycommand);
112 void Implements(char* List)
116 virtual ~ModuleKnock()
118 ServerInstance->Modes->DelMode(kn);
122 virtual Version GetVersion()
124 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
128 MODULE_INIT(ModuleKnock)