1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
16 /* $ModDesc: Provides support for /KNOCK and mode +K */
18 /** Handles the /KNOCK command
20 class CommandKnock : public Command
23 CommandKnock (InspIRCd* Instance) : Command(Instance,"KNOCK", 0, 2)
25 this->source = "m_knock.so";
26 syntax = "<channel> <reason>";
27 TRANSLATE3(TR_TEXT, TR_TEXT, TR_END);
30 CmdResult Handle (const char* const* parameters, int pcnt, User *user)
32 Channel* c = ServerInstance->FindChan(parameters[0]);
37 user->WriteNumeric(401, "%s %s :No such channel",user->nick, parameters[0]);
43 user->WriteNumeric(480, "%s :Can't KNOCK on %s, you are already on that channel.", user->nick, c->name);
47 if (c->IsModeSet('K'))
49 user->WriteNumeric(480, "%s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
53 if (!c->modes[CM_INVITEONLY])
55 user->WriteNumeric(480, "%s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
59 for (int i = 1; i < pcnt - 1; i++)
61 line = line + std::string(parameters[i]) + " ";
63 line = line + std::string(parameters[pcnt-1]);
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(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
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 CommandKnock* mycommand;
106 ModuleKnock(InspIRCd* Me) : Module(Me)
108 kn = new Knock(ServerInstance);
110 if (!ServerInstance->Modes->AddMode(kn))
111 throw ModuleException("Could not add new modes!");
113 mycommand = new CommandKnock(ServerInstance);
114 ServerInstance->AddCommand(mycommand);
119 virtual ~ModuleKnock()
121 ServerInstance->Modes->DelMode(kn);
125 virtual Version GetVersion()
127 return Version(1, 2, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
131 MODULE_INIT(ModuleKnock)