Bots file load/save is thread safe.

This commit is contained in:
UnknownShadow200 2017-08-27 18:38:45 +10:00
parent 9000302f43
commit 3f36248120
2 changed files with 6 additions and 4 deletions

View File

@ -29,7 +29,8 @@ namespace MCGalaxy.Bots {
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);
if (!File.Exists(path)) return;
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;
string path = BotsPath(lvl.MapName);
if (!File.Exists(path) && bots.Length == 0) return;

View File

@ -74,7 +74,7 @@ namespace MCGalaxy {
/// <remarks> true if both worldChat and Server.worldChat are true. </remarks>
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>();
BufferedBlockSender bulkSender;