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 * ---------------------------------------------------
25 #include "configreader.h"
28 /* $ModDesc: Provides support for /KNOCK and mode +K */
32 class cmd_knock : public command_t
35 cmd_knock (InspIRCd* Instance) : command_t(Instance,"KNOCK", 0, 2)
37 this->source = "m_knock.so";
38 syntax = "<channel> <reason>";
41 void Handle (const char** parameters, int pcnt, userrec *user)
43 chanrec* c = ServerInstance->FindChan(parameters[0]);
47 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
51 std::string line = "";
53 if (c->IsModeSet('K'))
55 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
59 for (int i = 1; i < pcnt - 1; i++)
61 line = line + std::string(parameters[i]) + " ";
63 line = line + std::string(parameters[pcnt-1]);
65 if (c->modes[CM_INVITEONLY])
67 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
68 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
73 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
79 class Knock : public ModeHandler
82 Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
84 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
88 if (!channel->IsModeSet('K'))
90 channel->SetMode('K',true);
91 return MODEACTION_ALLOW;
96 if (channel->IsModeSet('K'))
98 channel->SetMode('K',false);
99 return MODEACTION_ALLOW;
103 return MODEACTION_DENY;
107 class ModuleKnock : public Module
109 cmd_knock* mycommand;
112 ModuleKnock(InspIRCd* Me) : Module::Module(Me)
115 kn = new Knock(ServerInstance);
116 ServerInstance->AddMode(kn, 'K');
117 mycommand = new cmd_knock(ServerInstance);
118 ServerInstance->AddCommand(mycommand);
121 void Implements(char* List)
123 List[I_On005Numeric] = 1;
126 virtual void On005Numeric(std::string &output)
128 ServerInstance->Modes->InsertMode(output,"K",4);
131 virtual ~ModuleKnock()
136 virtual Version GetVersion()
138 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
142 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
144 class ModuleKnockFactory : public ModuleFactory
151 ~ModuleKnockFactory()
155 virtual Module * CreateModule(InspIRCd* Me)
157 return new ModuleKnock(Me);
163 extern "C" void * init_module( void )
165 return new ModuleKnockFactory;