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 List<string> cmd_names = new List<string>();
|
||||||
private static Dictionary<string, Command> cmds = new Dictionary<string, Command>();
|
private static Dictionary<string, Command> cmds = new Dictionary<string, Command>();
|
||||||
private List<ChatBot> bots = new List<ChatBot>();
|
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>();
|
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 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)); }
|
public void BotUnLoad(ChatBot b) { bots.RemoveAll(item => object.ReferenceEquals(item, b)); }
|
||||||
|
|
@ -411,9 +411,12 @@ namespace MinecraftClient
|
||||||
/// <param name="name">Name of the player</param>
|
/// <param name="name">Name of the player</param>
|
||||||
|
|
||||||
public void OnPlayerJoin(Guid uuid, string name)
|
public void OnPlayerJoin(Guid uuid, string name)
|
||||||
|
{
|
||||||
|
lock (onlinePlayers)
|
||||||
{
|
{
|
||||||
onlinePlayers[uuid] = name;
|
onlinePlayers[uuid] = name;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Triggered when a player has left the game
|
/// Triggered when a player has left the game
|
||||||
|
|
@ -421,9 +424,12 @@ namespace MinecraftClient
|
||||||
/// <param name="uuid">UUID of the player</param>
|
/// <param name="uuid">UUID of the player</param>
|
||||||
|
|
||||||
public void OnPlayerLeave(Guid uuid)
|
public void OnPlayerLeave(Guid uuid)
|
||||||
|
{
|
||||||
|
lock (onlinePlayers)
|
||||||
{
|
{
|
||||||
onlinePlayers.Remove(uuid);
|
onlinePlayers.Remove(uuid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a set of online player names
|
/// Get a set of online player names
|
||||||
|
|
@ -431,8 +437,11 @@ namespace MinecraftClient
|
||||||
/// <returns>Online player names</returns>
|
/// <returns>Online player names</returns>
|
||||||
|
|
||||||
public string[] getOnlinePlayers()
|
public string[] getOnlinePlayers()
|
||||||
|
{
|
||||||
|
lock (onlinePlayers)
|
||||||
{
|
{
|
||||||
return onlinePlayers.Values.Distinct().ToArray();
|
return onlinePlayers.Values.Distinct().ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue