Combine .env and .properties files into one.

This commit is contained in:
UnknownShadow200 2016-07-22 23:21:10 +10:00
parent f93523deb0
commit e01eba80e8
8 changed files with 110 additions and 87 deletions

View File

@ -185,7 +185,7 @@ namespace MCGalaxy.Commands {
EdgeLevel = lvl.EdgeLevel; CloudsHeight = lvl.CloudsHeight;
MaxFog = lvl.MaxFogDistance;
CloudsSpeed = lvl.CloudsSpeed; WeatherSpeed = lvl.WeatherSpeed;
EdgeBlock = lvl.EdgeBlock; HorizonBlock = lvl.HorizonBlock;
EdgeBlock = (byte)lvl.EdgeBlock; HorizonBlock = (byte)lvl.HorizonBlock;
WeatherFade = lvl.WeatherFade;
TerrainUrl = lvl.terrainUrl != "" ?
@ -205,52 +205,46 @@ namespace MCGalaxy.Commands {
string path = LevelInfo.FindPropertiesFile(name);
if (path != null)
PropertiesFile.Read(path, ParseProperty, '=');
path = "levels/level properties/" + name + ".env";
if (File.Exists(path))
PropertiesFile.Read(path, ParseEnv, '=');
if (Authors == null) Authors = "";
}
void ParseProperty(string key, string value) {
switch (key.ToLower()) {
case "physics": Physics = int.Parse(value); break;
case "guns": Guns = bool.Parse(value); break;
case "texture": TerrainUrl = value; break;
case "texturepack": TextureUrl = value; break;
case "clouds-speed": CloudsSpeed = int.Parse(value); break;
case "weather-speed": WeatherSpeed = int.Parse(value); break;
case "weather-fade": WeatherFade = int.Parse(value); break;
case "useblockdb": blockDB = bool.Parse(value); break;
case "realmowner": RealmOwner = value; break;
case "perbuild": build = GetPerm(value); break;
case "pervisit": visit = GetPerm(value); break;
case "perbuildmax": buildmax = GetPerm(value); break;
case "pervisitmax": visitmax = GetPerm(value); break;
case "visitwhitelist": VisitWhitelist = Parse(value); break;
case "visitblacklist": VisitBlacklist = Parse(value); break;
case "authors": Authors = value; break;
case "roundsplayed": TotalRounds = int.Parse(value); break;
case "RoundsHumanWon": HumanRounds = int.Parse(value); break;
case "likes": Likes = int.Parse(value); break;
case "dislikes": Dislikes = int.Parse(value); break;
}
}
void ParseEnv(string key, string value) {
switch (key.ToLower()) {
case "cloudcolor": Clouds = value; break;
case "fogcolor": Fog = value; break;
case "skycolor": Sky = value; break;
case "shadowcolor": Shadow = value; break;
case "lightcolor": Light = value; break;
case "edgeblock": EdgeBlock = byte.Parse(value); break;
case "edgelevel": EdgeLevel = short.Parse(value); break;
case "cloudsheight": CloudsHeight = short.Parse(value); break;
case "maxfog": MaxFog = short.Parse(value); break;
case "horizonblock": HorizonBlock = byte.Parse(value); break;
case "physics": Physics = int.Parse(value); break;
case "guns": Guns = bool.Parse(value); break;
case "useblockdb": blockDB = bool.Parse(value); break;
case "realmowner": RealmOwner = value; break;
case "perbuild": build = GetPerm(value); break;
case "pervisit": visit = GetPerm(value); break;
case "perbuildmax": buildmax = GetPerm(value); break;
case "pervisitmax": visitmax = GetPerm(value); break;
case "visitwhitelist": VisitWhitelist = Parse(value); break;
case "visitblacklist": VisitBlacklist = Parse(value); break;
case "authors": Authors = value; break;
case "roundsplayed": TotalRounds = int.Parse(value); break;
case "RoundsHumanWon": HumanRounds = int.Parse(value); break;
case "likes": Likes = int.Parse(value); break;
case "dislikes": Dislikes = int.Parse(value); break;
case "cloudcolor": Clouds = value; break;
case "fogcolor": Fog = value; break;
case "skycolor": Sky = value; break;
case "shadowcolor": Shadow = value; break;
case "lightcolor": Light = value; break;
case "edgeblock": EdgeBlock = byte.Parse(value); break;
case "edgelevel": EdgeLevel = short.Parse(value); break;
case "horizonblock": HorizonBlock = byte.Parse(value); break;
case "cloudsheight": CloudsHeight = short.Parse(value); break;
case "maxfog": MaxFog = short.Parse(value); break;
case "texture": TerrainUrl = value; break;
case "texturepack": TextureUrl = value; break;
case "clouds-speed": CloudsSpeed = int.Parse(value); break;
case "weather-speed": WeatherSpeed = int.Parse(value); break;
case "weather-fade": WeatherFade = int.Parse(value); break;
}
}

View File

@ -29,15 +29,6 @@ namespace MCGalaxy.Levels.IO {
Server.s.Log("Failed to save level properties!");
Logger.WriteError(ex);
return;
}
path = Path.ChangeExtension(path, ".env");
try {
using (CP437Writer writer = new CP437Writer(path))
WriteEnvProperties(level, writer);
} catch (Exception ex) {
Server.s.Log("Failed to save environment properties");
Logger.WriteError(ex);
}
}
@ -48,32 +39,13 @@ namespace MCGalaxy.Levels.IO {
ConfigElement.Serialise(Server.levelConfig, " settings", w, level);
}
static void WriteEnvProperties(Level level, StreamWriter writer) {
if(level.CloudColor != null)
writer.WriteLine("CloudColor = " + level.CloudColor);
if (level.SkyColor != null)
writer.WriteLine("SkyColor = " + level.SkyColor);
if (level.LightColor != null)
writer.WriteLine("LightColor = " + level.LightColor);
if (level.ShadowColor != null)
writer.WriteLine("ShadowColor = " + level.ShadowColor);
if (level.FogColor != null)
writer.WriteLine("FogColor = " + level.FogColor);
writer.WriteLine("EdgeLevel = " + level.EdgeLevel);
writer.WriteLine("CloudsHeight = " + level.CloudsHeight);
writer.WriteLine("MaxFog = " + level.MaxFogDistance);
writer.WriteLine("EdgeBlock = " + level.EdgeBlock);
writer.WriteLine("HorizonBlock = " + level.HorizonBlock);
}
public static void Load(Level level, string path) {
PropertiesFile.Read(path, ref level, PropLineProcessor);
}
public static void LoadEnv(Level level, string name) {
string path = "levels/level properties/" + name + ".env";
public static void LoadEnv(Level level) {
string path = "levels/level properties/" + level.name + ".env";
PropertiesFile.Read(path, ref level, EnvLineProcessor);
}

View File

@ -117,31 +117,39 @@ namespace MCGalaxy {
public bool growTrees;
[ConfigBool("Guns", "General", null, false)]
public bool guns = false;
public byte jailrotx, jailroty;
/// <summary> Color of the clouds (RGB packed into an int). Set to -1 to use client defaults. </summary>
public string CloudColor = null;
[ConfigString("CloudColor", "Env", null, "", true)]
public string CloudColor = "";
/// <summary> Color of the fog (RGB packed into an int). Set to -1 to use client defaults. </summary>
public string FogColor = null;
[ConfigString("FogColor", "Env", null, "", true)]
public string FogColor = "";
/// <summary> Color of the sky (RGB packed into an int). Set to -1 to use client defaults. </summary>
public string SkyColor = null;
[ConfigString("SkyColor", "Env", null, "", true)]
public string SkyColor = "";
/// <summary> Color of the blocks in shadows (RGB packed into an int). Set to -1 to use client defaults. </summary>
public string ShadowColor = null;
[ConfigString("ShadowColor", "Env", null, "", true)]
public string ShadowColor = "";
/// <summary> Color of the blocks in the light (RGB packed into an int). Set to -1 to use client defaults. </summary>
public string LightColor = null;
[ConfigString("LightColor", "Env", null, "", true)]
public string LightColor = "";
/// <summary> Elevation of the "ocean" that surrounds maps. Default is map height / 2. </summary>
[ConfigInt("EdgeLevel", "Env", null, -1, short.MinValue, short.MaxValue)]
public int EdgeLevel;
/// <summary> Elevation of the clouds. Default is map height + 2. </summary>
[ConfigInt("CloudsHeight", "Env", null, -1, short.MinValue, short.MaxValue)]
public int CloudsHeight;
/// <summary> Max fog distance the client can see.
/// Default is 0, meaning use the client-side defined maximum fog distance. </summary>
[ConfigInt("MaxFog", "Env", null, 0, short.MinValue, short.MaxValue)]
public int MaxFogDistance;
/// <summary> Clouds speed, in units of 256ths. Default is 256 (1 speed). </summary>
@ -157,13 +165,16 @@ namespace MCGalaxy {
public int WeatherFade = 128;
/// <summary> The block which will be displayed on the horizon. </summary>
public byte HorizonBlock = Block.water;
[ConfigInt("HorizonBlock", "Env", null, Block.water, 0, 255)]
public int HorizonBlock = Block.water;
/// <summary> The block which will be displayed on the edge of the map. </summary>
public byte EdgeBlock = Block.blackrock;
[ConfigInt("EdgeBlock", "Env", null, Block.blackrock, 0, 255)]
public int EdgeBlock = Block.blackrock;
public BlockDefinition[] CustomBlockDefs;
[ConfigInt("JailX", "Jail", null, 0, 0, 65535)]
public int jailx;
[ConfigInt("JailY", "Jail", null, 0, 0, 65535)]
@ -594,7 +605,8 @@ namespace MCGalaxy {
LvlProperties.Load(level, propsPath);
else
Server.s.Log(".properties file for level " + level.name + " was not found.");
LvlProperties.LoadEnv(level, level.name);
// Backwards compatibility for older levels which had .env files.
LvlProperties.LoadEnv(level);
} catch (Exception e) {
Server.ErrorLog(e);
}

View File

@ -49,7 +49,7 @@ namespace MCGalaxy {
}
public static void SetBlock(Player p, string value, EnvProp prop,
string variable, byte defValue, ref byte target) {
string variable, byte defValue, ref int target) {
if (IsResetString(value)) {
Player.Message(p, "Reset {0} for {0}%S to normal", variable, p.level.name);
target = defValue;
@ -93,7 +93,7 @@ namespace MCGalaxy {
SendEnvColorPackets(p, envType, value);
}
static bool CheckBlock(Player p, string value, string variable, ref byte modify) {
static bool CheckBlock(Player p, string value, string variable, ref int modify) {
byte extBlock = 0;
int block = DrawCmd.GetBlock(p, value, out extBlock, false);
if (block == -1 || block == Block.Zero) return false;

View File

@ -159,7 +159,7 @@ namespace MCGalaxy
string lastUrl = "";
public void SendCurrentMapAppearance() {
byte side = level.EdgeBlock, edge = level.HorizonBlock;
byte side = (byte)level.EdgeBlock, edge = (byte)level.HorizonBlock;
if (side >= Block.CpeCount && !hasBlockDefs)
side = level.GetFallback(side);
if (edge >= Block.CpeCount && !hasBlockDefs)

View File

@ -50,7 +50,7 @@ namespace MCGalaxy {
public event VoidHandler OnSettingsUpdate;
public static IRCBot IRC;
public static Thread locationChecker, blockThread;
public static Thread locationChecker;
public static WebServer APIServer, InfoServer;
public static DateTime StartTime, StartTimeLocal;

View File

@ -161,6 +161,50 @@ namespace MCGalaxy {
}
}
void CombineEnvFiles() {
if (!Directory.Exists("levels/level properties")) return;
try {
string[] files = Directory.GetFiles("levels/level properties", "*.env");
if (files.Length == 0) return;
Server.s.Log("Combining " + files.Length + " .env and .properties files..");
foreach (string envFile in files) {
try {
Combine(envFile);
} catch (Exception ex) {
Server.s.Log("Error while trying to combine .env and .properties file");
Server.ErrorLog(ex);
}
}
Server.s.Log("Finished combining .env and .properties files.");
} catch (Exception ex) {
Server.ErrorLog(ex);
}
}
static void Combine(string envFile) {
string name = Path.GetFileNameWithoutExtension(envFile);
string propFile = LevelInfo.FindPropertiesFile(name);
List<string> lines = new List<string>();
string line = null;
if (propFile != null) {
using (StreamReader r = new StreamReader(propFile)) {
while ((line = r.ReadLine()) != null)
lines.Add(line);
}
}
using (StreamReader r = new StreamReader(envFile)) {
while ((line = r.ReadLine()) != null)
lines.Add(line);
}
propFile = LevelInfo.PropertiesPath(name);
CP437Writer.WriteAllLines(propFile, lines.ToArray());
File.Delete(envFile);
}
void SetupSocket() {
Log("Creating listening socket on port " + port + "... ");
Setup();

View File

@ -105,14 +105,15 @@ namespace MCGalaxy {
Level[] loaded = LevelInfo.Loaded.Items;
foreach (Level l in loaded)
l.Unload();
Background.QueueOnce(CombineEnvFiles);
Background.QueueOnce(LoadMainLevel);
Plugin.Load();
Background.QueueOnce(LoadPlayerLists);
Background.QueueOnce(LoadAutoloadCommands);
Background.QueueOnce(MovePreviousLevelFiles);
Background.QueueOnce(SetupSocket);
Background.QueueOnce(SetupSocket);
Background.QueueOnce(InitTimers);
Background.QueueOnce(InitRest);
Background.QueueOnce(InitHeartbeat);