Lock Server.LobbyInfo to prevent races with callback threads.

This commit is contained in:
Paul Chote
2020-09-20 12:54:03 +01:00
committed by abcdefg30
parent 8d1f72c104
commit 0672553a07
4 changed files with 1156 additions and 1040 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -21,25 +21,28 @@ namespace OpenRA.Mods.Common.Server
{
public void ClientJoined(OpenRA.Server.Server server, Connection conn)
{
if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
return;
var defaults = new Session.Global();
LobbyCommands.LoadMapSettings(server, defaults, server.Map.Rules);
var options = server.Map.Rules.Actors["player"].TraitInfos<ILobbyOptions>()
.Concat(server.Map.Rules.Actors["world"].TraitInfos<ILobbyOptions>())
.SelectMany(t => t.LobbyOptions(server.Map.Rules));
var optionNames = new Dictionary<string, string>();
foreach (var o in options)
optionNames[o.Id] = o.Name;
foreach (var kv in server.LobbyInfo.GlobalSettings.LobbyOptions)
lock (server.LobbyInfo)
{
if (!defaults.LobbyOptions.TryGetValue(kv.Key, out var def) || kv.Value.Value != def.Value)
if (optionNames.TryGetValue(kv.Key, out var optionName))
server.SendOrderTo(conn, "Message", optionName + ": " + kv.Value.Value);
if (server.LobbyInfo.ClientWithIndex(conn.PlayerIndex).IsAdmin)
return;
var defaults = new Session.Global();
LobbyCommands.LoadMapSettings(server, defaults, server.Map.Rules);
var options = server.Map.Rules.Actors["player"].TraitInfos<ILobbyOptions>()
.Concat(server.Map.Rules.Actors["world"].TraitInfos<ILobbyOptions>())
.SelectMany(t => t.LobbyOptions(server.Map.Rules));
var optionNames = new Dictionary<string, string>();
foreach (var o in options)
optionNames[o.Id] = o.Name;
foreach (var kv in server.LobbyInfo.GlobalSettings.LobbyOptions)
{
if (!defaults.LobbyOptions.TryGetValue(kv.Key, out var def) || kv.Value.Value != def.Value)
if (optionNames.TryGetValue(kv.Key, out var optionName))
server.SendOrderTo(conn, "Message", optionName + ": " + kv.Value.Value);
}
}
}
}

View File

@@ -36,7 +36,11 @@ namespace OpenRA.Mods.Common.Server
lastPing = Game.RunTime;
// Ignore client timeout in singleplayer games to make debugging easier
if (server.LobbyInfo.NonBotClients.Count() < 2 && server.Type != ServerType.Dedicated)
var nonBotClientCount = 0;
lock (server.LobbyInfo)
nonBotClientCount = server.LobbyInfo.NonBotClients.Count();
if (nonBotClientCount < 2 && server.Type != ServerType.Dedicated)
foreach (var c in server.Conns.ToList())
server.SendOrderTo(c, "Ping", Game.RunTime.ToString());
else