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));
} else {
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,29 +41,33 @@ namespace MCGalaxy.Config {
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;
/// <summary> Specifies the restricted set of characters (asides from alphanumeric characters)
/// that this field is allowed to have. </summary>
/// <summary> Specifies the restricted set of characters (asides from alphanumeric characters)
/// that the value is allowed to have. </summary>
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,
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;
}
}

View File

@ -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 = "";

View File

@ -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