mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-07 02:23:20 +00:00
autorestart: Add sm_request_restart
This commit is contained in:
parent
72534ca62b
commit
fe40aaf34c
1 changed files with 33 additions and 7 deletions
|
@ -26,9 +26,22 @@ public void OnPluginStart()
|
||||||
SetFailState("This plugin is for L4D/L4D2 only.");
|
SetFailState("This plugin is for L4D/L4D2 only.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegAdminCmd("sm_request_restart", Command_RequestRestart, ADMFLAG_GENERIC);
|
||||||
|
|
||||||
CreateTimer(60.0, Timer_Check, _, TIMER_REPEAT);
|
CreateTimer(60.0, Timer_Check, _, TIMER_REPEAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Action Command_RequestRestart(int client, int args) {
|
||||||
|
if(IsServerEmpty()) {
|
||||||
|
ReplyToCommand(client, "Restarting...");
|
||||||
|
LogAction(client, -1, "requested to restart server if empty.");
|
||||||
|
ServerCommand("quit");
|
||||||
|
}else{
|
||||||
|
ReplyToCommand(client, "Players are online.");
|
||||||
|
}
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
public Action Timer_Check(Handle h) {
|
public Action Timer_Check(Handle h) {
|
||||||
// char time[8];
|
// char time[8];
|
||||||
// FormatTime(strtime, sizeof(strtime), "%H%M");
|
// FormatTime(strtime, sizeof(strtime), "%H%M");
|
||||||
|
@ -38,24 +51,37 @@ public Action Timer_Check(Handle h) {
|
||||||
// ServerCommand("quit");
|
// ServerCommand("quit");
|
||||||
// return Plugin_Stop;
|
// return Plugin_Stop;
|
||||||
// }else
|
// }else
|
||||||
if(IsServerEmpty()) {
|
if(IsServerEmptyWithOnlyBots()) {
|
||||||
//Server is stuck in non-hibernation with only bots, quit
|
//Server is stuck in non-hibernation with only bots, quit
|
||||||
LogAction(0, -1, "Detected server in hibernation with no players, restarting...");
|
LogAction(0, -1, "Detected server in hibernation with no players, restarting...");
|
||||||
ServerCommand("quit");
|
ServerCommand("quit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns true if there is a bot connected and there is no real players
|
bool IsServerEmptyWithOnlyBots() {
|
||||||
bool IsServerEmpty() {
|
bool hasBot;
|
||||||
bool hasClient;
|
for(int i = 1; i <= MaxClients; i++) {
|
||||||
for(int i = 1; i < MaxClients; i++) {
|
|
||||||
if(IsClientConnected(i) && IsClientInGame(i)) {
|
if(IsClientConnected(i) && IsClientInGame(i)) {
|
||||||
if(IsFakeClient(i))
|
if(IsFakeClient(i))
|
||||||
hasClient = true;
|
//Has a bot, but there could be other players.
|
||||||
|
hasBot = true;
|
||||||
else
|
else
|
||||||
|
//Is player, not empty.
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return hasClient;
|
return hasBot;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Returns true if there is a bot connected and there is no real players
|
||||||
|
bool IsServerEmpty() {
|
||||||
|
for(int i = 1; i <= MaxClients; i++) {
|
||||||
|
if(IsClientConnected(i) && IsClientInGame(i)) {
|
||||||
|
if(!IsFakeClient(i))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue