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 "helperfuncs.h"
25 #include "configreader.h"
28 /* $ModDesc: Provides support for /KNOCK and mode +K */
31 extern InspIRCd* ServerInstance;
33 class cmd_knock : public command_t
36 cmd_knock () : command_t("KNOCK", 0, 2)
38 this->source = "m_knock.so";
39 syntax = "<channel> <reason>";
42 void Handle (const char** parameters, int pcnt, userrec *user)
44 chanrec* c = ServerInstance->FindChan(parameters[0]);
48 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
52 std::string line = "";
54 if (c->IsModeSet('K'))
56 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
60 for (int i = 1; i < pcnt - 1; i++)
62 line = line + std::string(parameters[i]) + " ";
64 line = line + std::string(parameters[pcnt-1]);
66 if (c->modes[CM_INVITEONLY])
68 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
69 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
74 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
80 class Knock : public ModeHandler
83 Knock() : ModeHandler('K', 0, 0, false, MODETYPE_CHANNEL, false) { }
85 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
89 if (!channel->IsModeSet('K'))
91 channel->SetMode('K',true);
92 return MODEACTION_ALLOW;
97 if (channel->IsModeSet('K'))
99 channel->SetMode('K',false);
100 return MODEACTION_ALLOW;
104 return MODEACTION_DENY;
108 class ModuleKnock : public Module
110 cmd_knock* mycommand;
113 ModuleKnock(Server* Me) : Module::Module(Me)
117 Srv->AddMode(kn, 'K');
118 mycommand = new cmd_knock();
119 Srv->AddCommand(mycommand);
122 void Implements(char* List)
124 List[I_On005Numeric] = 1;
127 virtual void On005Numeric(std::string &output)
129 InsertMode(output,"K",4);
132 virtual ~ModuleKnock()
137 virtual Version GetVersion()
139 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
143 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
145 class ModuleKnockFactory : public ModuleFactory
152 ~ModuleKnockFactory()
156 virtual Module * CreateModule(Server* Me)
158 return new ModuleKnock(Me);
164 extern "C" void * init_module( void )
166 return new ModuleKnockFactory;