mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Make more file saving methods threadsafe.
This commit is contained in:
parent
cb9df3e60d
commit
0d3a6d31c1
@ -329,8 +329,17 @@ namespace MCGalaxy
|
||||
}
|
||||
}
|
||||
|
||||
static readonly object saveLock = new object();
|
||||
public static void SaveBlocks(IEnumerable<Blocks> givenList) {
|
||||
try {
|
||||
lock (saveLock)
|
||||
SaveBlocksCore(givenList);
|
||||
} catch (Exception e) {
|
||||
Server.ErrorLog(e);
|
||||
}
|
||||
}
|
||||
|
||||
static void SaveBlocksCore(IEnumerable<Blocks> givenList) {
|
||||
using (StreamWriter w = new StreamWriter("properties/block.properties")) {
|
||||
w.WriteLine("#Version 2");
|
||||
w.WriteLine("# This file dictates what levels may use what blocks");
|
||||
@ -350,8 +359,6 @@ namespace MCGalaxy
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) { Server.ErrorLog(e); }
|
||||
}
|
||||
|
||||
public static bool canPlace(Player p, byte type) {
|
||||
Blocks b = BlockList[type];
|
||||
|
@ -70,7 +70,13 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
static readonly object saveLock = new object();
|
||||
public static void Save() {
|
||||
lock (saveLock)
|
||||
SaveCore();
|
||||
}
|
||||
|
||||
static void SaveCore() {
|
||||
using (StreamWriter w = new StreamWriter("properties/ExtraCommandPermissions.properties")) {
|
||||
w.WriteLine("# This file is used for setting up additional permissions that are needed in commands!!");
|
||||
w.WriteLine("#");
|
||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Games {
|
||||
public sealed partial class Team {
|
||||
|
||||
public static Dictionary<string, Team> TeamsList = new Dictionary<string, Team>();
|
||||
static readonly object readLock = new object();
|
||||
static readonly object ioLock = new object();
|
||||
|
||||
public static Team FindTeam(Player p) {
|
||||
foreach (var team in TeamsList) {
|
||||
@ -46,7 +46,7 @@ namespace MCGalaxy.Games {
|
||||
}
|
||||
|
||||
public static void SaveList() {
|
||||
lock (readLock)
|
||||
lock (ioLock)
|
||||
using (CP437Writer w = new CP437Writer("extra/teams.txt"))
|
||||
foreach (var pair in TeamsList)
|
||||
{
|
||||
@ -62,7 +62,7 @@ namespace MCGalaxy.Games {
|
||||
public static void LoadList() {
|
||||
if (!File.Exists("extra/teams.txt")) return;
|
||||
Team team = new Team();
|
||||
lock (readLock)
|
||||
lock (ioLock)
|
||||
PropertiesFile.Read("extra/teams.txt", ref team, LineProcessor, '=');
|
||||
if (team.Name != null) TeamsList[team.Name] = team;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user