1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
24 #include "configreader.h"
27 /* $ModDesc: Provides support for /KNOCK and mode +K */
29 /** Handles the /KNOCK command
31 class cmd_knock : public command_t
34 cmd_knock (InspIRCd* Instance) : command_t(Instance,"KNOCK", 0, 2)
36 this->source = "m_knock.so";
37 syntax = "<channel> <reason>";
40 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
42 chanrec* c = ServerInstance->FindChan(parameters[0]);
46 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
50 std::string line = "";
52 if (c->IsModeSet('K'))
54 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
58 for (int i = 1; i < pcnt - 1; i++)
60 line = line + std::string(parameters[i]) + " ";
62 line = line + std::string(parameters[pcnt-1]);
64 if (c->modes[CM_INVITEONLY])
66 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
67 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
72 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
80 /** Handles channel mode +K
82 class Knock : public ModeHandler
85 Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
87 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
91 if (!channel->IsModeSet('K'))
93 channel->SetMode('K',true);
94 return MODEACTION_ALLOW;
99 if (channel->IsModeSet('K'))
101 channel->SetMode('K',false);
102 return MODEACTION_ALLOW;
106 return MODEACTION_DENY;
110 class ModuleKnock : public Module
112 cmd_knock* mycommand;
115 ModuleKnock(InspIRCd* Me) : Module::Module(Me)
118 kn = new Knock(ServerInstance);
119 ServerInstance->AddMode(kn, 'K');
120 mycommand = new cmd_knock(ServerInstance);
121 ServerInstance->AddCommand(mycommand);
124 void Implements(char* List)
128 virtual ~ModuleKnock()
130 ServerInstance->Modes->DelMode(kn);
134 virtual Version GetVersion()
136 return Version(1,0,0,1,VF_COMMON|VF_VENDOR);
140 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
142 class ModuleKnockFactory : public ModuleFactory
149 ~ModuleKnockFactory()
153 virtual Module * CreateModule(InspIRCd* Me)
155 return new ModuleKnock(Me);
161 extern "C" void * init_module( void )
163 return new ModuleKnockFactory;