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 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
62 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
67 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
75 /** Handles channel mode +K
77 class Knock : public ModeHandler
80 Knock(InspIRCd* Instance) : ModeHandler(Instance, '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(InspIRCd* Me) : Module::Module(Me)
113 kn = new Knock(ServerInstance);
114 if (!ServerInstance->AddMode(kn, 'K'))
115 throw ModuleException("Could not add new modes!");
116 mycommand = new cmd_knock(ServerInstance);
117 ServerInstance->AddCommand(mycommand);
120 void Implements(char* List)
124 virtual ~ModuleKnock()
126 ServerInstance->Modes->DelMode(kn);
130 virtual Version GetVersion()
132 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
136 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
138 class ModuleKnockFactory : public ModuleFactory
145 ~ModuleKnockFactory()
149 virtual Module * CreateModule(InspIRCd* Me)
151 return new ModuleKnock(Me);
157 extern "C" void * init_module( void )
159 return new ModuleKnockFactory;