X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_knock.cpp;h=8d2aa4543065be26e7b410ef41007c6d664cd37d;hb=9c6a2d1b5ba5a2aeb91d00e1115534fbde670841;hp=84838ec7f5f2bcfaa5c85775338035033503530f;hpb=3af9c3f8950f864bcf9cdd56127cd4014827dece;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp index 84838ec7f..8d2aa4543 100644 --- a/src/modules/m_knock.cpp +++ b/src/modules/m_knock.cpp @@ -28,7 +28,9 @@ class CommandKnock : public Command { public: - CommandKnock(Module* Creator) : Command(Creator,"KNOCK", 2) + bool sendnotice; + bool sendnumeric; + CommandKnock(Module* Creator) : Command(Creator,"KNOCK", 2, 2) { syntax = " "; Penalty = 5; @@ -38,8 +40,6 @@ class CommandKnock : public Command CmdResult Handle (const std::vector ¶meters, User *user) { Channel* c = ServerInstance->FindChan(parameters[0]); - std::string line; - if (!c) { user->WriteNumeric(401, "%s %s :No such channel",user->nick.c_str(), parameters[0].c_str()); @@ -64,13 +64,12 @@ class CommandKnock : public Command return CMD_FAILURE; } - for (int i = 1; i < (int)parameters.size() - 1; i++) - { - line = line + parameters[i] + " "; - } - line = line + parameters[parameters.size()-1]; + if (sendnotice) + c->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), parameters[1].c_str()); + + if (sendnumeric) + c->WriteChannelWithServ(ServerInstance->Config->ServerName, "710 %s %s %s :is KNOCKing: %s", c->name.c_str(), c->name.c_str(), user->GetFullHost().c_str(), parameters[1].c_str()); - c->WriteChannelWithServ((char*)ServerInstance->Config->ServerName.c_str(), "NOTICE %s :User %s is KNOCKing on %s (%s)", c->name.c_str(), user->nick.c_str(), c->name.c_str(), line.c_str()); user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str()); return CMD_SUCCESS; } @@ -96,15 +95,37 @@ class ModuleKnock : public Module public: ModuleKnock() : cmd(this), kn(this) { - if (!ServerInstance->Modes->AddMode(&kn)) - throw ModuleException("Could not add new modes!"); - ServerInstance->AddCommand(&cmd); - } + void init() + { + ServerInstance->Modules->AddService(kn); + ServerInstance->Modules->AddService(cmd); + + ServerInstance->Modules->Attach(I_OnRehash, this); + OnRehash(NULL); + } - virtual ~ModuleKnock() + void OnRehash(User* user) { + std::string knocknotify = ServerInstance->Config->ConfValue("knock")->getString("notify"); + irc::string notify(knocknotify.c_str()); + + if (notify == "numeric") + { + cmd.sendnotice = false; + cmd.sendnumeric = true; + } + else if (notify == "both") + { + cmd.sendnotice = true; + cmd.sendnumeric = true; + } + else + { + cmd.sendnotice = true; + cmd.sendnumeric = false; + } } virtual Version GetVersion()