]> jfr.im git - irc/rizon/znc.git/commitdiff
Add '/msg *status restart'
authorpsychon <redacted>
Wed, 27 Aug 2008 14:44:04 +0000 (14:44 +0000)
committerpsychon <redacted>
Wed, 27 Aug 2008 14:44:04 +0000 (14:44 +0000)
Thanks to kroimon for the patch.

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1174 726aef4b-f618-498e-8847-2d620e286838

ClientCommand.cpp
Utils.h
main.cpp

index 4359ffd258d70428f16a28c3344dcc3c7682e77b..113e974b475eee01aa0367a2c11c905168f051c4 100644 (file)
@@ -236,6 +236,15 @@ void CClient::UserCommand(const CString& sLine) {
                usleep(100000); // Sleep for 10ms to attempt to allow the previous Broadcast() to go through to all users
 
                throw CException(CException::EX_Shutdown);
+       } else if (m_pUser->IsAdmin() && sCommand.CaseCmp("RESTART") == 0) {
+               CString sMessage = sLine.Token(1, true);
+
+               if (sMessage.empty()) {
+                       sMessage = "ZNC is being restarted NOW!!";
+               }
+
+               CZNC::Get().Broadcast(sMessage);
+               throw CException(CException::EX_Restart);
        } else if (sCommand.CaseCmp("JUMP") == 0 ||
                        sCommand.CaseCmp("CONNECT") == 0) {
                if (m_pUser) {
@@ -1171,6 +1180,11 @@ void CClient::HelpUser() {
                Table.SetCell("Command", "Shutdown");
                Table.SetCell("Arguments", "[message]");
                Table.SetCell("Description", "Shutdown znc completely");
+
+               Table.AddRow();
+               Table.SetCell("Command", "Restart");
+               Table.SetCell("Arguments", "[message]");
+               Table.SetCell("Description", "Restarts znc");
        }
 
        if (Table.size()) {
diff --git a/Utils.h b/Utils.h
index 8b0c4d37143fa12d925a0cf6350c85ca9c5bfbc2..54a61eabc4bea4f12d05ecfb56ad87acce40972b 100644 (file)
--- a/Utils.h
+++ b/Utils.h
@@ -183,7 +183,8 @@ private:
 class CException {
 public:
        typedef enum {
-               EX_Shutdown
+               EX_Shutdown,
+               EX_Restart
        } EType;
 
        CException(EType e) {
index 59a6ee059bfb9e68f6fba572868fe035f0edb05a..5e25a309f14b0d222172f7da3cb9827b1fc42e55 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -260,10 +260,22 @@ int main(int argc, char** argv) {
        try {
                iRet = pZNC->Loop();
        } catch (CException e) {
-               // EX_Shutdown is thrown to exit
                switch (e.GetType()) {
                        case CException::EX_Shutdown:
                                iRet = 0;
+                               break;
+                       case CException::EX_Restart: {
+                               // strdup() because GCC is stupid
+                               char *args[] = {
+                                       strdup(argv[0]),
+                                       strdup("--datadir"),
+                                       strdup(pZNC->GetZNCPath().c_str()),
+                                       strdup(pZNC->GetConfigFile().c_str()),
+                                       NULL
+                               };
+                               execvp(args[0], args);
+                               CUtils::PrintError("Unable to restart znc [" + CString(strerror(errno)) + "]");
+                       } /* Fall through */
                        default:
                                iRet = 1;
                }