Skip to content

Commit

Permalink
fix: Updates more logging to Serilog (#1105)
Browse files Browse the repository at this point in the history
Adds more serilog logging and cleans up some server files.
  • Loading branch information
kamronbatman authored Jul 1, 2022
1 parent 1cf4a43 commit 38686c0
Show file tree
Hide file tree
Showing 30 changed files with 1,981 additions and 1,954 deletions.
27 changes: 15 additions & 12 deletions Projects/Server/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,9 @@ public int Amount

if (!Stackable && m_Amount > 1)
{
Console.WriteLine(
"Warning: 0x{0:X}: Amount changed for non-stackable item '{2}'. ({1})",
Serial.Value,
logger.Warning(
"{Serial}: Amount changed for non-stackable item '{Name}'. ({Amount})",
Serial,
m_Amount,
GetType().Name
);
Expand Down Expand Up @@ -3164,27 +3164,29 @@ public virtual void AddItem(Item item)

if (item == this)
{
Console.WriteLine(
"Warning: Adding item to itself: [0x{0} {1}].AddItem( [0x{2} {3}] )",
var customException = new InvalidOperationException("Adding item to itself");
logger.Warning(
customException,
"Adding item to itself: ({Serial1} {Item1}).AddItem({Serial2} {Item2})",
Serial,
GetType().Name,
item.Serial,
item.GetType().Name
);
Console.WriteLine(new StackTrace());
return;
}

if (IsChildOf(item))
{
Console.WriteLine(
"Warning: Adding parent item to child: [0x{0} {1}].AddItem( [0x{2} {3}] )",
var customException = new InvalidOperationException("Adding parent item to child");
logger.Warning(
customException,
"Adding parent item to child: [{Serial1} {Item1}].AddItem( [{Serial2} {Item2}] )",
Serial,
GetType().Name,
item.Serial,
item.GetType().Name
);
Console.WriteLine(new StackTrace());
return;
}

Expand Down Expand Up @@ -3270,9 +3272,10 @@ public static void ProcessDeltaQueue()

if (m_DeltaQueue.Count > 0)
{
Utility.PushColor(ConsoleColor.DarkYellow);
Console.WriteLine("Warning: {0} items left in delta queue after processing.", m_DeltaQueue.Count);
Utility.PopColor();
logger.Warning(
"{Count} items left in delta queue after processing.",
m_DeltaQueue.Count
);
}
}

Expand Down
84 changes: 50 additions & 34 deletions Projects/Server/Items/ItemBounds.cs
Original file line number Diff line number Diff line change
@@ -1,44 +1,60 @@
/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: [email protected] *
* File: ItemBounds.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/

using System;
using System.IO;
using Server.Logging;

namespace Server;

namespace Server
public static class ItemBounds
{
public static class ItemBounds
private static readonly ILogger logger = LogFactory.GetLogger(typeof(ItemBounds));

static ItemBounds()
{
static ItemBounds()
Table = new Rectangle2D[TileData.ItemTable.Length];

if (!File.Exists("Data/Binary/Bounds.bin"))
{
Table = new Rectangle2D[TileData.ItemTable.Length];

if (File.Exists("Data/Binary/Bounds.bin"))
{
using var fs = new FileStream(
"Data/Binary/Bounds.bin",
FileMode.Open,
FileAccess.Read,
FileShare.Read
);
var bin = new BinaryReader(fs);

var count = Math.Min(Table.Length, (int)(fs.Length / 8));

for (var i = 0; i < count; ++i)
{
int xMin = bin.ReadInt16();
int yMin = bin.ReadInt16();
int xMax = bin.ReadInt16();
int yMax = bin.ReadInt16();

Table[i].Set(xMin, yMin, xMax - xMin + 1, yMax - yMin + 1);
}

bin.Close();
}
else
{
Console.WriteLine("Warning: Data/Binary/Bounds.bin does not exist");
}
logger.Error("Data/Binary/Bounds.bin does not exist");
return;
}

public static Rectangle2D[] Table { get; }
using var fs = new FileStream(
"Data/Binary/Bounds.bin",
FileMode.Open,
FileAccess.Read,
FileShare.Read
);
var bin = new BinaryReader(fs);

var count = Math.Min(Table.Length, (int)(fs.Length / 8));

for (var i = 0; i < count; ++i)
{
int xMin = bin.ReadInt16();
int yMin = bin.ReadInt16();
int xMax = bin.ReadInt16();
int yMax = bin.ReadInt16();

Table[i].Set(xMin, yMin, xMax - xMin + 1, yMax - yMin + 1);
}

bin.Close();
}

public static Rectangle2D[] Table { get; }
}
23 changes: 11 additions & 12 deletions Projects/Server/Json/Converters/ClientVersionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Server.Json
namespace Server.Json;

public class ClientVersionConverter : JsonConverter<ClientVersion>
{
public class ClientVersionConverter : JsonConverter<ClientVersion>
public override ClientVersion Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
public override ClientVersion Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
if (reader.TokenType == JsonTokenType.String)
{
if (reader.TokenType == JsonTokenType.String)
{
return new ClientVersion(reader.GetString());
}

throw new JsonException("Value must be a string");
return new ClientVersion(reader.GetString());
}

public override void Write(Utf8JsonWriter writer, ClientVersion value, JsonSerializerOptions options) =>
writer.WriteStringValue(value.ToString());
throw new JsonException("Value must be a string");
}
}

public override void Write(Utf8JsonWriter writer, ClientVersion value, JsonSerializerOptions options) =>
writer.WriteStringValue(value.ToString());
}
15 changes: 7 additions & 8 deletions Projects/Server/Json/Converters/ClientVersionConverterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Server.Json
namespace Server.Json;

public class ClientVersionConverterFactory : JsonConverterFactory
{
public class ClientVersionConverterFactory : JsonConverterFactory
{
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(ClientVersion);
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(ClientVersion);

public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
new ClientVersionConverter();
}
}
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
new ClientVersionConverter();
}
Loading

0 comments on commit 38686c0

Please sign in to comment.