1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 #include "configreader.h"
22 /* $ModDesc: Provides support for /KNOCK and mode +K */
24 /** Handles the /KNOCK command
26 class cmd_knock : public command_t
29 cmd_knock (InspIRCd* Instance) : command_t(Instance,"KNOCK", 0, 2)
31 this->source = "m_knock.so";
32 syntax = "<channel> <reason>";
35 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
37 chanrec* c = ServerInstance->FindChan(parameters[0]);
41 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
45 std::string line = "";
47 if (c->IsModeSet('K'))
49 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
53 for (int i = 1; i < pcnt - 1; i++)
55 line = line + std::string(parameters[i]) + " ";
57 line = line + std::string(parameters[pcnt-1]);
59 if (!c->modes[CM_INVITEONLY])
61 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
65 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "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 /** Handles channel mode +K
73 class Knock : public ModeHandler
76 Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
78 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
82 if (!channel->IsModeSet('K'))
84 channel->SetMode('K',true);
85 return MODEACTION_ALLOW;
90 if (channel->IsModeSet('K'))
92 channel->SetMode('K',false);
93 return MODEACTION_ALLOW;
97 return MODEACTION_DENY;
101 class ModuleKnock : public Module
103 cmd_knock* mycommand;
106 ModuleKnock(InspIRCd* Me) : Module::Module(Me)
109 kn = new Knock(ServerInstance);
110 if (!ServerInstance->AddMode(kn, 'K'))
111 throw ModuleException("Could not add new modes!");
112 mycommand = new cmd_knock(ServerInstance);
113 ServerInstance->AddCommand(mycommand);
116 void Implements(char* List)
120 virtual ~ModuleKnock()
122 ServerInstance->Modes->DelMode(kn);
126 virtual Version GetVersion()
128 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
132 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
134 class ModuleKnockFactory : public ModuleFactory
141 ~ModuleKnockFactory()
145 virtual Module * CreateModule(InspIRCd* Me)
147 return new ModuleKnock(Me);
153 extern "C" void * init_module( void )
155 return new ModuleKnockFactory;