mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
More work on zones, now compiles.
This commit is contained in:
parent
7e098ad8f8
commit
d423f067a8
@ -16,7 +16,7 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using MCGalaxy.Commands.Moderation;
|
using MCGalaxy.Commands.World;
|
||||||
using MCGalaxy.Maths;
|
using MCGalaxy.Maths;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.Moderation {
|
namespace MCGalaxy.Commands.Moderation {
|
||||||
@ -32,29 +32,38 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
|
|
||||||
if (args[0].CaselessEq("add")) {
|
if (args[0].CaselessEq("add")) {
|
||||||
if (args.Length == 1) { Help(p); return; }
|
if (args.Length == 1) { Help(p); return; }
|
||||||
if (!CheckAdd(p, args, "Zone add")) return;
|
CreateZone(p, args, 1);
|
||||||
|
|
||||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
|
||||||
Player.Message(p, "Zone for: &b" + args[1] + ".");
|
|
||||||
p.MakeSelection(2, args[1], AddZone);
|
|
||||||
} else if (args[0].CaselessEq("del")) {
|
} else if (args[0].CaselessEq("del")) {
|
||||||
Player.Message(p, "Place a block where you would like to delete a zone.");
|
Player.Message(p, "Place a block where you would like to delete a zone.");
|
||||||
p.MakeSelection(1, null, DeleteZone);
|
p.MakeSelection(1, null, DeleteZone);
|
||||||
} else {
|
} else {
|
||||||
if (!CheckAdd(p, args, "Zone add")) return; // TODO: broken
|
CreateZone(p, args, 0);
|
||||||
|
|
||||||
Player.Message(p, "Place or break two blocks to determine the edges.");
|
|
||||||
Player.Message(p, "Zone for: &b" + args[0] + ".");
|
|
||||||
p.MakeSelection(2, args[0], AddZone);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckAdd(Player p, string[] args, string cmd) {
|
void CreateZone(Player p, string[] args, int offset) {
|
||||||
if (!Formatter.ValidName(p, args[1], "player or rank")) return false;
|
Zone z = new Zone(p.level);
|
||||||
|
z.Config.Name = args[offset];
|
||||||
|
PermissionCmd.Do(p, args, offset + 1, false, z.Access);
|
||||||
|
|
||||||
string reason = args.Length > 2 ? args[2] : "";
|
Player.Message(p, "Creating zone " + z.ColoredName);
|
||||||
args[1] = FindZoneOwner(p, cmd, args[1], ref reason);
|
Player.Message(p, "Place or break two blocks to determine the edges.");
|
||||||
return args[1] != null;
|
p.MakeSelection(2, z, AddZone);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AddZone(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
|
Zone z = (Zone)state;
|
||||||
|
z.MinX = (ushort)Math.Min(marks[0].X, marks[1].X);
|
||||||
|
z.MinY = (ushort)Math.Min(marks[0].Y, marks[1].Y);
|
||||||
|
z.MinZ = (ushort)Math.Min(marks[0].Z, marks[1].Z);
|
||||||
|
z.MaxX = (ushort)Math.Max(marks[0].X, marks[1].X);
|
||||||
|
z.MaxY = (ushort)Math.Max(marks[0].Y, marks[1].Y);
|
||||||
|
z.MaxZ = (ushort)Math.Max(marks[0].Z, marks[1].Z);
|
||||||
|
|
||||||
|
p.level.Zones.Add(z);
|
||||||
|
p.level.Save(true);
|
||||||
|
Player.Message(p, "Created zone " + z.ColoredName);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteZone(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
bool DeleteZone(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
||||||
@ -66,7 +75,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
Zone zn = lvl.Zones[i];
|
Zone zn = lvl.Zones[i];
|
||||||
if (P.X < zn.MinX || P.X > zn.MaxX || P.Y < zn.MinY || P.Y > zn.MaxY || P.Z < zn.MinZ || P.Z > zn.MaxZ) continue;
|
if (P.X < zn.MinX || P.X > zn.MaxX || P.Y < zn.MinY || P.Y > zn.MaxY || P.Z < zn.MinZ || P.Z > zn.MaxZ) continue;
|
||||||
|
|
||||||
if (!zn.Acess.CheckDetailed(p)) {
|
if (!zn.Access.CheckDetailed(p)) {
|
||||||
Player.Message(p, "Hence, you cannot delete this zone.");
|
Player.Message(p, "Hence, you cannot delete this zone.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -80,29 +89,6 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AddZone(Player p, Vec3S32[] marks, object state, ExtBlock block) {
|
|
||||||
Zone z = Zone.Create();
|
|
||||||
z.MinX = (ushort)Math.Min(marks[0].X, marks[1].X);
|
|
||||||
z.MinY = (ushort)Math.Min(marks[0].Y, marks[1].Y);
|
|
||||||
z.MinZ = (ushort)Math.Min(marks[0].Z, marks[1].Z);
|
|
||||||
z.MaxX = (ushort)Math.Max(marks[0].X, marks[1].X);
|
|
||||||
z.MaxY = (ushort)Math.Max(marks[0].Y, marks[1].Y);
|
|
||||||
z.MaxZ = (ushort)Math.Max(marks[0].Z, marks[1].Z);
|
|
||||||
z.Owner = (string)state;
|
|
||||||
z.Config.Name = state + state;
|
|
||||||
|
|
||||||
p.level.Zones.Add(z);
|
|
||||||
p.level.Save(true);
|
|
||||||
Player.Message(p, "Added zone for &b" + (string)state);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static string FindZoneOwner(Player p, string cmd, string name, ref string reason) {
|
|
||||||
if (Group.Find(name) != null)
|
|
||||||
return "grp" + Group.Find(name).Name;
|
|
||||||
return ModActionCmd.FindName(p, "zone", cmd, "", name, ref reason);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/Zone add [name] %H- Creates a zone only [name] can build in");
|
Player.Message(p, "%T/Zone add [name] %H- Creates a zone only [name] can build in");
|
||||||
Player.Message(p, "%T/Zone add [rank] %H- Creates a zone only [rank]+ can build in");
|
Player.Message(p, "%T/Zone add [rank] %H- Creates a zone only [rank]+ can build in");
|
||||||
@ -131,7 +117,7 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
if (!z.Contains(P.X, P.Y, P.Z)) continue;
|
if (!z.Contains(P.X, P.Y, P.Z)) continue;
|
||||||
found = true;
|
found = true;
|
||||||
|
|
||||||
AccessResult status = z.Acess.Check(p);
|
AccessResult status = z.Access.Check(p);
|
||||||
bool allowed = status == AccessResult.Allowed || status == AccessResult.Whitelisted;
|
bool allowed = status == AccessResult.Allowed || status == AccessResult.Whitelisted;
|
||||||
Player.Message(p, " Zone {0} %S- {1}{2}", z.ColoredName, allowed ? "&a" : "&c", status );
|
Player.Message(p, " Zone {0} %S- {1}{2}", z.ColoredName, allowed ? "&a" : "&c", status );
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace MCGalaxy.Commands.World {
|
|||||||
public override bool museumUsable { get { return false; } }
|
public override bool museumUsable { get { return false; } }
|
||||||
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
|
||||||
|
|
||||||
protected static void Do(Player p, string[] args, int offset, bool max, AccessController access) {
|
public static void Do(Player p, string[] args, int offset, bool max, AccessController access) {
|
||||||
for (int i = offset; i < args.Length; i++) {
|
for (int i = offset; i < args.Length; i++) {
|
||||||
string arg = args[i];
|
string arg = args[i];
|
||||||
if (arg[0] == '+' || arg[0] == '-') {
|
if (arg[0] == '+' || arg[0] == '-') {
|
||||||
|
@ -142,7 +142,7 @@ namespace MCGalaxy.Levels.IO {
|
|||||||
if (count == 0) return;
|
if (count == 0) return;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Zone z = Zone.Create();
|
Zone z = new Zone(lvl);
|
||||||
if (!TryRead_U16(buffer, gs, ref z.MinX) || !TryRead_U16(buffer, gs, ref z.MaxX)) return;
|
if (!TryRead_U16(buffer, gs, ref z.MinX) || !TryRead_U16(buffer, gs, ref z.MaxX)) return;
|
||||||
if (!TryRead_U16(buffer, gs, ref z.MinY) || !TryRead_U16(buffer, gs, ref z.MaxY)) return;
|
if (!TryRead_U16(buffer, gs, ref z.MinY) || !TryRead_U16(buffer, gs, ref z.MaxY)) return;
|
||||||
if (!TryRead_U16(buffer, gs, ref z.MinZ) || !TryRead_U16(buffer, gs, ref z.MaxZ)) return;
|
if (!TryRead_U16(buffer, gs, ref z.MinZ) || !TryRead_U16(buffer, gs, ref z.MaxZ)) return;
|
||||||
|
@ -205,7 +205,7 @@ namespace MCGalaxy {
|
|||||||
for (int i = 0; i < Zones.Count; i++) {
|
for (int i = 0; i < Zones.Count; i++) {
|
||||||
Zone zn = Zones[i];
|
Zone zn = Zones[i];
|
||||||
if (x < zn.MinX || x > zn.MaxX || y < zn.MinY || y > zn.MaxY || z < zn.MinZ || z > zn.MaxZ) continue;
|
if (x < zn.MinX || x > zn.MaxX || y < zn.MinY || y > zn.MaxY || z < zn.MinZ || z > zn.MaxZ) continue;
|
||||||
AccessResult access = zn.Acess.Check(p);
|
AccessResult access = zn.Access.Check(p);
|
||||||
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) return true;
|
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,11 +213,11 @@ namespace MCGalaxy {
|
|||||||
for (int i = 0; i < Zones.Count; i++) {
|
for (int i = 0; i < Zones.Count; i++) {
|
||||||
Zone zn = Zones[i];
|
Zone zn = Zones[i];
|
||||||
if (x < zn.MinX || x > zn.MaxX || y < zn.MinY || y > zn.MaxY || z < zn.MinZ || z > zn.MaxZ) continue;
|
if (x < zn.MinX || x > zn.MaxX || y < zn.MinY || y > zn.MaxY || z < zn.MinZ || z > zn.MaxZ) continue;
|
||||||
AccessResult access = zn.Acess.Check(p);
|
AccessResult access = zn.Access.Check(p);
|
||||||
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) continue;
|
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) continue;
|
||||||
|
|
||||||
if (p.ZoneSpam > DateTime.UtcNow) return false;
|
if (p.ZoneSpam > DateTime.UtcNow) return false;
|
||||||
zn.Acess.CheckDetailed(p);
|
zn.Access.CheckDetailed(p);
|
||||||
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
p.ZoneSpam = DateTime.UtcNow.AddSeconds(2);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -41,10 +41,11 @@ namespace MCGalaxy {
|
|||||||
internal static void LoadZones(Level level, string name) {
|
internal static void LoadZones(Level level, string name) {
|
||||||
if (!Database.TableExists("Zone" + name)) return;
|
if (!Database.TableExists("Zone" + name)) return;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
object ; // add to map perbuild.
|
bool changedPerbuild = false;
|
||||||
|
|
||||||
using (DataTable table = Database.Backend.GetRows("Zone" + name, "*")) {
|
using (DataTable table = Database.Backend.GetRows("Zone" + name, "*")) {
|
||||||
foreach (DataRow row in table.Rows) {
|
foreach (DataRow row in table.Rows) {
|
||||||
Zone z = Zone.Create();
|
Zone z = new Zone(level);
|
||||||
z.MinX = ushort.Parse(row["SmallX"].ToString());
|
z.MinX = ushort.Parse(row["SmallX"].ToString());
|
||||||
z.MinY = ushort.Parse(row["SmallY"].ToString());
|
z.MinY = ushort.Parse(row["SmallY"].ToString());
|
||||||
z.MinZ = ushort.Parse(row["SmallZ"].ToString());
|
z.MinZ = ushort.Parse(row["SmallZ"].ToString());
|
||||||
@ -55,10 +56,14 @@ namespace MCGalaxy {
|
|||||||
string owner = row["Owner"].ToString();
|
string owner = row["Owner"].ToString();
|
||||||
if (owner.StartsWith("grp")) {
|
if (owner.StartsWith("grp")) {
|
||||||
Group grp = Group.Find(owner.Substring(3));
|
Group grp = Group.Find(owner.Substring(3));
|
||||||
if (grp != null) z.Config.BuildMin = grp.Permission;
|
if (grp != null) z.Access.Min = grp.Permission;
|
||||||
|
} else if (z.CoversMap(level)) {
|
||||||
|
level.BuildAccess.Whitelisted.Add(owner);
|
||||||
|
changedPerbuild = true;
|
||||||
|
continue;
|
||||||
} else {
|
} else {
|
||||||
z.Config.BuildWhitelist.Add(owner);
|
z.Access.Whitelisted.Add(owner);
|
||||||
z.Config.BuildMin = LevelPermission.Admin;
|
z.Access.Min = LevelPermission.Admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
z.Config.Name = "Zone" + id;
|
z.Config.Name = "Zone" + id;
|
||||||
@ -67,6 +72,7 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changedPerbuild) Level.SaveSettings(level);
|
||||||
if (level.Zones.Count > 0 && !level.Save(true)) return;
|
if (level.Zones.Count > 0 && !level.Save(true)) return;
|
||||||
Database.Backend.DeleteTable("Zone" + name);
|
Database.Backend.DeleteTable("Zone" + name);
|
||||||
Logger.Log(LogType.SystemActivity, "Upgraded zones for map " + name);
|
Logger.Log(LogType.SystemActivity, "Upgraded zones for map " + name);
|
||||||
|
@ -82,23 +82,26 @@ namespace MCGalaxy {
|
|||||||
void Update() { lvl.Save(true); }
|
void Update() { lvl.Save(true); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Zone {
|
public class Zone {
|
||||||
public ushort MinX, MinY, MinZ;
|
public ushort MinX, MinY, MinZ;
|
||||||
public ushort MaxX, MaxY, MaxZ;
|
public ushort MaxX, MaxY, MaxZ;
|
||||||
|
|
||||||
public ZoneConfig Config;
|
public ZoneConfig Config;
|
||||||
public ZoneAccessController Acess;
|
public ZoneAccessController Access;
|
||||||
public string ColoredName { get { return Config.Color + Config.Name; } }
|
public string ColoredName { get { return Config.Color + Config.Name; } }
|
||||||
|
|
||||||
public bool Contains(int x, int y, int z) {
|
public bool Contains(int x, int y, int z) {
|
||||||
return x >= MinX && x <= MaxX && y >= MinY && y <= MaxY && z >= MinZ && z <= MaxZ;
|
return x >= MinX && x <= MaxX && y >= MinY && y <= MaxY && z >= MinZ && z <= MaxZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Zone Create() {
|
public bool CoversMap(Level lvl) {
|
||||||
Zone zone = new Zone();
|
return MinX == 0 && MinY == 0 && MinZ == 0 &&
|
||||||
zone.Config = new ZoneConfig();
|
MaxX == lvl.Width - 1 && MaxY == lvl.Height - 1 && MaxZ == lvl.Length - 1;
|
||||||
zone.Acess = new ZoneAccessController();
|
}
|
||||||
return zone;
|
|
||||||
|
public Zone(Level lvl) {
|
||||||
|
Config = new ZoneConfig();
|
||||||
|
Access = new ZoneAccessController(lvl, Config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user