mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Make all 'X is not a valid player/level name' messages consistent.
This commit is contained in:
parent
f8f17d69e8
commit
f18397f976
@ -36,7 +36,7 @@ namespace MCGalaxy.Commands
|
||||
if (args.Length < 2) { Help(p); return; }
|
||||
string ai = args[1].ToLower();
|
||||
|
||||
if (!Player.ValidName(ai)) { Player.Message(p, "Invalid AI name!"); return; }
|
||||
if (!ValidName(p, ai, "bot AI")) return;
|
||||
if (ai == "hunt" || ai == "kill") { Player.Message(p, "Reserved for special AI."); return; }
|
||||
|
||||
switch (args[0].ToLower()) {
|
||||
|
@ -28,7 +28,7 @@ namespace MCGalaxy.Commands {
|
||||
if (message == "") { Help(p); return; }
|
||||
if (p == null) { MessageInGameOnly(p); return; }
|
||||
|
||||
if (!Player.ValidName(message)) { Player.Message(p, "bot name " + message + " not valid!"); return; }
|
||||
if (!ValidName(p, message, "bot")) return;
|
||||
PlayerBot bot = new PlayerBot(message, p.level, p.pos[0], p.pos[1], p.pos[2], p.rot[0], 0);
|
||||
PlayerBot.Add(bot);
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ namespace MCGalaxy.Commands.CPE {
|
||||
Player.Message(p, "%H code is a single ascii character.");
|
||||
Player.Message(p, "%H fallback is the color code shown to non-supporting clients.");
|
||||
Player.Message(p, "%T/customcolors remove [code] %H- Removes that custom color.");
|
||||
Player.Message(p, "%T/customcolors list [offset] %H - lists all custom colors.");
|
||||
Player.Message(p, "%T/customcolors list [offset] %H- lists all custom colors.");
|
||||
Player.Message(p, "%T/customcolors edit [code] [name/fallback/hex]");
|
||||
}
|
||||
|
||||
|
@ -57,9 +57,7 @@ namespace MCGalaxy.Commands.CPE {
|
||||
skin = message;
|
||||
}
|
||||
|
||||
if (!Player.ValidName(skin)) {
|
||||
Player.Message(p, "\"" + skin + "\" is not a valid skin name."); return;
|
||||
}
|
||||
if (!ValidName(p, skin, "skin")) return;
|
||||
if ((isBot || who != p) && !CheckExtraPerm(p)) { MessageNeedPerms(p, "can change the skin of other players."); return; }
|
||||
|
||||
if (isBot) {
|
||||
|
@ -89,6 +89,12 @@ namespace MCGalaxy {
|
||||
Player.Message(p, "Can only {0} players ranked below {1}", action, grp.ColoredName);
|
||||
}
|
||||
|
||||
protected static bool ValidName(Player p, string name, string type) {
|
||||
if (Player.ValidName(name)) return true;
|
||||
Player.Message(p, "\"{0}\" is not a valid {1} name.", name, type);
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void MessageCannotUse(Player p) {
|
||||
var perms = GrpCommands.allowedCommands.Find(C => C.commandName == name);
|
||||
if (perms.disallow.Contains(p.group.Permission)) {
|
||||
|
@ -44,9 +44,7 @@ namespace MCGalaxy.Commands {
|
||||
if (matches == 1) {
|
||||
info = FromOnline(pl);
|
||||
} else {
|
||||
if (!Player.ValidName(message)) {
|
||||
Player.Message(p, "\"" + message + "\" is not a valid player name."); return;
|
||||
}
|
||||
if (!ValidName(p, message, "player")) return;
|
||||
Player.Message(p, "Searching database for the player..");
|
||||
OfflinePlayer target = PlayerInfo.FindOfflineMatches(p, message);
|
||||
if (target == null) return;
|
||||
|
@ -43,9 +43,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
Player who = PlayerInfo.Find(args[0]);
|
||||
|
||||
string target = who == null ? args[0] : who.name;
|
||||
if (!Player.ValidName(target)) {
|
||||
Player.Message(p, "Invalid name \"" + target + "\"."); return;
|
||||
}
|
||||
if (!ValidName(p, target, "player")) return;
|
||||
Group group = who == null ? Group.findPlayerGroup(args[0]) : who.group;
|
||||
if (!CheckPerms(target, group, p)) return;
|
||||
|
||||
|
@ -31,12 +31,8 @@ namespace MCGalaxy.Commands {
|
||||
public override void Use(Player p, string text) {
|
||||
string[] args = text.Split(' ');
|
||||
if (args.Length != 2) { Help(p); return; }
|
||||
if (!Player.ValidName(args[0])) {
|
||||
Player.SendMessage(p, "\"" + args[0] + "\" is not a valid player name."); return;
|
||||
}
|
||||
if (!Player.ValidName(args[1])) {
|
||||
Player.SendMessage(p, "\"" + args[1] + "\" is not a valid player name."); return;
|
||||
}
|
||||
if (!ValidName(p, args[0], "player")) return;
|
||||
if (!ValidName(p, args[1], "player")) return;
|
||||
|
||||
if (PlayerInfo.FindExact(args[0]) != null) {
|
||||
Player.SendMessage(p, "\"" + args[0] + "\" must be offline to use /infoswap."); return;
|
||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
Player who = PlayerInfo.Find(args[0]);
|
||||
|
||||
string target = who == null ? args[0] : who.name;
|
||||
if (!Player.ValidName(target)) { Player.Message(p, "Invalid name \"" + target + "\"."); return; }
|
||||
if (!ValidName(p, target, "player")) return;
|
||||
Group grp = who == null ? PlayerInfo.GetGroup(target) : who.group;
|
||||
if (p != null && grp.Permission >= p.group.Permission) {
|
||||
MessageTooHighRank(p, "temp ban", false); return;
|
||||
|
@ -95,7 +95,7 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
else { Help(p); return; }
|
||||
|
||||
if (!Player.ValidName(cpos.Owner)) { Player.Message(p, "INVALID NAME."); return; }
|
||||
if (!ValidName(p, cpos.Owner, "player or rank")) return;
|
||||
|
||||
cpos.x = 0; cpos.y = 0; cpos.z = 0; p.blockchangeObject = cpos;
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.World {
|
||||
}
|
||||
src = LevelInfo.FindMapMatches(p, src);
|
||||
if (src == null) return;
|
||||
if (!Player.ValidName(dst)) { Player.Message(p, "\"" + dst + "\" is not a valid level name."); return; }
|
||||
if (!ValidName(p, dst, "level")) return;
|
||||
if (LevelInfo.ExistsOffline(dst)) { Player.Message(p, "The level \"" + dst + "\" already exists."); return; }
|
||||
|
||||
try {
|
||||
|
@ -38,7 +38,7 @@ namespace MCGalaxy.Commands.World {
|
||||
lvl.Unload();
|
||||
}
|
||||
|
||||
if (!Player.ValidName(message)) { Player.Message(p, "\"" + message + "\" is not a valid level name."); return; }
|
||||
if (!ValidName(p, message, "level")) return;
|
||||
if (lvl == Server.mainLevel) { Player.Message(p, "Cannot delete the main level."); return; }
|
||||
|
||||
string map = LevelInfo.FindMapMatches(p, message);
|
||||
|
@ -39,9 +39,7 @@ namespace MCGalaxy.Commands {
|
||||
|
||||
if (args[0].CaselessEq("map")) {
|
||||
args[1] = args[1].ToLower();
|
||||
if (!Player.ValidName(args[1])) {
|
||||
Player.Message(p, "\"" + args[1] + "\" is not a valid level name."); return;
|
||||
}
|
||||
if (!ValidName(p, args[1], "level")) return;
|
||||
|
||||
string path = "text/lockdown/map/" + args[1];
|
||||
if (!File.Exists(path)) {
|
||||
|
@ -36,9 +36,7 @@ namespace MCGalaxy.Commands.World {
|
||||
PlayerActions.ChangeMap(p, Server.mainLevel.name);
|
||||
} else {
|
||||
if (!CheckExtraPerm(p)) { MessageNeedPerms(p, "change the main level"); return; }
|
||||
if (!Player.ValidName(message)) {
|
||||
Player.Message(p, "\"{0}\" is not a valid level name.", message); return;
|
||||
}
|
||||
if (!ValidName(p, message, "level")) return;
|
||||
|
||||
string map = LevelInfo.FindMapMatches(p, message);
|
||||
if (map == null) return;
|
||||
|
@ -43,9 +43,7 @@ namespace MCGalaxy.Commands.World {
|
||||
if (!MapGen.OkayAxis(y)) { Player.Message(p, "height must be divisible by 16, and >= 16"); return; }
|
||||
if (!MapGen.OkayAxis(z)) { Player.Message(p, "length must be divisible by 16, and >= to 16."); return; }
|
||||
|
||||
if (!Player.ValidName(name)) {
|
||||
Player.Message(p, "Invalid name!"); return;
|
||||
}
|
||||
if (!ValidName(p, name, "level")) return;
|
||||
if (LevelInfo.ExistsOffline(name)) {
|
||||
Player.Message(p, "Level \"" + name + "\" already exists!"); return;
|
||||
}
|
||||
|
@ -34,9 +34,7 @@ namespace MCGalaxy.Commands.World {
|
||||
Level lvl = LevelInfo.FindMatches(p, args[0]);
|
||||
if (lvl == null) return;
|
||||
string newName = args[1];
|
||||
if (!Player.ValidName(newName)) {
|
||||
Player.Message(p, "\"" + newName + "\" is not a valid level name."); return;
|
||||
}
|
||||
if (!ValidName(p, newName, "level")) return;
|
||||
|
||||
if (LevelInfo.ExistsOffline(newName)) { Player.Message(p, "Level already exists."); return; }
|
||||
if (lvl == Server.mainLevel) { Player.Message(p, "Cannot rename the main level."); return; }
|
||||
@ -50,7 +48,7 @@ namespace MCGalaxy.Commands.World {
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/renamelvl <level> <new name>");
|
||||
Player.Message(p, "%H- Renames <level> to <new name>");
|
||||
Player.Message(p, "%HRenames <level> to <new name>");
|
||||
Player.Message(p, "%HNote: Portals going to <level> will no longer work.");
|
||||
}
|
||||
}
|
||||
|
@ -164,9 +164,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
}
|
||||
|
||||
void SaveCopy(Player p, string file) {
|
||||
if (!Player.ValidName(file)) {
|
||||
Player.Message(p, "Bad file name"); return;
|
||||
}
|
||||
if (!ValidName(p, file, "saved copy")) return;
|
||||
|
||||
if (!Directory.Exists("extra/savecopy"))
|
||||
Directory.CreateDirectory("extra/savecopy");
|
||||
|
@ -82,9 +82,7 @@ namespace MCGalaxy.Commands {
|
||||
Player.Message(p, "You need to provide a player's name."); return;
|
||||
}
|
||||
if (!CheckExtraPerm(p)) { MessageNeedPerms(p, "can view the details of a report."); return; }
|
||||
if (!Player.ValidName(args[1])) {
|
||||
Player.Message(p, "\"" + args[1] + "\" is not a valid player name."); return;
|
||||
}
|
||||
if (!ValidName(p, args[1], "player")) return;
|
||||
|
||||
if (!File.Exists("extra/reported/" + args[1] + ".txt")) {
|
||||
Player.Message(p, "The player you specified has not been reported."); return;
|
||||
@ -98,9 +96,7 @@ namespace MCGalaxy.Commands {
|
||||
Player.Message(p, "You need to provide a player's name."); return;
|
||||
}
|
||||
if (!CheckExtraPerm(p)) { MessageNeedPerms(p, "can delete reports."); return; }
|
||||
if (!Player.ValidName(args[1])) {
|
||||
Player.Message(p, "\"" + args[1] + "\" is not a valid player name."); return;
|
||||
}
|
||||
if (!ValidName(p, args[1], "player")) return;
|
||||
|
||||
if (!File.Exists("extra/reported/" + args[1] + ".txt")) {
|
||||
Player.Message(p, "The player you specified has not been reported."); return;
|
||||
|
@ -681,8 +681,11 @@ Next: continue;
|
||||
}
|
||||
|
||||
public static bool ValidName(string name) {
|
||||
string allowedchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890._+";
|
||||
return name.All(ch => allowedchars.IndexOf(ch) != -1);
|
||||
const string valid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890._+";
|
||||
foreach (char c in name) {
|
||||
if (valid.IndexOf(c) == -1) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int GetBannedCount() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user