Replacing Networking (#271)

- [X] Removing Kestrel & Libuv
- [X] Cleaning up NetState
- [X] Removing System.IO.Pipelines
- [X] Cleaning up packet reading
- [X] Adds a maximum of 5000 sockets (configurable) to prevent OOM
- [X] Replaces the AsyncState with a thread-safe wrapped boolean called NetworkState
- [X] Removes Parallel.ForEach (no perf gain)
- [X] Removes custom houses compression on another thread
- [X] Test high load scenarios

Bumps release version
This commit is contained in:
Kamron Batman 2020-10-20 20:55:19 -07:00 • committed by GitHub
parent 8603e31023
commit 369a27b800
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
47 changed files with 1780 additions and 1569 deletions

View file

@ -171,7 +171,7 @@ namespace Server.Misc
{
if (ns.Connection != null)
{
Console.WriteLine("Client: {0}: Disconnecting, bad version", ns);
ns.WriteConsole("Disconnecting, bad version");
ns.Dispose();
}
}

View file

@ -29,7 +29,8 @@ namespace Server.Misc
public static void OnFastWalk(FastWalkEventArgs e)
{
e.Blocked = true; // disallow this fastwalk
Console.WriteLine("Client: {0}: Fast movement detected (name={1})", e.NetState, e.NetState.Mobile.Name);
var state = e.NetState;
state.WriteConsole("Fast movement detected (name={0})", state.Mobile.Name);
}
}
}

View file

@ -163,7 +163,7 @@ namespace Server
info.ScreenDepth = reader.ReadInt32();
info.DXMajor = reader.ReadInt16();
info.DXMinor = reader.ReadInt16();
info.VCDescription = reader.ReadUnicodeStringLESafe(64);
info.VCDescription = reader.ReadLittleUniSafe(64);
info.VCVendorID = reader.ReadInt32();
info.VCDeviceID = reader.ReadInt32();
info.VCMemory = reader.ReadInt32();
@ -171,8 +171,8 @@ namespace Server
info.ClientsRunning = reader.ReadByte();
info.ClientsInstalled = reader.ReadByte();
info.PartialInstalled = reader.ReadByte();
info.Language = reader.ReadUnicodeStringLESafe(4);
info.Unknown = reader.ReadStringSafe(64);
info.Language = reader.ReadLittleUniSafe(4);
info.Unknown = reader.ReadAsciiSafe(64);
info.TimeReceived = DateTime.UtcNow;

View file

@ -1,65 +0,0 @@
using System;
namespace Server.Misc
{
public class HexStringConverter
{
public static readonly uint[] m_Lookup32Chars = CreateLookup32Chars();
private static uint[] CreateLookup32Chars()
{
var result = new uint[256];
for (var i = 0; i < 256; i++)
{
var s = i.ToString("X2");
if (BitConverter.IsLittleEndian)
{
result[i] = s[0] + ((uint)s[1] << 16);
}
else
{
result[i] = s[1] + ((uint)s[0] << 16);
}
}
return result;
}
public static unsafe string GetString(ReadOnlySpan<byte> bytes)
{
var result = new string((char)0, bytes.Length * 2);
fixed (char* resultP = result)
{
var resultP2 = (uint*)resultP;
for (var i = 0; i < bytes.Length; i++)
{
resultP2[i] = m_Lookup32Chars[bytes[i]];
}
}
return result;
}
public static unsafe void GetBytes(string str, Span<byte> bytes)
{
fixed (char* strP = str)
{
var i = 0;
var j = 0;
while (i < str.Length)
{
int chr1 = strP[i++];
int chr2 = strP[i++];
if (BitConverter.IsLittleEndian)
{
bytes[j++] = (byte)(((chr1 - (chr1 >= 65 ? 55 : 48)) << 4) | (chr2 - (chr2 >= 65 ? 55 : 48)));
}
else
{
bytes[j++] = (byte)((chr1 - (chr1 >= 65 ? 55 : 48)) | ((chr2 - (chr2 >= 65 ? 55 : 48)) << 4));
}
}
}
}
}
}

View file

@ -1,9 +1,8 @@
using System;
using Server.Network;
namespace Server.Misc
{
public class ProtocolExtensions
public static class ProtocolExtensions
{
private static readonly PacketHandler[] m_Handlers = new PacketHandler[0x100];
@ -17,15 +16,8 @@ namespace Server.Misc
m_Handlers[packetID] = new PacketHandler(packetID, 0, ingame, onReceive);
}
public static PacketHandler GetHandler(int packetID)
{
if (packetID >= 0 && packetID < m_Handlers.Length)
{
return m_Handlers[packetID];
}
return null;
}
public static PacketHandler GetHandler(int packetID) =>
packetID >= 0 && packetID < m_Handlers.Length ? m_Handlers[packetID] : null;
public static void DecodeBundledPacket(NetState state, PacketReader reader)
{
@ -37,9 +29,8 @@ namespace Server.Misc
{
if (ph.Ingame && state.Mobile == null)
{
Console.WriteLine(
"Client: {0}: Sent ingame packet (0xF0x{1:X2}) before having been attached to a mobile",
state,
state.WriteConsole(
"Sent ingame packet (0xF0x{0:X2}) before having been attached to a mobile",
packetID
);
state.Dispose();