From 354a89e45b8070931fb052f2f4d94bee12f90e67 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 19:21:49 +0100 Subject: [PATCH 01/15] adminlog: use CModCommand --- modules/adminlog.cpp | 101 +++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/modules/adminlog.cpp b/modules/adminlog.cpp index 06ba032f..25673e33 100644 --- a/modules/adminlog.cpp +++ b/modules/adminlog.cpp @@ -24,6 +24,9 @@ class CAdminLogMod : public CModule { public: MODCONSTRUCTOR(CAdminLogMod) { + AddHelpCommand(); + AddCommand("Show", static_cast(&CAdminLogMod::OnShowCommand), "", "Show the logging target"); + AddCommand("Target", static_cast(&CAdminLogMod::OnTargetCommand), "", "Set the logging target"); openlog("znc", LOG_PID, LOG_DAEMON); } @@ -107,59 +110,63 @@ public: virtual void OnModCommand(const CString& sCommand) { if (!GetUser()->IsAdmin()) { PutModule("Access denied"); + } else { + HandleCommand(sCommand); + } + } + + void OnTargetCommand(const CString& sCommand) { + CString sArg = sCommand.Token(1, true); + CString sTarget; + CString sMessage; + LogMode mode; + + if (sArg.Equals("file")) { + sTarget = "file"; + sMessage = "Now only logging to file"; + mode = LOG_TO_FILE; + } else if (sArg.Equals("syslog")) { + sTarget = "syslog"; + sMessage = "Now only logging to syslog"; + mode = LOG_TO_SYSLOG; + } else if (sArg.Equals("both")) { + sTarget = "both"; + sMessage = "Now logging to file and syslog"; + mode = LOG_TO_BOTH; + } else { + if (sArg.empty()) { + PutModule("Usage: Target "); + } else { + PutModule("Unknown target"); + } return; } - CString sCmd = sCommand.Token(0); + Log(sMessage); + SetNV("target", sTarget); + m_eLogMode = mode; + PutModule(sMessage); + } - if (sCmd.Equals("target")) { - CString sArg = sCommand.Token(1, true); - CString sTarget; - CString sMessage; - LogMode mode; + void OnShowCommand(const CString& sCommand) { + CString sTarget; - if (sArg.Equals("file")) { - sTarget = "file"; - sMessage = "Now only logging to file"; - mode = LOG_TO_FILE; - } else if (sArg.Equals("syslog")) { - sTarget = "syslog"; - sMessage = "Now only logging to syslog"; - mode = LOG_TO_SYSLOG; - } else if (sArg.Equals("both")) { - sTarget = "both"; - sMessage = "Now logging to file and syslog"; - mode = LOG_TO_BOTH; - } else { - PutModule("Unknown target"); - return; - } + switch (m_eLogMode) + { + case LOG_TO_FILE: + sTarget = "file"; + break; + case LOG_TO_SYSLOG: + sTarget = "syslog"; + break; + case LOG_TO_BOTH: + sTarget = "both, file and syslog"; + break; + } - Log(sMessage); - SetNV("target", sTarget); - m_eLogMode = mode; - PutModule(sMessage); - } else if (sCmd.Equals("show")) { - CString sTarget; - - switch (m_eLogMode) - { - case LOG_TO_FILE: - sTarget = "file"; - break; - case LOG_TO_SYSLOG: - sTarget = "syslog"; - break; - case LOG_TO_BOTH: - sTarget = "both, file and syslog"; - break; - } - - PutModule("Logging is enabled for " + sTarget); - if (m_eLogMode != LOG_TO_SYSLOG) - PutModule("Log file will be written to [" + m_sLogFile + "]"); - } else - PutModule("Commands: show, target "); + PutModule("Logging is enabled for " + sTarget); + if (m_eLogMode != LOG_TO_SYSLOG) + PutModule("Log file will be written to [" + m_sLogFile + "]"); } private: enum LogMode { From 85e92f56694434ef4df123d416117e2c91871f8c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 19:31:48 +0100 Subject: [PATCH 02/15] autocycle: use CModCommand --- modules/autocycle.cpp | 90 +++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/modules/autocycle.cpp b/modules/autocycle.cpp index 0b815b98..717141ff 100644 --- a/modules/autocycle.cpp +++ b/modules/autocycle.cpp @@ -22,6 +22,10 @@ using std::vector; class CAutoCycleMod : public CModule { public: MODCONSTRUCTOR(CAutoCycleMod) { + AddHelpCommand(); + AddCommand("Add", static_cast(&CAutoCycleMod::OnAddCommand), "[!]<#chan>", "Add an entry, use !#chan to negate and * for wildcards"); + AddCommand("Del", static_cast(&CAutoCycleMod::OnDelCommand), "[!]<#chan>", "Remove an entry, needs to be an exact match"); + AddCommand("List", static_cast(&CAutoCycleMod::OnListCommand), "", "List all entries"); m_recentlyCycled.SetTTL(15 * 1000); } @@ -50,67 +54,45 @@ public: return true; } - virtual void OnModCommand(const CString& sLine) { - CString sCommand = sLine.Token(0); + void OnAddCommand(const CString& sLine) { + CString sChan = sLine.Token(1); - if (sCommand.Equals("ADD")) { - CString sChan = sLine.Token(1); - - if (AlreadyAdded(sChan)) { - PutModule(sChan + " is already added"); - } else if (Add(sChan)) { - PutModule("Added " + sChan + " to list"); - } else { - PutModule("Usage: Add [!]<#chan>"); - } - } else if (sCommand.Equals("DEL")) { - CString sChan = sLine.Token(1); - - if (Del(sChan)) - PutModule("Removed " + sChan + " from list"); - else - PutModule("Usage: Del [!]<#chan>"); - } else if (sCommand.Equals("LIST")) { - CTable Table; - Table.AddColumn("Chan"); - - for (unsigned int a = 0; a < m_vsChans.size(); a++) { - Table.AddRow(); - Table.SetCell("Chan", m_vsChans[a]); - } - - for (unsigned int b = 0; b < m_vsNegChans.size(); b++) { - Table.AddRow(); - Table.SetCell("Chan", "!" + m_vsNegChans[b]); - } - - if (Table.size()) { - PutModule(Table); - } else { - PutModule("You have no entries."); - } + if (AlreadyAdded(sChan)) { + PutModule(sChan + " is already added"); + } else if (Add(sChan)) { + PutModule("Added " + sChan + " to list"); } else { - CTable Table; - Table.AddColumn("Command"); - Table.AddColumn("Description"); + PutModule("Usage: Add [!]<#chan>"); + } + } + void OnDelCommand(const CString& sLine) { + CString sChan = sLine.Token(1); + + if (Del(sChan)) + PutModule("Removed " + sChan + " from list"); + else + PutModule("Usage: Del [!]<#chan>"); + } + + void OnListCommand(const CString& sLine) { + CTable Table; + Table.AddColumn("Chan"); + + for (unsigned int a = 0; a < m_vsChans.size(); a++) { Table.AddRow(); - Table.SetCell("Command", "Add"); - Table.SetCell("Description", "Add an entry, use !#chan to negate and * for wildcards"); + Table.SetCell("Chan", m_vsChans[a]); + } + for (unsigned int b = 0; b < m_vsNegChans.size(); b++) { Table.AddRow(); - Table.SetCell("Command", "Del"); - Table.SetCell("Description", "Remove an entry, needs to be an exact match"); + Table.SetCell("Chan", "!" + m_vsNegChans[b]); + } - Table.AddRow(); - Table.SetCell("Command", "List"); - Table.SetCell("Description", "List all entries"); - - if (Table.size()) { - PutModule(Table); - } else { - PutModule("You have no entries."); - } + if (Table.size()) { + PutModule(Table); + } else { + PutModule("You have no entries."); } } From 9e41fe869f6dbeca1e1077db40011b7a70afde06 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 21:16:58 +0100 Subject: [PATCH 03/15] autoop: use CModCommand --- modules/autoop.cpp | 277 +++++++++++++++++++++++++++------------------ 1 file changed, 164 insertions(+), 113 deletions(-) diff --git a/modules/autoop.cpp b/modules/autoop.cpp index dcbb8f4d..a5a7da6c 100644 --- a/modules/autoop.cpp +++ b/modules/autoop.cpp @@ -149,7 +149,16 @@ protected: class CAutoOpMod : public CModule { public: - MODCONSTRUCTOR(CAutoOpMod) {} + MODCONSTRUCTOR(CAutoOpMod) { + AddHelpCommand(); + AddCommand("ListUsers", static_cast(&CAutoOpMod::OnListUsersCommand), "", "List all users"); + AddCommand("AddChans", static_cast(&CAutoOpMod::OnAddChansCommand), " [channel] ...", "Adds channels to a user"); + AddCommand("DelChans", static_cast(&CAutoOpMod::OnDelChansCommand), " [channel] ...", "Removes channels from a user"); + AddCommand("AddMasks", static_cast(&CAutoOpMod::OnAddMasksCommand), " ,[mask] ...", "Adds masks to a user"); + AddCommand("DelMasks", static_cast(&CAutoOpMod::OnDelMasksCommand), " ,[mask] ...", "Removes masks from a user"); + AddCommand("AddUser", static_cast(&CAutoOpMod::OnAddUserCommand), " [,...] [channels]", "Adds a user"); + AddCommand("DelUser", static_cast(&CAutoOpMod::OnDelUserCommand), "", "Removes a user"); + } virtual bool OnLoad(const CString& sArgs, CString& sMessage) { AddTimer(new CAutoOpTimer(this)); @@ -229,121 +238,163 @@ public: } } - virtual void OnModCommand(const CString& sLine) { + void OnModCommand(const CString& sLine) { CString sCommand = sLine.Token(0).AsUpper(); - - if (sCommand.Equals("HELP")) { - PutModule("Commands are: ListUsers, AddChans, DelChans, AddMasks, DelMasks, AddUser, DelUser"); - } else if (sCommand.Equals("TIMERS")) { + if (sCommand.Equals("TIMERS")) { + // for testing purposes - hidden from help ListTimers(); - } else if (sCommand.Equals("ADDUSER") || sCommand.Equals("DELUSER")) { - CString sUser = sLine.Token(1); - CString sHost = sLine.Token(2); - CString sKey = sLine.Token(3); - - if (sCommand.Equals("ADDUSER")) { - if (sHost.empty()) { - PutModule("Usage: " + sCommand + " [,...] [channels]"); - } else { - CAutoOpUser* pUser = AddUser(sUser, sKey, sHost, sLine.Token(4, true)); - - if (pUser) { - SetNV(sUser, pUser->ToString()); - } - } - } else { - DelUser(sUser); - DelNV(sUser); - } - } else if (sCommand.Equals("LISTUSERS")) { - if (m_msUsers.empty()) { - PutModule("There are no users defined"); - return; - } - - CTable Table; - - Table.AddColumn("User"); - Table.AddColumn("Hostmasks"); - Table.AddColumn("Key"); - Table.AddColumn("Channels"); - - for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) { - VCString vsHostmasks; - it->second->GetHostmasks().Split(",", vsHostmasks); - for (unsigned int a = 0; a < vsHostmasks.size(); a++) { - Table.AddRow(); - if (a == 0) { - Table.SetCell("User", it->second->GetUsername()); - Table.SetCell("Key", it->second->GetUserKey()); - Table.SetCell("Channels", it->second->GetChannels()); - } else if (a == vsHostmasks.size()-1) { - Table.SetCell("User", "`-"); - } else { - Table.SetCell("User", "|-"); - } - Table.SetCell("Hostmasks", vsHostmasks[a]); - } - } - - PutModule(Table); - } else if (sCommand.Equals("ADDCHANS") || sCommand.Equals("DELCHANS")) { - CString sUser = sLine.Token(1); - CString sChans = sLine.Token(2, true); - - if (sChans.empty()) { - PutModule("Usage: " + sCommand + " [channel] ..."); - return; - } - - CAutoOpUser* pUser = FindUser(sUser); - - if (!pUser) { - PutModule("No such user"); - return; - } - - if (sCommand.Equals("ADDCHANS")) { - pUser->AddChans(sChans); - PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]"); - } else { - pUser->DelChans(sChans); - PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]"); - } - - SetNV(pUser->GetUsername(), pUser->ToString()); - } else if (sCommand.Equals("ADDMASKS") || sCommand.Equals("DELMASKS")) { - CString sUser = sLine.Token(1); - CString sHostmasks = sLine.Token(2, true); - - if (sHostmasks.empty()) { - PutModule("Usage: " + sCommand + " ,[mask] ..."); - return; - } - - CAutoOpUser* pUser = FindUser(sUser); - - if (!pUser) { - PutModule("No such user"); - return; - } - - if (sCommand.Equals("ADDMASKS")) { - pUser->AddHostmasks(sHostmasks); - PutModule("Hostmasks(s) added to user [" + pUser->GetUsername() + "]"); - SetNV(pUser->GetUsername(), pUser->ToString()); - } else { - if (pUser->DelHostmasks(sHostmasks)) { - PutModule("Removed user [" + pUser->GetUsername() + "] with key [" + pUser->GetUserKey() + "] and channels [" + pUser->GetChannels() + "]"); - DelUser(sUser); - DelNV(sUser); - } else { - PutModule("Hostmasks(s) Removed from user [" + pUser->GetUsername() + "]"); - SetNV(pUser->GetUsername(), pUser->ToString()); - } - } } else { - PutModule("Unknown command, try HELP"); + HandleCommand(sLine); + } + } + + void OnAddUserCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sHost = sLine.Token(2); + CString sKey = sLine.Token(3); + + if (sHost.empty()) { + PutModule("Usage: AddUser [,...] [channels]"); + } else { + CAutoOpUser* pUser = AddUser(sUser, sKey, sHost, sLine.Token(4, true)); + + if (pUser) { + SetNV(sUser, pUser->ToString()); + } + } + } + + void OnDelUserCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + + if (sUser.empty()) { + PutModule("Usage: DelUser "); + } else { + DelUser(sUser); + DelNV(sUser); + } + } + + void OnListUsersCommand(const CString& sLine) { + if (m_msUsers.empty()) { + PutModule("There are no users defined"); + return; + } + + CTable Table; + + Table.AddColumn("User"); + Table.AddColumn("Hostmasks"); + Table.AddColumn("Key"); + Table.AddColumn("Channels"); + + for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) { + VCString vsHostmasks; + it->second->GetHostmasks().Split(",", vsHostmasks); + for (unsigned int a = 0; a < vsHostmasks.size(); a++) { + Table.AddRow(); + if (a == 0) { + Table.SetCell("User", it->second->GetUsername()); + Table.SetCell("Key", it->second->GetUserKey()); + Table.SetCell("Channels", it->second->GetChannels()); + } else if (a == vsHostmasks.size()-1) { + Table.SetCell("User", "`-"); + } else { + Table.SetCell("User", "|-"); + } + Table.SetCell("Hostmasks", vsHostmasks[a]); + } + } + + PutModule(Table); + } + + void OnAddChansCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sChans = sLine.Token(2, true); + + if (sChans.empty()) { + PutModule("Usage: AddChans [channel] ..."); + return; + } + + CAutoOpUser* pUser = FindUser(sUser); + + if (!pUser) { + PutModule("No such user"); + return; + } + + pUser->AddChans(sChans); + PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]"); + SetNV(pUser->GetUsername(), pUser->ToString()); + } + + void OnDelChansCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sChans = sLine.Token(2, true); + + if (sChans.empty()) { + PutModule("Usage: DelChans [channel] ..."); + return; + } + + CAutoOpUser* pUser = FindUser(sUser); + + if (!pUser) { + PutModule("No such user"); + return; + } + + pUser->DelChans(sChans); + PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]"); + SetNV(pUser->GetUsername(), pUser->ToString()); + } + + void OnAddMasksCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sHostmasks = sLine.Token(2, true); + + if (sHostmasks.empty()) { + PutModule("Usage: AddMasks ,[mask] ..."); + return; + } + + CAutoOpUser* pUser = FindUser(sUser); + + if (!pUser) { + PutModule("No such user"); + return; + } + + pUser->AddHostmasks(sHostmasks); + PutModule("Hostmasks(s) added to user [" + pUser->GetUsername() + "]"); + SetNV(pUser->GetUsername(), pUser->ToString()); + } + + void OnDelMasksCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sHostmasks = sLine.Token(2, true); + + if (sHostmasks.empty()) { + PutModule("Usage: DelMasks ,[mask] ..."); + return; + } + + CAutoOpUser* pUser = FindUser(sUser); + + if (!pUser) { + PutModule("No such user"); + return; + } + + if (pUser->DelHostmasks(sHostmasks)) { + PutModule("Removed user [" + pUser->GetUsername() + "] with key [" + pUser->GetUserKey() + "] and channels [" + pUser->GetChannels() + "]"); + DelUser(sUser); + DelNV(sUser); + } else { + PutModule("Hostmasks(s) Removed from user [" + pUser->GetUsername() + "]"); + SetNV(pUser->GetUsername(), pUser->ToString()); } } From f1eaa7d63ee40b57a0038c3090926792da9cef04 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 21:23:58 +0100 Subject: [PATCH 04/15] autoreply: use CModCommand --- modules/autoreply.cpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/modules/autoreply.cpp b/modules/autoreply.cpp index 227a04bb..5c6fb60e 100644 --- a/modules/autoreply.cpp +++ b/modules/autoreply.cpp @@ -21,6 +21,9 @@ class CAutoReplyMod : public CModule { public: MODCONSTRUCTOR(CAutoReplyMod) { + AddHelpCommand(); + AddCommand("Set", static_cast(&CAutoReplyMod::OnSetCommand), "", "Sets a new reply"); + AddCommand("Show", static_cast(&CAutoReplyMod::OnShowCommand), "", "Displays the current query reply"); m_Messaged.SetTTL(1000 * 120); } @@ -70,20 +73,14 @@ public: return CONTINUE; } - virtual void OnModCommand(const CString& sCommand) { - const CString& sCmd = sCommand.Token(0); + void OnShowCommand(const CString& sCommand) { + PutModule("Current reply is: " + GetNV("Reply") + + " (" + GetReply() + ")"); + } - if (sCmd.Equals("SHOW")) { - PutModule("Current reply is: " + GetNV("Reply") - + " (" + GetReply() + ")"); - } else if (sCmd.Equals("SET")) { - SetReply(sCommand.Token(1, true)); - PutModule("New reply set"); - } else { - PutModule("Available commands are:"); - PutModule("Show - Displays the current query reply"); - PutModule("Set - Sets a new reply"); - } + void OnSetCommand(const CString& sCommand) { + SetReply(sCommand.Token(1, true)); + PutModule("New reply set"); } private: From 5295fed83e837fe4ff8afe36e5204f26400628f5 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 21:33:07 +0100 Subject: [PATCH 05/15] autovoice: use CModCommand --- modules/autovoice.cpp | 164 ++++++++++++++++++++++++------------------ 1 file changed, 95 insertions(+), 69 deletions(-) diff --git a/modules/autovoice.cpp b/modules/autovoice.cpp index ceba81a6..8f62197a 100644 --- a/modules/autovoice.cpp +++ b/modules/autovoice.cpp @@ -115,7 +115,14 @@ protected: class CAutoVoiceMod : public CModule { public: - MODCONSTRUCTOR(CAutoVoiceMod) {} + MODCONSTRUCTOR(CAutoVoiceMod) { + AddHelpCommand(); + AddCommand("ListUsers", static_cast(&CAutoVoiceMod::OnListUsersCommand), "", "List all users"); + AddCommand("AddChans", static_cast(&CAutoVoiceMod::OnAddChansCommand), " [channel] ...", "Adds channels to a user"); + AddCommand("DelChans", static_cast(&CAutoVoiceMod::OnDelChansCommand), " [channel] ...", "Removes channels from a user"); + AddCommand("AddUser", static_cast(&CAutoVoiceMod::OnAddUserCommand), " [channels]", "Adds a user"); + AddCommand("DelUser", static_cast(&CAutoVoiceMod::OnDelUserCommand), "", "Removes a user"); + } virtual bool OnLoad(const CString& sArgs, CString& sMessage) { // Load the chans from the command line @@ -165,79 +172,98 @@ public: } } - virtual void OnModCommand(const CString& sLine) { - CString sCommand = sLine.Token(0).AsUpper(); + void OnAddUserCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sHost = sLine.Token(2); - if (sCommand.Equals("HELP")) { - PutModule("Commands are: ListUsers, AddChans, DelChans, AddUser, DelUser"); - } else if (sCommand.Equals("ADDUSER") || sCommand.Equals("DELUSER")) { - CString sUser = sLine.Token(1); - CString sHost = sLine.Token(2); - - if (sCommand.Equals("ADDUSER")) { - if (sHost.empty()) { - PutModule("Usage: " + sCommand + " [channels]"); - } else { - CAutoVoiceUser* pUser = AddUser(sUser, sHost, sLine.Token(3, true)); - - if (pUser) { - SetNV(sUser, pUser->ToString()); - } - } - } else { - DelUser(sUser); - DelNV(sUser); - } - } else if (sCommand.Equals("LISTUSERS")) { - if (m_msUsers.empty()) { - PutModule("There are no users defined"); - return; - } - - CTable Table; - - Table.AddColumn("User"); - Table.AddColumn("Hostmask"); - Table.AddColumn("Channels"); - - for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) { - Table.AddRow(); - Table.SetCell("User", it->second->GetUsername()); - Table.SetCell("Hostmask", it->second->GetHostmask()); - Table.SetCell("Channels", it->second->GetChannels()); - } - - PutModule(Table); - } else if (sCommand.Equals("ADDCHANS") || sCommand.Equals("DELCHANS")) { - CString sUser = sLine.Token(1); - CString sChans = sLine.Token(2, true); - - if (sChans.empty()) { - PutModule("Usage: " + sCommand + " [channel] ..."); - return; - } - - CAutoVoiceUser* pUser = FindUser(sUser); - - if (!pUser) { - PutModule("No such user"); - return; - } - - if (sCommand.Equals("ADDCHANS")) { - pUser->AddChans(sChans); - PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]"); - } else { - pUser->DelChans(sChans); - PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]"); - } - - SetNV(pUser->GetUsername(), pUser->ToString()); + if (sHost.empty()) { + PutModule("Usage: AddUser [channels]"); } else { - PutModule("Unknown command, try HELP"); + CAutoVoiceUser* pUser = AddUser(sUser, sHost, sLine.Token(3, true)); + + if (pUser) { + SetNV(sUser, pUser->ToString()); + } } } + void OnDelUserCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + + if (sUser.empty()) { + PutModule("Usage: DelUser "); + } else { + DelUser(sUser); + DelNV(sUser); + } + } + + void OnListUsersCommand(const CString& sLine) { + if (m_msUsers.empty()) { + PutModule("There are no users defined"); + return; + } + + CTable Table; + + Table.AddColumn("User"); + Table.AddColumn("Hostmask"); + Table.AddColumn("Channels"); + + for (map::iterator it = m_msUsers.begin(); it != m_msUsers.end(); ++it) { + Table.AddRow(); + Table.SetCell("User", it->second->GetUsername()); + Table.SetCell("Hostmask", it->second->GetHostmask()); + Table.SetCell("Channels", it->second->GetChannels()); + } + + PutModule(Table); + } + + void OnAddChansCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sChans = sLine.Token(2, true); + + if (sChans.empty()) { + PutModule("Usage: AddChans [channel] ..."); + return; + } + + CAutoVoiceUser* pUser = FindUser(sUser); + + if (!pUser) { + PutModule("No such user"); + return; + } + + pUser->AddChans(sChans); + PutModule("Channel(s) added to user [" + pUser->GetUsername() + "]"); + + SetNV(pUser->GetUsername(), pUser->ToString()); + } + + void OnDelChansCommand(const CString& sLine) { + CString sUser = sLine.Token(1); + CString sChans = sLine.Token(2, true); + + if (sChans.empty()) { + PutModule("Usage: DelChans [channel] ..."); + return; + } + + CAutoVoiceUser* pUser = FindUser(sUser); + + if (!pUser) { + PutModule("No such user"); + return; + } + + pUser->DelChans(sChans); + PutModule("Channel(s) Removed from user [" + pUser->GetUsername() + "]"); + + SetNV(pUser->GetUsername(), pUser->ToString()); + } + CAutoVoiceUser* FindUser(const CString& sUser) { map::iterator it = m_msUsers.find(sUser.AsLower()); From 7bc1fa68e03eea74d63de55d0b8705ce16c5b665 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 21:45:08 +0100 Subject: [PATCH 06/15] blockuser: use CModCommand --- modules/blockuser.cpp | 90 +++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/modules/blockuser.cpp b/modules/blockuser.cpp index 945a93e2..b28fa4d1 100644 --- a/modules/blockuser.cpp +++ b/modules/blockuser.cpp @@ -23,7 +23,12 @@ using std::vector; class CBlockUser : public CModule { public: - MODCONSTRUCTOR(CBlockUser) {} + MODCONSTRUCTOR(CBlockUser) { + AddHelpCommand(); + AddCommand("List", static_cast(&CBlockUser::OnListCommand), "", "List blocked users"); + AddCommand("Block", static_cast(&CBlockUser::OnBlockCommand), "", "Block a user"); + AddCommand("Unblock", static_cast(&CBlockUser::OnUnblockCommand), "", "Unblock a user"); + } virtual ~CBlockUser() {} @@ -61,48 +66,59 @@ public: } void OnModCommand(const CString& sCommand) { - CString sCmd = sCommand.Token(0); - if (!GetUser()->IsAdmin()) { PutModule("Access denied"); + } else { + HandleCommand(sCommand); + } + } + + void OnListCommand(const CString& sCommand) { + CTable Table; + MCString::iterator it; + + Table.AddColumn("Blocked user"); + + for (it = BeginNV(); it != EndNV(); ++it) { + Table.AddRow(); + Table.SetCell("Blocked user", it->first); + } + + if (PutModule(Table) == 0) + PutModule("No users blocked"); + } + + void OnBlockCommand(const CString& sCommand) { + CString sUser = sCommand.Token(1, true); + + if (sUser.empty()) { + PutModule("Usage: Block "); return; } - if (sCmd.Equals("list")) { - CTable Table; - MCString::iterator it; - - Table.AddColumn("Blocked user"); - - for (it = BeginNV(); it != EndNV(); ++it) { - Table.AddRow(); - Table.SetCell("Blocked user", it->first); - } - - if (PutModule(Table) == 0) - PutModule("No users blocked"); - } else if (sCmd.Equals("block")) { - CString sUser = sCommand.Token(1, true); - - if (GetUser()->GetUserName().Equals(sUser)) { - PutModule("You can't block yourself"); - return; - } - - if (Block(sUser)) - PutModule("Blocked [" + sUser + "]"); - else - PutModule("Could not block [" + sUser + "] (misspelled?)"); - } else if (sCmd.Equals("unblock")) { - CString sUser = sCommand.Token(1, true); - - if (DelNV(sUser)) - PutModule("Unblocked [" + sUser + "]"); - else - PutModule("This user is not blocked"); - } else { - PutModule("Commands: list, block [user], unblock [user]"); + if (GetUser()->GetUserName().Equals(sUser)) { + PutModule("You can't block yourself"); + return; } + + if (Block(sUser)) + PutModule("Blocked [" + sUser + "]"); + else + PutModule("Could not block [" + sUser + "] (misspelled?)"); + } + + void OnUnblockCommand(const CString& sCommand) { + CString sUser = sCommand.Token(1, true); + + if (sUser.empty()) { + PutModule("Usage: Unblock "); + return; + } + + if (DelNV(sUser)) + PutModule("Unblocked [" + sUser + "]"); + else + PutModule("This user is not blocked"); } bool OnEmbeddedWebRequest(CWebSock& WebSock, const CString& sPageName, CTemplate& Tmpl) { From bf87ebb2631b55adce91294326106e8f19fa50c1 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 22:44:24 +0100 Subject: [PATCH 07/15] clientnotify: use CModCommand --- modules/clientnotify.cpp | 66 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/modules/clientnotify.cpp b/modules/clientnotify.cpp index 64fface8..25b78374 100644 --- a/modules/clientnotify.cpp +++ b/modules/clientnotify.cpp @@ -44,6 +44,11 @@ protected: public: MODCONSTRUCTOR(CClientNotifyMod) { + AddHelpCommand(); + AddCommand("Method", static_cast(&CClientNotifyMod::OnMethodCommand), "", "Sets the notify method"); + AddCommand("NewOnly", static_cast(&CClientNotifyMod::OnNewOnlyCommand), "", "Turns notifies for unseen IP addresses only on or off"); + AddCommand("OnDisconnect", static_cast(&CClientNotifyMod::OnDisconnectCommand), "", "Turns notifies on disconnecting clients on or off"); + AddCommand("Show", static_cast(&CClientNotifyMod::OnShowCommand), "", "Show the current settings"); } bool OnLoad(const CString& sArgs, CString& sMessage) { @@ -81,35 +86,48 @@ public: } } - void OnModCommand(const CString& sCommand) { - const CString& sCmd = sCommand.Token(0).AsLower(); + void OnMethodCommand(const CString& sCommand) { const CString& sArg = sCommand.Token(1, true).AsLower(); - if (sCmd.Equals("method") && !sArg.empty()) { - if(sArg != "notice" && sArg != "message" && sArg != "off") { - PutModule("Unknown method. Use one of: message / notice / off"); - } - else { - m_sMethod = sArg; - SaveSettings(); - PutModule("Saved."); - } + if (sArg != "notice" && sArg != "message" && sArg != "off") { + PutModule("Usage: Method "); + return; } - else if (sCmd.Equals("newonly") && !sArg.empty()) { - m_bNewOnly = (sArg == "on" || sArg == "true"); - SaveSettings(); - PutModule("Saved."); + + m_sMethod = sArg; + SaveSettings(); + PutModule("Saved."); + } + + void OnNewOnlyCommand(const CString& sCommand) { + const CString& sArg = sCommand.Token(1, true).AsLower(); + + if (sArg.empty()) { + PutModule("Usage: NewOnly "); + return; } - else if (sCmd.Equals("ondisconnect") && !sArg.empty()) { - m_bOnDisconnect = (sArg == "on" || sArg == "true"); - SaveSettings(); - PutModule("Saved."); - } - else { - PutModule("Current settings: Method: " + m_sMethod + ", for unseen IP addresses only: " + CString(m_bNewOnly) + - ", notify on disconnecting clients: " + CString(m_bOnDisconnect)); - PutModule("Commands: show, method , newonly , ondisconnect "); + + m_bNewOnly = sArg.ToBool(); + SaveSettings(); + PutModule("Saved."); + } + + void OnDisconnectCommand(const CString& sCommand) { + const CString& sArg = sCommand.Token(1, true).AsLower(); + + if (sArg.empty()) { + PutModule("Usage: OnDisconnect "); + return; } + + m_bOnDisconnect = sArg.ToBool(); + SaveSettings(); + PutModule("Saved."); + } + + void OnShowCommand(const CString& sLine) { + PutModule("Current settings: Method: " + m_sMethod + ", for unseen IP addresses only: " + CString(m_bNewOnly) + + ", notify on disconnecting clients: " + CString(m_bOnDisconnect)); } }; From 2a03a6ab9251fb256e06cfc2dd856abf49c25118 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 22:50:45 +0100 Subject: [PATCH 08/15] crypt: use CModCommand --- modules/crypt.cpp | 106 +++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/modules/crypt.cpp b/modules/crypt.cpp index 0daccf15..e65100cd 100644 --- a/modules/crypt.cpp +++ b/modules/crypt.cpp @@ -44,7 +44,13 @@ class CCryptMod : public CModule { } public: - MODCONSTRUCTOR(CCryptMod) {} + MODCONSTRUCTOR(CCryptMod) { + AddHelpCommand(); + AddCommand("DelKey", static_cast(&CCryptMod::OnDelKeyCommand), "<#chan|Nick>", "Remove a key for nick or channel"); + AddCommand("SetKey", static_cast(&CCryptMod::OnSetKeyCommand), "<#chan|Nick> ", "Set a key for nick or channel"); + AddCommand("ListKeys", static_cast(&CCryptMod::OnListKeysCommand), "", "List all keys"); + } + virtual ~CCryptMod() {} virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) { @@ -104,61 +110,57 @@ public: } - virtual void OnModCommand(const CString& sCommand) { - CString sCmd = sCommand.Token(0); + void OnDelKeyCommand(const CString& sCommand) { + CString sTarget = sCommand.Token(1); - if (sCmd.Equals("DELKEY")) { - CString sTarget = sCommand.Token(1); - - if (!sTarget.empty()) { - if (DelNV(sTarget.AsLower())) { - PutModule("Target [" + sTarget + "] deleted"); - } else { - PutModule("Target [" + sTarget + "] not found"); - } + if (!sTarget.empty()) { + if (DelNV(sTarget.AsLower())) { + PutModule("Target [" + sTarget + "] deleted"); } else { - PutModule("Usage DelKey <#chan|Nick>"); + PutModule("Target [" + sTarget + "] not found"); } - } else if (sCmd.Equals("SETKEY")) { - CString sTarget = sCommand.Token(1); - CString sKey = sCommand.Token(2, true); - - // Strip "cbc:" from beginning of string incase someone pastes directly from mircryption - sKey.TrimPrefix("cbc:"); - - if (!sKey.empty()) { - SetNV(sTarget.AsLower(), sKey); - PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]"); - } else { - PutModule("Usage: SetKey <#chan|Nick> "); - } - } else if (sCmd.Equals("LISTKEYS")) { - if (BeginNV() == EndNV()) { - PutModule("You have no encryption keys set."); - } else { - CTable Table; - Table.AddColumn("Target"); - Table.AddColumn("Key"); - - for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) { - Table.AddRow(); - Table.SetCell("Target", it->first); - Table.SetCell("Key", it->second); - } - - MCString::iterator it = FindNV(NICK_PREFIX_KEY); - if (it == EndNV()) { - Table.AddRow(); - Table.SetCell("Target", NICK_PREFIX_KEY); - Table.SetCell("Key", NickPrefix()); - } - - PutModule(Table); - } - } else if (sCmd.Equals("HELP")) { - PutModule("Try: SetKey, DelKey, ListKeys"); } else { - PutModule("Unknown command, try 'Help'"); + PutModule("Usage DelKey <#chan|Nick>"); + } + } + + void OnSetKeyCommand(const CString& sCommand) { + CString sTarget = sCommand.Token(1); + CString sKey = sCommand.Token(2, true); + + // Strip "cbc:" from beginning of string incase someone pastes directly from mircryption + sKey.TrimPrefix("cbc:"); + + if (!sKey.empty()) { + SetNV(sTarget.AsLower(), sKey); + PutModule("Set encryption key for [" + sTarget + "] to [" + sKey + "]"); + } else { + PutModule("Usage: SetKey <#chan|Nick> "); + } + } + + void OnListKeysCommand(const CString& sCommand) { + if (BeginNV() == EndNV()) { + PutModule("You have no encryption keys set."); + } else { + CTable Table; + Table.AddColumn("Target"); + Table.AddColumn("Key"); + + for (MCString::iterator it = BeginNV(); it != EndNV(); ++it) { + Table.AddRow(); + Table.SetCell("Target", it->first); + Table.SetCell("Key", it->second); + } + + MCString::iterator it = FindNV(NICK_PREFIX_KEY); + if (it == EndNV()) { + Table.AddRow(); + Table.SetCell("Target", NICK_PREFIX_KEY); + Table.SetCell("Key", NickPrefix()); + } + + PutModule(Table); } } From 85524f4408b5b1a449e634013f3949a7210ff1ff Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 23:04:04 +0100 Subject: [PATCH 09/15] ctcpflood: use CModCommand --- modules/ctcpflood.cpp | 58 +++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/modules/ctcpflood.cpp b/modules/ctcpflood.cpp index ac154e24..a8feecd3 100644 --- a/modules/ctcpflood.cpp +++ b/modules/ctcpflood.cpp @@ -22,6 +22,11 @@ public: MODCONSTRUCTOR(CCtcpFloodMod) { m_tLastCTCP = 0; m_iNumCTCP = 0; + + AddHelpCommand(); + AddCommand("Secs", static_cast(&CCtcpFloodMod::OnSecsCommand), "", "Set seconds limit"); + AddCommand("Lines", static_cast(&CCtcpFloodMod::OnLinesCommand), "", "Set lines limit"); + AddCommand("Show", static_cast(&CCtcpFloodMod::OnShowCommand), "", "Show the current limits"); } ~CCtcpFloodMod() { @@ -87,30 +92,41 @@ public: return Message(Nick, sMessage); } - void OnModCommand(const CString& sCommand) { - const CString& sCmd = sCommand.Token(0); + void OnSecsCommand(const CString& sCommand) { const CString& sArg = sCommand.Token(1, true); - if (sCmd.Equals("secs") && !sArg.empty()) { - m_iThresholdSecs = sArg.ToUInt(); - if (m_iThresholdSecs == 0) - m_iThresholdSecs = 1; - - PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]"); - Save(); - } else if (sCmd.Equals("lines") && !sArg.empty()) { - m_iThresholdMsgs = sArg.ToUInt(); - if (m_iThresholdMsgs == 0) - m_iThresholdMsgs = 2; - - PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]"); - Save(); - } else if (sCmd.Equals("show")) { - PutModule("Current limit is " + CString(m_iThresholdMsgs) + " CTCPs " - "in " + CString(m_iThresholdSecs) + " secs"); - } else { - PutModule("Commands: show, secs [limit], lines [limit]"); + if (sArg.empty()) { + PutModule("Usage: Secs "); + return; } + + m_iThresholdSecs = sArg.ToUInt(); + if (m_iThresholdSecs == 0) + m_iThresholdSecs = 1; + + PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]"); + Save(); + } + + void OnLinesCommand(const CString& sCommand) { + const CString& sArg = sCommand.Token(1, true); + + if (sArg.empty()) { + PutModule("Usage: Lines "); + return; + } + + m_iThresholdMsgs = sArg.ToUInt(); + if (m_iThresholdMsgs == 0) + m_iThresholdMsgs = 2; + + PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]"); + Save(); + } + + void OnShowCommand(const CString& sCommand) { + PutModule("Current limit is " + CString(m_iThresholdMsgs) + " CTCPs " + "in " + CString(m_iThresholdSecs) + " secs"); } private: From 44bab0a6bede6be96ce44d165933ad053e1e07e8 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 23:12:28 +0100 Subject: [PATCH 10/15] keepnick: use CModCommand --- modules/keepnick.cpp | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/modules/keepnick.cpp b/modules/keepnick.cpp index 9d178da7..7d467a75 100644 --- a/modules/keepnick.cpp +++ b/modules/keepnick.cpp @@ -34,7 +34,12 @@ private: class CKeepNickMod : public CModule { public: - MODCONSTRUCTOR(CKeepNickMod) {} + MODCONSTRUCTOR(CKeepNickMod) { + AddHelpCommand(); + AddCommand("Enable", static_cast(&CKeepNickMod::OnEnableCommand), "", "Try to get your primary nick"); + AddCommand("Disable", static_cast(&CKeepNickMod::OnDisableCommand), "", "No longer trying to get your primary nick"); + AddCommand("State", static_cast(&CKeepNickMod::OnStateCommand), "", "Show the current state"); + } ~CKeepNickMod() {} @@ -168,23 +173,21 @@ public: return CONTINUE; } - void OnModCommand(const CString& sCommand) { - CString sCmd = sCommand.AsUpper(); + void OnEnableCommand(const CString& sCommand) { + Enable(); + PutModule("Trying to get your primary nick"); + } - if (sCmd == "ENABLE") { - Enable(); - PutModule("Trying to get your primary nick"); - } else if (sCmd == "DISABLE") { - Disable(); - PutModule("No longer trying to get your primary nick"); - } else if (sCmd == "STATE") { - if (m_pTimer) - PutModule("Currently trying to get your primary nick"); - else - PutModule("Currently disabled, try 'enable'"); - } else { - PutModule("Commands: Enable, Disable, State"); - } + void OnDisableCommand(const CString& sCommand) { + Disable(); + PutModule("No longer trying to get your primary nick"); + } + + void OnStateCommand(const CString& sCommand) { + if (m_pTimer) + PutModule("Currently trying to get your primary nick"); + else + PutModule("Currently disabled, try 'enable'"); } private: From 88c397a7003ceaaaf13411d946ca7d7ae01d167b Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 23:29:19 +0100 Subject: [PATCH 11/15] kickrejoin: use CModCommand --- modules/kickrejoin.cpp | 52 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/modules/kickrejoin.cpp b/modules/kickrejoin.cpp index d9e42cc9..4f1e709b 100644 --- a/modules/kickrejoin.cpp +++ b/modules/kickrejoin.cpp @@ -50,7 +50,11 @@ private: unsigned int delay; public: - MODCONSTRUCTOR(CRejoinMod) {} + MODCONSTRUCTOR(CRejoinMod) { + AddHelpCommand(); + AddCommand("SetDelay", static_cast(&CRejoinMod::OnSetDelayCommand), "", "Set the rejoin delay"); + AddCommand("ShowDelay", static_cast(&CRejoinMod::OnShowDelayCommand), "", "Show the rejoin delay"); + } virtual ~CRejoinMod() {} virtual bool OnLoad(const CString& sArgs, CString& sErrorMsg) { @@ -75,33 +79,29 @@ public: return true; } - virtual void OnModCommand(const CString& sCommand) { - CString sCmdName = sCommand.Token(0).AsLower(); + void OnSetDelayCommand(const CString& sCommand) { + int i; + i = sCommand.Token(1).ToInt(); - if (sCmdName == "setdelay") { - int i; - i = sCommand.Token(1).ToInt(); - - if (i < 0) { - PutModule("Negative delays don't make any sense!"); - return; - } - - delay = i; - SetNV("delay", CString(delay)); - - if (delay) - PutModule("Rejoin delay set to " + CString(delay) + " seconds"); - else - PutModule("Rejoin delay disabled"); - } else if (sCmdName == "showdelay") { - if (delay) - PutModule("Rejoin delay enabled, " + CString(delay) + " seconds"); - else - PutModule("Rejoin delay disabled"); - } else { - PutModule("Commands: setdelay , showdelay"); + if (i < 0) { + PutModule("Negative delays don't make any sense!"); + return; } + + delay = i; + SetNV("delay", CString(delay)); + + if (delay) + PutModule("Rejoin delay set to " + CString(delay) + " seconds"); + else + PutModule("Rejoin delay disabled"); + } + + void OnShowDelayCommand(const CString& sCommand) { + if (delay) + PutModule("Rejoin delay enabled, " + CString(delay) + " seconds"); + else + PutModule("Rejoin delay disabled"); } virtual void OnKick(const CNick& OpNick, const CString& sKickedNick, CChan& pChan, const CString& sMessage) { From 4b6a5042ada91af32eec400e78957805e2a1c147 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 23:38:42 +0100 Subject: [PATCH 12/15] listsockets: use CModCommand --- modules/listsockets.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/modules/listsockets.cpp b/modules/listsockets.cpp index 6b883eaa..10575cd9 100644 --- a/modules/listsockets.cpp +++ b/modules/listsockets.cpp @@ -64,7 +64,10 @@ private: class CListSockets : public CModule { public: - MODCONSTRUCTOR(CListSockets) {} + MODCONSTRUCTOR(CListSockets) { + AddHelpCommand(); + AddCommand("List", static_cast(&CListSockets::OnListCommand), "[-n]", "Show the list of active sockets. Pass -n to show IP addresses"); + } virtual bool OnLoad(const CString& sArgs, CString& sMessage) { @@ -128,20 +131,14 @@ public: return false; } - virtual void OnModCommand(const CString& sLine) { - CString sCommand = sLine.Token(0); + void OnListCommand(const CString& sLine) { CString sArg = sLine.Token(1, true); - if (sCommand.Equals("LIST")) { - bool bShowHosts = true; - if (sArg.Equals("-n")) { - bShowHosts = false; - } - ShowSocks(bShowHosts); - } else { - PutModule("Use 'list' to view a list of active sockets"); - PutModule("Use 'list -n' if you want IP addresses to be displayed"); + bool bShowHosts = true; + if (sArg.Equals("-n")) { + bShowHosts = false; } + ShowSocks(bShowHosts); } CString GetSocketState(Csock* pSocket) { From ac7cf938c67f9b75e04febd014b87bd859458378 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 23:47:33 +0100 Subject: [PATCH 13/15] savebuff: use CModCommand --- modules/savebuff.cpp | 50 ++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/modules/savebuff.cpp b/modules/savebuff.cpp index 10e7b5a3..67ae11d4 100644 --- a/modules/savebuff.cpp +++ b/modules/savebuff.cpp @@ -59,6 +59,11 @@ public: { m_bBootError = false; m_bFirstLoad = false; + + AddHelpCommand(); + AddCommand("SetPass", static_cast(&CSaveBuff::OnSetPassCommand), "", "Sets the password"); + AddCommand("Replay", static_cast(&CSaveBuff::OnReplayCommand), "", "Replays the buffer"); + AddCommand("Save", static_cast(&CSaveBuff::OnSaveCommand), "", "Saves all buffers"); } virtual ~CSaveBuff() { @@ -206,18 +211,21 @@ public: } } - virtual void OnModCommand(const CString& sCmdLine) + void OnSetPassCommand(const CString& sCmdLine) + { + CString sArgs = sCmdLine.Token(1, true); + + PutModule("Password set to [" + sArgs + "]"); + m_sPassword = CBlowfish::MD5(sArgs); + } + + void OnModCommand(const CString& sCmdLine) { CString sCommand = sCmdLine.Token(0); CString sArgs = sCmdLine.Token(1, true); - if (sCommand.Equals("setpass")) - { - PutModule("Password set to [" + sArgs + "]"); - m_sPassword = CBlowfish::MD5(sArgs); - - } else if (sCommand.Equals("dumpbuff")) - { + if (sCommand.Equals("dumpbuff")) { + // for testing purposes - hidden from help CString sFile; if (DecryptBuffer(sArgs, sFile)) { @@ -233,17 +241,23 @@ public: } } PutModule("//!-- EOF " + sArgs); - } else if (sCommand.Equals("replay")) - { - Replay(sArgs); - PutModule("Replayed " + sArgs); + } else { + HandleCommand(sCmdLine); + } + } - } else if (sCommand.Equals("save")) - { - SaveBufferToDisk(); - PutModule("Done."); - } else - PutModule("Unknown command [" + sCommand + "]"); + void OnReplayCommand(const CString& sCmdLine) + { + CString sArgs = sCmdLine.Token(1, true); + + Replay(sArgs); + PutModule("Replayed " + sArgs); + } + + void OnSaveCommand(const CString& sCmdLine) + { + SaveBufferToDisk(); + PutModule("Done."); } void Replay(const CString & sBuffer) From 57b25ab2775642ae1081628e1625f03ae795f67a Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 3 Nov 2014 23:55:21 +0100 Subject: [PATCH 14/15] simple_away: use CModCommand --- modules/simple_away.cpp | 84 ++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 51 deletions(-) diff --git a/modules/simple_away.cpp b/modules/simple_away.cpp index 48362512..fc62d361 100644 --- a/modules/simple_away.cpp +++ b/modules/simple_away.cpp @@ -47,6 +47,12 @@ public: m_iAwayWait = SIMPLE_AWAY_DEFAULT_TIME; m_bClientSetAway = false; m_bWeSetAway = false; + + AddHelpCommand(); + AddCommand("Reason", static_cast(&CSimpleAway::OnReasonCommand), "[]", "Prints or sets the away reason (%s is replaced with the time you were set away)"); + AddCommand("Timer", static_cast(&CSimpleAway::OnTimerCommand), "", "Prints the current time to wait before setting you away"); + AddCommand("SetTimer", static_cast(&CSimpleAway::OnSetTimerCommand), "", "Sets the time to wait before setting you away"); + AddCommand("DisableTimer", static_cast(&CSimpleAway::OnDisableTimerCommand), "", "Disables the wait time before setting you away"); } virtual ~CSimpleAway() {} @@ -102,62 +108,38 @@ public: SetAway(); } - virtual void OnModCommand(const CString& sLine) { - CString sCommand = sLine.Token(0); - - if (sCommand.Equals("help")) { - CTable Table; - Table.AddColumn("Command"); - Table.AddColumn("Description"); - Table.AddRow(); - Table.SetCell("Command", "Reason []"); - Table.SetCell("Description", "Prints and optionally sets the away reason."); - Table.AddRow(); - Table.SetCell("Command", "Timer"); - Table.SetCell("Description", "Prints the current time to wait before setting you away."); - Table.AddRow(); - Table.SetCell("Command", "SetTimer