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 * ---------------------------------------------------
22 #include "helperfuncs.h"
24 /* $ModDesc: Provides support for /KNOCK and mode +K */
28 void handle_knock(char **parameters, int pcnt, userrec *user)
30 chanrec* c = Srv->FindChannel(parameters[0]);
31 std::string line = "";
33 for (int i = 1; i < pcnt - 1; i++)
35 line = line + std::string(parameters[i]) + " ";
37 line = line + std::string(parameters[pcnt-1]);
39 if (c->IsCustomModeSet('K'))
41 WriteServ(user->fd,"480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
44 if (c->binarymodes & CM_INVITEONLY)
46 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());
47 WriteServ(user->fd,"NOTICE %s :KNOCKing on %s",user->nick,c->name);
52 WriteServ(user->fd,"480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
58 class ModuleKnock : public Module
65 Srv->AddExtendedMode('K',MT_CHANNEL,false,0,0);
66 Srv->AddCommand("KNOCK",handle_knock,0,2,"m_knock.so");
69 virtual void On005Numeric(std::string &output)
71 std::stringstream line(output);
72 std::string temp1, temp2;
76 if (temp1.substr(0,10) == "CHANMODES=")
78 // append the chanmode to the end
79 temp1 = temp1.substr(10,temp1.length());
80 temp1 = "CHANMODES=" + temp1 + "K";
82 temp2 = temp2 + temp1 + " ";
86 output = temp2.substr(0,temp2.length()-1) + std::string(" KNOCK");
88 else output = output + std::string(" KNOCK");
91 virtual ~ModuleKnock()
96 virtual Version GetVersion()
98 return Version(1,0,0,1,VF_STATIC|VF_VENDOR);
101 virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list ¶ms)
103 // check if this is our mode character...
104 if ((modechar == 'K') && (type == MT_CHANNEL))
116 // stuff down here is the module-factory stuff. For basic modules you can ignore this.
118 class ModuleKnockFactory : public ModuleFactory
125 ~ModuleKnockFactory()
129 virtual Module * CreateModule()
131 return new ModuleKnock;
137 extern "C" void * init_module( void )
139 return new ModuleKnockFactory;