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 */
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 class Knock : public ModeHandler
83 Knock(InspIRCd* Instance) : ModeHandler(Instance, '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(InspIRCd* Me) : Module::Module(Me)
116 kn = new Knock(ServerInstance);
117 ServerInstance->AddMode(kn, 'K');
118 mycommand = new cmd_knock(ServerInstance);
119 ServerInstance->AddCommand(mycommand);
122 void Implements(char* List)
126 virtual ~ModuleKnock()
128 ServerInstance->Modes->DelMode(kn);
132 virtual Version GetVersion()
134 return Version(1,0,0,1,VF_COMMON|VF_VENDOR);
138 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
140 class ModuleKnockFactory : public ModuleFactory
147 ~ModuleKnockFactory()
151 virtual Module * CreateModule(InspIRCd* Me)
153 return new ModuleKnock(Me);
159 extern "C" void * init_module( void )
161 return new ModuleKnockFactory;