From 3fe14f6ed2f921c18ef0fa62da2c920e56af274c Mon Sep 17 00:00:00 2001 From: prozacx Date: Tue, 19 Apr 2005 18:26:18 +0000 Subject: [PATCH] Added SHUTDOWN user command by way of an exception git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@154 726aef4b-f618-498e-8847-2d620e286838 --- UserSock.cpp | 3 +++ Utils.h | 18 ++++++++++++++++++ main.cpp | 15 ++++++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/UserSock.cpp b/UserSock.cpp index 7777b9f2..000ec424 100644 --- a/UserSock.cpp +++ b/UserSock.cpp @@ -453,6 +453,8 @@ void CUserSock::UserCommand(const string& sLine) { PutStatus("Detaching you from [" + sChan + "]"); pChan->DetachUser(); } + } else if (strcasecmp(sCommand.c_str(), "SHUTDOWN") == 0) { + throw CException(CException::EX_Shutdown); } else if (strcasecmp(sCommand.c_str(), "JUMP") == 0) { if (m_pUser) { if (m_pIRCSock) { @@ -788,6 +790,7 @@ void CUserSock::HelpUser() { Table.AddRow(); Table.SetCell("Command", "ListNicks"); Table.SetCell("Arguments", "<#chan>"); Table.SetCell("Description", "List all nicks on a channel"); Table.AddRow(); Table.SetCell("Command", "Topics"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Show topics in all channels"); Table.AddRow(); Table.SetCell("Command", "SetBuffer"); Table.SetCell("Arguments", "<#chan> [linecount]"); Table.SetCell("Description", "Set the buffer count for a channel"); + Table.AddRow(); Table.SetCell("Command", "Shutdown"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Shutdown znc completely"); Table.AddRow(); Table.SetCell("Command", "Jump"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Jump to the next server in the list"); Table.AddRow(); Table.SetCell("Command", "Send"); Table.SetCell("Arguments", " "); Table.SetCell("Description", "Send a shell file to a nick on IRC"); Table.AddRow(); Table.SetCell("Command", "Get"); Table.SetCell("Arguments", ""); Table.SetCell("Description", "Send a shell file to yourself"); diff --git a/Utils.h b/Utils.h index 95382c36..618dffc8 100644 --- a/Utils.h +++ b/Utils.h @@ -65,6 +65,24 @@ protected: }; +class CException { +public: + typedef enum { + EX_Shutdown, + } EType; + + CException(EType e) { + m_eType = e; + } + virtual ~CException() {} + + EType GetType() const { return m_eType; } +private: +protected: + EType m_eType; +}; + + class CTable : public vector* > { public: CTable(); diff --git a/main.cpp b/main.cpp index 98a021d7..e7d46da9 100644 --- a/main.cpp +++ b/main.cpp @@ -198,7 +198,20 @@ int main(int argc, char** argv) { sigaction(SIGSEGV, &sa, (struct sigaction *)NULL); sigaction(SIGTERM, &sa, (struct sigaction *)NULL); - int iRet = pZNC->Loop(); + int iRet = 0; + + try { + iRet = pZNC->Loop(); + } catch (CException e) { + // EX_Shutdown is thrown to exit + switch (e.GetType()) { + case CException::EX_Shutdown: + iRet = 0; + default: + iRet = 1; + } + } + delete pZNC; return iRet;