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"
26 /* $ModDesc: Provides support for /KNOCK and mode +K */
30 class cmd_knock : public command_t
33 cmd_knock () : command_t("KNOCK", 0, 2)
35 this->source = "m_knock.so";
36 syntax = "<channel> <reason>";
39 void Handle (const char** parameters, int pcnt, userrec *user)
41 chanrec* c = Srv->FindChannel(parameters[0]);
45 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
49 std::string line = "";
51 if (c->IsModeSet('K'))
53 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
57 for (int i = 1; i < pcnt - 1; i++)
59 line = line + std::string(parameters[i]) + " ";
61 line = line + std::string(parameters[pcnt-1]);
63 if (c->modes[CM_INVITEONLY])
65 c->WriteChannelWithServ((char*)Srv->GetServerName().c_str(), "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
66 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
71 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
77 class Knock : public ModeHandler
80 Knock() : ModeHandler('K', 0, 0, false, MODETYPE_CHANNEL, false) { }
82 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
86 if (!channel->IsModeSet('K'))
88 channel->SetMode('K',true);
89 return MODEACTION_ALLOW;
94 if (channel->IsModeSet('K'))
96 channel->SetMode('K',false);
97 return MODEACTION_ALLOW;
101 return MODEACTION_DENY;
105 class ModuleKnock : public Module
107 cmd_knock* mycommand;
110 ModuleKnock(Server* Me) : Module::Module(Me)
114 Srv->AddMode(kn, 'K');
115 mycommand = new cmd_knock();
116 Srv->AddCommand(mycommand);
119 void Implements(char* List)
121 List[I_On005Numeric] = 1;
124 virtual void On005Numeric(std::string &output)
126 InsertMode(output,"K",4);
129 virtual ~ModuleKnock()
134 virtual Version GetVersion()
136 return Version(1,0,0,1,VF_STATIC|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(Server* Me)
155 return new ModuleKnock(Me);
161 extern "C" void * init_module( void )
163 return new ModuleKnockFactory;