simplify AccessController

This commit is contained in:
UnknownShadow200 2018-06-01 23:02:38 +10:00
parent 9343f7c995
commit d9302b9e1a
5 changed files with 30 additions and 45 deletions

View File

@ -30,7 +30,7 @@ namespace MCGalaxy.Core {
if (cmd == "pony") {
p.cancelcommand = true;
if (!MessageCmd.CanSpeak(p, cmd)) return;
int ponycount = p.Extras.GetInt("MCGalaxy_Core_Pony", 0);
int ponycount = p.Extras.GetInt("MCG_PONY", 0);
if (ponycount < 2) {
Chat.MessageGlobal("{0} %Sjust so happens to be a proud brony! Everyone give {0} %Sa brohoof!", p.ColoredName);
@ -44,7 +44,7 @@ namespace MCGalaxy.Core {
} else if (cmd == "rainbowdashlikescoolthings") {
p.cancelcommand = true;
if (!MessageCmd.CanSpeak(p, cmd)) return;
int rdcount = p.Extras.GetInt("MCGalaxy_Core_RD", 0);
int rdcount = p.Extras.GetInt("MCG_RD", 0);
if (rdcount < 2) {
Chat.MessageGlobal("&4T&6H&eI&aS&3 S&9E&1R&4V&6E&eR &aJ&3U&9S&1T &4G&6O&eT &a2&30 &9P&1E&4R&6C&eE&aN&3T &9C&1O&4O&6L&eE&aR&3!");

View File

@ -158,8 +158,22 @@ namespace MCGalaxy {
}
public abstract void OnPermissionChanged(Player p, Level lvl, Group grp, string type);
public abstract void OnListChanged(Player p, Level lvl, string name, bool whitelist, bool removedFromOpposite);
public void OnPermissionChanged(Player p, Level lvl, Group grp, string type) {
string msg = type + " rank changed to " + grp.ColoredName;
ApplyChanges(p, lvl, msg);
}
public void OnListChanged(Player p, Level lvl, string name, bool whitelist, bool removedFromOpposite) {
string msg = PlayerInfo.GetColoredName(p, name);
if (removedFromOpposite) {
msg += " %Swas removed from the " + Type + (whitelist ? " blacklist" : " whitelist");
} else {
msg += " %Swas build" + (whitelist ? " whitelisted" : " blacklisted");
}
ApplyChanges(p, lvl, msg);
}
protected abstract void ApplyChanges(Player p, Level lvl, string msg);
bool CheckRank(Player p, LevelPermission perm, string type, bool newPerm) {
if (p != null && perm > p.Rank) {
@ -236,24 +250,9 @@ namespace MCGalaxy {
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"; } }
public override void OnPermissionChanged(Player p, Level lvl, Group grp, string type) {
string msg = type + " rank changed to " + grp.ColoredName;
DoChange(p, lvl, msg);
}
public override void OnListChanged(Player p, Level lvl, string name, bool whitelist, bool removedFromOpposite) {
string msg = PlayerInfo.GetColoredName(p, name);
if (removedFromOpposite) {
msg += " %Swas removed from the " + Type + (whitelist ? " blacklist" : " whitelist");
} else {
msg += " %Swas " + Type + (whitelist ? " whitelisted" : " blacklisted");
}
DoChange(p, lvl, msg);
}
void DoChange(Player p, Level lvl, string msg) {
protected override void ApplyChanges(Player p, Level lvl, string msg) {
Update(lvl);
Logger.Log(LogType.UserActivity, "{0} %Son {1}", msg, lvlName);

View File

@ -192,9 +192,9 @@ namespace MCGalaxy {
}
bool CheckRank(Player p) {
if (p.ZoneSpam <= DateTime.UtcNow) {
if (p.lastAccessStatus <= DateTime.UtcNow) {
BuildAccess.CheckDetailed(p);
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
p.lastAccessStatus = DateTime.UtcNow.AddSeconds(2);
}
if (p.level == this) return p.AllowBuild;
@ -233,9 +233,9 @@ namespace MCGalaxy {
AccessResult access = zn.Access.Check(p);
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) continue;
if (p.ZoneSpam > DateTime.UtcNow) return false;
if (p.lastAccessStatus > DateTime.UtcNow) return false;
zn.Access.CheckDetailed(p);
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
p.lastAccessStatus = DateTime.UtcNow.AddSeconds(2);
return false;
}
return CheckRank(p);
@ -432,15 +432,16 @@ namespace MCGalaxy {
public void UpdateBlock(Player p, ushort x, ushort y, ushort z, BlockID block,
ushort flags = BlockDBFlags.ManualPlace, bool buffered = false) {
BlockID old = GetBlock(x, y, z);
int index;
BlockID old = GetBlock(x, y, z, out index);
bool drawn = (flags & BlockDBFlags.ManualPlace) != 0;
int type = DoBlockchange(p, x, y, z, block, drawn);
if (type == 0) return; // no block change performed
BlockDB.Cache.Add(p, x, y, z, flags, old, block);
if (type == 1) return; // not different visually
int index = PosToInt(x, y, z);
if (buffered) BlockQueue.Add(p, index, block);
else Player.GlobalBlockchange(this, x, y, z, block);
}

View File

@ -58,26 +58,11 @@ namespace MCGalaxy {
protected override string ActionIng { get { return "building in"; } }
protected override string Type { get { return "build"; } }
protected override string MaxCmd { get { return null; } }
public override void OnPermissionChanged(Player p, Level lvl, Group grp, string type) {
string msg = type + " rank changed to " + grp.ColoredName + " %Sin " + ColoredName;
DoChange(p, lvl, msg);
}
public override void OnListChanged(Player p, Level lvl, string name, bool whitelist, bool removedFromOpposite) {
string msg = PlayerInfo.GetColoredName(p, name);
if (removedFromOpposite) {
msg += " %Swas removed from the build" + (whitelist ? " blacklist" : " whitelist");
} else {
msg += " %Swas build" + (whitelist ? " whitelisted" : " blacklisted");
}
msg += "in " + ColoredName;
DoChange(p, lvl, msg);
}
void DoChange(Player p, Level lvl, string msg) {
protected override void ApplyChanges(Player p, Level lvl, string msg) {
lvl.Save(true);
msg += " %Sin " + ColoredName;
Logger.Log(LogType.UserActivity, "{0} %Son {1}", msg, lvl.name);
Chat.MessageLevel(lvl, msg);

View File

@ -119,7 +119,7 @@ namespace MCGalaxy {
public DateTime FirstLogin, LastLogin;
public bool staticCommands;
public DateTime ZoneSpam;
internal DateTime lastAccessStatus;
public VolatileArray<SchedulerTask> CriticalTasks = new VolatileArray<SchedulerTask>();
public bool aiming;