Browse Source

Added command to output current uptime

Provides a reference to when the server is scheduled for downtime again,
in case some maintenance should be performed.
nosoop 7 years ago
parent
commit
8f5afa2d8e
1 changed files with 29 additions and 1 deletions
  1. 29 1
      scripting/csrd_uptime_limiter.sp

+ 29 - 1
scripting/csrd_uptime_limiter.sp

@@ -15,7 +15,7 @@
 
 #pragma newdecls required
 
-#define PLUGIN_VERSION "0.1.0"
+#define PLUGIN_VERSION "0.2.0"
 public Plugin myinfo = {
     name = "[CSRD] Uptime Limiter",
     author = "nosoop",
@@ -26,6 +26,34 @@ public Plugin myinfo = {
 
 int g_nMaxUptimeLimit = 60 * 60 * 12;
 
+public void OnPluginStart() {
+	RegAdminCmd("csrd_uptime", AdminCmd_GetUptime, ADMFLAG_ROOT,
+			"Outputs the server's current uptime.");
+}
+
+/**
+ * Command to output current uptime.
+ */
+public Action AdminCmd_GetUptime(int client, int argc) {
+	char uptime[64], limit[64];
+	FormatDuration(uptime, sizeof(uptime), GetUptime());
+	FormatDuration(limit, sizeof(limit), g_nMaxUptimeLimit);
+	
+	ReplyToCommand(client, "Uptime: %s (limit %s)", uptime, limit);
+	
+	return Plugin_Handled;
+}
+
+/**
+ * Pretty-prints a duration of nSeconds as hours / minutes / seconds.
+ */
+void FormatDuration(char[] buffer, int maxlen, int nSeconds) {
+	Format(buffer, maxlen, "%d hours, %d minutes, %d seconds",
+			nSeconds / 3600,
+			(nSeconds % 3600) / 60,
+			nSeconds % 60);
+}
+
 /**
  * Called when the Waiting for Players round state begins.
  * At least one client, human or bot, must be connected for this forward to be called.