mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-29 08:32:14 -04:00
Style: Make LevelAccess cleaner
This commit is contained in:
parent
11ccfe430c
commit
04b8e79664
@ -38,9 +38,8 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
who.color = newRank.color;
|
who.color = newRank.color;
|
||||||
|
|
||||||
who.group = newRank;
|
who.group = newRank;
|
||||||
LevelAccessResult access = who.level.BuildAccess.Check(who, false);
|
LevelAccess access = who.level.BuildAccess.Check(who);
|
||||||
who.AllowBuild = access == LevelAccessResult.Whitelisted
|
who.AllowBuild = access == LevelAccess.Whitelisted || access == LevelAccess.Allowed;
|
||||||
|| access == LevelAccessResult.Allowed;
|
|
||||||
|
|
||||||
who.SetPrefix();
|
who.SetPrefix();
|
||||||
who.Send(Packet.UserType(who));
|
who.Send(Packet.UserType(who));
|
||||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
int totalFixed = 0;
|
int totalFixed = 0;
|
||||||
Level lvl = p.level;
|
Level lvl = p.level;
|
||||||
if (p != null && !lvl.BuildAccess.CheckDetailed(p, false)) {
|
if (p != null && !lvl.BuildAccess.CheckDetailed(p)) {
|
||||||
Player.Message(p, "Hence you cannot use /fixgrass on this map"); return;
|
Player.Message(p, "Hence you cannot use /fixgrass on this map"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
}
|
}
|
||||||
Level level = args.Length == 1 ? p.level : LevelInfo.FindMatches(p, args[0]);
|
Level level = args.Length == 1 ? p.level : LevelInfo.FindMatches(p, args[0]);
|
||||||
if (level == null) return;
|
if (level == null) return;
|
||||||
LevelAccess access = isVisit ? level.VisitAccess : level.BuildAccess;
|
LevelAccessController access = isVisit ? level.VisitAccess : level.BuildAccess;
|
||||||
|
|
||||||
string name = args.Length == 1 ? args[0] : args[1];
|
string name = args.Length == 1 ? args[0] : args[1];
|
||||||
bool include = name[0] == '+';
|
bool include = name[0] == '+';
|
||||||
|
@ -78,18 +78,20 @@ namespace MCGalaxy.Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool CheckVisitPerm(Player p, Player who, bool confirmed) {
|
static bool CheckVisitPerm(Player p, Player who, bool confirmed) {
|
||||||
LevelAccessResult result = p.level.VisitAccess.Check(who, confirmed);
|
LevelAccess result = p.level.VisitAccess.Check(who);
|
||||||
if (result == LevelAccessResult.Allowed) return true;
|
if (result == LevelAccess.Allowed) return true;
|
||||||
if (result == LevelAccessResult.Whitelisted) return true;
|
if (result == LevelAccess.Whitelisted) return true;
|
||||||
|
if (result == LevelAccess.AboveMaxRank && confirmed) return true;
|
||||||
|
if (result == LevelAccess.BelowMinRank && confirmed) return true;
|
||||||
|
|
||||||
if (result == LevelAccessResult.Blacklisted) {
|
if (result == LevelAccess.Blacklisted) {
|
||||||
Player.Message(p, "{0} %Sis blacklisted from visiting this map.", who.ColoredName);
|
Player.Message(p, "{0} %Sis blacklisted from visiting this map.", who.ColoredName);
|
||||||
return false;
|
return false;
|
||||||
} else if (result == LevelAccessResult.BelowMinRank) {
|
} else if (result == LevelAccess.BelowMinRank) {
|
||||||
Player.Message(p, "Only {0}%S+ may normally visit this map. {1}%S is ranked {2}",
|
Player.Message(p, "Only {0}%S+ may normally visit this map. {1}%S is ranked {2}",
|
||||||
Group.GetColoredName(p.level.permissionvisit),
|
Group.GetColoredName(p.level.permissionvisit),
|
||||||
who.ColoredName, who.group.ColoredName);
|
who.ColoredName, who.group.ColoredName);
|
||||||
} else if (result == LevelAccessResult.AboveMaxRank) {
|
} else if (result == LevelAccess.AboveMaxRank) {
|
||||||
Player.Message(p, "Only {0}%S and below may normally visit this map. {1}%S is ranked {2}",
|
Player.Message(p, "Only {0}%S and below may normally visit this map. {1}%S is ranked {2}",
|
||||||
Group.GetColoredName(p.level.pervisitmax),
|
Group.GetColoredName(p.level.pervisitmax),
|
||||||
who.ColoredName, who.group.ColoredName);
|
who.ColoredName, who.group.ColoredName);
|
||||||
|
@ -52,7 +52,7 @@ namespace MCGalaxy.Drawing.Ops {
|
|||||||
Player.Message(p, "Drawing commands are turned off on this map.");
|
Player.Message(p, "Drawing commands are turned off on this map.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (op.Level != null && op.Level.BuildAccess.Check(p) == LevelAccessResult.Blacklisted) {
|
if (op.Level != null && op.Level.BuildAccess.Check(p) == LevelAccess.Blacklisted) {
|
||||||
Player.Message(p, "You are blacklisted from building in this map, " +
|
Player.Message(p, "You are blacklisted from building in this map, " +
|
||||||
"hence you cannot draw in this map");
|
"hence you cannot draw in this map");
|
||||||
return false;
|
return false;
|
||||||
|
@ -228,14 +228,14 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
bool CheckRank(Player p) {
|
bool CheckRank(Player p) {
|
||||||
if (p.ZoneSpam <= DateTime.UtcNow) {
|
if (p.ZoneSpam <= DateTime.UtcNow) {
|
||||||
BuildAccess.CheckDetailed(p, false);
|
BuildAccess.CheckDetailed(p);
|
||||||
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
||||||
}
|
}
|
||||||
if (p.level == this) return p.AllowBuild;
|
if (p.level == this) return p.AllowBuild;
|
||||||
|
|
||||||
LevelAccessResult access = BuildAccess.Check(p, false);
|
LevelAccess access = BuildAccess.Check(p);
|
||||||
return access == LevelAccessResult.Whitelisted
|
return access == LevelAccess.Whitelisted
|
||||||
|| access == LevelAccessResult.Allowed;
|
|| access == LevelAccess.Allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z,
|
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z,
|
||||||
|
@ -147,7 +147,7 @@ namespace MCGalaxy {
|
|||||||
public bool Buildable = true;
|
public bool Buildable = true;
|
||||||
[ConfigBool("Deletable", "Permissions", null, true)]
|
[ConfigBool("Deletable", "Permissions", null, true)]
|
||||||
public bool Deletable = true;
|
public bool Deletable = true;
|
||||||
public LevelAccess VisitAccess, BuildAccess;
|
public LevelAccessController VisitAccess, BuildAccess;
|
||||||
|
|
||||||
[ConfigPerm("PerBuildMax", "Permissions", null, LevelPermission.Nobody, true)]
|
[ConfigPerm("PerBuildMax", "Permissions", null, LevelPermission.Nobody, true)]
|
||||||
public LevelPermission perbuildmax = LevelPermission.Nobody;
|
public LevelPermission perbuildmax = LevelPermission.Nobody;
|
||||||
|
@ -93,8 +93,8 @@ namespace MCGalaxy {
|
|||||||
rotx = 0; roty = 0;
|
rotx = 0; roty = 0;
|
||||||
|
|
||||||
ZoneList = new List<Zone>();
|
ZoneList = new List<Zone>();
|
||||||
VisitAccess = new LevelAccess(this, true);
|
VisitAccess = new LevelAccessController(this, true);
|
||||||
BuildAccess = new LevelAccess(this, false);
|
BuildAccess = new LevelAccessController(this, false);
|
||||||
listCheckExists = new SparseBitSet(Width, Height, Length);
|
listCheckExists = new SparseBitSet(Width, Height, Length);
|
||||||
listUpdateExists = new SparseBitSet(Width, Height, Length);
|
listUpdateExists = new SparseBitSet(Width, Height, Length);
|
||||||
}
|
}
|
||||||
|
@ -21,14 +21,14 @@ using System.Collections.Generic;
|
|||||||
namespace MCGalaxy {
|
namespace MCGalaxy {
|
||||||
|
|
||||||
/// <summary> Encapuslates access permissions (visit or build) for a level. </summary>
|
/// <summary> Encapuslates access permissions (visit or build) for a level. </summary>
|
||||||
public sealed class LevelAccess {
|
public sealed class LevelAccessController {
|
||||||
|
|
||||||
/// <summary> Whether these access permissions apply to
|
/// <summary> Whether these access permissions apply to
|
||||||
/// visit (true) or build (false) permission for the level. </summary>
|
/// visit (true) or build (false) permission for the level. </summary>
|
||||||
public readonly bool IsVisit;
|
public readonly bool IsVisit;
|
||||||
readonly Level lvl;
|
readonly Level lvl;
|
||||||
|
|
||||||
public LevelAccess(Level lvl, bool isVisit) {
|
public LevelAccessController(Level lvl, bool isVisit) {
|
||||||
this.lvl = lvl;
|
this.lvl = lvl;
|
||||||
IsVisit = isVisit;
|
IsVisit = isVisit;
|
||||||
}
|
}
|
||||||
@ -63,38 +63,38 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
|
|
||||||
/// <summary> Returns the allowed state for the given player. </summary>
|
/// <summary> Returns the allowed state for the given player. </summary>
|
||||||
public LevelAccessResult Check(Player p, bool ignoreRankPerm = false) {
|
public LevelAccess Check(Player p) {
|
||||||
if (Blacklisted.CaselessContains(p.name))
|
if (Blacklisted.CaselessContains(p.name))
|
||||||
return LevelAccessResult.Blacklisted;
|
return LevelAccess.Blacklisted;
|
||||||
if (Whitelisted.CaselessContains(p.name))
|
if (Whitelisted.CaselessContains(p.name))
|
||||||
return LevelAccessResult.Whitelisted;
|
return LevelAccess.Whitelisted;
|
||||||
if (ignoreRankPerm)
|
|
||||||
return LevelAccessResult.Allowed;
|
|
||||||
|
|
||||||
if (p.Rank < Min)
|
if (p.Rank < Min)
|
||||||
return LevelAccessResult.BelowMinRank;
|
return LevelAccess.BelowMinRank;
|
||||||
string maxCmd = IsVisit ? "pervisitmax" : "perbuildmax";
|
string maxCmd = IsVisit ? "pervisitmax" : "perbuildmax";
|
||||||
if (p.Rank > Max && !p.group.CanExecute(maxCmd))
|
if (p.Rank > Max && !p.group.CanExecute(maxCmd))
|
||||||
return LevelAccessResult.AboveMaxRank;
|
return LevelAccess.AboveMaxRank;
|
||||||
return LevelAccessResult.Allowed;
|
return LevelAccess.Allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Returns whether the given player is allowed for these access permissions. </summary>
|
/// <summary> Returns whether the given player is allowed for these access permissions. </summary>
|
||||||
/// <remarks> If the player is not allowed by these access permissions,
|
/// <remarks> If the player is not allowed by these access permissions,
|
||||||
/// sends a message to the player describing why they are not. </remarks>
|
/// sends a message to the player describing why they are not. </remarks>
|
||||||
public bool CheckDetailed(Player p, bool ignoreRankPerm = false) {
|
public bool CheckDetailed(Player p, bool ignoreRankPerm = false) {
|
||||||
LevelAccessResult result = Check(p, ignoreRankPerm);
|
LevelAccess result = Check(p);
|
||||||
if (result == LevelAccessResult.Allowed) return true;
|
if (result == LevelAccess.Allowed) return true;
|
||||||
if (result == LevelAccessResult.Whitelisted) return true;
|
if (result == LevelAccess.Whitelisted) return true;
|
||||||
|
if (result == LevelAccess.AboveMaxRank && ignoreRankPerm) return true;
|
||||||
|
if (result == LevelAccess.BelowMinRank && ignoreRankPerm) return true;
|
||||||
|
|
||||||
if (result == LevelAccessResult.Blacklisted) {
|
if (result == LevelAccess.Blacklisted) {
|
||||||
string action = IsVisit ? "going to" : "building in";
|
string action = IsVisit ? "going to" : "building in";
|
||||||
Player.Message(p, "You are blacklisted from {1} {0}.", lvl.name, action);
|
Player.Message(p, "You are blacklisted from {1} {0}.", lvl.name, action);
|
||||||
} else if (result == LevelAccessResult.BelowMinRank) {
|
} else if (result == LevelAccess.BelowMinRank) {
|
||||||
string action = IsVisit? "go to" : "build in";
|
string action = IsVisit? "go to" : "build in";
|
||||||
Player.Message(p, "Only {2}%S+ may {1} {0}.",
|
Player.Message(p, "Only {2}%S+ may {1} {0}.",
|
||||||
lvl.name, action, Group.GetColoredName(Min));
|
lvl.name, action, Group.GetColoredName(Min));
|
||||||
} else if (result == LevelAccessResult.AboveMaxRank) {
|
} else if (result == LevelAccess.AboveMaxRank) {
|
||||||
string action = IsVisit? "go to" : "build in";
|
string action = IsVisit? "go to" : "build in";
|
||||||
Player.Message(p, "Only {2} %Sand below may {1} {0}.",
|
Player.Message(p, "Only {2} %Sand below may {1} {0}.",
|
||||||
lvl.name, action, Group.GetColoredName(Max));
|
lvl.name, action, Group.GetColoredName(Max));
|
||||||
@ -227,9 +227,8 @@ namespace MCGalaxy {
|
|||||||
foreach (Player p in players) {
|
foreach (Player p in players) {
|
||||||
if (p.level != lvl) continue;
|
if (p.level != lvl) continue;
|
||||||
|
|
||||||
LevelAccessResult access = Check(p, false);
|
LevelAccess access = Check(p);
|
||||||
p.AllowBuild = access == LevelAccessResult.Whitelisted
|
p.AllowBuild = access == LevelAccess.Whitelisted || access == LevelAccess.Allowed;
|
||||||
|| access == LevelAccessResult.Allowed;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,9 +238,8 @@ namespace MCGalaxy {
|
|||||||
foreach (Player p in players) {
|
foreach (Player p in players) {
|
||||||
if (p.level != lvl) continue;
|
if (p.level != lvl) continue;
|
||||||
|
|
||||||
LevelAccessResult access = Check(p, false);
|
LevelAccess access = Check(p);
|
||||||
bool allowVisit = access == LevelAccessResult.Whitelisted
|
bool allowVisit = access == LevelAccess.Whitelisted || access == LevelAccess.Allowed;
|
||||||
|| access == LevelAccessResult.Allowed;
|
|
||||||
if (allowVisit) continue;
|
if (allowVisit) continue;
|
||||||
|
|
||||||
Player.Message(p, "&cNo longer allowed to visit %S{0}", lvl.name);
|
Player.Message(p, "&cNo longer allowed to visit %S{0}", lvl.name);
|
||||||
@ -250,7 +248,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum LevelAccessResult {
|
public enum LevelAccess {
|
||||||
|
|
||||||
/// <summary> The player is whitelisted and always allowed. </summary>
|
/// <summary> The player is whitelisted and always allowed. </summary>
|
||||||
Whitelisted,
|
Whitelisted,
|
||||||
|
@ -312,9 +312,8 @@ namespace MCGalaxy {
|
|||||||
useCheckpointSpawn = false;
|
useCheckpointSpawn = false;
|
||||||
lastCheckpointIndex = -1;
|
lastCheckpointIndex = -1;
|
||||||
|
|
||||||
LevelAccessResult access = level.BuildAccess.Check(this, false);
|
LevelAccess access = level.BuildAccess.Check(this);
|
||||||
AllowBuild = access == LevelAccessResult.Whitelisted
|
AllowBuild = access == LevelAccess.Whitelisted || access == LevelAccess.Allowed;
|
||||||
|| access == LevelAccessResult.Allowed;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (hasBlockDefs) {
|
if (hasBlockDefs) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user