Updates teleporter generator (#105)

This commit is contained in:
Kamron Batman 2020-04-12 23:04:44 -07:00 committed by GitHub
parent 141ec11330
commit be0c33bc8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 15228 additions and 1440 deletions

View file

@ -0,0 +1,15 @@
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)
=> Map.Parse(reader.GetString());
public override void Write(Utf8JsonWriter writer, Map value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.Name);
}
}

View file

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Server.Json
{
public class Point3dConverter : JsonConverter<Point3D>
{
public override Point3D Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.StartArray)
throw new JsonException("Point3d must be an array of x, y, z");
var data = new int[3];
int count = 0;
while (true)
{
reader.Read();
if (reader.TokenType == JsonTokenType.EndArray)
break;
if (reader.TokenType == JsonTokenType.Number)
{
if (count < 3)
data[count] = reader.GetInt32();
count++;
}
}
if (count < 2 || count > 3)
throw new JsonException("Point3d must be an array of x, y, z");
return new Point3D(data[0], data[1], data[2]);
}
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();
}
}
}

View file

@ -294,8 +294,6 @@ namespace Server.Network
return -1;
}
Console.WriteLine("Processing Packet... {0:X}", packetId);
if (!ns.Seeded)
{
if (packetId == 0xEF)