using System; using System.IO; using System.Text; using System.Reflection; using System.Collections.Generic; using System.Data; using System.Text.RegularExpressions; using System.Threading; using System.Timers; using PRoCon.Core; using PRoCon.Core.Plugin; using PRoCon.Core.Plugin.Commands; using PRoCon.Core.Players; using PRoCon.Core.Players.Items; using PRoCon.Core.Battlemap; using PRoCon.Core.Maps; using PRoCon.Core.HttpServer; namespace PRoConEvents { public class CAutoRestarter : PRoConPluginAPI, IPRoConPluginInterface { private bool restarting; private System.Timers.Timer RestartTimer; private bool autoRestartEnable; private int autoRestartDelay; private bool m_isPluginEnabled; public CAutoRestarter() { this.restarting = false; this.autoRestartEnable = false; this.autoRestartDelay = 15; this.m_isPluginEnabled = false; } public string GetPluginName() { return "Automatic Restarter"; } public string GetPluginVersion() { return "1.0"; } public string GetPluginAuthor() { return "Flash_Hit"; } public string GetPluginWebsite() { return "battlelog.battlefield.com/bf3/platoon/3307924585064219629/"; } public string GetPluginDescription() { return @"

Description

At the end of a round you can perform an automatic restart.

You can set a delay to restart after X seconds.

Settings

Enabled

Enables/Disables AutoRestart

Delay

Number of seconds before restarting. Default 15 seconds (It will show '45 seconds left' on Scoreboard).
"; } public void OnPluginLoaded(string strHostName, string strPort, string strPRoConVersion) { this.RegisterEvents(this.GetType().Name, "OnRoundOver"); } public void OnPluginEnable() { this.ExecuteCommand("procon.protected.pluginconsole.write", "^bAutomatic Restarter ^2Enabled!"); this.m_isPluginEnabled = true; } public void OnPluginDisable() { this.ExecuteCommand("procon.protected.pluginconsole.write", "^bAutomatic Restarter ^1Disabled!" ); this.m_isPluginEnabled = false; } public List GetDisplayPluginVariables() { List lstReturn = new List(); lstReturn.Add(new CPluginVariable("AutoRestart|Enabled", typeof(bool), autoRestartEnable)); lstReturn.Add(new CPluginVariable("AutoRestart|Delay", typeof(int), autoRestartDelay)); return lstReturn; } public List GetPluginVariables() { return GetDisplayPluginVariables(); } public void SetPluginVariable(string strVariable, string strValue) { if (Regex.Match(strVariable, @"Enabled").Success) { bool tmpAutoRestartEnable = false; Boolean.TryParse(strValue, out tmpAutoRestartEnable); autoRestartEnable = tmpAutoRestartEnable; } else if (Regex.Match(strVariable, @"Delay").Success) { int tmpTime = 15; int.TryParse(strValue, out tmpTime); autoRestartDelay = tmpTime; } } #region events public void OnRoundOver(int winningTeamId) { if (this.autoRestartEnable == true && this.m_isPluginEnabled == true) { SetRestartTimer(); } } #endregion private void SetRestartTimer() { RestartTimer = new System.Timers.Timer(1001 + (this.autoRestartDelay * 1000)); RestartTimer.Elapsed += OnRestart; RestartTimer.Enabled = true; } private void OnRestart(object source, ElapsedEventArgs e) { this.ExecuteCommand("procon.protected.pluginconsole.write", "restarting..."); this.ExecuteCommand("procon.protected.send", "mapList.runNextRound"); RestartTimer.Enabled = false; } } }