Stop the service after being empty for 2 days

Revision as of 17:22, 3 April 2023 by TCAWiki (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This script will stop the game server if it has been empty for 2 days. Add the IronPython script for the query monitoring event. A MySQL database is required.

import clr
clr.AddReference('TCAdmin.SDK')
from System import DateTime, String
from TCAdmin.SDK.Database import DatabaseManager

now = DateTime.UtcNow
start = ThisService.StartTime
if now.Subtract(start).Days >= 2 :
  Script.WriteToConsole("Checking stats for players in the last 2 days...")
  db = DatabaseManager.CreateDatabaseManager()
  dt = db.Execute(String.Format("select * from tc_game_service_detailed_stats where service_id={0} and players > 0 and detailed_date >= ( CURDATE() - INTERVAL 2 DAY )", ThisService.ServiceId))
  if dt.Rows.Count == 0 :
    Script.WriteToConsole("Stopping...")
    ThisService.Stop("No players connected in the last 2 days")
Retrieved from "https://help.tcadmin.com/index.php?title=Stop_the_service_after_being_empty_for_2_days&oldid=2543"