mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Combine .env and .properties files into one.
This commit is contained in:
parent
f93523deb0
commit
e01eba80e8
@ -185,7 +185,7 @@ namespace MCGalaxy.Commands {
|
|||||||
EdgeLevel = lvl.EdgeLevel; CloudsHeight = lvl.CloudsHeight;
|
EdgeLevel = lvl.EdgeLevel; CloudsHeight = lvl.CloudsHeight;
|
||||||
MaxFog = lvl.MaxFogDistance;
|
MaxFog = lvl.MaxFogDistance;
|
||||||
CloudsSpeed = lvl.CloudsSpeed; WeatherSpeed = lvl.WeatherSpeed;
|
CloudsSpeed = lvl.CloudsSpeed; WeatherSpeed = lvl.WeatherSpeed;
|
||||||
EdgeBlock = lvl.EdgeBlock; HorizonBlock = lvl.HorizonBlock;
|
EdgeBlock = (byte)lvl.EdgeBlock; HorizonBlock = (byte)lvl.HorizonBlock;
|
||||||
WeatherFade = lvl.WeatherFade;
|
WeatherFade = lvl.WeatherFade;
|
||||||
|
|
||||||
TerrainUrl = lvl.terrainUrl != "" ?
|
TerrainUrl = lvl.terrainUrl != "" ?
|
||||||
@ -205,52 +205,46 @@ namespace MCGalaxy.Commands {
|
|||||||
string path = LevelInfo.FindPropertiesFile(name);
|
string path = LevelInfo.FindPropertiesFile(name);
|
||||||
if (path != null)
|
if (path != null)
|
||||||
PropertiesFile.Read(path, ParseProperty, '=');
|
PropertiesFile.Read(path, ParseProperty, '=');
|
||||||
|
|
||||||
path = "levels/level properties/" + name + ".env";
|
|
||||||
if (File.Exists(path))
|
|
||||||
PropertiesFile.Read(path, ParseEnv, '=');
|
|
||||||
if (Authors == null) Authors = "";
|
if (Authors == null) Authors = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParseProperty(string key, string value) {
|
void ParseProperty(string key, string value) {
|
||||||
switch (key.ToLower()) {
|
switch (key.ToLower()) {
|
||||||
case "physics": Physics = int.Parse(value); break;
|
case "physics": Physics = int.Parse(value); break;
|
||||||
case "guns": Guns = bool.Parse(value); break;
|
case "guns": Guns = bool.Parse(value); break;
|
||||||
case "texture": TerrainUrl = value; break;
|
case "useblockdb": blockDB = bool.Parse(value); break;
|
||||||
case "texturepack": TextureUrl = value; break;
|
case "realmowner": RealmOwner = value; break;
|
||||||
case "clouds-speed": CloudsSpeed = int.Parse(value); break;
|
|
||||||
case "weather-speed": WeatherSpeed = int.Parse(value); break;
|
case "perbuild": build = GetPerm(value); break;
|
||||||
case "weather-fade": WeatherFade = int.Parse(value); break;
|
case "pervisit": visit = GetPerm(value); break;
|
||||||
case "useblockdb": blockDB = bool.Parse(value); break;
|
case "perbuildmax": buildmax = GetPerm(value); break;
|
||||||
case "realmowner": RealmOwner = value; break;
|
case "pervisitmax": visitmax = GetPerm(value); break;
|
||||||
|
case "visitwhitelist": VisitWhitelist = Parse(value); break;
|
||||||
case "perbuild": build = GetPerm(value); break;
|
case "visitblacklist": VisitBlacklist = Parse(value); break;
|
||||||
case "pervisit": visit = GetPerm(value); break;
|
|
||||||
case "perbuildmax": buildmax = GetPerm(value); break;
|
case "authors": Authors = value; break;
|
||||||
case "pervisitmax": visitmax = GetPerm(value); break;
|
case "roundsplayed": TotalRounds = int.Parse(value); break;
|
||||||
case "visitwhitelist": VisitWhitelist = Parse(value); break;
|
case "RoundsHumanWon": HumanRounds = int.Parse(value); break;
|
||||||
case "visitblacklist": VisitBlacklist = Parse(value); break;
|
case "likes": Likes = int.Parse(value); break;
|
||||||
|
case "dislikes": Dislikes = int.Parse(value); break;
|
||||||
case "authors": Authors = value; break;
|
|
||||||
case "roundsplayed": TotalRounds = int.Parse(value); break;
|
case "cloudcolor": Clouds = value; break;
|
||||||
case "RoundsHumanWon": HumanRounds = int.Parse(value); break;
|
case "fogcolor": Fog = value; break;
|
||||||
case "likes": Likes = int.Parse(value); break;
|
case "skycolor": Sky = value; break;
|
||||||
case "dislikes": Dislikes = int.Parse(value); break;
|
case "shadowcolor": Shadow = value; break;
|
||||||
}
|
case "lightcolor": Light = value; break;
|
||||||
}
|
|
||||||
|
case "edgeblock": EdgeBlock = byte.Parse(value); break;
|
||||||
void ParseEnv(string key, string value) {
|
case "edgelevel": EdgeLevel = short.Parse(value); break;
|
||||||
switch (key.ToLower()) {
|
case "horizonblock": HorizonBlock = byte.Parse(value); break;
|
||||||
case "cloudcolor": Clouds = value; break;
|
case "cloudsheight": CloudsHeight = short.Parse(value); break;
|
||||||
case "fogcolor": Fog = value; break;
|
case "maxfog": MaxFog = short.Parse(value); break;
|
||||||
case "skycolor": Sky = value; break;
|
|
||||||
case "shadowcolor": Shadow = value; break;
|
case "texture": TerrainUrl = value; break;
|
||||||
case "lightcolor": Light = value; break;
|
case "texturepack": TextureUrl = value; break;
|
||||||
case "edgeblock": EdgeBlock = byte.Parse(value); break;
|
case "clouds-speed": CloudsSpeed = int.Parse(value); break;
|
||||||
case "edgelevel": EdgeLevel = short.Parse(value); break;
|
case "weather-speed": WeatherSpeed = int.Parse(value); break;
|
||||||
case "cloudsheight": CloudsHeight = short.Parse(value); break;
|
case "weather-fade": WeatherFade = int.Parse(value); break;
|
||||||
case "maxfog": MaxFog = short.Parse(value); break;
|
|
||||||
case "horizonblock": HorizonBlock = byte.Parse(value); break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,15 +29,6 @@ namespace MCGalaxy.Levels.IO {
|
|||||||
Server.s.Log("Failed to save level properties!");
|
Server.s.Log("Failed to save level properties!");
|
||||||
Logger.WriteError(ex);
|
Logger.WriteError(ex);
|
||||||
return;
|
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);
|
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) {
|
public static void Load(Level level, string path) {
|
||||||
PropertiesFile.Read(path, ref level, PropLineProcessor);
|
PropertiesFile.Read(path, ref level, PropLineProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadEnv(Level level, string name) {
|
public static void LoadEnv(Level level) {
|
||||||
string path = "levels/level properties/" + name + ".env";
|
string path = "levels/level properties/" + level.name + ".env";
|
||||||
PropertiesFile.Read(path, ref level, EnvLineProcessor);
|
PropertiesFile.Read(path, ref level, EnvLineProcessor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,31 +117,39 @@ namespace MCGalaxy {
|
|||||||
public bool growTrees;
|
public bool growTrees;
|
||||||
[ConfigBool("Guns", "General", null, false)]
|
[ConfigBool("Guns", "General", null, false)]
|
||||||
public bool guns = false;
|
public bool guns = false;
|
||||||
|
|
||||||
public byte jailrotx, jailroty;
|
public byte jailrotx, jailroty;
|
||||||
|
|
||||||
/// <summary> Color of the clouds (RGB packed into an int). Set to -1 to use client defaults. </summary>
|
/// <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>
|
/// <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>
|
/// <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>
|
/// <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>
|
/// <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>
|
/// <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;
|
public int EdgeLevel;
|
||||||
|
|
||||||
/// <summary> Elevation of the clouds. Default is map height + 2. </summary>
|
/// <summary> Elevation of the clouds. Default is map height + 2. </summary>
|
||||||
|
[ConfigInt("CloudsHeight", "Env", null, -1, short.MinValue, short.MaxValue)]
|
||||||
public int CloudsHeight;
|
public int CloudsHeight;
|
||||||
|
|
||||||
/// <summary> Max fog distance the client can see.
|
/// <summary> Max fog distance the client can see.
|
||||||
/// Default is 0, meaning use the client-side defined maximum fog distance. </summary>
|
/// 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;
|
public int MaxFogDistance;
|
||||||
|
|
||||||
/// <summary> Clouds speed, in units of 256ths. Default is 256 (1 speed). </summary>
|
/// <summary> Clouds speed, in units of 256ths. Default is 256 (1 speed). </summary>
|
||||||
@ -157,13 +165,16 @@ namespace MCGalaxy {
|
|||||||
public int WeatherFade = 128;
|
public int WeatherFade = 128;
|
||||||
|
|
||||||
/// <summary> The block which will be displayed on the horizon. </summary>
|
/// <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>
|
/// <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;
|
public BlockDefinition[] CustomBlockDefs;
|
||||||
|
|
||||||
|
|
||||||
[ConfigInt("JailX", "Jail", null, 0, 0, 65535)]
|
[ConfigInt("JailX", "Jail", null, 0, 0, 65535)]
|
||||||
public int jailx;
|
public int jailx;
|
||||||
[ConfigInt("JailY", "Jail", null, 0, 0, 65535)]
|
[ConfigInt("JailY", "Jail", null, 0, 0, 65535)]
|
||||||
@ -594,7 +605,8 @@ namespace MCGalaxy {
|
|||||||
LvlProperties.Load(level, propsPath);
|
LvlProperties.Load(level, propsPath);
|
||||||
else
|
else
|
||||||
Server.s.Log(".properties file for level " + level.name + " was not found.");
|
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) {
|
} catch (Exception e) {
|
||||||
Server.ErrorLog(e);
|
Server.ErrorLog(e);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void SetBlock(Player p, string value, EnvProp prop,
|
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)) {
|
if (IsResetString(value)) {
|
||||||
Player.Message(p, "Reset {0} for {0}%S to normal", variable, p.level.name);
|
Player.Message(p, "Reset {0} for {0}%S to normal", variable, p.level.name);
|
||||||
target = defValue;
|
target = defValue;
|
||||||
@ -93,7 +93,7 @@ namespace MCGalaxy {
|
|||||||
SendEnvColorPackets(p, envType, value);
|
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;
|
byte extBlock = 0;
|
||||||
int block = DrawCmd.GetBlock(p, value, out extBlock, false);
|
int block = DrawCmd.GetBlock(p, value, out extBlock, false);
|
||||||
if (block == -1 || block == Block.Zero) return false;
|
if (block == -1 || block == Block.Zero) return false;
|
||||||
|
@ -159,7 +159,7 @@ namespace MCGalaxy
|
|||||||
|
|
||||||
string lastUrl = "";
|
string lastUrl = "";
|
||||||
public void SendCurrentMapAppearance() {
|
public void SendCurrentMapAppearance() {
|
||||||
byte side = level.EdgeBlock, edge = level.HorizonBlock;
|
byte side = (byte)level.EdgeBlock, edge = (byte)level.HorizonBlock;
|
||||||
if (side >= Block.CpeCount && !hasBlockDefs)
|
if (side >= Block.CpeCount && !hasBlockDefs)
|
||||||
side = level.GetFallback(side);
|
side = level.GetFallback(side);
|
||||||
if (edge >= Block.CpeCount && !hasBlockDefs)
|
if (edge >= Block.CpeCount && !hasBlockDefs)
|
||||||
|
@ -50,7 +50,7 @@ namespace MCGalaxy {
|
|||||||
public event VoidHandler OnSettingsUpdate;
|
public event VoidHandler OnSettingsUpdate;
|
||||||
|
|
||||||
public static IRCBot IRC;
|
public static IRCBot IRC;
|
||||||
public static Thread locationChecker, blockThread;
|
public static Thread locationChecker;
|
||||||
public static WebServer APIServer, InfoServer;
|
public static WebServer APIServer, InfoServer;
|
||||||
public static DateTime StartTime, StartTimeLocal;
|
public static DateTime StartTime, StartTimeLocal;
|
||||||
|
|
||||||
|
@ -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() {
|
void SetupSocket() {
|
||||||
Log("Creating listening socket on port " + port + "... ");
|
Log("Creating listening socket on port " + port + "... ");
|
||||||
Setup();
|
Setup();
|
||||||
|
@ -105,14 +105,15 @@ namespace MCGalaxy {
|
|||||||
Level[] loaded = LevelInfo.Loaded.Items;
|
Level[] loaded = LevelInfo.Loaded.Items;
|
||||||
foreach (Level l in loaded)
|
foreach (Level l in loaded)
|
||||||
l.Unload();
|
l.Unload();
|
||||||
|
|
||||||
|
Background.QueueOnce(CombineEnvFiles);
|
||||||
Background.QueueOnce(LoadMainLevel);
|
Background.QueueOnce(LoadMainLevel);
|
||||||
Plugin.Load();
|
Plugin.Load();
|
||||||
Background.QueueOnce(LoadPlayerLists);
|
Background.QueueOnce(LoadPlayerLists);
|
||||||
Background.QueueOnce(LoadAutoloadCommands);
|
Background.QueueOnce(LoadAutoloadCommands);
|
||||||
Background.QueueOnce(MovePreviousLevelFiles);
|
Background.QueueOnce(MovePreviousLevelFiles);
|
||||||
Background.QueueOnce(SetupSocket);
|
|
||||||
|
|
||||||
|
Background.QueueOnce(SetupSocket);
|
||||||
Background.QueueOnce(InitTimers);
|
Background.QueueOnce(InitTimers);
|
||||||
Background.QueueOnce(InitRest);
|
Background.QueueOnce(InitRest);
|
||||||
Background.QueueOnce(InitHeartbeat);
|
Background.QueueOnce(InitHeartbeat);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user