Implement proper access permission checking for /perbuild too.

This commit is contained in:
UnknownShadow200 2016-08-24 16:15:39 +10:00
parent 38eb620214
commit 4c8e6fd95b
7 changed files with 44 additions and 51 deletions

View File

@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.World {
Level lvl = LvlFile.Load(name, path);
lvl.setPhysics(0);
lvl.backedup = true;
lvl.permissionbuild = LevelPermission.Admin;
lvl.permissionbuild = LevelPermission.Nobody;
lvl.jailx = (ushort)(lvl.spawnx * 32);
lvl.jaily = (ushort)(lvl.spawny * 32);

View File

@ -49,7 +49,9 @@ namespace MCGalaxy.Commands.World {
}
setter(level, grp.Permission);
UpdateAllowBuild(level);
Level.SaveSettings(level);
Server.s.Log(level.name + " " + target + " permission changed to " + grp.Permission + ".");
Chat.MessageLevel(level, target + " permission changed to " + grp.ColoredName + "%S.");
if (p == null || p.level != level)
@ -95,12 +97,22 @@ namespace MCGalaxy.Commands.World {
list.Add(name);
other.CaselessRemove(name);
UpdateAllowBuild(level);
Level.SaveSettings(level);
string msg = name + " was " + target + " " + mode + "ed";
Server.s.Log(msg + " on " + level.name);
Chat.MessageLevel(level, msg);
if (p == null || p.level != level)
Player.Message(p, msg + " on {0}.", level.name);
}
static void UpdateAllowBuild(Level level) {
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.level != level) continue;
p.AllowBuild = level.BuildAccess.Check(p, false);
}
}
}
}

View File

@ -41,7 +41,6 @@ namespace MCGalaxy.Levels.IO {
ushort height = BitConverter.ToUInt16(header, 4);
Level lvl = new Level(name, width, height, length);
lvl.permissionbuild = (LevelPermission)30;
lvl.spawnx = BitConverter.ToUInt16(header, 6);
lvl.spawnz = BitConverter.ToUInt16(header, 8);
lvl.spawny = BitConverter.ToUInt16(header, 10);

View File

@ -173,28 +173,27 @@ namespace MCGalaxy {
return true;
}
bool CheckZonePerms(Player p, ushort x, ushort y, ushort z,
ref bool AllowBuild, ref bool inZone, ref string Owners) {
bool CheckZonePerms(Player p, ushort x, ushort y, ushort z, ref bool inZone) {
if (p.Rank < LevelPermission.Admin) {
bool foundDel = FindZones(p, x, y, z, ref inZone, ref AllowBuild, ref Owners);
if (!AllowBuild) {
if (p.ZoneSpam <= DateTime.UtcNow) {
if (Owners != "")
Player.Message(p, "This zone belongs to &b" + Owners.Remove(0, 2) + ".");
else
Player.Message(p, "This zone belongs to no one.");
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
}
return false;
}
string owners = "";
bool zoneAllow = FindZones(p, x, y, z, ref inZone, ref owners);
if (zoneAllow) return true;
if (p.ZoneSpam > DateTime.UtcNow) return false;
if (owners != "")
Player.Message(p, "This zone belongs to &b" + owners.Remove(0, 2) + ".");
else
Player.Message(p, "This zone belongs to no one.");
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
return false;
}
return true;
}
bool FindZones(Player p, ushort x, ushort y, ushort z,
ref bool inZone, ref bool AllowBuild, ref string Owners) {
if (ZoneList.Count == 0) { AllowBuild = true; return false; }
bool foundDel = false;
ref bool inZone, ref string Owners) {
if (ZoneList.Count == 0) return true;
bool zoneAllow = true;
for (int i = 0; i < ZoneList.Count; i++) {
Zone zn = ZoneList[i];
@ -204,39 +203,23 @@ namespace MCGalaxy {
inZone = true;
if (zn.Owner.Length >= 3 && zn.Owner.StartsWith("grp")) {
string grpName = zn.Owner.Substring(3);
if (Group.Find(grpName).Permission <= p.Rank) {
AllowBuild = true; break;
}
AllowBuild = false;
if (Group.Find(grpName).Permission <= p.Rank) return true;
Owners += ", " + grpName;
} else {
if (zn.Owner.CaselessEq(p.name)) {
AllowBuild = true; break;
}
AllowBuild = false;
if (zn.Owner.CaselessEq(p.name)) return true;
Owners += ", " + zn.Owner;
}
zoneAllow = false;
}
return foundDel;
return zoneAllow;
}
bool CheckRank(Player p, bool AllowBuild, bool inZone) {
if (p.Rank < permissionbuild && (!inZone || !AllowBuild)) {
if (p.ZoneSpam <= DateTime.UtcNow) {
Player.Message(p, "Must be at least " + PermissionToName(permissionbuild) + " to build here");
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
}
return false;
bool CheckRank(Player p) {
if (p.ZoneSpam <= DateTime.UtcNow) {
BuildAccess.CheckDetailed(p, false);
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
}
if (p.Rank > perbuildmax && (!inZone || !AllowBuild) && !p.group.CanExecute("perbuildmax")) {
if (p.ZoneSpam <= DateTime.UtcNow) {
Player.Message(p, "Your rank must be " + perbuildmax + " or lower to build here!");
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
}
return false;
}
return true;
return p.AllowBuild;
}
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z,
@ -244,13 +227,9 @@ namespace MCGalaxy {
if (!Block.AllowBreak(b) && !Block.canPlace(p, b) && !Block.BuildIn(b)) return false;
if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref type)) return false;
string Owners = "";
bool AllowBuild = true, inZone = false;
if (!CheckZonePerms(p, x, y, z, ref AllowBuild, ref inZone, ref Owners))
return false;
if (Owners.Length == 0 && !CheckRank(p, AllowBuild, inZone))
return false;
return true;
bool inZone = false;
if (!CheckZonePerms(p, x, y, z, ref inZone)) return false;
return inZone || CheckRank(p);
}
public void Blockchange(Player p, ushort x, ushort y, ushort z,

View File

@ -86,7 +86,7 @@ namespace MCGalaxy {
if (p.Rank > Max && !p.group.CanExecute(maxCmd)) {
Group grp = Group.findPerm(Max);
string grpName = grp == null ? "&f" + Max : grp.ColoredName;
Player.Message(p, "Only {2} and below may {1} in {0}.", name, action, grpName); return false;
Player.Message(p, "Only {2}%S and below may {1} {0}.", name, action, grpName); return false;
}
return true;
}

View File

@ -321,6 +321,7 @@ namespace MCGalaxy {
bool success = true;
useCheckpointSpawn = false;
lastCheckpointIndex = -1;
AllowBuild = level.BuildAccess.Check(this, false);
try {
if (hasBlockDefs) {

View File

@ -149,6 +149,8 @@ namespace MCGalaxy {
// Only used for possession.
//Using for anything else can cause unintended effects!
public bool canBuild = true;
/// <summary> Whether the player has build permission in the current world. </summary>
public bool AllowBuild = true;
public int money, loginMoney;
public long overallBlocks, TotalDrawn, TotalPlaced, TotalDeleted;