]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Make /status message easier to read
authorWuzzy <Wuzzy2@mail.ru>
Wed, 17 Mar 2021 18:03:00 +0000 (19:03 +0100)
committersfan5 <sfan5@live.de>
Fri, 15 Oct 2021 16:13:57 +0000 (18:13 +0200)
src/server.cpp
src/util/string.h

index 7fb9a78e966b5833237f82e7000fdba191f7f35b..5022221ee62a4c5c7269ce8b342e4f0b591cc70e 100644 (file)
@@ -3119,15 +3119,16 @@ std::string Server::getStatusString()
        std::ostringstream os(std::ios_base::binary);
        os << "# Server: ";
        // Version
-       os << "version=" << g_version_string;
+       os << "version" << g_version_string;
        // Uptime
-       os << ", uptime=" << m_uptime_counter->get();
+       os << " | uptime: " << duration_to_string((int) m_uptime_counter->get());
        // Max lag estimate
-       os << ", max_lag=" << (m_env ? m_env->getMaxLagEstimate() : 0);
+       os << " | max lag: " << std::setprecision(3);
+       os << (m_env ? m_env->getMaxLagEstimate() : 0) << "s";
 
        // Information about clients
        bool first = true;
-       os << ", clients={";
+       os << " | clients: ";
        if (m_env) {
                std::vector<session_t> clients = m_clients.getClientIDs();
                for (session_t client_id : clients) {
@@ -3144,7 +3145,6 @@ std::string Server::getStatusString()
                        os << name;
                }
        }
-       os << "}";
 
        if (m_env && !((ServerMap*)(&m_env->getMap()))->isSavingEnabled())
                os << std::endl << "# Server: " << " WARNING: Map saving is disabled.";
index 21f1d6877baf4d863bb4be5ade23188e54bc3dcd..bca998f56993b8f57b6940d62e7570fccc987b35 100644 (file)
@@ -661,28 +661,49 @@ inline const char *bool_to_cstr(bool val)
        return val ? "true" : "false";
 }
 
+/**
+ * Converts a duration in seconds to a pretty-printed duration in
+ * days, hours, minutes and seconds.
+ *
+ * @param sec duration in seconds
+ * @return pretty-printed duration
+ */
 inline const std::string duration_to_string(int sec)
 {
+       std::ostringstream ss;
+       const char *neg = "";
+       if (sec < 0) {
+               sec = -sec;
+               neg = "-";
+       }
+       int total_sec = sec;
        int min = sec / 60;
        sec %= 60;
        int hour = min / 60;
        min %= 60;
+       int day = hour / 24;
+       hour %= 24;
+
+       if (day > 0) {
+               ss << neg << day << "d";
+               if (hour > 0 || min > 0 || sec > 0)
+                       ss << " ";
+       }
 
-       std::stringstream ss;
        if (hour > 0) {
-               ss << hour << "h";
+               ss << neg << hour << "h";
                if (min > 0 || sec > 0)
                        ss << " ";
        }
 
        if (min > 0) {
-               ss << min << "min";
+               ss << neg << min << "min";
                if (sec > 0)
                        ss << " ";
        }
 
-       if (sec > 0) {
-               ss << sec << "s";
+       if (sec > 0 || total_sec == 0) {
+               ss << neg << sec << "s";
        }
 
        return ss.str();