mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Fix concurrency crashes for player list
Bug report by doranchak (forum post no 1136)
This commit is contained in:
parent
e3c38ed6ac
commit
858ad12783
1 changed files with 13 additions and 4 deletions
|
|
@ -20,7 +20,7 @@ namespace MinecraftClient
|
|||
private static List<string> cmd_names = new List<string>();
|
||||
private static Dictionary<string, Command> cmds = new Dictionary<string, Command>();
|
||||
private List<ChatBot> bots = new List<ChatBot>();
|
||||
private Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid,string>();
|
||||
private readonly Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid,string>();
|
||||
private static List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>();
|
||||
public void BotLoad(ChatBot b) { b.SetHandler(this); bots.Add(b); b.Initialize(); Settings.SingleCommand = ""; }
|
||||
public void BotUnLoad(ChatBot b) { bots.RemoveAll(item => object.ReferenceEquals(item, b)); }
|
||||
|
|
@ -412,7 +412,10 @@ namespace MinecraftClient
|
|||
|
||||
public void OnPlayerJoin(Guid uuid, string name)
|
||||
{
|
||||
onlinePlayers[uuid] = name;
|
||||
lock (onlinePlayers)
|
||||
{
|
||||
onlinePlayers[uuid] = name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -422,7 +425,10 @@ namespace MinecraftClient
|
|||
|
||||
public void OnPlayerLeave(Guid uuid)
|
||||
{
|
||||
onlinePlayers.Remove(uuid);
|
||||
lock (onlinePlayers)
|
||||
{
|
||||
onlinePlayers.Remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -432,7 +438,10 @@ namespace MinecraftClient
|
|||
|
||||
public string[] getOnlinePlayers()
|
||||
{
|
||||
return onlinePlayers.Values.Distinct().ToArray();
|
||||
lock (onlinePlayers)
|
||||
{
|
||||
return onlinePlayers.Values.Distinct().ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue