Fix multiple zones not showing.

This commit is contained in:
UnknownShadow200 2018-01-28 13:39:07 +11:00
parent c557b4128c
commit 02a1d6aa58
12 changed files with 58 additions and 32 deletions

View File

@ -100,8 +100,7 @@ namespace MCGalaxy {
unsafe static byte NextFreeId(PlayerBot bot) { unsafe static byte NextFreeId(PlayerBot bot) {
byte* used = stackalloc byte[256]; byte* used = stackalloc byte[256];
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++) used[i] = 0;
used[i] = 0;
PlayerBot[] bots = bot.level.Bots.Items; PlayerBot[] bots = bot.level.Bots.Items;
for (int i = 0; i < bots.Length; i++) { for (int i = 0; i < bots.Length; i++) {

View File

@ -72,7 +72,7 @@ namespace MCGalaxy.Commands.Moderation {
zone.MaxY = (ushort)Math.Max(marks[0].Y, marks[1].Y); zone.MaxY = (ushort)Math.Max(marks[0].Y, marks[1].Y);
zone.MaxZ = (ushort)Math.Max(marks[0].Z, marks[1].Z); zone.MaxZ = (ushort)Math.Max(marks[0].Z, marks[1].Z);
p.level.Zones.Add(zone); zone.AddTo(p.level);
p.level.Save(true); p.level.Save(true);
Player.Message(p, "Created zone " + zone.ColoredName); Player.Message(p, "Created zone " + zone.ColoredName);
return false; return false;
@ -137,8 +137,9 @@ namespace MCGalaxy.Commands.Moderation {
Level lvl = p.level; Level lvl = p.level;
bool found = false; bool found = false;
for (int i = 0; i < lvl.Zones.Count; i++) { Zone[] zones = lvl.Zones.Items;
Zone z = lvl.Zones[i]; for (int i = 0; i < zones.Length; i++) {
Zone z = zones[i];
if (!z.Contains(P.X, P.Y, P.Z)) continue; if (!z.Contains(P.X, P.Y, P.Z)) continue;
found = true; found = true;
@ -163,7 +164,8 @@ namespace MCGalaxy.Commands.Moderation {
public override bool museumUsable { get { return false; } } public override bool museumUsable { get { return false; } }
public override void Use(Player p, string message) { public override void Use(Player p, string message) {
MultiPageOutput.Output(p, p.level.Zones, FormatZone, "ZoneList", "zones", message, true); Zone[] zones = p.level.Zones.Items;
MultiPageOutput.Output(p, zones, FormatZone, "ZoneList", "zones", message, true);
} }
static string FormatZone(Zone zone) { static string FormatZone(Zone zone) {

View File

@ -59,7 +59,8 @@ namespace MCGalaxy.Core {
// TODO: unshow old zones here?? // TODO: unshow old zones here??
if (p.Supports(CpeExt.SelectionCuboid)) { if (p.Supports(CpeExt.SelectionCuboid)) {
foreach (Zone zn in level.Zones) { zn.Show(p); } Zone[] zones = level.Zones.Items;
foreach (Zone zn in zones) { zn.Show(p); }
} }
if (!level.Config.Guns && p.aiming) { if (!level.Config.Guns && p.aiming) {

View File

@ -137,11 +137,11 @@ namespace MCGalaxy.Levels.IO {
} }
static void WriteZonesSection(Level lvl, Stream gs, byte[] buffer) { static void WriteZonesSection(Level lvl, Stream gs, byte[] buffer) {
List<Zone> zones = lvl.Zones; Zone[] zones = lvl.Zones.Items;
if (zones.Count == 0) return; if (zones.Length == 0) return;
gs.WriteByte(0x51); gs.WriteByte(0x51);
NetUtils.WriteI32(zones.Count, buffer, 0); NetUtils.WriteI32(zones.Length, buffer, 0);
gs.Write(buffer, 0, sizeof(int)); gs.Write(buffer, 0, sizeof(int));
foreach (Zone z in zones) { foreach (Zone z in zones) {

View File

@ -164,7 +164,7 @@ namespace MCGalaxy.Levels.IO {
ConfigElement.Parse(elems, key, value, z.Config); ConfigElement.Parse(elems, key, value, z.Config);
} }
lvl.Zones.Add(z); z.AddTo(lvl);
} }
} }

View File

@ -199,19 +199,20 @@ namespace MCGalaxy {
public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z, ExtBlock old, ExtBlock block) { public bool CheckAffectPermissions(Player p, ushort x, ushort y, ushort z, ExtBlock old, ExtBlock block) {
if (!p.group.Blocks[old.BlockID] && !Block.AllowBreak(old.BlockID) && !Block.BuildIn(old.BlockID)) return false; if (!p.group.Blocks[old.BlockID] && !Block.AllowBreak(old.BlockID) && !Block.BuildIn(old.BlockID)) return false;
if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref block.BlockID)) return false; if (p.PlayingTntWars && !CheckTNTWarsChange(p, x, y, z, ref block.BlockID)) return false;
if (Zones.Count == 0) return CheckRank(p); Zone[] zones = Zones.Items;
if (zones.Length == 0) return CheckRank(p);
// Check zones specifically allowed in // Check zones specifically allowed in
for (int i = 0; i < Zones.Count; i++) { for (int i = 0; i < zones.Length; 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.Access.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;
} }
// Check zones denied from // Check zones denied from
for (int i = 0; i < Zones.Count; i++) { for (int i = 0; i < zones.Length; 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.Access.Check(p); AccessResult access = zn.Access.Check(p);
if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) continue; if (access == AccessResult.Allowed || access == AccessResult.Whitelisted) continue;

View File

@ -75,7 +75,7 @@ namespace MCGalaxy {
BufferedBlockSender bulkSender; BufferedBlockSender bulkSender;
public List<UndoPos> UndoBuffer = new List<UndoPos>(); public List<UndoPos> UndoBuffer = new List<UndoPos>();
public List<Zone> Zones; public VolatileArray<Zone> Zones = new VolatileArray<Zone>();
public bool backedup; public bool backedup;
public BlockDB BlockDB; public BlockDB BlockDB;
public LevelAccessController VisitAccess, BuildAccess; public LevelAccessController VisitAccess, BuildAccess;

View File

@ -73,7 +73,6 @@ namespace MCGalaxy {
spawnz = (ushort)(Length / 2); spawnz = (ushort)(Length / 2);
rotx = 0; roty = 0; rotx = 0; roty = 0;
Zones = new List<Zone>();
VisitAccess = new LevelAccessController(this, true); VisitAccess = new LevelAccessController(this, true);
BuildAccess = new LevelAccessController(this, false); BuildAccess = new LevelAccessController(this, false);
listCheckExists = new SparseBitSet(Width, Height, Length); listCheckExists = new SparseBitSet(Width, Height, Length);
@ -105,7 +104,8 @@ namespace MCGalaxy {
} }
public Zone FindZoneExact(string name) { public Zone FindZoneExact(string name) {
foreach (Zone zone in Zones) { Zone[] zones = Zones.Items;
foreach (Zone zone in zones) {
if (zone.Config.Name.CaselessEq(name)) return zone; if (zone.Config.Name.CaselessEq(name)) return zone;
} }
return null; return null;

View File

@ -68,7 +68,7 @@ namespace MCGalaxy {
z.Config.Name = "Zone" + id; z.Config.Name = "Zone" + id;
id++; id++;
level.Zones.Add(z); z.AddTo(level);
} }
} }

View File

@ -18,8 +18,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using MCGalaxy.Config; using MCGalaxy.Config;
using MCGalaxy.Network;
using MCGalaxy.Maths; using MCGalaxy.Maths;
using MCGalaxy.Network;
namespace MCGalaxy { namespace MCGalaxy {
@ -99,6 +99,12 @@ namespace MCGalaxy {
public ZoneAccessController Access; public ZoneAccessController Access;
public string ColoredName { get { return Config.Color + Config.Name; } } public string ColoredName { get { return Config.Color + Config.Name; } }
public Zone(Level lvl) {
Config = new ZoneConfig();
Access = new ZoneAccessController(lvl, Config);
}
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;
} }
@ -108,27 +114,45 @@ namespace MCGalaxy {
MaxX == lvl.Width - 1 && MaxY == lvl.Height - 1 && MaxZ == lvl.Length - 1; MaxX == lvl.Width - 1 && MaxY == lvl.Height - 1 && MaxZ == lvl.Length - 1;
} }
public bool Shows { get { return Config.ShowAlpha != 0 && Config.ShowColor != ""; } } public bool Shows { get { return Config.ShowAlpha != 0 && Config.ShowColor != ""; } }
public void Show(Player p) { public void Show(Player p) {
if (!p.Supports(CpeExt.SelectionCuboid) || !Shows) return; if (!p.Supports(CpeExt.SelectionCuboid) || !Shows) return;
ColorDesc col = Colors.ParseHex(Config.ShowColor); ColorDesc col = Colors.ParseHex(Config.ShowColor);
p.Send(Packet.MakeSelection( p.Send(Packet.MakeSelection(
ID, "", new Vec3U16(MinX, MinY, MinZ), ID, "", new Vec3U16(MinX, MinY, MinZ),
new Vec3U16((ushort)(MaxX + 1), (ushort)(MaxY + 1), (ushort)(MaxZ + 1)), new Vec3U16((ushort)(MaxX + 1), (ushort)(MaxY + 1), (ushort)(MaxZ + 1)),
col.R, col.G, col.B, Config.ShowAlpha, p.hasCP437)); col.R, col.G, col.B, Config.ShowAlpha, p.hasCP437));
} }
public void ShowAll(Level lvl) { public void ShowAll(Level lvl) {
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) { foreach (Player p in players) {
if (p.level == lvl) Show(p); if (p.level == lvl) Show(p);
} }
} }
public Zone(Level lvl) { public void AddTo(Level level) {
Config = new ZoneConfig(); lock (level.Zones.locker) {
Access = new ZoneAccessController(lvl, Config); ID = NextFreeZoneId(level);
level.Zones.Add(this);
}
}
unsafe byte NextFreeZoneId(Level level) {
byte* used = stackalloc byte[256];
for (int i = 0; i < 256; i++) used[i] = 0;
Zone[] zones = level.Zones.Items;
for (int i = 0; i < zones.Length; i++) {
byte id = zones[i].ID;
used[id] = 1;
}
for (byte i = 0; i <= 255; i++ ) {
if (used[i] == 0) return i;
}
return 255;
} }
} }
} }

View File

@ -176,8 +176,7 @@ namespace MCGalaxy {
unsafe static byte NextFreeId() { unsafe static byte NextFreeId() {
byte* used = stackalloc byte[256]; byte* used = stackalloc byte[256];
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++) used[i] = 0;
used[i] = 0;
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
for (int i = 0; i < players.Length; i++) { for (int i = 0; i < players.Length; i++) {

View File

@ -90,7 +90,7 @@ namespace MCGalaxy {
/// <summary> Find partial matches of 'name' against the list of zones in a map. </summary> /// <summary> Find partial matches of 'name' against the list of zones in a map. </summary>
public static Zone FindZones(Player p, Level lvl, string name) { public static Zone FindZones(Player p, Level lvl, string name) {
int matches = 0; int matches = 0;
return Find<Zone>(p, name, out matches, lvl.Zones, return Find<Zone>(p, name, out matches, lvl.Zones.Items,
null, z => z.Config.Name, "zones"); null, z => z.Config.Name, "zones");
} }