mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 22:30:52 -04:00
Cleanup AccessController
This commit is contained in:
parent
ef830df75e
commit
6e279952ff
@ -184,7 +184,7 @@ namespace MCGalaxy.Commands.Info {
|
||||
public ushort Width, Height, Length;
|
||||
public string Name, MapName;
|
||||
public long BlockDBEntries = -1;
|
||||
public LevelAccessController Visit, Build;
|
||||
public AccessController Visit, Build;
|
||||
public LevelConfig Config;
|
||||
|
||||
public void FromLevel(Level lvl) {
|
||||
|
@ -27,7 +27,9 @@ namespace MCGalaxy {
|
||||
|
||||
public abstract LevelPermission Min { 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; }
|
||||
/// <summary> List of players who are never allowd to access. </summary>
|
||||
public abstract List<string> Blacklisted { get; }
|
||||
|
||||
protected abstract string ColoredName { get; }
|
||||
@ -202,47 +204,46 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
/// <summary> Encapuslates access permissions (visit or build) for a level. </summary>
|
||||
public sealed class LevelAccessController : AccessController {
|
||||
|
||||
public readonly bool IsVisit;
|
||||
public sealed class LevelAccessController : AccessController {
|
||||
readonly bool isVisit;
|
||||
readonly LevelConfig cfg;
|
||||
readonly string lvlName;
|
||||
|
||||
public LevelAccessController(LevelConfig cfg, string levelName, bool isVisit) {
|
||||
this.cfg = cfg;
|
||||
this.lvlName = levelName;
|
||||
IsVisit = isVisit;
|
||||
this.isVisit = isVisit;
|
||||
}
|
||||
|
||||
public override LevelPermission Min {
|
||||
get { return IsVisit ? cfg.VisitMin : cfg.BuildMin; }
|
||||
get { return isVisit ? cfg.VisitMin : cfg.BuildMin; }
|
||||
set {
|
||||
if (IsVisit) cfg.VisitMin = value;
|
||||
if (isVisit) cfg.VisitMin = value;
|
||||
else cfg.BuildMin = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override LevelPermission Max {
|
||||
get { return IsVisit ? cfg.VisitMax : cfg.BuildMax; }
|
||||
get { return isVisit ? cfg.VisitMax : cfg.BuildMax; }
|
||||
set {
|
||||
if (IsVisit) cfg.VisitMax = value;
|
||||
if (isVisit) cfg.VisitMax = value;
|
||||
else cfg.BuildMax = value;
|
||||
}
|
||||
}
|
||||
|
||||
public override List<string> Whitelisted {
|
||||
get { return IsVisit ? cfg.VisitWhitelist : cfg.BuildWhitelist; }
|
||||
get { return isVisit ? cfg.VisitWhitelist : cfg.BuildWhitelist; }
|
||||
}
|
||||
|
||||
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 Action { get { return IsVisit ? "go to" : "build in"; } }
|
||||
protected override string ActionIng { get { return IsVisit ? "going to" : "building in"; } }
|
||||
protected override string Type { get { return IsVisit ? "visit" : "build"; } }
|
||||
protected override string MaxCmd { get { return IsVisit ? "PerVisit" : "PerBuild"; } }
|
||||
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 Type { get { return isVisit ? "visit" : "build"; } }
|
||||
protected override string MaxCmd { get { return isVisit ? "PerVisit" : "PerBuild"; } }
|
||||
|
||||
|
||||
protected override void ApplyChanges(Player p, Level lvl, string msg) {
|
||||
@ -258,14 +259,14 @@ namespace MCGalaxy {
|
||||
void Update(Level lvl) {
|
||||
cfg.SaveFor(lvlName);
|
||||
if (lvl == null) return;
|
||||
if (IsVisit && lvl == Server.mainLevel) return;
|
||||
if (isVisit && lvl == Server.mainLevel) return;
|
||||
Player[] players = PlayerInfo.Online.Items;
|
||||
|
||||
foreach (Player p in players) {
|
||||
if (p.level != lvl) continue;
|
||||
bool allowed = CheckAllowed(p);
|
||||
|
||||
if (!IsVisit) {
|
||||
if (!isVisit) {
|
||||
p.AllowBuild = allowed;
|
||||
} else if (!allowed) {
|
||||
p.Message("%WNo longer allowed to visit %S{0}", ColoredName);
|
||||
|
@ -271,8 +271,6 @@ namespace MCGalaxy {
|
||||
|
||||
[ConfigTimespan("MinRoundTime", "Game", 4, true)]
|
||||
public TimeSpan RoundTime = TimeSpan.FromMinutes(5);
|
||||
[ConfigTimespan("MaxRoundTime", "Game", 7, true)]
|
||||
public TimeSpan __MaxRoundTime = TimeSpan.FromMinutes(7);
|
||||
[ConfigBool("DrawingAllowed", "Game", true)]
|
||||
public bool Drawing = true;
|
||||
[ConfigInt("RoundsPlayed", "Game", 0)]
|
||||
|
@ -137,8 +137,8 @@ namespace MCGalaxy {
|
||||
Level lvl; LevelConfig cfg = GetConfig(map, out lvl);
|
||||
if (lvl != null) return Check(p, plRank, lvl, action);
|
||||
|
||||
LevelAccessController visit = new LevelAccessController(cfg, map, true);
|
||||
LevelAccessController build = new LevelAccessController(cfg, map, false);
|
||||
AccessController visit = new LevelAccessController(cfg, map, true);
|
||||
AccessController build = new LevelAccessController(cfg, map, false);
|
||||
if (!visit.CheckDetailed(p, plRank) || !build.CheckDetailed(p, plRank)) {
|
||||
p.Message("Hence, you cannot {0}.", action); return false;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ namespace MCGalaxy {
|
||||
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);
|
||||
LevelPermission plRank = skip ? LevelPermission.Nobody : p.Rank;
|
||||
if (!visitAccess.CheckDetailed(p, plRank)) return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user