diff --git a/GUI/Window.cs b/GUI/Window.cs
index 8ff06993c..333a4c823 100644
--- a/GUI/Window.cs
+++ b/GUI/Window.cs
@@ -142,7 +142,7 @@ namespace MCGalaxy.Gui {
Invoke(new VoidDelegate(SettingsUpdate));
} else {
Text = Server.name + " - MCGalaxy " + Server.VersionString;
- notifyIcon1.Text = ("MCGalaxy Server: " + Server.name).Truncate(64);
+ notifyIcon1.Text = ("MCGalaxy Server: " + Server.name).Truncate(63);
}
}
diff --git a/MCGalaxy/Config/StringAttributes.cs b/MCGalaxy/Config/StringAttributes.cs
index 5817ba989..6c8751c62 100644
--- a/MCGalaxy/Config/StringAttributes.cs
+++ b/MCGalaxy/Config/StringAttributes.cs
@@ -41,29 +41,33 @@ namespace MCGalaxy.Config {
public sealed class ConfigStringAttribute : ConfigAttribute {
- /// Whether the empty string is an allowed, or if is treated as the default value.
+ /// Whether an empty string is an allowed for the value, or if it is treated as the default value.
public bool AllowEmpty;
- /// Specifies the restricted set of characters (asides from alphanumeric characters)
- /// that this field is allowed to have.
+ /// Specifies the restricted set of characters (asides from alphanumeric characters)
+ /// that the value is allowed to have.
public string AllowedChars;
+ /// Maximum number of characters allowed in the value. 0 means no limit.
+ public int MaxLength = 0;
+
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) {
AllowEmpty = allowEmpty;
AllowedChars = allowedChars;
+ MaxLength = maxLength;
}
public override object Parse(string value) {
if (value == "") {
if (!AllowEmpty) {
- Server.s.Log("Config key \"" + Name + "\" has no value, using default of " + DefaultValue);
- return DefaultValue;
+ Server.s.Log("Config key \"" + Name + "\" has no value, using default of " + DefaultValue);
+ return DefaultValue;
}
return "";
} else if (AllowedChars == null) {
- return value;
+ return Truncate(value);
}
foreach (char c in value) {
@@ -71,11 +75,19 @@ namespace MCGalaxy.Config {
continue;
if (AllowedChars.IndexOf(c) == -1) {
- Server.s.Log("Config key \"" + Name + "\" contains " +
+ Server.s.Log("Config key \"" + Name + "\" contains " +
"a non-allowed character, using default of " + DefaultValue);
- 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;
}
}
diff --git a/MCGalaxy/Levels/Level.Fields.cs b/MCGalaxy/Levels/Level.Fields.cs
index bf61c5da6..371f38498 100644
--- a/MCGalaxy/Levels/Level.Fields.cs
+++ b/MCGalaxy/Levels/Level.Fields.cs
@@ -27,7 +27,7 @@ namespace MCGalaxy {
public sealed partial class Level : IDisposable {
public string name;
- [ConfigString("MOTD", "General", null, "ignore", true)]
+ [ConfigString("MOTD", "General", null, "ignore", true, null, 128)]
public string motd = "ignore";
public byte rotx, roty;
@@ -90,7 +90,7 @@ namespace MCGalaxy {
// Environment settings
[ConfigInt("Weather", "Env", null, 0, 0, 2)]
public int Weather;
- [ConfigString("Texture", "Env", null, "", true)]
+ [ConfigString("Texture", "Env", null, "", true, null, 64)]
public string terrainUrl = "";
[ConfigString("TexturePack", "Env", null, "", true)]
public string texturePackUrl = "";
diff --git a/MCGalaxy/Server/Server.Fields.cs b/MCGalaxy/Server/Server.Fields.cs
index 9122e0d2b..91b459c0b 100644
--- a/MCGalaxy/Server/Server.Fields.cs
+++ b/MCGalaxy/Server/Server.Fields.cs
@@ -169,10 +169,10 @@ namespace MCGalaxy {
public static bool TablistBots = false;
[ConfigString("server-name", "General", null,
- "[MCGalaxy] Default", false, "![]&:.,{}~-+()?_/\\' ")]
+ "[MCGalaxy] Default", false, "![]&:.,{}~-+()?_/\\' ", 64)]
public static string name = "[MCGalaxy] Default";
[ConfigString("motd", "General", null, "Welcome",
- false, "=![]&:.,{}~-+()?_/\\' ")]
+ false, "=![]&:.,{}~-+()?_/\\' ", 128)]
public static string motd = "Welcome!";
[ConfigInt("max-players", "Server", null, 12, 1, 128)]
public static int players = 12;
@@ -372,9 +372,9 @@ namespace MCGalaxy {
public static bool guestJoinNotify = true;
[ConfigBool("guest-leave-notify", "Other", null, 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 = "";
- [ConfigString("default-texture-pack-url", "General", null, "", true)]
+ [ConfigString("default-texture-pack-url", "General", null, "", true, null, 64)]
public static string defaultTextureUrl = "";
//hackrank stuff