mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Implement proper access permission checking for /perbuild too.
This commit is contained in:
parent
38eb620214
commit
4c8e6fd95b
@ -41,7 +41,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
Level lvl = LvlFile.Load(name, path);
|
Level lvl = LvlFile.Load(name, path);
|
||||||
lvl.setPhysics(0);
|
lvl.setPhysics(0);
|
||||||
lvl.backedup = true;
|
lvl.backedup = true;
|
||||||
lvl.permissionbuild = LevelPermission.Admin;
|
lvl.permissionbuild = LevelPermission.Nobody;
|
||||||
|
|
||||||
lvl.jailx = (ushort)(lvl.spawnx * 32);
|
lvl.jailx = (ushort)(lvl.spawnx * 32);
|
||||||
lvl.jaily = (ushort)(lvl.spawny * 32);
|
lvl.jaily = (ushort)(lvl.spawny * 32);
|
||||||
|
@ -49,7 +49,9 @@ namespace MCGalaxy.Commands.World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setter(level, grp.Permission);
|
setter(level, grp.Permission);
|
||||||
|
UpdateAllowBuild(level);
|
||||||
Level.SaveSettings(level);
|
Level.SaveSettings(level);
|
||||||
|
|
||||||
Server.s.Log(level.name + " " + target + " permission changed to " + grp.Permission + ".");
|
Server.s.Log(level.name + " " + target + " permission changed to " + grp.Permission + ".");
|
||||||
Chat.MessageLevel(level, target + " permission changed to " + grp.ColoredName + "%S.");
|
Chat.MessageLevel(level, target + " permission changed to " + grp.ColoredName + "%S.");
|
||||||
if (p == null || p.level != level)
|
if (p == null || p.level != level)
|
||||||
@ -95,12 +97,22 @@ namespace MCGalaxy.Commands.World {
|
|||||||
list.Add(name);
|
list.Add(name);
|
||||||
other.CaselessRemove(name);
|
other.CaselessRemove(name);
|
||||||
|
|
||||||
|
UpdateAllowBuild(level);
|
||||||
Level.SaveSettings(level);
|
Level.SaveSettings(level);
|
||||||
|
|
||||||
string msg = name + " was " + target + " " + mode + "ed";
|
string msg = name + " was " + target + " " + mode + "ed";
|
||||||
Server.s.Log(msg + " on " + level.name);
|
Server.s.Log(msg + " on " + level.name);
|
||||||
Chat.MessageLevel(level, msg);
|
Chat.MessageLevel(level, msg);
|
||||||
if (p == null || p.level != level)
|
if (p == null || p.level != level)
|
||||||
Player.Message(p, msg + " on {0}.", level.name);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -41,7 +41,6 @@ namespace MCGalaxy.Levels.IO {
|
|||||||
ushort height = BitConverter.ToUInt16(header, 4);
|
ushort height = BitConverter.ToUInt16(header, 4);
|
||||||
|
|
||||||
Level lvl = new Level(name, width, height, length);
|
Level lvl = new Level(name, width, height, length);
|
||||||
lvl.permissionbuild = (LevelPermission)30;
|
|
||||||
lvl.spawnx = BitConverter.ToUInt16(header, 6);
|
lvl.spawnx = BitConverter.ToUInt16(header, 6);
|
||||||
lvl.spawnz = BitConverter.ToUInt16(header, 8);
|
lvl.spawnz = BitConverter.ToUInt16(header, 8);
|
||||||
lvl.spawny = BitConverter.ToUInt16(header, 10);
|
lvl.spawny = BitConverter.ToUInt16(header, 10);
|
||||||
|
@ -173,28 +173,27 @@ namespace MCGalaxy {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckZonePerms(Player p, ushort x, ushort y, ushort z,
|
bool CheckZonePerms(Player p, ushort x, ushort y, ushort z, ref bool inZone) {
|
||||||
ref bool AllowBuild, ref bool inZone, ref string Owners) {
|
|
||||||
if (p.Rank < LevelPermission.Admin) {
|
if (p.Rank < LevelPermission.Admin) {
|
||||||
bool foundDel = FindZones(p, x, y, z, ref inZone, ref AllowBuild, ref Owners);
|
string owners = "";
|
||||||
if (!AllowBuild) {
|
bool zoneAllow = FindZones(p, x, y, z, ref inZone, ref owners);
|
||||||
if (p.ZoneSpam <= DateTime.UtcNow) {
|
if (zoneAllow) return true;
|
||||||
if (Owners != "")
|
if (p.ZoneSpam > DateTime.UtcNow) return false;
|
||||||
Player.Message(p, "This zone belongs to &b" + Owners.Remove(0, 2) + ".");
|
|
||||||
else
|
if (owners != "")
|
||||||
Player.Message(p, "This zone belongs to no one.");
|
Player.Message(p, "This zone belongs to &b" + owners.Remove(0, 2) + ".");
|
||||||
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
else
|
||||||
}
|
Player.Message(p, "This zone belongs to no one.");
|
||||||
return false;
|
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FindZones(Player p, ushort x, ushort y, ushort z,
|
bool FindZones(Player p, ushort x, ushort y, ushort z,
|
||||||
ref bool inZone, ref bool AllowBuild, ref string Owners) {
|
ref bool inZone, ref string Owners) {
|
||||||
if (ZoneList.Count == 0) { AllowBuild = true; return false; }
|
if (ZoneList.Count == 0) return true;
|
||||||
bool foundDel = false;
|
bool zoneAllow = true;
|
||||||
|
|
||||||
for (int i = 0; i < ZoneList.Count; i++) {
|
for (int i = 0; i < ZoneList.Count; i++) {
|
||||||
Zone zn = ZoneList[i];
|
Zone zn = ZoneList[i];
|
||||||
@ -204,39 +203,23 @@ namespace MCGalaxy {
|
|||||||
inZone = true;
|
inZone = true;
|
||||||
if (zn.Owner.Length >= 3 && zn.Owner.StartsWith("grp")) {
|
if (zn.Owner.Length >= 3 && zn.Owner.StartsWith("grp")) {
|
||||||
string grpName = zn.Owner.Substring(3);
|
string grpName = zn.Owner.Substring(3);
|
||||||
if (Group.Find(grpName).Permission <= p.Rank) {
|
if (Group.Find(grpName).Permission <= p.Rank) return true;
|
||||||
AllowBuild = true; break;
|
|
||||||
}
|
|
||||||
AllowBuild = false;
|
|
||||||
Owners += ", " + grpName;
|
Owners += ", " + grpName;
|
||||||
} else {
|
} else {
|
||||||
if (zn.Owner.CaselessEq(p.name)) {
|
if (zn.Owner.CaselessEq(p.name)) return true;
|
||||||
AllowBuild = true; break;
|
|
||||||
}
|
|
||||||
AllowBuild = false;
|
|
||||||
Owners += ", " + zn.Owner;
|
Owners += ", " + zn.Owner;
|
||||||
}
|
}
|
||||||
|
zoneAllow = false;
|
||||||
}
|
}
|
||||||
return foundDel;
|
return zoneAllow;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckRank(Player p, bool AllowBuild, bool inZone) {
|
bool CheckRank(Player p) {
|
||||||
if (p.Rank < permissionbuild && (!inZone || !AllowBuild)) {
|
if (p.ZoneSpam <= DateTime.UtcNow) {
|
||||||
if (p.ZoneSpam <= DateTime.UtcNow) {
|
BuildAccess.CheckDetailed(p, false);
|
||||||
Player.Message(p, "Must be at least " + PermissionToName(permissionbuild) + " to build here");
|
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
||||||
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return p.AllowBuild;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z,
|
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 (!Block.AllowBreak(b) && !Block.canPlace(p, b) && !Block.BuildIn(b)) return false;
|
||||||
if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref type)) return false;
|
if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref type)) return false;
|
||||||
|
|
||||||
string Owners = "";
|
bool inZone = false;
|
||||||
bool AllowBuild = true, inZone = false;
|
if (!CheckZonePerms(p, x, y, z, ref inZone)) return false;
|
||||||
if (!CheckZonePerms(p, x, y, z, ref AllowBuild, ref inZone, ref Owners))
|
return inZone || CheckRank(p);
|
||||||
return false;
|
|
||||||
if (Owners.Length == 0 && !CheckRank(p, AllowBuild, inZone))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Blockchange(Player p, ushort x, ushort y, ushort z,
|
public void Blockchange(Player p, ushort x, ushort y, ushort z,
|
||||||
|
@ -86,7 +86,7 @@ namespace MCGalaxy {
|
|||||||
if (p.Rank > Max && !p.group.CanExecute(maxCmd)) {
|
if (p.Rank > Max && !p.group.CanExecute(maxCmd)) {
|
||||||
Group grp = Group.findPerm(Max);
|
Group grp = Group.findPerm(Max);
|
||||||
string grpName = grp == null ? "&f" + Max : grp.ColoredName;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -321,6 +321,7 @@ namespace MCGalaxy {
|
|||||||
bool success = true;
|
bool success = true;
|
||||||
useCheckpointSpawn = false;
|
useCheckpointSpawn = false;
|
||||||
lastCheckpointIndex = -1;
|
lastCheckpointIndex = -1;
|
||||||
|
AllowBuild = level.BuildAccess.Check(this, false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (hasBlockDefs) {
|
if (hasBlockDefs) {
|
||||||
|
@ -149,6 +149,8 @@ namespace MCGalaxy {
|
|||||||
// Only used for possession.
|
// Only used for possession.
|
||||||
//Using for anything else can cause unintended effects!
|
//Using for anything else can cause unintended effects!
|
||||||
public bool canBuild = true;
|
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 int money, loginMoney;
|
||||||
public long overallBlocks, TotalDrawn, TotalPlaced, TotalDeleted;
|
public long overallBlocks, TotalDrawn, TotalPlaced, TotalDeleted;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user