mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Bots file load/save is thread safe.
This commit is contained in:
parent
9000302f43
commit
3f36248120
@ -29,7 +29,8 @@ namespace MCGalaxy.Bots {
|
|||||||
return "extra/bots/" + mapName + ".json";
|
return "extra/bots/" + mapName + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Load(Level lvl) {
|
public static void Load(Level lvl) { lock (lvl.botsIOLock) { LoadCore(lvl); } }
|
||||||
|
static void LoadCore(Level lvl) {
|
||||||
string path = BotsPath(lvl.MapName);
|
string path = BotsPath(lvl.MapName);
|
||||||
if (!File.Exists(path)) return;
|
if (!File.Exists(path)) return;
|
||||||
string json = File.ReadAllText(path);
|
string json = File.ReadAllText(path);
|
||||||
@ -49,7 +50,8 @@ namespace MCGalaxy.Bots {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Save(Level lvl) {
|
public static void Save(Level lvl) { lock (lvl.botsIOLock) { SaveCore(lvl); } }
|
||||||
|
static void SaveCore(Level lvl) {
|
||||||
PlayerBot[] bots = lvl.Bots.Items;
|
PlayerBot[] bots = lvl.Bots.Items;
|
||||||
string path = BotsPath(lvl.MapName);
|
string path = BotsPath(lvl.MapName);
|
||||||
if (!File.Exists(path) && bots.Length == 0) return;
|
if (!File.Exists(path) && bots.Length == 0) return;
|
||||||
|
@ -74,7 +74,7 @@ namespace MCGalaxy {
|
|||||||
/// <remarks> true if both worldChat and Server.worldChat are true. </remarks>
|
/// <remarks> true if both worldChat and Server.worldChat are true. </remarks>
|
||||||
public bool SeesServerWideChat { get { return Config.ServerWideChat && ServerConfig.ServerWideChat; } }
|
public bool SeesServerWideChat { get { return Config.ServerWideChat && ServerConfig.ServerWideChat; } }
|
||||||
|
|
||||||
internal readonly object queueLock = new object(), saveLock = new object(), savePropsLock = new object();
|
internal readonly object queueLock = new object(), saveLock = new object(), savePropsLock = new object(), botsIOLock = new object();
|
||||||
public List<ulong> blockqueue = new List<ulong>();
|
public List<ulong> blockqueue = new List<ulong>();
|
||||||
BufferedBlockSender bulkSender;
|
BufferedBlockSender bulkSender;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user