Dedicated servers can use autorestart
This commit is contained in:
@@ -327,6 +327,13 @@ namespace Barotrauma
|
|||||||
new GUIMessageBox("", string.Join(" ", args));
|
new GUIMessageBox("", string.Join(" ", args));
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
commands.Add(new Command("autorestart", "autorestart: Toggle autorestart on/off when hosting a server.", (string[] args) =>
|
||||||
|
{
|
||||||
|
if (GameMain.Server == null) return;
|
||||||
|
GameMain.NetLobbyScreen.ToggleAutoRestart();
|
||||||
|
NewMessage(GameMain.Server.AutoRestart ? "Automatic restart enabled." : "Automatic restart disabled.", Color.White);
|
||||||
|
}));
|
||||||
|
|
||||||
commands.Add(new Command("debugdraw", "debugdraw: Toggle the debug drawing mode on/off.", (string[] args) =>
|
commands.Add(new Command("debugdraw", "debugdraw: Toggle the debug drawing mode on/off.", (string[] args) =>
|
||||||
{
|
{
|
||||||
GameMain.DebugDraw = !GameMain.DebugDraw;
|
GameMain.DebugDraw = !GameMain.DebugDraw;
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private GUIDropDown shuttleList;
|
private GUIDropDown shuttleList;
|
||||||
|
|
||||||
|
|
||||||
private Sprite backgroundSprite;
|
private Sprite backgroundSprite;
|
||||||
|
|
||||||
private GUITextBox serverMessage;
|
private GUITextBox serverMessage;
|
||||||
|
|
||||||
|
private float autoRestartTimer;
|
||||||
|
|
||||||
public GUITextBox ServerMessage
|
public GUITextBox ServerMessage
|
||||||
{
|
{
|
||||||
get { return serverMessage; }
|
get { return serverMessage; }
|
||||||
@@ -154,6 +155,17 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string AutoRestartText()
|
||||||
|
{
|
||||||
|
if (GameMain.Server != null)
|
||||||
|
{
|
||||||
|
if (!GameMain.Server.AutoRestart || GameMain.Server.ConnectedClients.Count == 0) return "";
|
||||||
|
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(GameMain.Server.AutoRestartTimer, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (autoRestartTimer == 0.0f) return "";
|
||||||
|
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(autoRestartTimer, 0));
|
||||||
|
}
|
||||||
|
|
||||||
public NetLobbyScreen()
|
public NetLobbyScreen()
|
||||||
{
|
{
|
||||||
@@ -596,6 +608,12 @@ namespace Barotrauma
|
|||||||
autoRestartTimer = timer;
|
autoRestartTimer = timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ToggleAutoRestart()
|
||||||
|
{
|
||||||
|
autoRestartBox.Selected = !autoRestartBox.Selected;
|
||||||
|
ToggleAutoRestart(autoRestartBox);
|
||||||
|
}
|
||||||
|
|
||||||
private bool ToggleAutoRestart(GUITickBox tickBox)
|
private bool ToggleAutoRestart(GUITickBox tickBox)
|
||||||
{
|
{
|
||||||
if (GameMain.Server == null) return false;
|
if (GameMain.Server == null) return false;
|
||||||
|
|||||||
@@ -131,6 +131,14 @@ namespace Barotrauma
|
|||||||
GameMain.Server.EndGame();
|
GameMain.Server.EndGame();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
commands.Add(new Command("autorestart", "autorestart: Toggle automatic round restarting on/off.", (string[] args) =>
|
||||||
|
{
|
||||||
|
if (GameMain.Server == null) return;
|
||||||
|
|
||||||
|
GameMain.Server.AutoRestart = !GameMain.Server.AutoRestart;
|
||||||
|
NewMessage(GameMain.Server.AutoRestart ? "Automatic restart enabled." : "Automatic restart disabled.", Color.White);
|
||||||
|
}));
|
||||||
|
|
||||||
commands.Add(new Command("entitydata", "", (string[] args) =>
|
commands.Add(new Command("entitydata", "", (string[] args) =>
|
||||||
{
|
{
|
||||||
if (args.Length == 0) return;
|
if (args.Length == 0) return;
|
||||||
|
|||||||
@@ -249,6 +249,36 @@ namespace Barotrauma
|
|||||||
NewMessage("Crew AI enabled", Color.White);
|
NewMessage("Crew AI enabled", Color.White);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
commands.Add(new Command("autorestartinterval", "autorestartinterval [seconds]: Set how long the server waits between rounds before automatically starting a new one.", (string[] args) =>
|
||||||
|
{
|
||||||
|
if (GameMain.Server == null) return;
|
||||||
|
if (args.Length > 0)
|
||||||
|
{
|
||||||
|
int parsedInt = 0;
|
||||||
|
if (int.TryParse(args[0], out parsedInt) && parsedInt >= 0)
|
||||||
|
{
|
||||||
|
GameMain.Server.AutoRestartInterval = parsedInt;
|
||||||
|
NewMessage("Autorestart interval set to " + GameMain.Server.AutoRestartInterval + " seconds.", Color.White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
commands.Add(new Command("autorestarttimer", "autorestarttimer [seconds]: Set the current autorestart countdown to the specified value.", (string[] args) =>
|
||||||
|
{
|
||||||
|
if (GameMain.Server == null) return;
|
||||||
|
if (args.Length > 0)
|
||||||
|
{
|
||||||
|
int parsedInt = 0;
|
||||||
|
if (int.TryParse(args[0], out parsedInt) && parsedInt >= 0)
|
||||||
|
{
|
||||||
|
GameMain.Server.AutoRestartTimer = parsedInt;
|
||||||
|
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||||
|
NewMessage("Autorestart timer set to " + GameMain.Server.AutoRestartTimer + " seconds.", Color.White);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
commands.Add(new Command("kick", "kick [name]: Kick a player out of the server.", (string[] args) =>
|
commands.Add(new Command("kick", "kick [name]: Kick a player out of the server.", (string[] args) =>
|
||||||
{
|
{
|
||||||
if (GameMain.NetworkMember == null || args.Length == 0) return;
|
if (GameMain.NetworkMember == null || args.Length == 0) return;
|
||||||
|
|||||||
@@ -408,10 +408,10 @@ namespace Barotrauma.Networking
|
|||||||
initiatedStartGame = false;
|
initiatedStartGame = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count>0)
|
else if (autoRestart && Screen.Selected == GameMain.NetLobbyScreen && connectedClients.Count > 0)
|
||||||
{
|
{
|
||||||
AutoRestartTimer -= deltaTime;
|
AutoRestartTimer -= deltaTime;
|
||||||
if (AutoRestartTimer < 0.0f && GameMain.NetLobbyScreen.StartButtonEnabled)
|
if (AutoRestartTimer < 0.0f && !initiatedStartGame)
|
||||||
{
|
{
|
||||||
StartGame();
|
StartGame();
|
||||||
}
|
}
|
||||||
@@ -1057,6 +1057,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private IEnumerable<object> InitiateStartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode)
|
private IEnumerable<object> InitiateStartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode)
|
||||||
{
|
{
|
||||||
|
initiatedStartGame = true;
|
||||||
GameMain.NetLobbyScreen.StartButtonEnabled = false;
|
GameMain.NetLobbyScreen.StartButtonEnabled = false;
|
||||||
|
|
||||||
if (connectedClients.Any())
|
if (connectedClients.Any())
|
||||||
@@ -1113,9 +1114,7 @@ namespace Barotrauma.Networking
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode)
|
private IEnumerable<object> StartGame(Submarine selectedSub, Submarine selectedShuttle, GameModePreset selectedMode)
|
||||||
{
|
{
|
||||||
initiatedStartGame = true;
|
|
||||||
|
|
||||||
entityEventManager.Clear();
|
entityEventManager.Clear();
|
||||||
|
|
||||||
GameMain.NetLobbyScreen.StartButtonEnabled = false;
|
GameMain.NetLobbyScreen.StartButtonEnabled = false;
|
||||||
@@ -1353,7 +1352,12 @@ namespace Barotrauma.Networking
|
|||||||
Mission mission = GameMain.GameSession.Mission;
|
Mission mission = GameMain.GameSession.Mission;
|
||||||
GameMain.GameSession.gameMode.End(endMessage);
|
GameMain.GameSession.gameMode.End(endMessage);
|
||||||
|
|
||||||
if (autoRestart) AutoRestartTimer = AutoRestartInterval;
|
if (autoRestart)
|
||||||
|
{
|
||||||
|
AutoRestartTimer = AutoRestartInterval;
|
||||||
|
//send a netlobby update to get the clients' autorestart timers up to date
|
||||||
|
GameMain.NetLobbyScreen.LastUpdateID++;
|
||||||
|
}
|
||||||
|
|
||||||
if (SaveServerLogs) log.Save();
|
if (SaveServerLogs) log.Save();
|
||||||
|
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ namespace Barotrauma.Networking
|
|||||||
public float AutoRestartInterval
|
public float AutoRestartInterval
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
private set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HasDefaultValue(true, true)]
|
[HasDefaultValue(true, true)]
|
||||||
@@ -166,7 +166,7 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
public bool AutoRestart
|
public bool AutoRestart
|
||||||
{
|
{
|
||||||
get { return (connectedClients.Count != 0) && autoRestart; }
|
get { return autoRestart; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
autoRestart = value;
|
autoRestart = value;
|
||||||
@@ -236,6 +236,8 @@ namespace Barotrauma.Networking
|
|||||||
doc.Root.SetAttributeValue("maxplayers", maxPlayers);
|
doc.Root.SetAttributeValue("maxplayers", maxPlayers);
|
||||||
doc.Root.SetAttributeValue("enableupnp", config.EnableUPnP);
|
doc.Root.SetAttributeValue("enableupnp", config.EnableUPnP);
|
||||||
|
|
||||||
|
doc.Root.SetAttributeValue("autorestart", autoRestart);
|
||||||
|
|
||||||
doc.Root.SetAttributeValue("SubSelection", subSelectionMode.ToString());
|
doc.Root.SetAttributeValue("SubSelection", subSelectionMode.ToString());
|
||||||
doc.Root.SetAttributeValue("ModeSelection", modeSelectionMode.ToString());
|
doc.Root.SetAttributeValue("ModeSelection", modeSelectionMode.ToString());
|
||||||
|
|
||||||
@@ -279,6 +281,14 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
ObjectProperties = ObjectProperty.InitProperties(this, doc.Root);
|
ObjectProperties = ObjectProperty.InitProperties(this, doc.Root);
|
||||||
|
|
||||||
|
AutoRestart = ToolBox.GetAttributeBool(doc.Root, "autorestart", false);
|
||||||
|
#if CLIENT
|
||||||
|
if (autoRestart)
|
||||||
|
{
|
||||||
|
GameMain.NetLobbyScreen.SetAutoRestart(autoRestart, AutoRestartInterval);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
subSelectionMode = SelectionMode.Manual;
|
subSelectionMode = SelectionMode.Manual;
|
||||||
Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "SubSelection", "Manual"), out subSelectionMode);
|
Enum.TryParse<SelectionMode>(ToolBox.GetAttributeString(doc.Root, "SubSelection", "Manual"), out subSelectionMode);
|
||||||
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
|
Voting.AllowSubVoting = subSelectionMode == SelectionMode.Vote;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace Barotrauma
|
|||||||
public UInt16 LastUpdateID
|
public UInt16 LastUpdateID
|
||||||
{
|
{
|
||||||
get { if (GameMain.Server != null && lastUpdateID < 1) lastUpdateID++; return lastUpdateID; }
|
get { if (GameMain.Server != null && lastUpdateID < 1) lastUpdateID++; return lastUpdateID; }
|
||||||
set { if (GameMain.Server != null) return; lastUpdateID = value; }
|
set { lastUpdateID = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//for guitextblock delegate
|
//for guitextblock delegate
|
||||||
@@ -23,20 +23,6 @@ namespace Barotrauma
|
|||||||
|
|
||||||
private string levelSeed = "";
|
private string levelSeed = "";
|
||||||
|
|
||||||
private float autoRestartTimer;
|
|
||||||
|
|
||||||
public string AutoRestartText()
|
|
||||||
{
|
|
||||||
if (GameMain.Server != null)
|
|
||||||
{
|
|
||||||
if (!GameMain.Server.AutoRestart) return "";
|
|
||||||
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(GameMain.Server.AutoRestartTimer, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (autoRestartTimer == 0.0f) return "";
|
|
||||||
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(autoRestartTimer, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ToggleTraitorsEnabled(int dir)
|
public void ToggleTraitorsEnabled(int dir)
|
||||||
{
|
{
|
||||||
if (GameMain.Server == null) return;
|
if (GameMain.Server == null) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user