From 25d5c7f32c16f90a427fdd9b3f2a79551f236306 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 6 Jan 2017 08:09:41 +1100 Subject: [PATCH] fix /mi showing wrong permission levels, more work on making code work without core ranks --- MCGalaxy/Blocks/Block.Permissions.cs | 6 +- MCGalaxy/Commands/Information/CmdClones.cs | 2 +- MCGalaxy/Commands/Information/CmdCommands.cs | 2 +- MCGalaxy/Commands/Information/CmdMapInfo.cs | 76 +++++++++---------- MCGalaxy/Commands/Information/CmdViewRanks.cs | 3 +- MCGalaxy/Commands/Moderation/CmdBan.cs | 2 +- MCGalaxy/Commands/Moderation/CmdPatrol.cs | 7 +- MCGalaxy/Commands/Moderation/CmdUnban.cs | 4 +- .../LavaSurvival/LavaSurvival.Settings.cs | 4 +- MCGalaxy/Levels/Level.cs | 11 ++- MCGalaxy/Player/Group/Group.cs | 32 ++++++-- MCGalaxy/Player/Group/GroupCommands.cs | 6 +- 12 files changed, 88 insertions(+), 67 deletions(-) diff --git a/MCGalaxy/Blocks/Block.Permissions.cs b/MCGalaxy/Blocks/Block.Permissions.cs index e5395be3d..30881f9e4 100644 --- a/MCGalaxy/Blocks/Block.Permissions.cs +++ b/MCGalaxy/Blocks/Block.Permissions.cs @@ -127,9 +127,9 @@ namespace MCGalaxy try { byte block = Block.Byte(line.Split(' ')[0]); - LevelPermission lowestRank = Level.PermissionFromName(line.Split(' ')[2]); - if (lowestRank != LevelPermission.Null) - BlockList[block].lowestRank = lowestRank; + Group group = Group.Find(line.Split(' ')[2]); + if (group != null) + BlockList[block].lowestRank = group.Permission; else throw new InvalidDataException("Line " + line + " is invalid."); } diff --git a/MCGalaxy/Commands/Information/CmdClones.cs b/MCGalaxy/Commands/Information/CmdClones.cs index 627c3903d..184ea7b16 100644 --- a/MCGalaxy/Commands/Information/CmdClones.cs +++ b/MCGalaxy/Commands/Information/CmdClones.cs @@ -51,7 +51,7 @@ namespace MCGalaxy.Commands { if (alts.Count == 0) { Player.Message(p, "Could not find any record of the player entered."); return; } if (alts.Count == 1) { Player.Message(p, name + " has no clones."); return; } - Group banned = Group.findPerm(LevelPermission.Banned); + Group banned = Group.BannedRank; Player.Message(p, "These players have the same IP address:"); Player.Message(p, alts.Join(alt => FormatAlt(alt, banned))); } diff --git a/MCGalaxy/Commands/Information/CmdCommands.cs b/MCGalaxy/Commands/Information/CmdCommands.cs index ace00f8b2..4d4be742a 100644 --- a/MCGalaxy/Commands/Information/CmdCommands.cs +++ b/MCGalaxy/Commands/Information/CmdCommands.cs @@ -77,7 +77,7 @@ namespace MCGalaxy.Commands { case "oldmenu": case "command": case "": - Group pGroup = p != null ? p.group : Group.findPerm(LevelPermission.Nobody); + Group pGroup = p != null ? p.group : Group.NobodyRank; PrintRankCommands(p, sort, modifier, pGroup, true); break; case "commandsall": case "commandall": diff --git a/MCGalaxy/Commands/Information/CmdMapInfo.cs b/MCGalaxy/Commands/Information/CmdMapInfo.cs index 1366f0aa0..a0eba0c3d 100644 --- a/MCGalaxy/Commands/Information/CmdMapInfo.cs +++ b/MCGalaxy/Commands/Information/CmdMapInfo.cs @@ -257,43 +257,43 @@ namespace MCGalaxy.Commands { void ParseProperty(string key, string value) { switch (key.ToLower()) { - case "physics": Physics = int.Parse(value); break; - case "guns": Guns = bool.Parse(value); break; - case "useblockdb": blockDB = bool.Parse(value); break; - case "realmowner": RealmOwner = value; break; - - case "perbuild": build = GetPerm(value); break; - case "pervisit": visit = GetPerm(value); break; - case "perbuildmax": buildmax = GetPerm(value); break; - case "pervisitmax": visitmax = GetPerm(value); break; - case "visitwhitelist": VisitWhitelist = Parse(value); break; - case "visitblacklist": VisitBlacklist = Parse(value); break; - case "buildwhitelist": BuildWhitelist = Parse(value); break; - case "buildblacklist": BuildBlacklist = Parse(value); break; - - case "authors": Authors = value; break; - case "roundsplayed": TotalRounds = int.Parse(value); break; - case "roundshumanwon": HumanRounds = int.Parse(value); break; - case "likes": Likes = int.Parse(value); break; - case "dislikes": Dislikes = int.Parse(value); break; - - case "cloudcolor": Clouds = value; break; - case "fogcolor": Fog = value; break; - case "skycolor": Sky = value; break; - case "shadowcolor": Shadow = value; break; - case "lightcolor": Light = value; break; - - case "edgeblock": EdgeBlock = byte.Parse(value); break; - case "edgelevel": EdgeLevel = short.Parse(value); break; - case "horizonblock": HorizonBlock = byte.Parse(value); break; - case "cloudsheight": CloudsHeight = short.Parse(value); break; - case "maxfog": MaxFog = short.Parse(value); break; - - case "texture": TerrainUrl = value; break; - case "texturepack": TextureUrl = value; break; - case "clouds-speed": CloudsSpeed = int.Parse(value); break; - case "weather-speed": WeatherSpeed = int.Parse(value); break; - case "weather-fade": WeatherFade = int.Parse(value); break; + case "physics": Physics = int.Parse(value); break; + case "guns": Guns = bool.Parse(value); break; + case "useblockdb": blockDB = bool.Parse(value); break; + case "realmowner": RealmOwner = value; break; + + case "perbuild": build = GetPerm(value); break; + case "pervisit": visit = GetPerm(value); break; + case "perbuildmax": buildmax = GetPerm(value); break; + case "pervisitmax": visitmax = GetPerm(value); break; + case "visitwhitelist": VisitWhitelist = Parse(value); break; + case "visitblacklist": VisitBlacklist = Parse(value); break; + case "buildwhitelist": BuildWhitelist = Parse(value); break; + case "buildblacklist": BuildBlacklist = Parse(value); break; + + case "authors": Authors = value; break; + case "roundsplayed": TotalRounds = int.Parse(value); break; + case "roundshumanwon": HumanRounds = int.Parse(value); break; + case "likes": Likes = int.Parse(value); break; + case "dislikes": Dislikes = int.Parse(value); break; + + case "cloudcolor": Clouds = value; break; + case "fogcolor": Fog = value; break; + case "skycolor": Sky = value; break; + case "shadowcolor": Shadow = value; break; + case "lightcolor": Light = value; break; + + case "edgeblock": EdgeBlock = byte.Parse(value); break; + case "edgelevel": EdgeLevel = short.Parse(value); break; + case "horizonblock": HorizonBlock = byte.Parse(value); break; + case "cloudsheight": CloudsHeight = short.Parse(value); break; + case "maxfog": MaxFog = short.Parse(value); break; + + case "texture": TerrainUrl = value; break; + case "texturepack": TextureUrl = value; break; + case "clouds-speed": CloudsSpeed = int.Parse(value); break; + case "weather-speed": WeatherSpeed = int.Parse(value); break; + case "weather-fade": WeatherFade = int.Parse(value); break; } } @@ -303,7 +303,7 @@ namespace MCGalaxy.Commands { } static LevelPermission GetPerm(string value) { - LevelPermission perm = Level.PermissionFromName(value); + LevelPermission perm = Group.ParsePermOrName(value); return perm != LevelPermission.Null ? perm : LevelPermission.Guest; } } diff --git a/MCGalaxy/Commands/Information/CmdViewRanks.cs b/MCGalaxy/Commands/Information/CmdViewRanks.cs index a6f0c0236..c8426e004 100644 --- a/MCGalaxy/Commands/Information/CmdViewRanks.cs +++ b/MCGalaxy/Commands/Information/CmdViewRanks.cs @@ -39,8 +39,7 @@ namespace MCGalaxy.Commands { } string modifer = args.Length > 1 ? args[1] : ""; - Group grp = message.CaselessEq("banned") ? - Group.findPerm(LevelPermission.Banned) : Group.FindMatches(p, args[0]); + Group grp = message.CaselessEq("banned") ? Group.BannedRank : Group.FindMatches(p, args[0]); if (grp == null) return; List list = grp.playerList.All(); diff --git a/MCGalaxy/Commands/Moderation/CmdBan.cs b/MCGalaxy/Commands/Moderation/CmdBan.cs index eed91f93d..05413854e 100644 --- a/MCGalaxy/Commands/Moderation/CmdBan.cs +++ b/MCGalaxy/Commands/Moderation/CmdBan.cs @@ -66,7 +66,7 @@ namespace MCGalaxy.Commands.Moderation { Ban.DeleteBan(target); Ban.BanPlayer(p, target, reason, stealth, group.name); - RankCmd.ChangeRank(target, group, Group.findPerm(LevelPermission.Banned), who); + RankCmd.ChangeRank(target, group, Group.BannedRank, who); if (args.Length == 1) Player.AddNote(target, p, "B"); else Player.AddNote(target, p, "B", reason); diff --git a/MCGalaxy/Commands/Moderation/CmdPatrol.cs b/MCGalaxy/Commands/Moderation/CmdPatrol.cs index 5bd1a7964..264114265 100644 --- a/MCGalaxy/Commands/Moderation/CmdPatrol.cs +++ b/MCGalaxy/Commands/Moderation/CmdPatrol.cs @@ -16,7 +16,7 @@ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Licenses for the specific language governing permissions and limitations under the Licenses. -*/ + */ using System; using System.Collections.Generic; @@ -52,14 +52,15 @@ namespace MCGalaxy.Commands { Player[] online = PlayerInfo.Online.Items; foreach (Player p in online) { - if ((int)p.Rank <= perm) players.Add(p.name); + if ((int)p.Rank <= perm) players.Add(p.name); } return players; } public override void Help(Player p) { Player.Message(p, "%T/patrol"); - Player.Message(p, "%HTeleports you to a random " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + " or lower"); + LevelPermission perm = (LevelPermission)CommandOtherPerms.GetPerm(this); + Player.Message(p, "%HTeleports you to a random {0} %Sor lower", Group.GetColoredName(perm)); } } } diff --git a/MCGalaxy/Commands/Moderation/CmdUnban.cs b/MCGalaxy/Commands/Moderation/CmdUnban.cs index fe67c8c4e..b6ac1522f 100644 --- a/MCGalaxy/Commands/Moderation/CmdUnban.cs +++ b/MCGalaxy/Commands/Moderation/CmdUnban.cs @@ -37,7 +37,7 @@ namespace MCGalaxy.Commands.Moderation { void Unban(Player p, string name, string reason) { string srcFull = p == null ? "(console)" : p.ColoredName + "%S"; string src = p == null ? "(console)" : p.name; - Group banned = Group.findPerm(LevelPermission.Banned); + Group banned = Group.BannedRank; // Check tempbans first foreach (Server.TempBan tban in Server.tempBans) { @@ -65,7 +65,7 @@ namespace MCGalaxy.Commands.Moderation { Server.IRC.Say(name + " was unbanned by " + src + "."); Ban.UnbanPlayer(p, name, reason); - Group banned = Group.findPerm(LevelPermission.Banned); + Group banned = Group.BannedRank; Player who = PlayerInfo.Find(name); RankCmd.ChangeRank(name, banned, Group.standard, who, false); diff --git a/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs b/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs index 45bacecea..ce2419748 100644 --- a/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs +++ b/MCGalaxy/Games/LavaSurvival/LavaSurvival.Settings.cs @@ -79,8 +79,8 @@ namespace MCGalaxy.Games { w.WriteLine("vote-count = " + voteCount); w.WriteLine("vote-time = " + voteTime); w.WriteLine("lives = " + lifeNum); - w.WriteLine("setup-rank = " + Level.PermissionToName(setupRank)); - w.WriteLine("control-rank = " + Level.PermissionToName(controlRank)); + w.WriteLine("setup-rank = " + Group.GetName(setupRank)); + w.WriteLine("control-rank = " + Group.GetName(controlRank)); w.WriteLine("maps = " + maps.Join()); } } diff --git a/MCGalaxy/Levels/Level.cs b/MCGalaxy/Levels/Level.cs index 69818e2da..2a026f39c 100644 --- a/MCGalaxy/Levels/Level.cs +++ b/MCGalaxy/Levels/Level.cs @@ -444,15 +444,14 @@ namespace MCGalaxy { } } + [Obsolete("Use Group.Find()")] public static LevelPermission PermissionFromName(string name) { - Group foundGroup = Group.Find(name); - return foundGroup != null ? foundGroup.Permission : LevelPermission.Null; + Group grp = Group.Find(name); + return grp != null ? grp.Permission : LevelPermission.Null; } - public static string PermissionToName(LevelPermission perm) { - Group foundGroup = Group.findPerm(perm); - return foundGroup != null ? foundGroup.name : ((int)perm).ToString(); - } + [Obsolete("Use Group.GetName()")] + public static string PermissionToName(LevelPermission perm) { return Group.GetName(perm); } public bool HasPlayers() { Player[] players = PlayerInfo.Online.Items; diff --git a/MCGalaxy/Player/Group/Group.cs b/MCGalaxy/Player/Group/Group.cs index 9b8b49d06..d75c3b8ee 100644 --- a/MCGalaxy/Player/Group/Group.cs +++ b/MCGalaxy/Player/Group/Group.cs @@ -38,6 +38,7 @@ namespace MCGalaxy { public static bool cancelrank = false; //Move along...nothing to see here... internal static void because(Player p, Group newrank) { if (OnPlayerRankSet != null) { OnPlayerRankSet(p, newrank); } OnPlayerRankSetEvent.Call(p, newrank); } + public string name; public string trueName; public string color; @@ -52,7 +53,12 @@ namespace MCGalaxy { public PlayerList playerList; public string MOTD = ""; public bool[] CanModify = new bool[256]; - + + public static Group BannedRank { get { return findPerm(LevelPermission.Banned); } } + public static Group GuestRank { get { return findPerm(LevelPermission.Guest); } } + public static Group NobodyRank { get { return findPerm(LevelPermission.Nobody); } } + public static Group standard; + /// Create a new group object public Group() { Permission = LevelPermission.Null; @@ -94,7 +100,7 @@ namespace MCGalaxy { /// Fill the blocks that this group can use public void FillBlocks() { for (int i = 0; i < CanModify.Length; i++) - CanModify[i] = Block.canPlace(Permission, (byte)i); + CanModify[i] = Block.canPlace(Permission, (byte)i); } public bool CanExecute(string cmdName) { @@ -107,7 +113,6 @@ namespace MCGalaxy { public bool CanExecute(Command cmd) { return commands.Contains(cmd); } public static List GroupList = new List(); - public static Group standard; static readonly object saveLock = new object(); /// Load up all server groups @@ -131,7 +136,7 @@ namespace MCGalaxy { GroupList.Add(new Group(LevelPermission.Nobody, 65536, -1, "Nobody", '0', String.Empty, "nobody.txt")); GroupList.Sort((a, b) => a.Permission.CompareTo(b.Permission)); - if (Group.Find(Server.defaultRank) != null) { + if (Find(Server.defaultRank) != null) { standard = Group.Find(Server.defaultRank); } else { standard = Group.findPerm(LevelPermission.Guest); @@ -158,6 +163,7 @@ namespace MCGalaxy { OnGroupSaveEvent.Call(); } + /// Check whether a group with that name exists. public static bool Exists(string name) { name = name.ToLower(); @@ -198,7 +204,7 @@ namespace MCGalaxy { if (name == "noone") name = "nobody"; } - /// Finds the group with has the given permission level. + /// Finds the group which has the given permission level. public static Group findPerm(LevelPermission Perm) { return GroupList.Find(grp => grp.Permission == Perm); } @@ -207,6 +213,7 @@ namespace MCGalaxy { public static Group findPermInt(int Perm) { return GroupList.Find(grp => (int)grp.Permission == Perm); } + /// Get the group name that player /playerName/ is in /// The player Name @@ -244,6 +251,12 @@ namespace MCGalaxy { return grp != null && grp.playerList.Contains(name); } + public static string GetName(LevelPermission perm) { + Group grp = findPerm(perm); + if (grp != null) return grp.trueName; + return ((int)perm).ToString(); + } + public static string GetColoredName(LevelPermission perm) { Group grp = findPerm(perm); if (grp != null) return grp.ColoredName; @@ -255,5 +268,14 @@ namespace MCGalaxy { if (grp != null) return grp.color; return Colors.white; } + + public static LevelPermission ParsePermOrName(string value) { + sbyte perm; + if (sbyte.TryParse(value, out perm)) + return (LevelPermission)perm; + + Group grp = Find(value); + return grp != null ? grp.Permission : LevelPermission.Null; + } } } diff --git a/MCGalaxy/Player/Group/GroupCommands.cs b/MCGalaxy/Player/Group/GroupCommands.cs index 240c060a9..e81acdb5b 100644 --- a/MCGalaxy/Player/Group/GroupCommands.cs +++ b/MCGalaxy/Player/Group/GroupCommands.cs @@ -117,11 +117,11 @@ namespace MCGalaxy { if (!cmdNames.Contains(key)) { Server.s.Log("Incorrect command name: " + key); - } else if (Level.PermissionFromName(value) == LevelPermission.Null) { + } else if (Group.Find(value) == null) { Server.s.Log("Incorrect value given for " + key + ", using default value."); - } else{ + } else { perms.commandName = key; - perms.lowestRank = Level.PermissionFromName(value); + perms.lowestRank = Group.Find(value).Permission; for (int i = 0; i < allowedCommands.Count; i++) { if (allowedCommands[i].commandName == key) {