using System;
using Addon;
using System.Threading;
namespace InfRestart
{
//"<class name> : CPlugin" is needed to inherit the functions
public class InfRestart : CPlugin
{
public override void OnServerLoad()
{
ServerPrint("InfectedRestarter(V5) (by: Pieter [idea/help:JariZ,zxz0O0] <a href="http://www.itsmods.com" target="_blank" rel="noopener" class="mycode_url">www.itsmods.com</a>)");
}
public override void OnPlayerDisconnect(ServerClient Client)
{
String DVg_gametype = GetDvar("g_gametype");
ServerPrint("[InfectedRestarter] Gametype = (" + DVg_gametype + ")");
String DCpname = Client.Name;
String DCpXUID = Client.XUID;
if (DVg_gametype == "infect")
{
ServerPrint("[InfectedRestarter] OnDisconnect triggerred by: (" + DCpname + ") XUID: (" + DCpXUID + ")");
ThreadPool.
QueueUserWorkItem(new WaitCallback
(irth
)); }
else
{
ServerPrint("[InfectedRestarter] OnDisconnect triggerred, but Gametype = (" + DVg_gametype + ") so restarter doesnt care :likeaboss:");
}
}
void irth(object o)
{
try
{
Thread.Sleep(5000); //wait 5 seconds for enabling (to avoid fast_restart looping)
int axis = 0;
int allies = 0;
foreach (ServerClient client in GetClients())
{
if (client.Team == Teams.Allies)
{
allies++;
}
else if (client.Team == Teams.Axis)
{
axis++;
}
else
{
ServerPrint("[InfectedRestarter-DEBUG] No teamcount raised, Team value found was: (" + client.Team + ")");
}
}
if (axis == 0)
{
ServerSay("[^1Infected-Restart^7] The last ^2INFECTED^7 has disconnected! Server will ^2fast_restart^7 in ^25 seconds!", true);
Thread.Sleep(5000);
ServerPrint("[InfectedRestarter] Fast_restart triggerred: (Allies:" + allies + " - Axis:" + axis + ")");
ServerCommand("fast_restart");
return;
}
ServerPrint("[InfectedRestarter-DEBUG] End of procedure. wait till next disconnect");
return;
}
catch (Exception e) { ServerPrint("[InfectedRestarterException] " + e.Message); }
return;
}
}
}