Needs sv_hibernate_when_empty 0 or it won't work.
PHP Code:
Handle g_hTimer = null;
public void OnClientDisconnect_Post(int client)
{
char sPass[64];
FindConVar("sv_password").GetString(sPass, sizeof(sPass));
if(StrEqual(sPass, "")) return;
bool bPlayers = false;
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
bPlayers = true;
break;
}
}
if(bPlayers) return;
if(g_hTimer != null)
{
delete g_hTimer;
g_hTimer = null;
}
g_hTimer = CreateTimer(600.0, Timer_RemovePassword);
}
public void OnClientPutInServer(int client)
{
if(IsValidClient(client) && g_hTimer != null)
{
delete g_hTimer;
g_hTimer = null;
}
}
public Action Timer_RemovePassword(Handle hTimer)
{
FindConVar("sv_password").SetString("");
delete g_hTimer;
g_hTimer = null;
return Plugin_Stop;
}
stock bool IsValidClient(int client)
{
return client >= 1 &&
client <= MaxClients &&
IsClientConnected(client) &&
!IsFakeClient(client);
}