Merge branch 'master' of github.com:Hetal728/MCGalaxy

This commit is contained in:
UnknownShadow200 2016-09-21 09:51:22 +10:00
commit 0e4012fce1
4 changed files with 28 additions and 16 deletions

View File

@ -142,7 +142,7 @@ namespace MCGalaxy.Gui {
Invoke(new VoidDelegate(SettingsUpdate)); Invoke(new VoidDelegate(SettingsUpdate));
} else { } else {
Text = Server.name + " - MCGalaxy " + Server.VersionString; Text = Server.name + " - MCGalaxy " + Server.VersionString;
notifyIcon1.Text = ("MCGalaxy Server: " + Server.name).Truncate(64); notifyIcon1.Text = ("MCGalaxy Server: " + Server.name).Truncate(63);
} }
} }

View File

@ -41,18 +41,22 @@ namespace MCGalaxy.Config {
public sealed class ConfigStringAttribute : ConfigAttribute { public sealed class ConfigStringAttribute : ConfigAttribute {
/// <summary> Whether the empty string is an allowed, or if is treated as the default value. </summary> /// <summary> Whether an empty string is an allowed for the value, or if it is treated as the default value. </summary>
public bool AllowEmpty; public bool AllowEmpty;
/// <summary> Specifies the restricted set of characters (asides from alphanumeric characters) /// <summary> Specifies the restricted set of characters (asides from alphanumeric characters)
/// that this field is allowed to have. </summary> /// that the value is allowed to have. </summary>
public string AllowedChars; public string AllowedChars;
/// <summary> Maximum number of characters allowed in the value. 0 means no limit. </summary>
public int MaxLength = 0;
public ConfigStringAttribute(string name, string section, string desc, string defValue, public ConfigStringAttribute(string name, string section, string desc, string defValue,
bool allowEmpty = false, string allowedChars = null) bool allowEmpty = false, string allowedChars = null, int maxLength = 0)
: base(name, section, desc, defValue) { : base(name, section, desc, defValue) {
AllowEmpty = allowEmpty; AllowEmpty = allowEmpty;
AllowedChars = allowedChars; AllowedChars = allowedChars;
MaxLength = maxLength;
} }
public override object Parse(string value) { public override object Parse(string value) {
@ -63,7 +67,7 @@ namespace MCGalaxy.Config {
} }
return ""; return "";
} else if (AllowedChars == null) { } else if (AllowedChars == null) {
return value; return Truncate(value);
} }
foreach (char c in value) { foreach (char c in value) {
@ -76,6 +80,14 @@ namespace MCGalaxy.Config {
return DefaultValue; return DefaultValue;
} }
} }
return Truncate(value);
}
string Truncate(string value) {
if (MaxLength > 0 && value.Length > MaxLength) {
value = value.Substring(0, MaxLength);
Server.s.Log("Config key \"" + Name + "\" is too long, truncating to " + value);
}
return value; return value;
} }
} }

View File

@ -27,7 +27,7 @@ namespace MCGalaxy {
public sealed partial class Level : IDisposable { public sealed partial class Level : IDisposable {
public string name; public string name;
[ConfigString("MOTD", "General", null, "ignore", true)] [ConfigString("MOTD", "General", null, "ignore", true, null, 128)]
public string motd = "ignore"; public string motd = "ignore";
public byte rotx, roty; public byte rotx, roty;
@ -90,7 +90,7 @@ namespace MCGalaxy {
// Environment settings // Environment settings
[ConfigInt("Weather", "Env", null, 0, 0, 2)] [ConfigInt("Weather", "Env", null, 0, 0, 2)]
public int Weather; public int Weather;
[ConfigString("Texture", "Env", null, "", true)] [ConfigString("Texture", "Env", null, "", true, null, 64)]
public string terrainUrl = ""; public string terrainUrl = "";
[ConfigString("TexturePack", "Env", null, "", true)] [ConfigString("TexturePack", "Env", null, "", true)]
public string texturePackUrl = ""; public string texturePackUrl = "";

View File

@ -169,10 +169,10 @@ namespace MCGalaxy {
public static bool TablistBots = false; public static bool TablistBots = false;
[ConfigString("server-name", "General", null, [ConfigString("server-name", "General", null,
"[MCGalaxy] Default", false, "![]&:.,{}~-+()?_/\\' ")] "[MCGalaxy] Default", false, "![]&:.,{}~-+()?_/\\' ", 64)]
public static string name = "[MCGalaxy] Default"; public static string name = "[MCGalaxy] Default";
[ConfigString("motd", "General", null, "Welcome", [ConfigString("motd", "General", null, "Welcome",
false, "=![]&:.,{}~-+()?_/\\' ")] false, "=![]&:.,{}~-+()?_/\\' ", 128)]
public static string motd = "Welcome!"; public static string motd = "Welcome!";
[ConfigInt("max-players", "Server", null, 12, 1, 128)] [ConfigInt("max-players", "Server", null, 12, 1, 128)]
public static int players = 12; public static int players = 12;
@ -372,9 +372,9 @@ namespace MCGalaxy {
public static bool guestJoinNotify = true; public static bool guestJoinNotify = true;
[ConfigBool("guest-leave-notify", "Other", null, true)] [ConfigBool("guest-leave-notify", "Other", null, true)]
public static bool guestLeaveNotify = true; public static bool guestLeaveNotify = true;
[ConfigString("default-texture-url", "General", null, "", true)] [ConfigString("default-texture-url", "General", null, "", true, null, 64)]
public static string defaultTerrainUrl = ""; public static string defaultTerrainUrl = "";
[ConfigString("default-texture-pack-url", "General", null, "", true)] [ConfigString("default-texture-pack-url", "General", null, "", true, null, 64)]
public static string defaultTextureUrl = ""; public static string defaultTextureUrl = "";
//hackrank stuff //hackrank stuff