00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "inspircd.h"
00015 #include "users.h"
00016 #include "channels.h"
00017 #include "modules.h"
00018
00019
00020
00023 class cmd_knock : public command_t
00024 {
00025 public:
00026 cmd_knock (InspIRCd* Instance) : command_t(Instance,"KNOCK", 0, 2)
00027 {
00028 this->source = "m_knock.so";
00029 syntax = "<channel> <reason>";
00030 }
00031
00032 CmdResult Handle (const char** parameters, int pcnt, userrec *user)
00033 {
00034 chanrec* c = ServerInstance->FindChan(parameters[0]);
00035 std::string line;
00036
00037 if (!c)
00038 {
00039 user->WriteServ("401 %s %s :No such channel",user->nick, parameters[0]);
00040 return CMD_FAILURE;
00041 }
00042
00043 if (c->HasUser(user))
00044 {
00045 user->WriteServ("480 %s :Can't KNOCK on %s, you are already on that channel.", user->nick, c->name);
00046 return CMD_FAILURE;
00047 }
00048
00049 if (c->IsModeSet('K'))
00050 {
00051 user->WriteServ("480 %s :Can't KNOCK on %s, +K is set.",user->nick, c->name);
00052 return CMD_FAILURE;
00053 }
00054
00055 if (!c->modes[CM_INVITEONLY])
00056 {
00057 user->WriteServ("480 %s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick, c->name);
00058 return CMD_FAILURE;
00059 }
00060
00061 for (int i = 1; i < pcnt - 1; i++)
00062 {
00063 line = line + std::string(parameters[i]) + " ";
00064 }
00065 line = line + std::string(parameters[pcnt-1]);
00066
00067 c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name, user->nick, c->name, line.c_str());
00068 user->WriteServ("NOTICE %s :KNOCKing on %s",user->nick,c->name);
00069 return CMD_SUCCESS;
00070 }
00071 };
00072
00075 class Knock : public ModeHandler
00076 {
00077 public:
00078 Knock(InspIRCd* Instance) : ModeHandler(Instance, 'K', 0, 0, false, MODETYPE_CHANNEL, false) { }
00079
00080 ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)
00081 {
00082 if (adding)
00083 {
00084 if (!channel->IsModeSet('K'))
00085 {
00086 channel->SetMode('K',true);
00087 return MODEACTION_ALLOW;
00088 }
00089 }
00090 else
00091 {
00092 if (channel->IsModeSet('K'))
00093 {
00094 channel->SetMode('K',false);
00095 return MODEACTION_ALLOW;
00096 }
00097 }
00098
00099 return MODEACTION_DENY;
00100 }
00101 };
00102
00103 class ModuleKnock : public Module
00104 {
00105 cmd_knock* mycommand;
00106 Knock* kn;
00107 public:
00108 ModuleKnock(InspIRCd* Me) : Module(Me)
00109 {
00110
00111 kn = new Knock(ServerInstance);
00112 if (!ServerInstance->AddMode(kn, 'K'))
00113 throw ModuleException("Could not add new modes!");
00114 mycommand = new cmd_knock(ServerInstance);
00115 ServerInstance->AddCommand(mycommand);
00116 }
00117
00118 void Implements(char* List)
00119 {
00120 }
00121
00122 virtual ~ModuleKnock()
00123 {
00124 ServerInstance->Modes->DelMode(kn);
00125 DELETE(kn);
00126 }
00127
00128 virtual Version GetVersion()
00129 {
00130 return Version(1, 1, 0, 1, VF_COMMON | VF_VENDOR, API_VERSION);
00131 }
00132 };
00133
00134 MODULE_INIT(ModuleKnock)