Cleanup AccessController

This commit is contained in:
UnknownShadow200 2019-08-03 22:14:16 +10:00
parent ef830df75e
commit 6e279952ff
5 changed files with 21 additions and 22 deletions

View File

@ -184,7 +184,7 @@ namespace MCGalaxy.Commands.Info {
public ushort Width, Height, Length; public ushort Width, Height, Length;
public string Name, MapName; public string Name, MapName;
public long BlockDBEntries = -1; public long BlockDBEntries = -1;
public LevelAccessController Visit, Build; public AccessController Visit, Build;
public LevelConfig Config; public LevelConfig Config;
public void FromLevel(Level lvl) { public void FromLevel(Level lvl) {

View File

@ -27,7 +27,9 @@ namespace MCGalaxy {
public abstract LevelPermission Min { get; set; } public abstract LevelPermission Min { get; set; }
public abstract LevelPermission Max { get; set; } public abstract LevelPermission Max { get; set; }
/// <summary> List of players who are always allowed to access. </summary>
public abstract List<string> Whitelisted { get; } public abstract List<string> Whitelisted { get; }
/// <summary> List of players who are never allowd to access. </summary>
public abstract List<string> Blacklisted { get; } public abstract List<string> Blacklisted { get; }
protected abstract string ColoredName { get; } protected abstract string ColoredName { get; }
@ -202,47 +204,46 @@ 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 LevelAccessController : AccessController { public sealed class LevelAccessController : AccessController {
readonly bool isVisit;
public readonly bool IsVisit;
readonly LevelConfig cfg; readonly LevelConfig cfg;
readonly string lvlName; readonly string lvlName;
public LevelAccessController(LevelConfig cfg, string levelName, bool isVisit) { public LevelAccessController(LevelConfig cfg, string levelName, bool isVisit) {
this.cfg = cfg; this.cfg = cfg;
this.lvlName = levelName; this.lvlName = levelName;
IsVisit = isVisit; this.isVisit = isVisit;
} }
public override LevelPermission Min { public override LevelPermission Min {
get { return IsVisit ? cfg.VisitMin : cfg.BuildMin; } get { return isVisit ? cfg.VisitMin : cfg.BuildMin; }
set { set {
if (IsVisit) cfg.VisitMin = value; if (isVisit) cfg.VisitMin = value;
else cfg.BuildMin = value; else cfg.BuildMin = value;
} }
} }
public override LevelPermission Max { public override LevelPermission Max {
get { return IsVisit ? cfg.VisitMax : cfg.BuildMax; } get { return isVisit ? cfg.VisitMax : cfg.BuildMax; }
set { set {
if (IsVisit) cfg.VisitMax = value; if (isVisit) cfg.VisitMax = value;
else cfg.BuildMax = value; else cfg.BuildMax = value;
} }
} }
public override List<string> Whitelisted { public override List<string> Whitelisted {
get { return IsVisit ? cfg.VisitWhitelist : cfg.BuildWhitelist; } get { return isVisit ? cfg.VisitWhitelist : cfg.BuildWhitelist; }
} }
public override List<string> Blacklisted { public override List<string> Blacklisted {
get { return IsVisit ? cfg.VisitBlacklist : cfg.BuildBlacklist; } get { return isVisit ? cfg.VisitBlacklist : cfg.BuildBlacklist; }
} }
protected override string ColoredName { get { return cfg.Color + lvlName; } } protected override string ColoredName { get { return cfg.Color + lvlName; } }
protected override string Action { get { return IsVisit ? "go to" : "build in"; } } protected override string Action { get { return isVisit ? "go to" : "build in"; } }
protected override string ActionIng { get { return IsVisit ? "going to" : "building in"; } } protected override string ActionIng { get { return isVisit ? "going to" : "building in"; } }
protected override string Type { get { return IsVisit ? "visit" : "build"; } } protected override string Type { get { return isVisit ? "visit" : "build"; } }
protected override string MaxCmd { get { return IsVisit ? "PerVisit" : "PerBuild"; } } protected override string MaxCmd { get { return isVisit ? "PerVisit" : "PerBuild"; } }
protected override void ApplyChanges(Player p, Level lvl, string msg) { protected override void ApplyChanges(Player p, Level lvl, string msg) {
@ -258,14 +259,14 @@ namespace MCGalaxy {
void Update(Level lvl) { void Update(Level lvl) {
cfg.SaveFor(lvlName); cfg.SaveFor(lvlName);
if (lvl == null) return; if (lvl == null) return;
if (IsVisit && lvl == Server.mainLevel) return; if (isVisit && lvl == Server.mainLevel) return;
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) { foreach (Player p in players) {
if (p.level != lvl) continue; if (p.level != lvl) continue;
bool allowed = CheckAllowed(p); bool allowed = CheckAllowed(p);
if (!IsVisit) { if (!isVisit) {
p.AllowBuild = allowed; p.AllowBuild = allowed;
} else if (!allowed) { } else if (!allowed) {
p.Message("%WNo longer allowed to visit %S{0}", ColoredName); p.Message("%WNo longer allowed to visit %S{0}", ColoredName);

View File

@ -271,8 +271,6 @@ namespace MCGalaxy {
[ConfigTimespan("MinRoundTime", "Game", 4, true)] [ConfigTimespan("MinRoundTime", "Game", 4, true)]
public TimeSpan RoundTime = TimeSpan.FromMinutes(5); public TimeSpan RoundTime = TimeSpan.FromMinutes(5);
[ConfigTimespan("MaxRoundTime", "Game", 7, true)]
public TimeSpan __MaxRoundTime = TimeSpan.FromMinutes(7);
[ConfigBool("DrawingAllowed", "Game", true)] [ConfigBool("DrawingAllowed", "Game", true)]
public bool Drawing = true; public bool Drawing = true;
[ConfigInt("RoundsPlayed", "Game", 0)] [ConfigInt("RoundsPlayed", "Game", 0)]

View File

@ -137,8 +137,8 @@ namespace MCGalaxy {
Level lvl; LevelConfig cfg = GetConfig(map, out lvl); Level lvl; LevelConfig cfg = GetConfig(map, out lvl);
if (lvl != null) return Check(p, plRank, lvl, action); if (lvl != null) return Check(p, plRank, lvl, action);
LevelAccessController visit = new LevelAccessController(cfg, map, true); AccessController visit = new LevelAccessController(cfg, map, true);
LevelAccessController build = new LevelAccessController(cfg, map, false); AccessController build = new LevelAccessController(cfg, map, false);
if (!visit.CheckDetailed(p, plRank) || !build.CheckDetailed(p, plRank)) { if (!visit.CheckDetailed(p, plRank) || !build.CheckDetailed(p, plRank)) {
p.Message("Hence, you cannot {0}.", action); return false; p.Message("Hence, you cannot {0}.", action); return false;
} }

View File

@ -79,7 +79,7 @@ namespace MCGalaxy {
return false; return false;
} }
LevelAccessController visitAccess = new LevelAccessController(cfg, map, true); AccessController visitAccess = new LevelAccessController(cfg, map, true);
bool skip = p.summonedMap != null && p.summonedMap.CaselessEq(map); bool skip = p.summonedMap != null && p.summonedMap.CaselessEq(map);
LevelPermission plRank = skip ? LevelPermission.Nobody : p.Rank; LevelPermission plRank = skip ? LevelPermission.Nobody : p.Rank;
if (!visitAccess.CheckDetailed(p, plRank)) return false; if (!visitAccess.CheckDetailed(p, plRank)) return false;