fix(core): Fixes region base type (#635)
Fixes `Region` being loaded instead of `BaseRegion` as the default region type.
This commit is contained in:
parent
803b4a33cb
commit
cc5a8dc4fa
5 changed files with 211 additions and 190 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -22,9 +22,11 @@ namespace Server.Json
|
||||||
{
|
{
|
||||||
public class DynamicJson
|
public class DynamicJson
|
||||||
{
|
{
|
||||||
[JsonPropertyName("type")] public string Type { get; set; }
|
[JsonPropertyName("type")]
|
||||||
|
public string Type { get; set; }
|
||||||
|
|
||||||
[JsonExtensionData] public Dictionary<string, JsonElement> data { get; set; }
|
[JsonExtensionData]
|
||||||
|
public Dictionary<string, JsonElement> data { get; set; }
|
||||||
|
|
||||||
public bool GetProperty<T>(string key, JsonSerializerOptions options, out T t)
|
public bool GetProperty<T>(string key, JsonSerializerOptions options, out T t)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -591,12 +591,33 @@ namespace Server
|
||||||
|
|
||||||
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic |
|
const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic |
|
||||||
BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
||||||
if (type.GetMethod("Serialize", bindingFlags) == null)
|
|
||||||
|
var hasSerializeMethod = false;
|
||||||
|
var hasDeserializeMethod = false;
|
||||||
|
|
||||||
|
foreach (var method in type.GetMethods(bindingFlags))
|
||||||
|
{
|
||||||
|
if (method.Name == "Serialize")
|
||||||
|
{
|
||||||
|
hasSerializeMethod = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method.Name == "Deserialize")
|
||||||
|
{
|
||||||
|
var parameters = method.GetParameters();
|
||||||
|
if (parameters.Length == 1 && parameters[0].ParameterType == typeof(IGenericReader))
|
||||||
|
{
|
||||||
|
hasDeserializeMethod = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSerializeMethod)
|
||||||
{
|
{
|
||||||
errors.AppendLine(" - No Serialize() method");
|
errors.AppendLine(" - No Serialize() method");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type.GetMethod("Deserialize", bindingFlags) == null)
|
if (!hasDeserializeMethod)
|
||||||
{
|
{
|
||||||
errors.AppendLine(" - No Deserialize() method");
|
errors.AppendLine(" - No Deserialize() method");
|
||||||
}
|
}
|
||||||
|
|
@ -608,6 +629,10 @@ namespace Server
|
||||||
Utility.PopColor();
|
Utility.PopColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (AmbiguousMatchException e)
|
||||||
|
{
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
Console.WriteLine("Warning: Exception in serialization verification of type {0}", type);
|
Console.WriteLine("Warning: Exception in serialization verification of type {0}", type);
|
||||||
|
|
|
||||||
|
|
@ -179,8 +179,6 @@ namespace Server
|
||||||
|
|
||||||
public static List<Region> Regions { get; } = new();
|
public static List<Region> Regions { get; } = new();
|
||||||
|
|
||||||
public static Type DefaultRegionType { get; set; } = typeof(Region);
|
|
||||||
|
|
||||||
public static TimeSpan StaffLogoutDelay { get; set; } = TimeSpan.Zero;
|
public static TimeSpan StaffLogoutDelay { get; set; } = TimeSpan.Zero;
|
||||||
|
|
||||||
public static TimeSpan DefaultLogoutDelay { get; set; } = TimeSpan.FromMinutes(5.0);
|
public static TimeSpan DefaultLogoutDelay { get; set; } = TimeSpan.FromMinutes(5.0);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Server.Buffers;
|
||||||
using Server.Gumps;
|
using Server.Gumps;
|
||||||
using Server.Json;
|
using Server.Json;
|
||||||
using Server.Mobiles;
|
using Server.Mobiles;
|
||||||
|
|
@ -31,12 +32,12 @@ namespace Server.Regions
|
||||||
|
|
||||||
public BaseRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
public BaseRegion(DynamicJson json, JsonSerializerOptions options) : base(json, options)
|
||||||
{
|
{
|
||||||
if (json.data.TryGetValue("rune", out var runeName))
|
if (json.GetProperty<string>("rune", options, out var runeName))
|
||||||
{
|
{
|
||||||
RuneName = runeName.GetString();
|
RuneName = runeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
NoLogoutDelay = json.data.TryGetValue("logoutDelay", out var logoutDelay) && !logoutDelay.GetBoolean();
|
NoLogoutDelay = json.GetProperty<bool>("logoutDelay", options, out var logoutDelay) && !logoutDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ExcludeFromParentSpawns { get; set; }
|
public bool ExcludeFromParentSpawns { get; set; }
|
||||||
|
|
@ -56,11 +57,6 @@ namespace Server.Regions
|
||||||
|
|
||||||
public bool NoLogoutDelay { get; set; }
|
public bool NoLogoutDelay { get; set; }
|
||||||
|
|
||||||
public static void Configure()
|
|
||||||
{
|
|
||||||
DefaultRegionType = typeof(BaseRegion);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetRuneNameFor(Region region)
|
public static string GetRuneNameFor(Region region)
|
||||||
{
|
{
|
||||||
while (region != null)
|
while (region != null)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue