]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_knock.cpp
Merge pull request #1157 from SaberUK/insp20+fix-cron-restart
[user/henk/code/inspircd.git] / src / modules / m_knock.cpp
index 8cd5088bcff0033feeba4366eb89f1740e790e3b..8d2aa4543065be26e7b410ef41007c6d664cd37d 100644 (file)
@@ -28,6 +28,8 @@
 class CommandKnock : public Command
 {
  public:
+       bool sendnotice;
+       bool sendnumeric;
        CommandKnock(Module* Creator) : Command(Creator,"KNOCK", 2, 2)
        {
                syntax = "<channel> <reason>";
@@ -62,7 +64,12 @@ class CommandKnock : public Command
                        return CMD_FAILURE;
                }
 
-               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 (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());
+
                user->WriteServ("NOTICE %s :KNOCKing on %s", user->nick.c_str(), c->name.c_str());
                return CMD_SUCCESS;
        }
@@ -88,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);
 
-       virtual ~ModuleKnock()
+               ServerInstance->Modules->Attach(I_OnRehash, this);
+               OnRehash(NULL);
+       }
+
+       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()