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:
parent
8603e31023
commit
369a27b800
47 changed files with 1780 additions and 1569 deletions
|
|
@ -5,7 +5,7 @@ using Server.Misc;
|
|||
|
||||
namespace Server
|
||||
{
|
||||
public class AccessRestrictions
|
||||
public static class AccessRestrictions
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
|
|
@ -16,7 +16,7 @@ namespace Server
|
|||
{
|
||||
try
|
||||
{
|
||||
var ip = ((IPEndPoint)e.Context.RemoteEndPoint).Address;
|
||||
var ip = ((IPEndPoint)e.Connection.RemoteEndPoint).Address;
|
||||
|
||||
if (Firewall.IsBlocked(ip))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ namespace Server.Misc
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Client: {0}: Deleting character {1} (0x{2:X})", state, index, m.Serial.Value);
|
||||
state.WriteConsole("Deleting character {0} (0x{1:X})", index, m.Serial.Value);
|
||||
|
||||
acct.Comments.Add(new AccountComment("System", $"Character #{index + 1} {m} deleted by {state}"));
|
||||
|
||||
|
|
|
|||
|
|
@ -73,15 +73,15 @@ namespace Server.Engines.Chat
|
|||
return;
|
||||
}
|
||||
|
||||
var lang = reader.ReadStringSafe(4);
|
||||
var lang = reader.ReadAsciiSafe(4);
|
||||
int actionID = reader.ReadInt16();
|
||||
var param = reader.ReadUnicodeString();
|
||||
var param = reader.ReadBigUniSafe();
|
||||
|
||||
var handler = ChatActionHandlers.GetHandler(actionID);
|
||||
|
||||
if (handler == null)
|
||||
{
|
||||
Console.WriteLine("Client: {0}: Unknown chat action 0x{1:X}: {2}", state, actionID, param);
|
||||
state.WriteConsole("Unknown chat action 0x{0:X}: {1}", actionID, param);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -295,7 +295,12 @@ namespace Server.Items
|
|||
{
|
||||
var door = doors[i];
|
||||
|
||||
if (door?.Open == true)
|
||||
if (door == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (door.Open)
|
||||
{
|
||||
return AddonFitResult.DoorsNotClosed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -378,8 +378,8 @@ namespace Server.Items
|
|||
|
||||
reader.Seek(4, SeekOrigin.Current); // Skip flags and page count
|
||||
|
||||
var title = reader.ReadStringSafe(60);
|
||||
var author = reader.ReadStringSafe(30);
|
||||
var title = reader.ReadAsciiSafe(60);
|
||||
var author = reader.ReadAsciiSafe(30);
|
||||
|
||||
book.Title = Utility.FixHtml(title);
|
||||
book.Author = Utility.FixHtml(author);
|
||||
|
|
@ -404,7 +404,7 @@ namespace Server.Items
|
|||
return;
|
||||
}
|
||||
|
||||
var title = reader.ReadUTF8StringSafe(titleLength);
|
||||
var title = reader.ReadUTF8Safe(titleLength);
|
||||
|
||||
int authorLength = reader.ReadUInt16();
|
||||
|
||||
|
|
@ -413,7 +413,7 @@ namespace Server.Items
|
|||
return;
|
||||
}
|
||||
|
||||
var author = reader.ReadUTF8StringSafe(authorLength);
|
||||
var author = reader.ReadUTF8Safe(authorLength);
|
||||
|
||||
book.Title = Utility.FixHtml(title);
|
||||
book.Author = Utility.FixHtml(author);
|
||||
|
|
@ -452,7 +452,7 @@ namespace Server.Items
|
|||
|
||||
for (var j = 0; j < lineCount; ++j)
|
||||
{
|
||||
if ((lines[j] = reader.ReadUTF8StringSafe()).Length >= 80)
|
||||
if ((lines[j] = reader.ReadUTF8Safe()).Length >= 80)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ namespace Server.Engines.Mahjong
|
|||
RegisterSubCommand(0x18, MoveDealerIndicator);
|
||||
}
|
||||
|
||||
public static void OnPacket(NetState state, PacketReader reader)
|
||||
public static void OnPacket(NetState state,PacketReader reader)
|
||||
{
|
||||
var game = World.FindItem(reader.ReadUInt32()) as MahjongGame;
|
||||
|
||||
|
|
|
|||
|
|
@ -315,7 +315,7 @@ namespace Server.Items
|
|||
}
|
||||
}
|
||||
|
||||
var subject = reader.ReadUTF8StringSafe(reader.ReadByte());
|
||||
var subject = reader.ReadUTF8Safe(reader.ReadByte());
|
||||
|
||||
if (subject.Length == 0)
|
||||
{
|
||||
|
|
@ -331,7 +331,7 @@ namespace Server.Items
|
|||
|
||||
for (var i = 0; i < lines.Length; ++i)
|
||||
{
|
||||
lines[i] = reader.ReadUTF8StringSafe(reader.ReadByte());
|
||||
lines[i] = reader.ReadUTF8Safe(reader.ReadByte());
|
||||
}
|
||||
|
||||
board.PostMessage(from, thread, subject, lines);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -5634,105 +5634,90 @@ namespace Server.Mobiles
|
|||
|
||||
protected override void OnTick()
|
||||
{
|
||||
if (DateTime.UtcNow >= m_NextHourlyCheck)
|
||||
{
|
||||
m_NextHourlyCheck = DateTime.UtcNow + TimeSpan.FromHours(1.0);
|
||||
}
|
||||
else
|
||||
if (DateTime.UtcNow < m_NextHourlyCheck)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_NextHourlyCheck = DateTime.UtcNow + TimeSpan.FromHours(1.0);
|
||||
|
||||
var toRelease = new List<BaseCreature>();
|
||||
|
||||
// added array for wild creatures in house regions to be removed
|
||||
var toRemove = new List<BaseCreature>();
|
||||
|
||||
Parallel.ForEach(
|
||||
World.Mobiles.Values,
|
||||
m =>
|
||||
foreach (var m in World.Mobiles.Values)
|
||||
{
|
||||
if (!(m is BaseCreature c))
|
||||
{
|
||||
if (!(m is BaseCreature c))
|
||||
{
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c is BaseMount mount && mount.Rider != null)
|
||||
{
|
||||
mount.OwnerAbandonTime = DateTime.MinValue;
|
||||
return;
|
||||
}
|
||||
if (c is BaseMount mount && mount.Rider != null)
|
||||
{
|
||||
mount.OwnerAbandonTime = DateTime.MinValue;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c.IsDeadPet)
|
||||
{
|
||||
var owner = c.ControlMaster;
|
||||
if (c.IsDeadPet)
|
||||
{
|
||||
var owner = c.ControlMaster;
|
||||
|
||||
if (!c.IsStabled && (owner?.Deleted != false || owner.Map != c.Map ||
|
||||
!owner.InRange(c, 12) || !c.CanSee(owner) || !c.InLOS(owner)))
|
||||
if (!c.IsStabled && (owner?.Deleted != false || owner.Map != c.Map ||
|
||||
!owner.InRange(c, 12) || !c.CanSee(owner) || !c.InLOS(owner)))
|
||||
{
|
||||
if (c.OwnerAbandonTime == DateTime.MinValue)
|
||||
{
|
||||
if (c.OwnerAbandonTime == DateTime.MinValue)
|
||||
{
|
||||
c.OwnerAbandonTime = DateTime.UtcNow;
|
||||
}
|
||||
else if (c.OwnerAbandonTime + c.BondingAbandonDelay <= DateTime.UtcNow)
|
||||
{
|
||||
lock (toRemove)
|
||||
{
|
||||
toRemove.Add(c);
|
||||
}
|
||||
}
|
||||
c.OwnerAbandonTime = DateTime.UtcNow;
|
||||
}
|
||||
else
|
||||
else if (c.OwnerAbandonTime + c.BondingAbandonDelay <= DateTime.UtcNow)
|
||||
{
|
||||
c.OwnerAbandonTime = DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
else if (c.Controlled && c.Commandable)
|
||||
{
|
||||
c.OwnerAbandonTime = DateTime.MinValue;
|
||||
|
||||
if (c.Map != Map.Internal)
|
||||
{
|
||||
c.Loyalty -= BaseCreature.MaxLoyalty / 10;
|
||||
|
||||
if (c.Loyalty < BaseCreature.MaxLoyalty / 10)
|
||||
{
|
||||
c.Say(1043270, c.Name); // * ~1_NAME~ looks around desperately *
|
||||
c.PlaySound(c.GetIdleSound());
|
||||
}
|
||||
|
||||
if (c.Loyalty <= 0)
|
||||
{
|
||||
lock (toRelease)
|
||||
{
|
||||
toRelease.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// added lines to check if a wild creature in a house region has to be removed or not
|
||||
if (!c.Controlled && !c.IsStabled && (c.Region.IsPartOf<HouseRegion>() && c.CanBeDamaged() ||
|
||||
c.RemoveIfUntamed && c.Spawner == null))
|
||||
{
|
||||
c.RemoveStep++;
|
||||
|
||||
if (c.RemoveStep >= 20)
|
||||
{
|
||||
lock (toRemove)
|
||||
{
|
||||
toRemove.Add(c);
|
||||
}
|
||||
toRemove.Add(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c.RemoveStep = 0;
|
||||
c.OwnerAbandonTime = DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
);
|
||||
else if (c.Controlled && c.Commandable)
|
||||
{
|
||||
c.OwnerAbandonTime = DateTime.MinValue;
|
||||
|
||||
if (c.Map != Map.Internal)
|
||||
{
|
||||
c.Loyalty -= BaseCreature.MaxLoyalty / 10;
|
||||
|
||||
if (c.Loyalty < BaseCreature.MaxLoyalty / 10)
|
||||
{
|
||||
c.Say(1043270, c.Name); // * ~1_NAME~ looks around desperately *
|
||||
c.PlaySound(c.GetIdleSound());
|
||||
}
|
||||
|
||||
if (c.Loyalty <= 0)
|
||||
{
|
||||
toRelease.Add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// added lines to check if a wild creature in a house region has to be removed or not
|
||||
if (!c.Controlled && !c.IsStabled && (c.Region.IsPartOf<HouseRegion>() && c.CanBeDamaged() ||
|
||||
c.RemoveIfUntamed && c.Spawner == null))
|
||||
{
|
||||
c.RemoveStep++;
|
||||
|
||||
if (c.RemoveStep >= 20)
|
||||
{
|
||||
toRemove.Add(c);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
c.RemoveStep = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Parallelize this
|
||||
foreach (var c in toRelease)
|
||||
{
|
||||
c.Say(1043255, c.Name); // ~1_NAME~ appears to have decided that is better off without a master!
|
||||
|
|
|
|||
|
|
@ -373,8 +373,7 @@ namespace Server.Multis
|
|||
4 => new GenericHouseDoor(facing, 0x6B5, 0xEA, 0xF1),
|
||||
5 => new GenericHouseDoor(facing, 0x6C5, 0xEC, 0xF3),
|
||||
6 => new GenericHouseDoor(facing, 0x6D5, 0xEA, 0xF1),
|
||||
7 => new GenericHouseDoor(facing, 0x6E5, 0xEA, 0xF1),
|
||||
_ => door
|
||||
_ => new GenericHouseDoor(facing, 0x6E5, 0xEA, 0xF1),
|
||||
};
|
||||
}
|
||||
else if (itemID >= 0x314 && itemID < 0x364)
|
||||
|
|
@ -484,8 +483,7 @@ namespace Server.Multis
|
|||
door = type switch
|
||||
{
|
||||
0 => new GenericHouseDoor(facing, 0x367B, 0xED, 0xF4),
|
||||
1 => new GenericHouseDoor(facing, 0x368B, 0xEC, 0x3E7),
|
||||
_ => door
|
||||
_ => new GenericHouseDoor(facing, 0x368B, 0xEC, 0x3E7),
|
||||
};
|
||||
}
|
||||
else if (itemID >= 0x409B && itemID < 0x40A3)
|
||||
|
|
@ -1978,14 +1976,9 @@ namespace Server.Multis
|
|||
|
||||
public void OnRevised()
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
Revision = ++Foundation.LastRevision;
|
||||
|
||||
m_PacketCache?.Release();
|
||||
|
||||
m_PacketCache = null;
|
||||
}
|
||||
Revision = ++Foundation.LastRevision;
|
||||
m_PacketCache?.Release();
|
||||
m_PacketCache = null;
|
||||
}
|
||||
|
||||
public void SendGeneralInfoTo(NetState state)
|
||||
|
|
@ -1995,19 +1988,18 @@ namespace Server.Multis
|
|||
|
||||
public void SendDetailedInfoTo(NetState state)
|
||||
{
|
||||
if (state != null)
|
||||
if (state == null)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (m_PacketCache == null)
|
||||
{
|
||||
DesignStateDetailed.SendDetails(state, Foundation, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Send(m_PacketCache);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_PacketCache == null)
|
||||
{
|
||||
DesignStateDetailed.SendDetails(state, Foundation, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
state.Send(m_PacketCache);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2444,22 +2436,8 @@ namespace Server.Multis
|
|||
{
|
||||
public const int MaxItemsPerStairBuffer = 750;
|
||||
|
||||
private static readonly ConcurrentQueue<SendQueueEntry> m_SendQueue;
|
||||
private static readonly AutoResetEvent m_Sync;
|
||||
|
||||
private readonly byte[][] m_PlaneBuffers;
|
||||
|
||||
private readonly bool[] m_PlaneUsed = new bool[9];
|
||||
private readonly byte[] m_PrimBuffer = new byte[4];
|
||||
private readonly byte[][] m_StairBuffers;
|
||||
|
||||
static DesignStateDetailed()
|
||||
{
|
||||
m_SendQueue = new ConcurrentQueue<SendQueueEntry>();
|
||||
m_Sync = new AutoResetEvent(false);
|
||||
|
||||
Task.Run(ProcessCompression);
|
||||
}
|
||||
|
||||
public DesignStateDetailed(uint serial, int revision, int xMin, int yMin, int xMax, int yMax, MultiTileEntry[] tiles)
|
||||
: base(0xD8)
|
||||
|
|
@ -2479,26 +2457,26 @@ namespace Server.Multis
|
|||
var width = xMax - xMin + 1;
|
||||
var height = yMax - yMin + 1;
|
||||
|
||||
m_PlaneBuffers = new byte[9][];
|
||||
var planeBuffers = new byte[9][];
|
||||
|
||||
for (var i = 0; i < m_PlaneBuffers.Length; ++i)
|
||||
for (var i = 0; i < planeBuffers.Length; ++i)
|
||||
{
|
||||
m_PlaneBuffers[i] = ArrayPool<byte>.Shared.Rent(0x400);
|
||||
planeBuffers[i] = ArrayPool<byte>.Shared.Rent(0x400);
|
||||
}
|
||||
|
||||
m_StairBuffers = new byte[6][];
|
||||
var stairBuffers = new byte[6][];
|
||||
|
||||
for (var i = 0; i < m_StairBuffers.Length; ++i)
|
||||
for (var i = 0; i < stairBuffers.Length; ++i)
|
||||
{
|
||||
m_StairBuffers[i] = ArrayPool<byte>.Shared.Rent(MaxItemsPerStairBuffer * 5);
|
||||
stairBuffers[i] = ArrayPool<byte>.Shared.Rent(MaxItemsPerStairBuffer * 5);
|
||||
}
|
||||
|
||||
Clear(m_PlaneBuffers[0], width * height * 2);
|
||||
Clear(planeBuffers[0], width * height * 2);
|
||||
|
||||
for (var i = 0; i < 4; ++i)
|
||||
{
|
||||
Clear(m_PlaneBuffers[1 + i], (width - 1) * (height - 2) * 2);
|
||||
Clear(m_PlaneBuffers[5 + i], width * (height - 1) * 2);
|
||||
Clear(planeBuffers[1 + i], (width - 1) * (height - 2) * 2);
|
||||
Clear(planeBuffers[5 + i], width * (height - 1) * 2);
|
||||
}
|
||||
|
||||
var totalStairsUsed = 0;
|
||||
|
|
@ -2532,7 +2510,7 @@ namespace Server.Multis
|
|||
default:
|
||||
{
|
||||
var stairBufferIndex = totalStairsUsed / MaxItemsPerStairBuffer;
|
||||
var stairBuffer = m_StairBuffers[stairBufferIndex];
|
||||
var stairBuffer = stairBuffers[stairBufferIndex];
|
||||
|
||||
var byteIndex = totalStairsUsed % MaxItemsPerStairBuffer * 5;
|
||||
|
||||
|
|
@ -2541,7 +2519,7 @@ namespace Server.Multis
|
|||
|
||||
stairBuffer[byteIndex++] = (byte)mte.OffsetX;
|
||||
stairBuffer[byteIndex++] = (byte)mte.OffsetY;
|
||||
stairBuffer[byteIndex++] = (byte)mte.OffsetZ;
|
||||
stairBuffer[byteIndex] = (byte)mte.OffsetZ;
|
||||
|
||||
++totalStairsUsed;
|
||||
|
||||
|
|
@ -2570,7 +2548,7 @@ namespace Server.Multis
|
|||
if (x < 0 || y < 0 || y >= size || index + 1 >= 0x400)
|
||||
{
|
||||
var stairBufferIndex = totalStairsUsed / MaxItemsPerStairBuffer;
|
||||
var stairBuffer = m_StairBuffers[stairBufferIndex];
|
||||
var stairBuffer = stairBuffers[stairBufferIndex];
|
||||
|
||||
var byteIndex = totalStairsUsed % MaxItemsPerStairBuffer * 5;
|
||||
|
||||
|
|
@ -2579,27 +2557,27 @@ namespace Server.Multis
|
|||
|
||||
stairBuffer[byteIndex++] = (byte)mte.OffsetX;
|
||||
stairBuffer[byteIndex++] = (byte)mte.OffsetY;
|
||||
stairBuffer[byteIndex++] = (byte)mte.OffsetZ;
|
||||
stairBuffer[byteIndex] = (byte)mte.OffsetZ;
|
||||
|
||||
++totalStairsUsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_PlaneUsed[plane] = true;
|
||||
m_PlaneBuffers[plane][index] = (byte)(mte.ItemId >> 8);
|
||||
m_PlaneBuffers[plane][index + 1] = (byte)mte.ItemId;
|
||||
planeBuffers[plane][index] = (byte)(mte.ItemId >> 8);
|
||||
planeBuffers[plane][index + 1] = (byte)mte.ItemId;
|
||||
}
|
||||
}
|
||||
|
||||
var planeCount = 0;
|
||||
|
||||
var m_DeflatedBuffer = ArrayPool<byte>.Shared.Rent(0x2000);
|
||||
var deflatedBuffer = ArrayPool<byte>.Shared.Rent(0x2000);
|
||||
|
||||
for (var i = 0; i < m_PlaneBuffers.Length; ++i)
|
||||
for (var i = 0; i < planeBuffers.Length; ++i)
|
||||
{
|
||||
if (!m_PlaneUsed[i])
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(m_PlaneBuffers[i]);
|
||||
ArrayPool<byte>.Shared.Return(planeBuffers[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -2620,11 +2598,11 @@ namespace Server.Multis
|
|||
size = width * (height - 1) * 2;
|
||||
}
|
||||
|
||||
var inflatedBuffer = m_PlaneBuffers[i];
|
||||
var inflatedBuffer = planeBuffers[i];
|
||||
|
||||
var deflatedLength = m_DeflatedBuffer.Length;
|
||||
var deflatedLength = deflatedBuffer.Length;
|
||||
var ce = Zlib.Pack(
|
||||
m_DeflatedBuffer,
|
||||
deflatedBuffer,
|
||||
ref deflatedLength,
|
||||
inflatedBuffer,
|
||||
size,
|
||||
|
|
@ -2642,7 +2620,7 @@ namespace Server.Multis
|
|||
Write((byte)size);
|
||||
Write((byte)deflatedLength);
|
||||
Write((byte)(((size >> 4) & 0xF0) | ((deflatedLength >> 8) & 0xF)));
|
||||
Write(m_DeflatedBuffer, 0, deflatedLength);
|
||||
Write(deflatedBuffer, 0, deflatedLength);
|
||||
|
||||
totalLength += 4 + deflatedLength;
|
||||
ArrayPool<byte>.Shared.Return(inflatedBuffer);
|
||||
|
|
@ -2663,11 +2641,11 @@ namespace Server.Multis
|
|||
|
||||
var size = count * 5;
|
||||
|
||||
var inflatedBuffer = m_StairBuffers[i];
|
||||
var inflatedBuffer = stairBuffers[i];
|
||||
|
||||
var deflatedLength = m_DeflatedBuffer.Length;
|
||||
var deflatedLength = deflatedBuffer.Length;
|
||||
var ce = Zlib.Pack(
|
||||
m_DeflatedBuffer,
|
||||
deflatedBuffer,
|
||||
ref deflatedLength,
|
||||
inflatedBuffer,
|
||||
size,
|
||||
|
|
@ -2685,17 +2663,17 @@ namespace Server.Multis
|
|||
Write((byte)size);
|
||||
Write((byte)deflatedLength);
|
||||
Write((byte)(((size >> 4) & 0xF0) | ((deflatedLength >> 8) & 0xF)));
|
||||
Write(m_DeflatedBuffer, 0, deflatedLength);
|
||||
Write(deflatedBuffer, 0, deflatedLength);
|
||||
|
||||
totalLength += 4 + deflatedLength;
|
||||
}
|
||||
|
||||
for (var i = 0; i < m_StairBuffers.Length; ++i)
|
||||
for (var i = 0; i < stairBuffers.Length; ++i)
|
||||
{
|
||||
ArrayPool<byte>.Shared.Return(m_StairBuffers[i]);
|
||||
ArrayPool<byte>.Shared.Return(stairBuffers[i]);
|
||||
}
|
||||
|
||||
ArrayPool<byte>.Shared.Return(m_DeflatedBuffer);
|
||||
ArrayPool<byte>.Shared.Return(deflatedBuffer);
|
||||
|
||||
Stream.Seek(15, SeekOrigin.Begin);
|
||||
|
||||
|
|
@ -2749,106 +2727,28 @@ namespace Server.Multis
|
|||
}
|
||||
}
|
||||
|
||||
public static void ProcessCompression()
|
||||
{
|
||||
while (!Core.Closing)
|
||||
{
|
||||
m_Sync.WaitOne();
|
||||
|
||||
var count = m_SendQueue.Count;
|
||||
|
||||
while (count > 0 && m_SendQueue.TryDequeue(out var sqe))
|
||||
{
|
||||
try
|
||||
{
|
||||
Packet p;
|
||||
|
||||
lock (sqe.m_Root)
|
||||
{
|
||||
p = sqe.m_Root.PacketCache;
|
||||
}
|
||||
|
||||
if (p == null)
|
||||
{
|
||||
p = new DesignStateDetailed(
|
||||
sqe.m_Serial,
|
||||
sqe.m_Revision,
|
||||
sqe.m_xMin,
|
||||
sqe.m_yMin,
|
||||
sqe.m_xMax,
|
||||
sqe.m_yMax,
|
||||
sqe.m_Tiles
|
||||
);
|
||||
p.SetStatic();
|
||||
|
||||
lock (sqe.m_Root)
|
||||
{
|
||||
if (sqe.m_Revision == sqe.m_Root.Revision)
|
||||
{
|
||||
sqe.m_Root.PacketCache = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sqe.m_NetState.Send(p);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
try
|
||||
{
|
||||
using var op = new StreamWriter("dsd_exceptions.txt", true);
|
||||
op.WriteLine(e);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
count = m_SendQueue.Count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendDetails(NetState ns, HouseFoundation house, DesignState state)
|
||||
{
|
||||
m_SendQueue.Enqueue(new SendQueueEntry(ns, house, state));
|
||||
var p = state.PacketCache;
|
||||
|
||||
m_Sync.Set();
|
||||
}
|
||||
|
||||
private class SendQueueEntry
|
||||
{
|
||||
public readonly NetState m_NetState;
|
||||
public readonly int m_Revision;
|
||||
public readonly DesignState m_Root;
|
||||
public readonly uint m_Serial;
|
||||
public readonly MultiTileEntry[] m_Tiles;
|
||||
public readonly int m_xMax;
|
||||
public readonly int m_xMin;
|
||||
public readonly int m_yMax;
|
||||
public readonly int m_yMin;
|
||||
|
||||
public SendQueueEntry(NetState ns, HouseFoundation foundation, DesignState state)
|
||||
if (p == null)
|
||||
{
|
||||
m_NetState = ns;
|
||||
m_Serial = foundation.Serial;
|
||||
m_Revision = state.Revision;
|
||||
m_Root = state;
|
||||
|
||||
var mcl = state.Components;
|
||||
p = new DesignStateDetailed(
|
||||
house.Serial,
|
||||
state.Revision,
|
||||
mcl.Min.X,
|
||||
mcl.Min.Y,
|
||||
mcl.Max.X,
|
||||
mcl.Max.Y,
|
||||
mcl.List
|
||||
);
|
||||
|
||||
m_xMin = mcl.Min.X;
|
||||
m_yMin = mcl.Min.Y;
|
||||
m_xMax = mcl.Max.X;
|
||||
m_yMax = mcl.Max.Y;
|
||||
|
||||
m_Tiles = mcl.List;
|
||||
p.SetStatic();
|
||||
state.PacketCache = p;
|
||||
}
|
||||
|
||||
ns.Send(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,19 +12,10 @@
|
|||
<Delete Files="..\..\Distribution\Assemblies\Argon2.Bindings.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\BouncyCastle.Crypto.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\MailKit.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.AspNetCore.Connections.Abstractions.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.AspNetCore.Http.Features.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.Extensions.Configuration.Abstractions.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.Extensions.DependencyInjection.Abstractions.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.Extensions.FileProviders.Abstractions.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.Extensions.Hosting.Abstractions.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.Extensions.Logging.Abstractions.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\Microsoft.Extensions.Primitives.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\MimeKit.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\$(AssemblyName).dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\$(AssemblyName).deps.json" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\$(AssemblyName).pdb" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\System.IO.Pipelines.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\libargon2.dll" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\libargon2.dylib" ContinueOnError="true" />
|
||||
<Delete Files="..\..\Distribution\Assemblies\libargon2.so" ContinueOnError="true" />
|
||||
|
|
@ -37,12 +28,6 @@
|
|||
<ProjectReference Include="..\Server\Server.csproj" Private="false" PrivateAssets="All" IncludeAssets="None">
|
||||
<IncludeInPackage>false</IncludeInPackage>
|
||||
</ProjectReference>
|
||||
<!-- Transient package version resolution -->
|
||||
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="3.1.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.5" />
|
||||
<!-- Direct packages -->
|
||||
<PackageReference Include="MailKit" Version="2.8.0" />
|
||||
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.31">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue