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 /* $ModDesc: Provides support for /KNOCK and mode +K */
21 /** Handles the /KNOCK command
23 class cmd_knock : public command_t
26 cmd_knock (InspIRCd* Instance) : command_t(Instance,"KNOCK", 0, 2)
28 this->source = "m_knock.so";
29 syntax = "<channel> <reason>";
32 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
34 chanrec* c = ServerInstance->FindChan(parameters[0]);
38 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
42 std::string line = "";
44 if (c->IsModeSet('K'))
46 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
50 for (int i = 1; i < pcnt - 1; i++)
52 line = line + std::string(parameters[i]) + " ";
54 line = line + std::string(parameters[pcnt-1]);
56 if (!c->modes[CM_INVITEONLY])
58 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
62 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
63 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
68 /** Handles channel mode +K
70 class Knock : public ModeHandler
73 Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
75 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
79 if (!channel->IsModeSet('K'))
81 channel->SetMode('K',true);
82 return MODEACTION_ALLOW;
87 if (channel->IsModeSet('K'))
89 channel->SetMode('K',false);
90 return MODEACTION_ALLOW;
94 return MODEACTION_DENY;
98 class ModuleKnock : public Module
100 cmd_knock* mycommand;
103 ModuleKnock(InspIRCd* Me) : Module(Me)
106 kn = new Knock(ServerInstance);
107 if (!ServerInstance->AddMode(kn, 'K'))
108 throw ModuleException("Could not add new modes!");
109 mycommand = new cmd_knock(ServerInstance);
110 ServerInstance->AddCommand(mycommand);
113 void Implements(char* List)
117 virtual ~ModuleKnock()
119 ServerInstance->Modes->DelMode(kn);
123 virtual Version GetVersion()
125 return Version(1,1,0,1,VF_COMMON|VF_VENDOR,API_VERSION);
129 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
131 class ModuleKnockFactory : public ModuleFactory
138 ~ModuleKnockFactory()
142 virtual Module * CreateModule(InspIRCd* Me)
144 return new ModuleKnock(Me);
150 extern "C" DllExport void * init_module( void )
152 return new ModuleKnockFactory;