Cleanup/Housekeeping (#242)

This commit is contained in:
Kamron Batman 2020-09-12 15:31:21 -07:00 committed by GitHub
parent 90ede0659f
commit 741e8d8300
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
228 changed files with 6292 additions and 2690 deletions

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: IPEndPointConverter.cs *
* *
@ -25,7 +25,9 @@ namespace Server.Json
public override IPEndPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (IPEndPoint.TryParse(reader.GetString(), out var ipep))
{
return ipep;
}
throw new JsonException("IPEndPoint must be in the correct format");
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: IPEndPointConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: MapConverter.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: MapConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: NullableStructSerializer.cs *
* *
@ -25,9 +25,13 @@ namespace System.Text.Json.Serialization
public override void Write(Utf8JsonWriter writer, TStruct? value, JsonSerializerOptions options)
{
if (value == null)
{
writer.WriteNullValue();
}
else
{
JsonSerializer.Serialize(writer, value.Value, options);
}
}
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: NullableStructSerializerFactory.cs *
* *
@ -20,7 +20,9 @@ namespace System.Text.Json.Serialization
public override bool CanConvert(Type typeToConvert)
{
if (!typeToConvert.IsGenericType || typeToConvert.GetGenericTypeDefinition() != typeof(Nullable<>))
{
return false;
}
var structType = typeToConvert.GenericTypeArguments[0];
return !structType.IsPrimitive && structType.Namespace?.StartsWith(nameof(System)) != true && !structType.IsEnum;

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Point2DConverter.cs *
* *
@ -30,19 +30,25 @@ namespace Server.Json
{
reader.Read();
if (reader.TokenType == JsonTokenType.EndArray)
{
break;
}
if (reader.TokenType == JsonTokenType.Number)
{
if (count < 2)
{
data[count] = reader.GetInt32();
}
count++;
}
}
if (count > 2)
{
throw new JsonException("Point2D must be an array of x, y");
}
return new Point2D(data[0], data[1]);
}
@ -55,10 +61,14 @@ namespace Server.Json
{
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();
@ -72,7 +82,9 @@ namespace Server.Json
reader.Read();
if (reader.TokenType != JsonTokenType.Number)
{
throw new JsonException($"Value for {key} must be a number");
}
data[i] = reader.GetInt32();
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Point2DConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Point3DConverter.cs *
* *
@ -30,19 +30,25 @@ namespace Server.Json
{
reader.Read();
if (reader.TokenType == JsonTokenType.EndArray)
{
break;
}
if (reader.TokenType == JsonTokenType.Number)
{
if (count < 3)
{
data[count] = reader.GetInt32();
}
count++;
}
}
if (count > 3)
{
throw new JsonException("Point3D must be an array of x, y, z");
}
return new Point3D(data[0], data[1], data[2]);
}
@ -55,10 +61,14 @@ namespace Server.Json
{
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();
@ -73,7 +83,9 @@ namespace Server.Json
reader.Read();
if (reader.TokenType != JsonTokenType.Number)
{
throw new JsonException($"Value for {key} must be a number");
}
data[i] = reader.GetInt32();
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Point3DConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Rectangle3DConverter.cs *
* *
@ -30,19 +30,25 @@ namespace Server.Json
{
reader.Read();
if (reader.TokenType == JsonTokenType.EndArray)
{
break;
}
if (reader.TokenType == JsonTokenType.Number)
{
if (count < 6)
{
data[count] = reader.GetInt32();
}
count++;
}
}
if (count > 6)
{
throw new JsonException("Rectangle3D must be an array of x, y, z, h, w, d");
}
return new Rectangle3D(data[0], data[1], data[2], data[3], data[4], data[5]);
}
@ -59,10 +65,14 @@ namespace Server.Json
{
reader.Read();
if (reader.TokenType == JsonTokenType.EndObject)
{
break;
}
if (reader.TokenType != JsonTokenType.PropertyName)
{
throw new JsonException("Invalid json structure for Rectangle3D object");
}
var key = reader.GetString();
@ -71,7 +81,9 @@ namespace Server.Json
if (key == "start" || key == "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;
@ -107,20 +119,31 @@ namespace Server.Json
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;
if (i == 2)
{
hasZ = true;
}
continue;
}
if (objType > -1 && objType != 1)
{
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 == 12 || i == 15) hasZ = true;
if (i == 12 || i == 15)
{
hasZ = true;
}
}
if (!hasZ)

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Rectangle3DConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: TimeSpanConverter.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: TimeSpanConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: TypeConverter.cs *
* *
@ -24,7 +24,9 @@ namespace Server.Json
public override Type Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.String)
{
throw new JsonException("The JSON value could not be converted to System.Type");
}
return AssemblyHandler.FindFirstTypeForName(reader.GetString());
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: TypeConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: WorldLocationConverter.cs *
* *
@ -32,14 +32,20 @@ namespace Server.Json
{
reader.Read();
if (reader.TokenType == JsonTokenType.EndArray)
{
break;
}
if (reader.TokenType == JsonTokenType.Number)
{
if (count < 3)
{
data[count] = reader.GetInt32();
}
else if (count == 3)
{
map = Map.Maps[reader.GetInt32()];
}
count++;
}
@ -52,7 +58,9 @@ namespace Server.Json
}
if (!hasMap || count < 3 || count > 4)
{
throw new JsonException("WorldLocation must be an array of x, y, z, and map");
}
return new WorldLocation(data[0], data[1], data[2], map);
}
@ -70,10 +78,14 @@ namespace Server.Json
{
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();
@ -88,17 +100,23 @@ namespace Server.Json
};
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();
@ -108,7 +126,9 @@ namespace Server.Json
if (i == 3)
{
if (hasXYZ)
{
throw new JsonException("WorldLocation must have loc or x, y, z, but not both");
}
hasLoc = true;
var loc = new Point3DConverter().Read(ref reader, typeof(Point3D), options);
@ -128,7 +148,9 @@ namespace Server.Json
}
if (!hasMap || count < 2)
{
throw new JsonException("WorldLocation must have an x, y, z, and map properties");
}
return new WorldLocation(data[0], data[1], data[2], map);
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: WorldLocationConverterFactory.cs *
* *

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: DynamicJson.cs *
* *
@ -41,7 +41,9 @@ namespace Server.Json
public bool GetEnumProperty<T>(string key, JsonSerializerOptions options, out T t) where T : struct, Enum
{
if (data.TryGetValue(key, out var el))
{
return Enum.TryParse(el.ToObject<string>(options), out t);
}
t = default;
return false;

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2020 - ModernUO Development Team *
* Copyright 2019-2020 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: JsonConfig.cs *
* *