Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #define MONITORING_INTERVAL 2400.0 //server restarts every 40 minutes
- #define SHUTDOWN_DELAY 6.0 // When server's empty, restart after this many seconds
- Handle g_hTimer_PendingShutdown;
- Handle g_hTimer_EnableServerImmunity;
- bool g_bMapChange;
- public Plugin:myinfo =
- {
- name = "L4D2 Smart Server Restarter",
- author = "Visor, moified by drixevel (Keith Warren)",
- description = "Restarts the server after the game is finished",
- version = "1.3.3.7"
- };
- public void OnPluginStart()
- {
- CreateTimer(MONITORING_INTERVAL, CheckForPlayers, _, TIMER_REPEAT);
- }
- public Action CheckForPlayers(Handle timer)
- {
- ExecuteShutdownTimer();
- }
- public void OnClientDisconnect_Post(int client)
- {
- ExecuteShutdownTimer();
- }
- void ExecuteShutdownTimer()
- {
- // Check if there are no players on the servers
- if (GetRealClientCount() == 0 && g_hTimer_PendingShutdown == null)
- {
- // No players; let's wait and see if anyone joins within the specified interval
- g_hTimer_PendingShutdown = CreateTimer(SHUTDOWN_DELAY, ShutdownTimer);
- }
- }
- public Action ShutdownTimer(Handle timer)
- {
- // No one has joined within the allocated time? Shutdown the server
- if (GetRealClientCount() == 0 && g_hTimer_EnableServerImmunity == null)
- {
- ServerCommand("quit");
- }
- else // Someone did join. Go back to monitoring...
- {
- g_hTimer_PendingShutdown = null;
- return Plugin_Stop;
- }
- }
- int GetRealClientCount()
- {
- int count;
- for (int i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i) && !IsFakeClient(i))
- {
- count++;
- }
- }
- return count;
- }
- /* ---------- boolean values----------*/
- public void OnMapEnd()
- {
- KillTimerSafe(g_hTimer_EnableServerImmunity);
- g_hTimer_EnableServerImmunity = CreateTimer(120.0, DisableServerShutdownImmunity);
- g_bMapChange = true;
- }
- public void OnMapStart()
- {
- g_bMapChange = false;
- }
- public Action DisableServerShutdownImmunity(Handle timer)
- {
- g_hTimer_EnableServerImmunity = null;
- }
- public void OnClientPutInServer(int client)
- {
- if (!g_bMapChange)
- {
- KillTimerSafe(g_hTimer_EnableServerImmunity);
- }
- }
- void KillTimerSafe(Handle& timer)
- {
- if (timer != null)
- {
- KillTimer(timer);
- timer = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement