Skip to content

Commit

Permalink
Log when non-existent portals/message blocks are autodeleted from a l…
Browse files Browse the repository at this point in the history
…evel
  • Loading branch information
UnknownShadow200 committed Apr 21, 2022
1 parent d6bf620 commit 6a5c4eb
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion MCGalaxy/Commands/building/CmdMaze.cs
Expand Up @@ -28,7 +28,7 @@ public sealed class CmdMaze : DrawCmd

protected override DrawOp GetDrawOp(DrawArgs dArgs) {
MazeDrawOp op = new MazeDrawOp();
op.RNG = MapGen.MakeRng(dArgs.Message);
op.rng = MapGen.MakeRng(dArgs.Message);
return op;
}

Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/Drawing/DrawOps/MazeDrawOp.cs
Expand Up @@ -26,7 +26,7 @@ public class MazeDrawOp : CuboidHollowsDrawOp
{
public override string Name { get { return "Maze"; } }

public Random RNG;
public Random rng;
bool[,] wall;
int width, length;

Expand Down Expand Up @@ -58,7 +58,7 @@ public class MazeDrawOp : CuboidHollowsDrawOp
for (ushort z = 0; z <= length; z++)
if (wall[x, z])
{
output(Place((ushort)(min.X + x + 1), y, (ushort)(min.Z + z + 1), Block.DoubleSlab));
output(Place((ushort)(min.X + x + 1), y, (ushort)(min.Z + z + 1), Block.DoubleSlab));
output(Place((ushort)(min.X + x + 1), (ushort)(y + 1), (ushort)(min.Z + z + 1), Block.Leaves));
output(Place((ushort)(min.X + x + 1), (ushort)(y + 2), (ushort)(min.Z + z + 1), Block.Leaves));
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public class MazeDrawOp : CuboidHollowsDrawOp

void MoveRandomDir(GridNode P, out GridNode P1, out GridNode P2) {
while (true) {
int dir = RNG.Next(4);
int dir = rng.Next(4);

switch (dir) {
case 0: //go up
Expand Down
18 changes: 16 additions & 2 deletions MCGalaxy/Levels/LevelDB.cs
Expand Up @@ -94,23 +94,37 @@ public static class LevelDB {
level.hasPortals = coords.Count > 0;
if (!level.hasPortals) return;

foreach (Vec3U16 p in coords) {
int deleted = 0;
foreach (Vec3U16 p in coords)
{
BlockID block = level.GetBlock(p.X, p.Y, p.Z);
if (level.Props[block].IsPortal) continue;

Portal.Delete(map, p.X, p.Y, p.Z);
deleted++;
}

if (deleted == 0) return;
Logger.Log(LogType.BackgroundActivity, "Autodeleted {0} non-existent portals in {1}", deleted, level.name);
}

internal static void LoadMessages(Level level, string map) {
List<Vec3U16> coords = MessageBlock.GetAllCoords(map);
level.hasMessageBlocks = coords.Count > 0;
if (!level.hasMessageBlocks) return;

foreach (Vec3U16 p in coords) {
int deleted = 0;
foreach (Vec3U16 p in coords)
{
BlockID block = level.GetBlock(p.X, p.Y, p.Z);
if (level.Props[block].IsMessageBlock) continue;

MessageBlock.Delete(map, p.X, p.Y, p.Z);
deleted++;
}

if (deleted == 0) return;
Logger.Log(LogType.BackgroundActivity, "Autodeleted {0} non-existent message blocks in {1}", deleted, level.name);
}

internal static ColumnDesc[] createPortals = new ColumnDesc[] {
Expand Down
14 changes: 7 additions & 7 deletions MCGalaxy/Server/FileLogger.cs
Expand Up @@ -21,11 +21,11 @@
using System.Text;
using MCGalaxy.Tasks;

namespace MCGalaxy {
public static class FileLogger {

public static string LogPath { get { return msgPath; } }
namespace MCGalaxy
{
public static class FileLogger
{
public static string LogPath { get { return msgPath; } }
public static string ErrorLogPath { get { return errPath; } }

static bool disposed;
Expand All @@ -52,8 +52,8 @@ public static class FileLogger {
if (now.Year == last.Year && now.Month == last.Month && now.Day == last.Day) return;

last = now;
msgPath = "logs/" + now.ToString("yyyy-MM-dd").Replace("/", "-") + ".txt";
errPath = "logs/errors/" + now.ToString("yyyy-MM-dd").Replace("/", "-") + "error.log";
msgPath = "logs/" + now.ToString("yyyy-MM-dd") + ".txt";
errPath = "logs/errors/" + now.ToString("yyyy-MM-dd") + "error.log";
}

static void LogMessage(LogType type, string message) {
Expand Down
4 changes: 2 additions & 2 deletions MCGalaxy/Server/Logger.cs
Expand Up @@ -84,8 +84,8 @@ public enum LogType {

/// <summary> Centralised class for outputting log messages. </summary>
/// <remarks> Outputs can be a file on disc, GUI, the console, etc subscribed to the LogHandler delegate. </remarks>
public static class Logger {
public static class Logger
{
public static LogHandler LogHandler;
static readonly object logLock = new object();

Expand Down

0 comments on commit 6a5c4eb

Please sign in to comment.