Disallow starting a game without players

This commit is contained in:
abcdefg30
2022-06-26 13:13:02 +02:00
committed by Matthias Mailänder
parent ea72c50fb4
commit ee3c54b572
3 changed files with 15 additions and 0 deletions

View File

@@ -33,6 +33,9 @@ namespace OpenRA.Mods.Common.Server
[TranslationReference] [TranslationReference]
static readonly string NoStartUntilRequiredSlotsFull = "no-start-until-required-slots-full"; static readonly string NoStartUntilRequiredSlotsFull = "no-start-until-required-slots-full";
[TranslationReference]
static readonly string NoStartWithoutPlayers = "no-start-without-players";
[TranslationReference] [TranslationReference]
static readonly string TwoHumansRequired = "two-humans-required"; static readonly string TwoHumansRequired = "two-humans-required";
@@ -252,6 +255,10 @@ namespace OpenRA.Mods.Common.Server
if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null)) if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null))
return; return;
// Don't start without any players
if (server.LobbyInfo.Slots.All(sl => server.LobbyInfo.ClientInSlot(sl.Key) == null))
return;
if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo)) if (LobbyUtils.InsufficientEnabledSpawnPoints(server.Map, server.LobbyInfo))
return; return;
@@ -296,6 +303,12 @@ namespace OpenRA.Mods.Common.Server
return true; return true;
} }
if (server.LobbyInfo.Slots.All(sl => server.LobbyInfo.ClientInSlot(sl.Key) == null))
{
server.SendOrderTo(conn, "Message", NoStartWithoutPlayers);
return true;
}
if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && server.LobbyInfo.NonBotPlayers.Count() < 2) if (!server.LobbyInfo.GlobalSettings.EnableSingleplayer && server.LobbyInfo.NonBotPlayers.Count() < 2)
{ {
server.SendLocalizedMessageTo(conn, TwoHumansRequired); server.SendLocalizedMessageTo(conn, TwoHumansRequired);

View File

@@ -383,6 +383,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{ {
startGameButton.IsDisabled = () => configurationDisabled() || map.Status != MapStatus.Available || startGameButton.IsDisabled = () => configurationDisabled() || map.Status != MapStatus.Available ||
orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) || orderManager.LobbyInfo.Slots.Any(sl => sl.Value.Required && orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) ||
orderManager.LobbyInfo.Slots.All(sl => orderManager.LobbyInfo.ClientInSlot(sl.Key) == null) ||
(!orderManager.LobbyInfo.GlobalSettings.EnableSingleplayer && orderManager.LobbyInfo.NonBotPlayers.Count() < 2) || (!orderManager.LobbyInfo.GlobalSettings.EnableSingleplayer && orderManager.LobbyInfo.NonBotPlayers.Count() < 2) ||
insufficientPlayerSpawns; insufficientPlayerSpawns;

View File

@@ -6,6 +6,7 @@ two-humans-required = This server requires at least two human players to start a
unknown-server-command = Unknown server command: { $command } unknown-server-command = Unknown server command: { $command }
only-only-host-start-game = Only the host can start the game. only-only-host-start-game = Only the host can start the game.
no-start-until-required-slots-full = Unable to start the game until required slots are full. no-start-until-required-slots-full = Unable to start the game until required slots are full.
no-start-without-players = Unable to start the game with no players.
insufficient-enabled-spawnPoints = Unable to start the game until more spawn points are enabled. insufficient-enabled-spawnPoints = Unable to start the game until more spawn points are enabled.
malformed-command = Malformed { $command } command malformed-command = Malformed { $command } command
chat-disabled = chat-disabled =