mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Make more file saving methods threadsafe.
This commit is contained in:
parent
cb9df3e60d
commit
0d3a6d31c1
@ -329,28 +329,35 @@ namespace MCGalaxy
|
||||
}
|
||||
}
|
||||
|
||||
static readonly object saveLock = new object();
|
||||
public static void SaveBlocks(IEnumerable<Blocks> givenList) {
|
||||
try {
|
||||
using (StreamWriter w = new StreamWriter("properties/block.properties")) {
|
||||
w.WriteLine("#Version 2");
|
||||
w.WriteLine("# This file dictates what levels may use what blocks");
|
||||
w.WriteLine("# If someone has royally screwed up the ranks, just delete this file and let the server restart");
|
||||
w.WriteLine("# Allowed ranks: " + Group.concatList(false, false, true));
|
||||
w.WriteLine("# Disallow and allow can be left empty, just make sure there's 2 spaces between the colons");
|
||||
w.WriteLine("# This works entirely on permission values, not names. Do not enter a rank name. Use its permission value");
|
||||
w.WriteLine("# BlockName : LowestRank : Disallow : Allow");
|
||||
w.WriteLine("# lava : 60 : 80,67 : 40,41,55");
|
||||
w.WriteLine("");
|
||||
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");
|
||||
w.WriteLine("# If someone has royally screwed up the ranks, just delete this file and let the server restart");
|
||||
w.WriteLine("# Allowed ranks: " + Group.concatList(false, false, true));
|
||||
w.WriteLine("# Disallow and allow can be left empty, just make sure there's 2 spaces between the colons");
|
||||
w.WriteLine("# This works entirely on permission values, not names. Do not enter a rank name. Use its permission value");
|
||||
w.WriteLine("# BlockName : LowestRank : Disallow : Allow");
|
||||
w.WriteLine("# lava : 60 : 80,67 : 40,41,55");
|
||||
w.WriteLine("");
|
||||
|
||||
foreach (Blocks bs in givenList) {
|
||||
if (bs.IncludeInBlockProperties()) {
|
||||
string line = Block.Name(bs.type) + " : " + (int)bs.lowestRank + " : " + GrpCommands.getInts(bs.disallow) + " : " + GrpCommands.getInts(bs.allow);
|
||||
w.WriteLine(line);
|
||||
}
|
||||
foreach (Blocks bs in givenList) {
|
||||
if (bs.IncludeInBlockProperties()) {
|
||||
string line = Block.Name(bs.type) + " : " + (int)bs.lowestRank + " : " + GrpCommands.getInts(bs.disallow) + " : " + GrpCommands.getInts(bs.allow);
|
||||
w.WriteLine(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) { Server.ErrorLog(e); }
|
||||
}
|
||||
|
||||
public static bool canPlace(Player p, byte 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