Right click lobby spawns to disable or remove players.

This commit is contained in:
Trevor Nichols
2020-07-19 11:11:27 +10:00
committed by abcdefg30
parent 13581c030d
commit d66e0bb22e
30 changed files with 165 additions and 45 deletions

View File

@@ -43,6 +43,7 @@ namespace OpenRA.Mods.Common.Server
{ "faction", Faction },
{ "team", Team },
{ "spawn", Spawn },
{ "clear_spawn", ClearPlayerSpawn },
{ "color", PlayerColor },
{ "sync_lobby", SyncLobby }
};
@@ -123,6 +124,11 @@ namespace OpenRA.Mods.Common.Server
if (server.LobbyInfo.Slots.Any(sl => sl.Value.Required && server.LobbyInfo.ClientInSlot(sl.Key) == null))
return;
// Can't have insufficient spawns
var availableSpawnPointCount = server.Map.SpawnPoints.Length - server.LobbyInfo.DisabledSpawnPoints.Count;
if (availableSpawnPointCount < server.LobbyInfo.Clients.Count(c => !c.IsObserver))
return;
server.StartGame();
}
}
@@ -170,6 +176,13 @@ namespace OpenRA.Mods.Common.Server
return true;
}
var availableSpawnPointCount = server.Map.SpawnPoints.Length - server.LobbyInfo.DisabledSpawnPoints.Count;
if (availableSpawnPointCount < server.LobbyInfo.Clients.Count(c => !c.IsObserver))
{
server.SendOrderTo(conn, "Message", "Unable to start the game until more spawn points are enabled.");
return true;
}
server.StartGame();
return true;
@@ -473,6 +486,8 @@ namespace OpenRA.Mods.Common.Server
if (c.Slot != null && !server.LobbyInfo.Slots[c.Slot].LockColor)
c.Color = c.PreferredColor = SanitizePlayerColor(server, c.Color, c.Index, conn);
server.LobbyInfo.DisabledSpawnPoints.Clear();
server.SyncLobbyInfo();
server.SendMessage("{0} changed the map to {1}.".F(client.Name, server.Map.Title));
@@ -811,6 +826,45 @@ namespace OpenRA.Mods.Common.Server
}
}
static bool ClearPlayerSpawn(S server, Connection conn, Session.Client client, string s)
{
var spawnPoint = Exts.ParseIntegerInvariant(s);
if (spawnPoint == 0)
return true;
var existingClient = server.LobbyInfo.Clients.FirstOrDefault(cc => cc.SpawnPoint == spawnPoint);
if (client != existingClient && !client.IsAdmin)
{
server.SendOrderTo(conn, "Message", "Only admins can clear spawn points.");
return true;
}
// Clearing a selected spawn point removes the player
if (existingClient != null)
{
// Prevent a map-defined lock spawn from being affected
if (existingClient.Slot != null && server.LobbyInfo.Slots[existingClient.Slot].LockSpawn)
return true;
existingClient.SpawnPoint = 0;
if (existingClient.State == Session.ClientState.Ready)
existingClient.State = Session.ClientState.NotReady;
server.SyncLobbyClients();
return true;
}
// Clearing an empty spawn point prevents it from being selected
// Clearing a disabled spawn restores it for use
if (!server.LobbyInfo.DisabledSpawnPoints.Contains(spawnPoint))
server.LobbyInfo.DisabledSpawnPoints.Add(spawnPoint);
else
server.LobbyInfo.DisabledSpawnPoints.Remove(spawnPoint);
server.SyncLobbyInfo();
return true;
}
static bool Spawn(S server, Connection conn, Session.Client client, string s)
{
lock (server.LobbyInfo)