mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
fix /mi showing wrong permission levels, more work on making code work without core ranks
This commit is contained in:
parent
abe20df16a
commit
25d5c7f32c
@ -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.");
|
||||
}
|
||||
|
@ -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)));
|
||||
}
|
||||
|
@ -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":
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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<string> list = grp.playerList.All();
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
/// <summary> Create a new group object </summary>
|
||||
public Group() {
|
||||
Permission = LevelPermission.Null;
|
||||
@ -94,7 +100,7 @@ namespace MCGalaxy {
|
||||
/// <summary> Fill the blocks that this group can use </summary>
|
||||
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<Group> GroupList = new List<Group>();
|
||||
public static Group standard;
|
||||
static readonly object saveLock = new object();
|
||||
|
||||
/// <summary> Load up all server groups </summary>
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Check whether a group with that name exists. </summary>
|
||||
public static bool Exists(string name) {
|
||||
name = name.ToLower();
|
||||
@ -198,7 +204,7 @@ namespace MCGalaxy {
|
||||
if (name == "noone") name = "nobody";
|
||||
}
|
||||
|
||||
/// <summary> Finds the group with has the given permission level. </summary>
|
||||
/// <summary> Finds the group which has the given permission level. </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Get the group name that player /playerName/ is in </summary>
|
||||
/// <param name="name">The player Name</param>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user