From 876b3d4151005871431de8e2e1937e4adf1fa23f Mon Sep 17 00:00:00 2001 From: Christian Heusel Date: Thu, 17 Nov 2022 18:30:16 +0100 Subject: [PATCH] split up the option into two separate ones --- modules/clientnotify.cpp | 54 +++++++++++++++++------------- test/integration/tests/modules.cpp | 4 +-- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/modules/clientnotify.cpp b/modules/clientnotify.cpp index bb1560be..e9a96796 100644 --- a/modules/clientnotify.cpp +++ b/modules/clientnotify.cpp @@ -22,7 +22,7 @@ using std::set; class CClientNotifyMod : public CModule { protected: CString m_sMethod; - CString m_sNewNotifyOn; + bool m_bNewOnly{}; bool m_bOnDisconnect{}; bool m_bNotifyOnNewIP{}; @@ -34,7 +34,8 @@ class CClientNotifyMod : public CModule { void SaveSettings() { SetNV("method", m_sMethod); SetNV("newonly", m_bNewOnly ? "1" : "0"); - SetNV("newnotifyon", m_sNewNotifyOn); + SetNV("notifyonnewip", m_bNotifyOnNewIP ? "1" : "0"); + SetNV("notifyonnewclientid", m_bNotifyOnNewClientID ? "1" : "0"); SetNV("ondisconnect", m_bOnDisconnect ? "1" : "0"); } @@ -55,9 +56,12 @@ class CClientNotifyMod : public CModule { AddCommand("NewOnly", t_d(""), t_d("Turns notifications for unseen connections on or off"), [=](const CString& sLine) { OnNewOnlyCommand(sLine); }); - AddCommand("NewNotifyOn", t_d(""), - t_d("Specifies whether you want to be notified about new connections with new IPs, new ClientIDs connecting or in bot cases"), - [=](const CString& sLine) { OnNewNotifyOn(sLine); }); + AddCommand("NotifyOnNewIP", t_d(""), + t_d("Specifies whether you want to be notified about new connections with new IPs"), + [=](const CString& sLine) { OnNotifyOnNewIP(sLine); }); + AddCommand("NotifyOnNewID", t_d(""), + t_d("Specifies whether you want to be notified about new connections with new IDs"), + [=](const CString& sLine) { OnNotifyOnNewID(sLine); }); AddCommand( "OnDisconnect", t_d(""), t_d("Turns notifications for clients disconnecting on or off"), @@ -74,13 +78,10 @@ class CClientNotifyMod : public CModule { m_sMethod = "message"; } - if (m_sNewNotifyOn != "ip" && m_sNewNotifyOn != "clientid" && - m_sNewNotifyOn != "both") { - m_sNewNotifyOn = "ip"; - } - // default = off for these: + m_bNotifyOnNewIP = (GetNV("notifyonnewip") == "1"); + m_bNotifyOnNewClientID = (GetNV("notifyonnewclientid") == "1"); m_bNewOnly = (GetNV("newonly") == "1"); m_bOnDisconnect = (GetNV("ondisconnect") == "1"); @@ -159,24 +160,28 @@ class CClientNotifyMod : public CModule { PutModule(t_s("Saved.")); } - void OnNewNotifyOn(const CString& sCommand) { + void OnNotifyOnNewIP(const CString& sCommand) { const CString sArg = sCommand.Token(1, true).AsLower(); - if (sArg != "ip" && sArg != "clientid" && sArg != "both") { - PutModule(t_s("Usage: NewNotifyOn ")); + if (sArg.empty()) { + PutModule(t_s("Usage: NotifyOnNewIP ")); return; } - if (sArg == "both") { - m_bNotifyOnNewIP = true; - m_bNotifyOnNewClientID = true; - } else if (sArg == "ip") { - m_bNotifyOnNewIP = true; - } else if (sArg == "clientid") { - m_bNotifyOnNewClientID = true; + m_bNotifyOnNewIP = sArg.ToBool(); + SaveSettings(); + PutModule(t_s("Saved.")); + } + + void OnNotifyOnNewID(const CString& sCommand) { + const CString sArg = sCommand.Token(1, true).AsLower(); + + if (sArg.empty()) { + PutModule(t_s("Usage: NotifyOnNewID ")); + return; } - m_sNewNotifyOn = sArg; + m_bNotifyOnNewClientID = sArg.ToBool(); SaveSettings(); PutModule(t_s("Saved.")); } @@ -196,9 +201,10 @@ class CClientNotifyMod : public CModule { void OnShowCommand(const CString& sLine) { PutModule( - t_f("Current settings: Method: {1}, for unseen only: " - "{2}, unseen notify method: {3}, notify on disconnecting clients: {4}")( - m_sMethod, m_bNewOnly, m_sNewNotifyOn, m_bOnDisconnect)); + t_f("Current settings: Method: {1}, for unseen only: {2}, notify" + "for unseen IPs: {3}, notify for unseen IDs: {4}, notify on" + "disconnecting clients: {5}")( + m_sMethod, m_bNewOnly, m_bNotifyOnNewIP, m_bNotifyOnNewClientID, m_bOnDisconnect)); } }; diff --git a/test/integration/tests/modules.cpp b/test/integration/tests/modules.cpp index 3c19824b..d7b387c6 100644 --- a/test/integration/tests/modules.cpp +++ b/test/integration/tests/modules.cpp @@ -80,7 +80,7 @@ TEST_F(ZNCTest, ClientNotifyModule) { check_not_sent(client, ":Another client (127.0.0.1) authenticated as your user. Use the 'ListClients' command to see all 4 clients."); // choose to notify only on new client ids - client.Write("PRIVMSG *clientnotify :NewNotifyOn clientid"); + client.Write("PRIVMSG *clientnotify :NotifyOnNewID on"); auto client5 = LoginClient("identifier123"); client.ReadUntil(":Another client (127.0.0.1 / identifier123) authenticated as your user. Use the 'ListClients' command to see all 5 clients."); @@ -91,7 +91,7 @@ TEST_F(ZNCTest, ClientNotifyModule) { client.ReadUntil(":Another client (127.0.0.1 / not_identifier123) authenticated as your user. Use the 'ListClients' command to see all 7 clients."); // choose to notify from both clientids and new IPs - client.Write("PRIVMSG *clientnotify :NewNotifyOn both"); + client.Write("PRIVMSG *clientnotify :NotifyOnNewIP on"); auto client8 = LoginClient(); check_not_sent(client, ":Another client (127.0.0.1 / identifier123) authenticated as your user. Use the 'ListClients' command to see all 8 clients.");