mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Allow non-alphanumeric ascii characters for level names
These characters are \!#+,-.;=@[]^_{}~
This commit is contained in:
parent
92b976179a
commit
fde3e8799e
@ -64,7 +64,7 @@ namespace MCGalaxy.Commands.Info {
|
|||||||
string undoTime = grp.MaxUndo.Shorten(true, false);
|
string undoTime = grp.MaxUndo.Shorten(true, false);
|
||||||
|
|
||||||
p.Message("{0} %S- Draw: {1}, Undo: {2}, Perm: {3}",
|
p.Message("{0} %S- Draw: {1}, Undo: {2}, Perm: {3}",
|
||||||
grp.ColoredName, grp.DrawLimit, undoTime, (int)grp.Permission);
|
grp.ColoredName, grp.DrawLimit, undoTime, (int)grp.Permission);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (message.Length == 0) { Help(p); return; }
|
if (message.Length == 0) { Help(p); return; }
|
||||||
if (!Formatter.ValidName(p, message, "level")) return;
|
if (!Formatter.ValidMapName(p, message)) return;
|
||||||
|
|
||||||
string path = LevelInfo.BackupFilePath(p.level.name, message);
|
string path = LevelInfo.BackupFilePath(p.level.name, message);
|
||||||
if (File.Exists(path)) {
|
if (File.Exists(path)) {
|
||||||
|
@ -43,7 +43,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
if (!LevelInfo.Check(p, data.Rank, src, "copy this map")) return;
|
if (!LevelInfo.Check(p, data.Rank, src, "copy this map")) return;
|
||||||
|
|
||||||
string dst = args[1];
|
string dst = args[1];
|
||||||
if (!Formatter.ValidName(p, dst, "level")) return;
|
if (!Formatter.ValidMapName(p, dst)) return;
|
||||||
if (LevelInfo.MapExists(dst)) { p.Message("Level \"" + dst + "\" already exists."); return; }
|
if (LevelInfo.MapExists(dst)) { p.Message("Level \"" + dst + "\" already exists."); return; }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (message.Length == 0 || message.SplitSpaces().Length > 1) { Help(p); return; }
|
if (message.Length == 0 || message.SplitSpaces().Length > 1) { Help(p); return; }
|
||||||
if (!Formatter.ValidName(p, message, "level")) return;
|
if (!Formatter.ValidMapName(p, message)) return;
|
||||||
string map = Matcher.FindMaps(p, message);
|
string map = Matcher.FindMaps(p, message);
|
||||||
if (map == null) return;
|
if (map == null) return;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerActions.ChangeMap(p, map);
|
PlayerActions.ChangeMap(p, map);
|
||||||
} else if (Formatter.ValidName(p, message, "level")) {
|
} else if (Formatter.ValidMapName(p, message)) {
|
||||||
PlayerActions.ChangeMap(p, message);
|
PlayerActions.ChangeMap(p, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (message.Length == 0) { Help(p); return; }
|
if (message.Length == 0) { Help(p); return; }
|
||||||
if (!Formatter.ValidName(p, message, "level")) return;
|
if (!Formatter.ValidMapName(p, message)) return;
|
||||||
|
|
||||||
string path = Paths.ImportsDir + message;
|
string path = Paths.ImportsDir + message;
|
||||||
if (!Directory.Exists(Paths.ImportsDir)) {
|
if (!Directory.Exists(Paths.ImportsDir)) {
|
||||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
|
|
||||||
public override void Use(Player p, string map, CommandData data) {
|
public override void Use(Player p, string map, CommandData data) {
|
||||||
if (map.Length == 0) { Help(p); return; }
|
if (map.Length == 0) { Help(p); return; }
|
||||||
if (!Formatter.ValidName(p, map, "level")) return;
|
if (!Formatter.ValidMapName(p, map)) return;
|
||||||
|
|
||||||
map = Matcher.FindMaps(p, map);
|
map = Matcher.FindMaps(p, map);
|
||||||
if (map == null) return;
|
if (map == null) return;
|
||||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!CheckExtraPerm(p, data, 1)) return;
|
if (!CheckExtraPerm(p, data, 1)) return;
|
||||||
if (!Formatter.ValidName(p, message, "level")) return;
|
if (!Formatter.ValidMapName(p, message)) return;
|
||||||
if (!LevelInfo.Check(p, data.Rank, Server.mainLevel, "set main to another map")) return;
|
if (!LevelInfo.Check(p, data.Rank, Server.mainLevel, "set main to another map")) return;
|
||||||
|
|
||||||
string map = Matcher.FindMaps(p, message);
|
string map = Matcher.FindMaps(p, message);
|
||||||
|
@ -55,7 +55,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
if (!GetDimensions(p, args, 1, ref x, ref y, ref z)) return null;
|
if (!GetDimensions(p, args, 1, ref x, ref y, ref z)) return null;
|
||||||
string seed = args.Length == 6 ? args[5] : "";
|
string seed = args.Length == 6 ? args[5] : "";
|
||||||
|
|
||||||
if (!Formatter.ValidName(p, name, "level")) return null;
|
if (!Formatter.ValidMapName(p, name)) return null;
|
||||||
if (LevelInfo.MapExists(name)) {
|
if (LevelInfo.MapExists(name)) {
|
||||||
p.Message("Level \"{0}\" already exists", name); return null;
|
p.Message("Level \"{0}\" already exists", name); return null;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
Level lvl = Matcher.FindLevels(p, args[0]);
|
Level lvl = Matcher.FindLevels(p, args[0]);
|
||||||
if (lvl == null) return;
|
if (lvl == null) return;
|
||||||
string newMap = args[1].ToLower();
|
string newMap = args[1].ToLower();
|
||||||
if (!Formatter.ValidName(p, newMap, "level")) return;
|
if (!Formatter.ValidMapName(p, newMap)) return;
|
||||||
|
|
||||||
if (LevelInfo.MapExists(newMap)) { p.Message("Level already exists."); return; }
|
if (LevelInfo.MapExists(newMap)) { p.Message("Level already exists."); return; }
|
||||||
if (lvl == Server.mainLevel) { p.Message("Cannot rename the main level."); return; }
|
if (lvl == Server.mainLevel) { p.Message("Cannot rename the main level."); return; }
|
||||||
|
@ -160,13 +160,17 @@ namespace MCGalaxy.SQL {
|
|||||||
Database.Execute(sql.ToString(), args);
|
Database.Execute(sql.ToString(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static bool ValidNameChar(char c) {
|
||||||
|
return
|
||||||
|
c > ' ' && c != '"' && c != '%' && c != '&' &&
|
||||||
|
c != '\'' && c != '*' && c != '/' && c != ':' &&
|
||||||
|
c != '<' && c != '>' && c != '?' && c != '\\' &&
|
||||||
|
c != '`' && c != '|' && c <= '~';
|
||||||
|
}
|
||||||
|
|
||||||
protected static void ValidateTable(string name) {
|
protected static void ValidateTable(string name) {
|
||||||
foreach (char c in name) {
|
foreach (char c in name) {
|
||||||
if (c >= '0' && c <= '9') continue;
|
if (ValidNameChar(c)) continue;
|
||||||
if (c >= 'a' && c <= 'z') continue;
|
|
||||||
if (c >= 'A' && c <= 'Z') continue;
|
|
||||||
if (c == '+' || c == '_' || c == '@' || c == '-' || c == '.') continue;
|
|
||||||
|
|
||||||
throw new ArgumentException("Invalid character in table name: " + c);
|
throw new ArgumentException("Invalid character in table name: " + c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using MCGalaxy.Events.LevelEvents;
|
using MCGalaxy.Events.LevelEvents;
|
||||||
|
using MCGalaxy.SQL;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
|
|
||||||
@ -152,6 +153,13 @@ namespace MCGalaxy {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool ValidName(string map) {
|
||||||
|
foreach (char c in map) {
|
||||||
|
if (!IDatabaseBackend.ValidNameChar(c)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool IsRealmOwner(string name, string map) {
|
public static bool IsRealmOwner(string name, string map) {
|
||||||
Level lvl = null;
|
Level lvl = null;
|
||||||
LevelConfig cfg = GetConfig(map, out lvl);
|
LevelConfig cfg = GetConfig(map, out lvl);
|
||||||
|
@ -78,5 +78,11 @@ namespace MCGalaxy {
|
|||||||
p.Message("\"{0}\" is not a valid {1} name.", name, type);
|
p.Message("\"{0}\" is not a valid {1} name.", name, type);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool ValidMapName(Player p, string name) {
|
||||||
|
if (LevelInfo.ValidName(name)) return true;
|
||||||
|
p.Message("\"{0}\" is not a valid level name.", name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
/// <summary> Find partial matches of 'name' against the list of all map files. </summary>
|
/// <summary> Find partial matches of 'name' against the list of all map files. </summary>
|
||||||
public static string FindMaps(Player pl, string name) {
|
public static string FindMaps(Player pl, string name) {
|
||||||
if (!Formatter.ValidName(pl, name, "level")) return null;
|
if (!Formatter.ValidMapName(pl, name)) return null;
|
||||||
int matches;
|
int matches;
|
||||||
return Find(pl, name, out matches, LevelInfo.AllMapNames(),
|
return Find(pl, name, out matches, LevelInfo.AllMapNames(),
|
||||||
null, l => l, "levels", 10);
|
null, l => l, "levels", 10);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user