1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 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 void handle_knock(char **parameters, int pcnt, userrec *user)
32 chanrec* c = Srv->FindChannel(parameters[0]);
33 std::string line = "";
35 for (int i = 1; i < pcnt - 1; i++)
37 line = line + std::string(parameters[i]) + " ";
39 line = line + std::string(parameters[pcnt-1]);
41 if (c->IsCustomModeSet('K'))
43 WriteServ(user->fd,"480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
46 if (c->binarymodes & CM_INVITEONLY)
48 WriteChannelWithServ((char*)Srv->GetServerName().c_str(),c,"NOTICE %s :User %s is KNOCKing on %s (%s)",c->name,user->nick,c->name,line.c_str());
49 WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name);
54 WriteServ(user->fd,"480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
60 class ModuleKnock : public Module
67 Srv->AddExtendedMode('K',MT_CHANNEL,false,0,0);
68 Srv->AddCommand("KNOCK",handle_knock,0,2,"m_knock.so");
71 virtual void On005Numeric(std::string &output)
73 std::stringstream line(output);
74 std::string temp1, temp2;
78 if (temp1.substr(0,10) == "CHANMODES=")
80 // append the chanmode to the end
81 temp1 = temp1.substr(10,temp1.length());
82 temp1 = "CHANMODES=" + temp1 + "K";
84 temp2 = temp2 + temp1 + " ";
88 output = temp2.substr(0,temp2.length()-1) + std::string(" KNOCK");
90 else output = output + std::string(" KNOCK");
93 virtual ~ModuleKnock()
98 virtual Version GetVersion()
100 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
103 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
105 // check if this is our mode character...
106 if ((modechar == 'K') && (type == MT_CHANNEL))
118 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
120 class ModuleKnockFactory : public ModuleFactory
127 ~ModuleKnockFactory()
131 virtual Module * CreateModule()
133 return new ModuleKnock;
139 extern "C" void * init_module( void )
141 return new ModuleKnockFactory;