fix: Updates more logging to Serilog (#1105)
Adds more serilog logging and cleans up some server files.
This commit is contained in:
parent
1cf4a43c2c
commit
38686c09b2
30 changed files with 2261 additions and 2234 deletions
|
|
@ -687,9 +687,9 @@ namespace Server
|
|||
|
||||
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
|
||||
);
|
||||
|
|
@ -3164,27 +3164,29 @@ namespace Server
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -3270,9 +3272,10 @@ namespace Server
|
|||
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,44 +1,60 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* 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; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,21 +17,20 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class ClientVersionConverter : JsonConverter<ClientVersion>
|
||||
{
|
||||
public override ClientVersion Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
return new ClientVersion(reader.GetString());
|
||||
}
|
||||
namespace Server.Json;
|
||||
|
||||
throw new JsonException("Value must be a string");
|
||||
public class ClientVersionConverter : JsonConverter<ClientVersion>
|
||||
{
|
||||
public override ClientVersion Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (reader.TokenType == JsonTokenType.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());
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class ClientVersionConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(ClientVersion);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new ClientVersionConverter();
|
||||
}
|
||||
}
|
||||
public class ClientVersionConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(ClientVersion);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new ClientVersionConverter();
|
||||
}
|
||||
|
|
@ -18,133 +18,132 @@ using System.Runtime.CompilerServices;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
namespace Server.Json;
|
||||
|
||||
public class FlagsConverter<T> : JsonConverter<T> where T : struct, Enum
|
||||
{
|
||||
public class FlagsConverter<T> : JsonConverter<T> where T : struct, Enum
|
||||
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
var flags = 0ul;
|
||||
var underlyingType = Enum.GetUnderlyingType(typeof(T));
|
||||
|
||||
while (true)
|
||||
{
|
||||
var flags = 0ul;
|
||||
var underlyingType = Enum.GetUnderlyingType(typeof(T));
|
||||
|
||||
while (true)
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid Json structure for Flag object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
reader.Read();
|
||||
|
||||
if (!reader.GetBoolean() || !Enum.TryParse<T>(key, out var val))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
flags |= ConvertToUInt64(underlyingType, val);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (Type.GetTypeCode(underlyingType))
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
case TypeCode.SByte:
|
||||
{
|
||||
var num = (sbyte)flags;
|
||||
return Unsafe.As<sbyte, T>(ref num);
|
||||
}
|
||||
case TypeCode.Byte:
|
||||
{
|
||||
var num = (byte)flags;
|
||||
return Unsafe.As<byte, T>(ref num);
|
||||
}
|
||||
case TypeCode.Int16:
|
||||
{
|
||||
var num = (short)flags;
|
||||
return Unsafe.As<short, T>(ref num);
|
||||
}
|
||||
case TypeCode.UInt16:
|
||||
{
|
||||
var num = (ushort)flags;
|
||||
return Unsafe.As<ushort, T>(ref num);
|
||||
}
|
||||
case TypeCode.UInt32:
|
||||
{
|
||||
var num = (uint)flags;
|
||||
return Unsafe.As<uint, T>(ref num);
|
||||
}
|
||||
case TypeCode.Int64:
|
||||
{
|
||||
var num = (long)flags;
|
||||
return Unsafe.As<long, T>(ref num);
|
||||
}
|
||||
case TypeCode.UInt64:
|
||||
{
|
||||
return Unsafe.As<ulong, T>(ref flags);
|
||||
}
|
||||
default:
|
||||
{
|
||||
var num = (int)flags;
|
||||
return Unsafe.As<int, T>(ref num);
|
||||
}
|
||||
throw new JsonException("Invalid Json structure for Flag object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
reader.Read();
|
||||
|
||||
if (!reader.GetBoolean() || !Enum.TryParse<T>(key, out var val))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
flags |= ConvertToUInt64(underlyingType, val);
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
||||
switch (Type.GetTypeCode(underlyingType))
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
var underlyingType = Enum.GetUnderlyingType(typeof(T));
|
||||
var intValue = ConvertToUInt64(underlyingType, value);
|
||||
|
||||
foreach (var flagName in Enum.GetNames(typeof(T)))
|
||||
{
|
||||
var flagValue = Enum.Parse<T>(flagName, false);
|
||||
var flag = ConvertToUInt64(underlyingType, flagValue);
|
||||
|
||||
// Do not write out multi-bit values. This is a custom behavior
|
||||
if (flag > 0 && (flag & (flag - 1)) == 0)
|
||||
case TypeCode.SByte:
|
||||
{
|
||||
writer.WriteBoolean(flagName, (intValue & flag) == flag);
|
||||
var num = (sbyte)flags;
|
||||
return Unsafe.As<sbyte, T>(ref num);
|
||||
}
|
||||
case TypeCode.Byte:
|
||||
{
|
||||
var num = (byte)flags;
|
||||
return Unsafe.As<byte, T>(ref num);
|
||||
}
|
||||
case TypeCode.Int16:
|
||||
{
|
||||
var num = (short)flags;
|
||||
return Unsafe.As<short, T>(ref num);
|
||||
}
|
||||
case TypeCode.UInt16:
|
||||
{
|
||||
var num = (ushort)flags;
|
||||
return Unsafe.As<ushort, T>(ref num);
|
||||
}
|
||||
case TypeCode.UInt32:
|
||||
{
|
||||
var num = (uint)flags;
|
||||
return Unsafe.As<uint, T>(ref num);
|
||||
}
|
||||
case TypeCode.Int64:
|
||||
{
|
||||
var num = (long)flags;
|
||||
return Unsafe.As<long, T>(ref num);
|
||||
}
|
||||
case TypeCode.UInt64:
|
||||
{
|
||||
return Unsafe.As<ulong, T>(ref flags);
|
||||
}
|
||||
default:
|
||||
{
|
||||
var num = (int)flags;
|
||||
return Unsafe.As<int, T>(ref num);
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
||||
private static ulong ConvertToUInt64(Type underlyingType, object value) =>
|
||||
Type.GetTypeCode(underlyingType) switch
|
||||
{
|
||||
TypeCode.SByte => (ulong)(sbyte)value,
|
||||
TypeCode.Byte => (byte)value,
|
||||
TypeCode.Int16 => (ulong)(short)value,
|
||||
TypeCode.UInt16 => (ushort)value,
|
||||
TypeCode.Int32 => (ulong)(int)value,
|
||||
TypeCode.UInt32 => (uint)value,
|
||||
TypeCode.Int64 => (ulong)(long)value,
|
||||
TypeCode.UInt64 => (ulong)value,
|
||||
_ => throw new InvalidOperationException()
|
||||
};
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static ulong GetUnderlyingTypeLength(TypeCode typeCode) =>
|
||||
typeCode switch
|
||||
{
|
||||
TypeCode.Byte => 8,
|
||||
TypeCode.SByte => 8,
|
||||
TypeCode.Int16 => 16,
|
||||
TypeCode.UInt16 => 16,
|
||||
TypeCode.Char => 16,
|
||||
TypeCode.Int32 => 32,
|
||||
TypeCode.UInt32 => 32,
|
||||
TypeCode.Int64 => 64,
|
||||
TypeCode.UInt64 => 64,
|
||||
_ => 64
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
var underlyingType = Enum.GetUnderlyingType(typeof(T));
|
||||
var intValue = ConvertToUInt64(underlyingType, value);
|
||||
|
||||
foreach (var flagName in Enum.GetNames(typeof(T)))
|
||||
{
|
||||
var flagValue = Enum.Parse<T>(flagName, false);
|
||||
var flag = ConvertToUInt64(underlyingType, flagValue);
|
||||
|
||||
// Do not write out multi-bit values. This is a custom behavior
|
||||
if (flag > 0 && (flag & (flag - 1)) == 0)
|
||||
{
|
||||
writer.WriteBoolean(flagName, (intValue & flag) == flag);
|
||||
}
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
|
||||
private static ulong ConvertToUInt64(Type underlyingType, object value) =>
|
||||
Type.GetTypeCode(underlyingType) switch
|
||||
{
|
||||
TypeCode.SByte => (ulong)(sbyte)value,
|
||||
TypeCode.Byte => (byte)value,
|
||||
TypeCode.Int16 => (ulong)(short)value,
|
||||
TypeCode.UInt16 => (ushort)value,
|
||||
TypeCode.Int32 => (ulong)(int)value,
|
||||
TypeCode.UInt32 => (uint)value,
|
||||
TypeCode.Int64 => (ulong)(long)value,
|
||||
TypeCode.UInt64 => (ulong)value,
|
||||
_ => throw new InvalidOperationException()
|
||||
};
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static ulong GetUnderlyingTypeLength(TypeCode typeCode) =>
|
||||
typeCode switch
|
||||
{
|
||||
TypeCode.Byte => 8,
|
||||
TypeCode.SByte => 8,
|
||||
TypeCode.Int16 => 16,
|
||||
TypeCode.UInt16 => 16,
|
||||
TypeCode.Char => 16,
|
||||
TypeCode.Int32 => 32,
|
||||
TypeCode.UInt32 => 32,
|
||||
TypeCode.Int64 => 64,
|
||||
TypeCode.UInt64 => 64,
|
||||
_ => 64
|
||||
};
|
||||
}
|
||||
|
|
@ -17,21 +17,20 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class GuidConverter : JsonConverter<Guid>
|
||||
{
|
||||
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (Guid.TryParse(reader.GetString()!, out var guid))
|
||||
{
|
||||
return guid;
|
||||
}
|
||||
namespace Server.Json;
|
||||
|
||||
throw new JsonException("Guid must be in the correct format");
|
||||
public class GuidConverter : JsonConverter<Guid>
|
||||
{
|
||||
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (Guid.TryParse(reader.GetString()!, out var guid))
|
||||
{
|
||||
return guid;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString());
|
||||
throw new JsonException("Guid must be in the correct format");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class GuidConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Guid);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new GuidConverter();
|
||||
}
|
||||
}
|
||||
public class GuidConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Guid);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new GuidConverter();
|
||||
}
|
||||
|
|
@ -18,21 +18,20 @@ using System.Net;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class IPEndPointConverter : JsonConverter<IPEndPoint>
|
||||
{
|
||||
public override IPEndPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (IPEndPoint.TryParse(reader.GetString()!, out var ipep))
|
||||
{
|
||||
return ipep;
|
||||
}
|
||||
namespace Server.Json;
|
||||
|
||||
throw new JsonException("IPEndPoint must be in the correct format");
|
||||
public class IPEndPointConverter : JsonConverter<IPEndPoint>
|
||||
{
|
||||
public override IPEndPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
if (IPEndPoint.TryParse(reader.GetString()!, out var ipep))
|
||||
{
|
||||
return ipep;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, IPEndPoint value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString());
|
||||
throw new JsonException("IPEndPoint must be in the correct format");
|
||||
}
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, IPEndPoint value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
|
|
@ -18,13 +18,12 @@ using System.Net;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class IPEndPointConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(IPEndPoint);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new IPEndPointConverter();
|
||||
}
|
||||
}
|
||||
public class IPEndPointConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(IPEndPoint);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new IPEndPointConverter();
|
||||
}
|
||||
|
|
@ -17,19 +17,18 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class MapConverter : JsonConverter<Map>
|
||||
{
|
||||
public override Map Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.String => Map.Parse(reader.GetString()),
|
||||
JsonTokenType.Number => Map.Maps[reader.GetInt32()],
|
||||
_ => throw new JsonException("Value must be a number or string")
|
||||
};
|
||||
namespace Server.Json;
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Map value, JsonSerializerOptions options) =>
|
||||
writer.WriteStringValue(value.Name);
|
||||
}
|
||||
}
|
||||
public class MapConverter : JsonConverter<Map>
|
||||
{
|
||||
public override Map Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.String => Map.Parse(reader.GetString()),
|
||||
JsonTokenType.Number => Map.Maps[reader.GetInt32()],
|
||||
_ => throw new JsonException("Value must be a number or string")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Map value, JsonSerializerOptions options) =>
|
||||
writer.WriteStringValue(value.Name);
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class MapConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Map);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new MapConverter();
|
||||
}
|
||||
}
|
||||
public class MapConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Map);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new MapConverter();
|
||||
}
|
||||
|
|
@ -17,95 +17,94 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
namespace Server.Json;
|
||||
|
||||
public class Point2DConverter : JsonConverter<Point2D>
|
||||
{
|
||||
public class Point2DConverter : JsonConverter<Point2D>
|
||||
private Point2D DeserializeArray(ref Utf8JsonReader reader)
|
||||
{
|
||||
private Point2D DeserializeArray(ref Utf8JsonReader reader)
|
||||
Span<int> data = stackalloc int[2];
|
||||
var count = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
Span<int> data = stackalloc int[2];
|
||||
var count = 0;
|
||||
|
||||
while (true)
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
if (count < 2)
|
||||
{
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (count > 2)
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException("Point2D must be an array of x, y");
|
||||
}
|
||||
if (count < 2)
|
||||
{
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
|
||||
return new Point2D(data[0], data[1]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
private Point2D DeserializeObj(ref Utf8JsonReader reader)
|
||||
if (count > 2)
|
||||
{
|
||||
Span<int> data = stackalloc int[2];
|
||||
|
||||
while (true)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid json structure for Point2D object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
var i = key switch
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
_ => throw new JsonException($"Invalid property {key} for Point2D")
|
||||
};
|
||||
|
||||
reader.Read();
|
||||
|
||||
if (reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException($"Value for {key} must be a number");
|
||||
}
|
||||
|
||||
data[i] = reader.GetInt32();
|
||||
}
|
||||
|
||||
return new Point2D(data[0], data[1]);
|
||||
throw new JsonException("Point2D must be an array of x, y");
|
||||
}
|
||||
|
||||
public override Point2D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
return new Point2D(data[0], data[1]);
|
||||
}
|
||||
|
||||
private Point2D DeserializeObj(ref Utf8JsonReader reader)
|
||||
{
|
||||
Span<int> data = stackalloc int[2];
|
||||
|
||||
while (true)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid json structure for Point2D object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
var i = key switch
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
_ => throw new JsonException($"Invalid property {key} for Point2D")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Point2D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.X);
|
||||
writer.WriteNumberValue(value.Y);
|
||||
writer.WriteEndArray();
|
||||
reader.Read();
|
||||
|
||||
if (reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException($"Value for {key} must be a number");
|
||||
}
|
||||
|
||||
data[i] = reader.GetInt32();
|
||||
}
|
||||
|
||||
return new Point2D(data[0], data[1]);
|
||||
}
|
||||
}
|
||||
|
||||
public override Point2D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Point2D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.X);
|
||||
writer.WriteNumberValue(value.Y);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,14 +17,13 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class Point2DConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) =>
|
||||
typeToConvert == typeof(Point2D) || typeToConvert == typeof(IPoint2D);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new Point2DConverter();
|
||||
}
|
||||
}
|
||||
public class Point2DConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) =>
|
||||
typeToConvert == typeof(Point2D) || typeToConvert == typeof(IPoint2D);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new Point2DConverter();
|
||||
}
|
||||
|
|
@ -17,97 +17,96 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
namespace Server.Json;
|
||||
|
||||
public class Point3DConverter : JsonConverter<Point3D>
|
||||
{
|
||||
public class Point3DConverter : JsonConverter<Point3D>
|
||||
private Point3D DeserializeArray(ref Utf8JsonReader reader)
|
||||
{
|
||||
private Point3D DeserializeArray(ref Utf8JsonReader reader)
|
||||
Span<int> data = stackalloc int[3];
|
||||
var count = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
Span<int> data = stackalloc int[3];
|
||||
var count = 0;
|
||||
|
||||
while (true)
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
if (count < 3)
|
||||
{
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (count > 3)
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException("Point3D must be an array of x, y, z");
|
||||
}
|
||||
if (count < 3)
|
||||
{
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
|
||||
return new Point3D(data[0], data[1], data[2]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
private Point3D DeserializeObj(ref Utf8JsonReader reader)
|
||||
if (count > 3)
|
||||
{
|
||||
Span<int> data = stackalloc int[3];
|
||||
|
||||
while (true)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid json structure for Point3D object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
var i = key switch
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
"z" => 2,
|
||||
_ => throw new JsonException($"Invalid property {key} for Point3D")
|
||||
};
|
||||
|
||||
reader.Read();
|
||||
|
||||
if (reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException($"Value for {key} must be a number");
|
||||
}
|
||||
|
||||
data[i] = reader.GetInt32();
|
||||
}
|
||||
|
||||
return new Point3D(data[0], data[1], data[2]);
|
||||
throw new JsonException("Point3D must be an array of x, y, z");
|
||||
}
|
||||
|
||||
public override Point3D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
return new Point3D(data[0], data[1], data[2]);
|
||||
}
|
||||
|
||||
private Point3D DeserializeObj(ref Utf8JsonReader reader)
|
||||
{
|
||||
Span<int> data = stackalloc int[3];
|
||||
|
||||
while (true)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid json structure for Point3D object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
var i = key switch
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
"z" => 2,
|
||||
_ => throw new JsonException($"Invalid property {key} for Point3D")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Point3D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.X);
|
||||
writer.WriteNumberValue(value.Y);
|
||||
writer.WriteNumberValue(value.Z);
|
||||
writer.WriteEndArray();
|
||||
reader.Read();
|
||||
|
||||
if (reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException($"Value for {key} must be a number");
|
||||
}
|
||||
|
||||
data[i] = reader.GetInt32();
|
||||
}
|
||||
|
||||
return new Point3D(data[0], data[1], data[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public override Point3D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Point3D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.X);
|
||||
writer.WriteNumberValue(value.Y);
|
||||
writer.WriteNumberValue(value.Z);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,14 +17,13 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class Point3DConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) =>
|
||||
typeToConvert == typeof(Point3D) || typeToConvert == typeof(IPoint3D);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new Point3DConverter();
|
||||
}
|
||||
}
|
||||
public class Point3DConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) =>
|
||||
typeToConvert == typeof(Point3D) || typeToConvert == typeof(IPoint3D);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new Point3DConverter();
|
||||
}
|
||||
|
|
@ -17,168 +17,167 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
namespace Server.Json;
|
||||
|
||||
public class Rectangle3DConverter : JsonConverter<Rectangle3D>
|
||||
{
|
||||
public class Rectangle3DConverter : JsonConverter<Rectangle3D>
|
||||
private Rectangle3D DeserializeArray(ref Utf8JsonReader reader)
|
||||
{
|
||||
private Rectangle3D DeserializeArray(ref Utf8JsonReader reader)
|
||||
Span<int> data = stackalloc int[6];
|
||||
var count = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
Span<int> data = stackalloc int[6];
|
||||
var count = 0;
|
||||
|
||||
while (true)
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
if (count < 6)
|
||||
{
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (count > 6)
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException("Rectangle3D must be an array of x, y, z, h, w, d");
|
||||
}
|
||||
if (count < 6)
|
||||
{
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
|
||||
return new Rectangle3D(data[0], data[1], data[2], data[3], data[4], data[5]);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
private Rectangle3D DeserializeObj(ref Utf8JsonReader reader, JsonSerializerOptions options)
|
||||
if (count > 6)
|
||||
{
|
||||
Span<int> data = stackalloc int[6];
|
||||
throw new JsonException("Rectangle3D must be an array of x, y, z, h, w, d");
|
||||
}
|
||||
|
||||
// 0 - xyzwhd, 1 - x1y1z1x2y2z2, 2 - start/end
|
||||
var objType = -1;
|
||||
var hasZ = false;
|
||||
return new Rectangle3D(data[0], data[1], data[2], data[3], data[4], data[5]);
|
||||
}
|
||||
|
||||
while (true)
|
||||
private Rectangle3D DeserializeObj(ref Utf8JsonReader reader, JsonSerializerOptions options)
|
||||
{
|
||||
Span<int> data = stackalloc int[6];
|
||||
|
||||
// 0 - xyzwhd, 1 - x1y1z1x2y2z2, 2 - start/end
|
||||
var objType = -1;
|
||||
var hasZ = false;
|
||||
|
||||
while (true)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid json structure for Rectangle3D object");
|
||||
}
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid json structure for Rectangle3D object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
var key = reader.GetString();
|
||||
|
||||
reader.Read();
|
||||
reader.Read();
|
||||
|
||||
if (key is "start" or "end")
|
||||
{
|
||||
if (objType > -1 && objType != 2)
|
||||
{
|
||||
throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both.");
|
||||
}
|
||||
|
||||
objType = 2;
|
||||
|
||||
var point3D = reader.ToObject<Point3D>(options);
|
||||
var offset = key == "end" ? 3 : 0;
|
||||
data[0 + offset] = point3D.X;
|
||||
data[1 + offset] = point3D.Y;
|
||||
// We can't do implicit z-level. Abandon using Point3D deserialization?
|
||||
data[2 + offset] = point3D.Z;
|
||||
continue;
|
||||
}
|
||||
|
||||
var i = key switch
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
"z" => 2,
|
||||
"w" => 3,
|
||||
"width" => 3,
|
||||
"h" => 4,
|
||||
"height" => 4,
|
||||
"d" => 5,
|
||||
"depth" => 5,
|
||||
"x1" => 10,
|
||||
"y1" => 11,
|
||||
"z1" => 12,
|
||||
"x2" => 13,
|
||||
"y2" => 14,
|
||||
"z2" => 15,
|
||||
_ => throw new JsonException($"Invalid property {key} for Rectangle3D")
|
||||
};
|
||||
|
||||
if (i < 10)
|
||||
{
|
||||
if (objType > -1 && objType != 0)
|
||||
{
|
||||
throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both.");
|
||||
}
|
||||
|
||||
objType = 0;
|
||||
data[i] = reader.GetInt32();
|
||||
if (i == 2)
|
||||
{
|
||||
hasZ = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (objType > -1 && objType != 1)
|
||||
if (key is "start" or "end")
|
||||
{
|
||||
if (objType > -1 && objType != 2)
|
||||
{
|
||||
throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both.");
|
||||
}
|
||||
|
||||
objType = 1;
|
||||
data[i - 10] = reader.GetInt32();
|
||||
if (i is 12 or 15)
|
||||
objType = 2;
|
||||
|
||||
var point3D = reader.ToObject<Point3D>(options);
|
||||
var offset = key == "end" ? 3 : 0;
|
||||
data[0 + offset] = point3D.X;
|
||||
data[1 + offset] = point3D.Y;
|
||||
// We can't do implicit z-level. Abandon using Point3D deserialization?
|
||||
data[2 + offset] = point3D.Z;
|
||||
continue;
|
||||
}
|
||||
|
||||
var i = key switch
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
"z" => 2,
|
||||
"w" => 3,
|
||||
"width" => 3,
|
||||
"h" => 4,
|
||||
"height" => 4,
|
||||
"d" => 5,
|
||||
"depth" => 5,
|
||||
"x1" => 10,
|
||||
"y1" => 11,
|
||||
"z1" => 12,
|
||||
"x2" => 13,
|
||||
"y2" => 14,
|
||||
"z2" => 15,
|
||||
_ => throw new JsonException($"Invalid property {key} for Rectangle3D")
|
||||
};
|
||||
|
||||
if (i < 10)
|
||||
{
|
||||
if (objType > -1 && objType != 0)
|
||||
{
|
||||
throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both.");
|
||||
}
|
||||
|
||||
objType = 0;
|
||||
data[i] = reader.GetInt32();
|
||||
if (i == 2)
|
||||
{
|
||||
hasZ = true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!hasZ)
|
||||
if (objType > -1 && objType != 1)
|
||||
{
|
||||
// Bottom to top?
|
||||
data[2] = -128;
|
||||
data[5] = 127;
|
||||
throw new JsonException("Rectangle3D must have a start/end, or x/y/z/w/h/d, but not both.");
|
||||
}
|
||||
|
||||
return objType == 0
|
||||
? new Rectangle3D(data[0], data[1], data[2], data[3], data[4], data[5])
|
||||
: new Rectangle3D(
|
||||
new Point3D(data[0], data[1], data[2]),
|
||||
new Point3D(data[3], data[4], data[5])
|
||||
);
|
||||
objType = 1;
|
||||
data[i - 10] = reader.GetInt32();
|
||||
if (i is 12 or 15)
|
||||
{
|
||||
hasZ = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle3D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader, options),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Rectangle3D value, JsonSerializerOptions options)
|
||||
if (!hasZ)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.Start.X);
|
||||
writer.WriteNumberValue(value.Start.Y);
|
||||
writer.WriteNumberValue(value.Start.Z);
|
||||
writer.WriteNumberValue(value.Width);
|
||||
writer.WriteNumberValue(value.Height);
|
||||
writer.WriteNumberValue(value.Depth);
|
||||
writer.WriteEndArray();
|
||||
// Bottom to top?
|
||||
data[2] = -128;
|
||||
data[5] = 127;
|
||||
}
|
||||
|
||||
return objType == 0
|
||||
? new Rectangle3D(data[0], data[1], data[2], data[3], data[4], data[5])
|
||||
: new Rectangle3D(
|
||||
new Point3D(data[0], data[1], data[2]),
|
||||
new Point3D(data[3], data[4], data[5])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public override Rectangle3D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader, options),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Rectangle3D value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.Start.X);
|
||||
writer.WriteNumberValue(value.Start.Y);
|
||||
writer.WriteNumberValue(value.Start.Z);
|
||||
writer.WriteNumberValue(value.Width);
|
||||
writer.WriteNumberValue(value.Height);
|
||||
writer.WriteNumberValue(value.Depth);
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class Rectangle3DConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Rectangle3D);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new Rectangle3DConverter();
|
||||
}
|
||||
}
|
||||
public class Rectangle3DConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Rectangle3D);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new Rectangle3DConverter();
|
||||
}
|
||||
|
|
@ -17,14 +17,13 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class TimeSpanConverter : JsonConverter<TimeSpan>
|
||||
{
|
||||
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
=> TimeSpan.Parse(reader.GetString()!);
|
||||
namespace Server.Json;
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
}
|
||||
public class TimeSpanConverter : JsonConverter<TimeSpan>
|
||||
{
|
||||
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
=> TimeSpan.Parse(reader.GetString()!);
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
|
||||
=> writer.WriteStringValue(value.ToString());
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class TimeSpanConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(TimeSpan);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new TimeSpanConverter();
|
||||
}
|
||||
}
|
||||
public class TimeSpanConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(TimeSpan);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new TimeSpanConverter();
|
||||
}
|
||||
|
|
@ -16,29 +16,31 @@
|
|||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Server.Logging;
|
||||
|
||||
namespace Server.Json
|
||||
namespace Server.Json;
|
||||
|
||||
public class TypeConverter : JsonConverter<Type>
|
||||
{
|
||||
public class TypeConverter : JsonConverter<Type>
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(TypeConverter));
|
||||
|
||||
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
if (reader.TokenType != JsonTokenType.String)
|
||||
{
|
||||
if (reader.TokenType != JsonTokenType.String)
|
||||
{
|
||||
throw new JsonException("The JSON value could not be converted to System.Type");
|
||||
}
|
||||
|
||||
var typeName = reader.GetString();
|
||||
var type = AssemblyHandler.FindTypeByName(typeName);
|
||||
if (type == null)
|
||||
{
|
||||
Console.WriteLine("Invalid type {0} deserialized", typeName);
|
||||
}
|
||||
|
||||
return type;
|
||||
throw new JsonException("The JSON value could not be converted to System.Type");
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Type value, JsonSerializerOptions options) =>
|
||||
writer.WriteStringValue(value.FullName);
|
||||
var typeName = reader.GetString();
|
||||
var type = AssemblyHandler.FindTypeByName(typeName);
|
||||
if (type == null)
|
||||
{
|
||||
logger.Warning("Attempted to deserialize type {Type} which does not exist.", typeName);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, Type value, JsonSerializerOptions options) =>
|
||||
writer.WriteStringValue(value.FullName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class TypeConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Type);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new TypeConverter();
|
||||
}
|
||||
public class TypeConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(Type);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new TypeConverter();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,173 +17,172 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
namespace Server.Json;
|
||||
|
||||
public class WorldLocationConverter : JsonConverter<WorldLocation>
|
||||
{
|
||||
public class WorldLocationConverter : JsonConverter<WorldLocation>
|
||||
private static Point3DConverter _point3DConverter;
|
||||
private static MapConverter _mapConverter;
|
||||
|
||||
private WorldLocation DeserializeArray(ref Utf8JsonReader reader)
|
||||
{
|
||||
private static Point3DConverter _point3DConverter;
|
||||
private static MapConverter _mapConverter;
|
||||
Span<int> data = stackalloc int[3];
|
||||
var count = 0;
|
||||
var hasMap = false;
|
||||
Map map = null;
|
||||
|
||||
private WorldLocation DeserializeArray(ref Utf8JsonReader reader)
|
||||
while (true)
|
||||
{
|
||||
Span<int> data = stackalloc int[3];
|
||||
var count = 0;
|
||||
var hasMap = false;
|
||||
Map map = null;
|
||||
|
||||
while (true)
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndArray)
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
{
|
||||
if (count < 3)
|
||||
{
|
||||
break;
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.Number)
|
||||
else if (count == 3)
|
||||
{
|
||||
if (count < 3)
|
||||
{
|
||||
data[count] = reader.GetInt32();
|
||||
}
|
||||
else if (count == 3)
|
||||
{
|
||||
map = Map.Maps[reader.GetInt32()];
|
||||
hasMap = true;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
var key = reader.GetString();
|
||||
|
||||
if (count != 3 || hasMap)
|
||||
{
|
||||
throw new JsonException($"Value {key} is not valid for this element.");
|
||||
}
|
||||
|
||||
map = Map.Parse(key);
|
||||
map = Map.Maps[reader.GetInt32()];
|
||||
hasMap = true;
|
||||
break;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
if (!hasMap || count != 3)
|
||||
if (reader.TokenType == JsonTokenType.String)
|
||||
{
|
||||
throw new JsonException("WorldLocation must be an array of x, y, z, and map");
|
||||
}
|
||||
|
||||
return new WorldLocation(data[0], data[1], data[2], map);
|
||||
}
|
||||
|
||||
private WorldLocation DeserializeObj(ref Utf8JsonReader reader, JsonSerializerOptions options)
|
||||
{
|
||||
Span<int> data = stackalloc int[3];
|
||||
var count = 0;
|
||||
var hasLoc = false;
|
||||
var hasXYZ = false;
|
||||
var hasMap = false;
|
||||
Map map = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid Json structure for WorldLocation object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
var i = key switch
|
||||
if (count != 3 || hasMap)
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
"z" => 2,
|
||||
"loc" => 3,
|
||||
"map" => 4,
|
||||
_ => 5
|
||||
};
|
||||
|
||||
if (i == 5)
|
||||
{
|
||||
continue;
|
||||
throw new JsonException($"Value {key} is not valid for this element.");
|
||||
}
|
||||
|
||||
reader.Read();
|
||||
|
||||
if (i < 3)
|
||||
{
|
||||
if (hasLoc)
|
||||
{
|
||||
throw new JsonException("WorldLocation must have loc or x, y, z, but not both");
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException($"Value for {key} must be a number");
|
||||
}
|
||||
|
||||
hasXYZ = true;
|
||||
data[i] = reader.GetInt32();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == 3)
|
||||
{
|
||||
if (hasXYZ)
|
||||
{
|
||||
throw new JsonException("WorldLocation must have loc or x, y, z, but not both");
|
||||
}
|
||||
|
||||
hasLoc = true;
|
||||
|
||||
_point3DConverter ??= new Point3DConverter();
|
||||
|
||||
var loc = _point3DConverter.Read(ref reader, typeof(Point3D), options);
|
||||
data[0] = loc.X;
|
||||
data[1] = loc.Y;
|
||||
data[2] = loc.Z;
|
||||
count = 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
_mapConverter ??= new MapConverter();
|
||||
map = _mapConverter.Read(ref reader, typeof(Map), options);
|
||||
|
||||
map = Map.Parse(key);
|
||||
hasMap = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!hasMap || count != 3)
|
||||
{
|
||||
throw new JsonException("WorldLocation must have an x, y, z, and map properties");
|
||||
}
|
||||
|
||||
return new WorldLocation(data[0], data[1], data[2], map);
|
||||
}
|
||||
|
||||
public override WorldLocation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
if (!hasMap || count != 3)
|
||||
{
|
||||
throw new JsonException("WorldLocation must be an array of x, y, z, and map");
|
||||
}
|
||||
|
||||
return new WorldLocation(data[0], data[1], data[2], map);
|
||||
}
|
||||
|
||||
private WorldLocation DeserializeObj(ref Utf8JsonReader reader, JsonSerializerOptions options)
|
||||
{
|
||||
Span<int> data = stackalloc int[3];
|
||||
var count = 0;
|
||||
var hasLoc = false;
|
||||
var hasXYZ = false;
|
||||
var hasMap = false;
|
||||
Map map = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
reader.Read();
|
||||
if (reader.TokenType == JsonTokenType.EndObject)
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader, options),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
break;
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.PropertyName)
|
||||
{
|
||||
throw new JsonException("Invalid Json structure for WorldLocation object");
|
||||
}
|
||||
|
||||
var key = reader.GetString();
|
||||
|
||||
var i = key switch
|
||||
{
|
||||
"x" => 0,
|
||||
"y" => 1,
|
||||
"z" => 2,
|
||||
"loc" => 3,
|
||||
"map" => 4,
|
||||
_ => 5
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, WorldLocation value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.X);
|
||||
writer.WriteNumberValue(value.Y);
|
||||
writer.WriteNumberValue(value.Z);
|
||||
writer.WriteStringValue(value.Map.ToString());
|
||||
writer.WriteEndArray();
|
||||
if (i == 5)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
reader.Read();
|
||||
|
||||
if (i < 3)
|
||||
{
|
||||
if (hasLoc)
|
||||
{
|
||||
throw new JsonException("WorldLocation must have loc or x, y, z, but not both");
|
||||
}
|
||||
|
||||
if (reader.TokenType != JsonTokenType.Number)
|
||||
{
|
||||
throw new JsonException($"Value for {key} must be a number");
|
||||
}
|
||||
|
||||
hasXYZ = true;
|
||||
data[i] = reader.GetInt32();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i == 3)
|
||||
{
|
||||
if (hasXYZ)
|
||||
{
|
||||
throw new JsonException("WorldLocation must have loc or x, y, z, but not both");
|
||||
}
|
||||
|
||||
hasLoc = true;
|
||||
|
||||
_point3DConverter ??= new Point3DConverter();
|
||||
|
||||
var loc = _point3DConverter.Read(ref reader, typeof(Point3D), options);
|
||||
data[0] = loc.X;
|
||||
data[1] = loc.Y;
|
||||
data[2] = loc.Z;
|
||||
count = 3;
|
||||
continue;
|
||||
}
|
||||
|
||||
_mapConverter ??= new MapConverter();
|
||||
map = _mapConverter.Read(ref reader, typeof(Map), options);
|
||||
|
||||
hasMap = true;
|
||||
}
|
||||
|
||||
if (!hasMap || count != 3)
|
||||
{
|
||||
throw new JsonException("WorldLocation must have an x, y, z, and map properties");
|
||||
}
|
||||
|
||||
return new WorldLocation(data[0], data[1], data[2], map);
|
||||
}
|
||||
}
|
||||
|
||||
public override WorldLocation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
|
||||
reader.TokenType switch
|
||||
{
|
||||
JsonTokenType.StartArray => DeserializeArray(ref reader),
|
||||
JsonTokenType.StartObject => DeserializeObj(ref reader, options),
|
||||
_ => throw new JsonException("Invalid Json for Point3D")
|
||||
};
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, WorldLocation value, JsonSerializerOptions options)
|
||||
{
|
||||
writer.WriteStartArray();
|
||||
writer.WriteNumberValue(value.X);
|
||||
writer.WriteNumberValue(value.Y);
|
||||
writer.WriteNumberValue(value.Z);
|
||||
writer.WriteStringValue(value.Map.ToString());
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,13 +17,12 @@ using System;
|
|||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Server.Json
|
||||
{
|
||||
public class WorldLocationConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(WorldLocation);
|
||||
namespace Server.Json;
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new WorldLocationConverter();
|
||||
}
|
||||
}
|
||||
public class WorldLocationConverterFactory : JsonConverterFactory
|
||||
{
|
||||
public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(WorldLocation);
|
||||
|
||||
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options) =>
|
||||
new WorldLocationConverter();
|
||||
}
|
||||
|
|
@ -1,137 +1,152 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: Body.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 System.Runtime.CompilerServices;
|
||||
using Server.Logging;
|
||||
|
||||
namespace Server
|
||||
namespace Server;
|
||||
|
||||
public enum BodyType : byte
|
||||
{
|
||||
public enum BodyType : byte
|
||||
{
|
||||
Empty,
|
||||
Monster,
|
||||
Sea,
|
||||
Animal,
|
||||
Human,
|
||||
Equipment
|
||||
}
|
||||
Empty,
|
||||
Monster,
|
||||
Sea,
|
||||
Animal,
|
||||
Human,
|
||||
Equipment
|
||||
}
|
||||
|
||||
[Parsable]
|
||||
public readonly struct Body : IEquatable<object>, IEquatable<Body>, IEquatable<int>, IComparable<int>, IComparable<Body>
|
||||
{
|
||||
private static readonly BodyType[] m_Types = Array.Empty<BodyType>();
|
||||
[Parsable]
|
||||
public readonly struct Body : IEquatable<object>, IEquatable<Body>, IEquatable<int>, IComparable<int>, IComparable<Body>
|
||||
{
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(Body));
|
||||
|
||||
static Body()
|
||||
private static readonly BodyType[] m_Types = Array.Empty<BodyType>();
|
||||
|
||||
static Body()
|
||||
{
|
||||
if (!File.Exists("Data/bodyTable.cfg"))
|
||||
{
|
||||
if (File.Exists("Data/bodyTable.cfg"))
|
||||
logger.Error("Data/bodyTable.cfg does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
using var ip = new StreamReader("Data/bodyTable.cfg");
|
||||
m_Types = new BodyType[0x1000];
|
||||
|
||||
string line;
|
||||
|
||||
while ((line = ip.ReadLine()) != null)
|
||||
{
|
||||
if (line.Length == 0 || line.StartsWithOrdinal("#"))
|
||||
{
|
||||
using var ip = new StreamReader("Data/bodyTable.cfg");
|
||||
m_Types = new BodyType[0x1000];
|
||||
continue;
|
||||
}
|
||||
|
||||
string line;
|
||||
var split = line.Split('\t');
|
||||
|
||||
while ((line = ip.ReadLine()) != null)
|
||||
{
|
||||
if (line.Length == 0 || line.StartsWithOrdinal("#"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var split = line.Split('\t');
|
||||
|
||||
if (int.TryParse(split[0], out var bodyID) && Enum.TryParse(split[1], true, out BodyType type) &&
|
||||
bodyID >= 0 &&
|
||||
bodyID < m_Types.Length)
|
||||
{
|
||||
m_Types[bodyID] = type;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Invalid bodyTable entry:");
|
||||
Console.WriteLine(line);
|
||||
}
|
||||
}
|
||||
if (int.TryParse(split[0], out var bodyID) && Enum.TryParse(split[1], true, out BodyType type) &&
|
||||
bodyID >= 0 &&
|
||||
bodyID < m_Types.Length)
|
||||
{
|
||||
m_Types[bodyID] = type;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: Data/bodyTable.cfg does not exist");
|
||||
logger.Warning("Invalid bodyTable entry: {Entry}", line);
|
||||
}
|
||||
}
|
||||
|
||||
public Body(int bodyID) => BodyID = bodyID;
|
||||
|
||||
public BodyType Type => BodyID >= 0 && BodyID < m_Types.Length ? m_Types[BodyID] : BodyType.Empty;
|
||||
|
||||
public bool IsHuman => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Human
|
||||
&& BodyID != 402
|
||||
&& BodyID != 403
|
||||
&& BodyID != 607
|
||||
&& BodyID != 608
|
||||
&& BodyID != 694
|
||||
&& BodyID != 695
|
||||
&& BodyID != 970;
|
||||
|
||||
public bool IsGargoyle => BodyID is 666 or 667 or 694 or 695;
|
||||
|
||||
public bool IsMale => BodyID is 183 or 185 or 400 or 402 or 605 or 607 or 666 or 694 or 750;
|
||||
|
||||
public bool IsFemale => BodyID is 184 or 186 or 401 or 403 or 606 or 608 or 667 or 695 or 751;
|
||||
|
||||
public bool IsGhost => BodyID is 402 or 403 or 607 or 608 or 694 or 695 or 970;
|
||||
|
||||
public bool IsMonster => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Monster;
|
||||
|
||||
public bool IsAnimal => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Animal;
|
||||
|
||||
public bool IsEmpty => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Empty;
|
||||
|
||||
public bool IsSea => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Sea;
|
||||
|
||||
public bool IsEquipment => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Equipment;
|
||||
|
||||
public int BodyID { get; }
|
||||
|
||||
public static implicit operator int(Body a) => a.BodyID;
|
||||
|
||||
public static implicit operator Body(int a) => new(a);
|
||||
|
||||
public override string ToString() => $"0x{BodyID:X}";
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode() => BodyID.GetHashCode();
|
||||
|
||||
public override bool Equals(object o) => o is Body b && b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(Body b) => b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(int number) => number == BodyID;
|
||||
|
||||
public static bool operator ==(Body l, Body r) => l.BodyID == r.BodyID;
|
||||
|
||||
public static bool operator !=(Body l, Body r) => l.BodyID != r.BodyID;
|
||||
|
||||
public static bool operator >(Body l, Body r) => l.BodyID > r.BodyID;
|
||||
|
||||
public static bool operator >=(Body l, Body r) => l.BodyID >= r.BodyID;
|
||||
|
||||
public static bool operator <(Body l, Body r) => l.BodyID < r.BodyID;
|
||||
|
||||
public static bool operator <=(Body l, Body r) => l.BodyID <= r.BodyID;
|
||||
|
||||
public int CompareTo(Body other) => BodyID.CompareTo(other.BodyID);
|
||||
|
||||
public int CompareTo(int other) => BodyID.CompareTo(other);
|
||||
|
||||
public static Body Parse(string value) => Utility.ToInt32(value);
|
||||
}
|
||||
|
||||
public Body(int bodyID) => BodyID = bodyID;
|
||||
|
||||
public BodyType Type => BodyID >= 0 && BodyID < m_Types.Length ? m_Types[BodyID] : BodyType.Empty;
|
||||
|
||||
public bool IsHuman => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Human
|
||||
&& BodyID != 402
|
||||
&& BodyID != 403
|
||||
&& BodyID != 607
|
||||
&& BodyID != 608
|
||||
&& BodyID != 694
|
||||
&& BodyID != 695
|
||||
&& BodyID != 970;
|
||||
|
||||
public bool IsGargoyle => BodyID is 666 or 667 or 694 or 695;
|
||||
|
||||
public bool IsMale => BodyID is 183 or 185 or 400 or 402 or 605 or 607 or 666 or 694 or 750;
|
||||
|
||||
public bool IsFemale => BodyID is 184 or 186 or 401 or 403 or 606 or 608 or 667 or 695 or 751;
|
||||
|
||||
public bool IsGhost => BodyID is 402 or 403 or 607 or 608 or 694 or 695 or 970;
|
||||
|
||||
public bool IsMonster => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Monster;
|
||||
|
||||
public bool IsAnimal => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Animal;
|
||||
|
||||
public bool IsEmpty => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Empty;
|
||||
|
||||
public bool IsSea => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Sea;
|
||||
|
||||
public bool IsEquipment => BodyID >= 0
|
||||
&& BodyID < m_Types.Length
|
||||
&& m_Types[BodyID] == BodyType.Equipment;
|
||||
|
||||
public int BodyID { get; }
|
||||
|
||||
public static implicit operator int(Body a) => a.BodyID;
|
||||
|
||||
public static implicit operator Body(int a) => new(a);
|
||||
|
||||
public override string ToString() => $"0x{BodyID:X}";
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override int GetHashCode() => BodyID.GetHashCode();
|
||||
|
||||
public override bool Equals(object o) => o is Body b && b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(Body b) => b.BodyID == BodyID;
|
||||
|
||||
public bool Equals(int number) => number == BodyID;
|
||||
|
||||
public static bool operator ==(Body l, Body r) => l.BodyID == r.BodyID;
|
||||
|
||||
public static bool operator !=(Body l, Body r) => l.BodyID != r.BodyID;
|
||||
|
||||
public static bool operator >(Body l, Body r) => l.BodyID > r.BodyID;
|
||||
|
||||
public static bool operator >=(Body l, Body r) => l.BodyID >= r.BodyID;
|
||||
|
||||
public static bool operator <(Body l, Body r) => l.BodyID < r.BodyID;
|
||||
|
||||
public static bool operator <=(Body l, Body r) => l.BodyID <= r.BodyID;
|
||||
|
||||
public int CompareTo(Body other) => BodyID.CompareTo(other.BodyID);
|
||||
|
||||
public int CompareTo(int other) => BodyID.CompareTo(other);
|
||||
|
||||
public static Body Parse(string value) => Utility.ToInt32(value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -861,7 +861,7 @@ namespace Server
|
|||
{
|
||||
if (m_Spell != null && value != null)
|
||||
{
|
||||
Console.WriteLine("Warning: Spell has been overwritten");
|
||||
logger.Warning("Spell has been overwritten.");
|
||||
}
|
||||
|
||||
m_Spell = value;
|
||||
|
|
@ -5087,13 +5087,15 @@ namespace Server
|
|||
{
|
||||
item = oldItem.GetType().CreateInstance<T>();
|
||||
}
|
||||
catch
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(
|
||||
"Warning: {0}: Item must have a zero parameter constructor to be separated from a stack. '{1}'.",
|
||||
logger.Warning(
|
||||
e,
|
||||
"[{Serial} {Name}]: Item must have a zero parameter constructor to be separated from a stack.",
|
||||
oldItem.Serial,
|
||||
oldItem.GetType().Name
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -7685,9 +7687,7 @@ namespace Server
|
|||
|
||||
if (m_DeltaQueue.Count > 0)
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.DarkYellow);
|
||||
Console.WriteLine("Warning: {0} mobiles left in delta queue after processing.", m_DeltaQueue.Count);
|
||||
Utility.PopColor();
|
||||
logger.Warning("{Count} mobiles left in delta queue after processing.", m_DeltaQueue.Count);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -726,7 +726,7 @@ public partial class NetState : IComparable<NetState>
|
|||
catch (Exception ex)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine(ex);
|
||||
Console.WriteLine(ex);
|
||||
#endif
|
||||
TraceException(ex);
|
||||
Disconnect("Exception during HandleReceive");
|
||||
|
|
|
|||
|
|
@ -16,11 +16,14 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using Server.Logging;
|
||||
|
||||
namespace Server.Network;
|
||||
|
||||
public static class OutgoingContainerPackets
|
||||
{
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(OutgoingContainerPackets));
|
||||
|
||||
public static void SendDisplaySpellbook(this NetState ns, Serial book) => ns.SendDisplayContainer(book, -1);
|
||||
|
||||
public static void SendSpellbookContent(this NetState ns, Serial book, int graphic, int offset, ulong content)
|
||||
|
|
@ -136,7 +139,12 @@ public static class OutgoingContainerPackets
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Warning: ContainerContentUpdate on item with !(parent is Item)");
|
||||
logger.Warning(
|
||||
"ContainerContentUpdate on Item {Type} ({Serial}) where parent is not an Item",
|
||||
item.GetType().Name,
|
||||
item.Serial
|
||||
);
|
||||
|
||||
parentSerial = Serial.Zero;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using Server.Json;
|
||||
using Server.Logging;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
|
||||
|
|
@ -82,10 +83,11 @@ namespace Server
|
|||
|
||||
public class Region : IComparable<Region>
|
||||
{
|
||||
public static readonly int DefaultPriority = 50;
|
||||
private static readonly ILogger logger = LogFactory.GetLogger(typeof(Region));
|
||||
|
||||
public static readonly int MinZ = sbyte.MinValue;
|
||||
public static readonly int MaxZ = sbyte.MaxValue + 1;
|
||||
public const int DefaultPriority = 50;
|
||||
public const int MinZ = sbyte.MinValue;
|
||||
public const int MaxZ = sbyte.MaxValue + 1;
|
||||
|
||||
public Region(string name, Map map, int priority, params Rectangle2D[] area) : this(
|
||||
name,
|
||||
|
|
@ -156,7 +158,7 @@ namespace Server
|
|||
|
||||
if (Area.Length == 0)
|
||||
{
|
||||
Console.WriteLine("Empty area for region '{0}'", this);
|
||||
logger.Debug("Empty area for region '{Region}'", this);
|
||||
}
|
||||
|
||||
if (json.GetProperty("go", options, out Point3D go))
|
||||
|
|
@ -368,7 +370,7 @@ namespace Server
|
|||
|
||||
if (Children.Count > 0)
|
||||
{
|
||||
Console.WriteLine("Warning: Unregistering region '{0}' with children", this);
|
||||
logger.Warning("Unregistering region '{Region}' with children", this);
|
||||
}
|
||||
|
||||
if (Parent != null)
|
||||
|
|
|
|||
|
|
@ -136,7 +136,6 @@ namespace Server
|
|||
|
||||
if (Lock is < SkillLock.Up or > SkillLock.Locked)
|
||||
{
|
||||
Console.WriteLine("Bad skill lock -> {0}.{1}", owner.Owner, Lock);
|
||||
Lock = SkillLock.Up;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue