Updates Packets & Randomizer (#43)
* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand. * WIP - Rewriting packets. * Cleanup and updates README * Converts more packets * Fixes header * Converts Effects packets. * Forgot the send command * Adds the start of containers packets. * Adds message packets with caching * Extends the send methods * Starts to add Acquire methods * Converted the packets * Cleanup * Cleanup * Adds more packets * Adds more packets * Fixes clearing arrays from pool. Adds Mobile Incoming * Converts more packets. * Moves more packets * Moves more packets * Test compression * Merges * Migrating to an idiomatic syntax that also supports compression, and proxying. * Optimize the stack alloc. Changes attributes * Converted container packets * Visual Studio doesn't auto save files. I am still getting used to subpar IDEs. * Adds static packet caching. Will profile later. Converts more packets * Fixes packets and changes how compression is configured * WIP - Adds basics for Gumps. Not finished though. * Fix file * Fixes formatting * Changed SpanWriter to be more idiomatic. * Fixes Span vs RawSpan and missing stackallocs * Converts over some more gumps * WIP - Deletes 32bit support. * Drops RDRand32 support. * Fixes gump compilation * Converting gump components * Removes old huffman compression function * Revert signature for backwards compatibility * WIP - Converting more gump components * Creates ArraySet for the strings. Updates AppendTo to reference that. * Converts the maining gump components * Cleans up gump components * Cleans up directives * Cleans up ArraySet and moves it. Adds null-coalescing-assignment * Cleanup, Target Packets, and C# 8 changes. * Removed OPL Packet * World packets * Fixing packet uses * Cleans up code. Fixes packet uses in various places. * More cleanup for packets * Code cleanup * Converts more packet uses and cleans up more code * More code cleanup * Finishes fixing the packets in Item * Updates secure trade packets * Updates core and gets it to compile. * Moved packets to scripts. Fixed account handler use of packets * Code cleanup * Updates chat packets * Code cleanuo * Adds party packets, but need to implement them. * Party packets WIP * Finishes party packets * Rearrange movement namespaces and classes * Finishes plant packets * Code Formatting * Fixes moving effects * Code cleanup, eliminates equipinfo * Adds more packets. Fixes bugs with various packets. * Finishes mahjon packets * Fixes mahjong packet * Code cleanup * Finishes mahjong packets * Adds Map packets * Add multifacet maps and charts * Cleans up some packets with UTF8 * Optimizes packets * Cleans up more packets. Moves the MessageHelper * Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets. * Updates protocol extensions packet receiver * Fixes a few bugs. Fixes a few more packets. * Code cleanup and fixing more packets * Fixes packet effects * Cleaned up more code * Buff Icon cleanup * Removed unused constructors * Code Cleanup. Adds BoatHS Packets * Moves house files. Updates house foundation packets. * Deployment cleanup * Fixes: * Code cleanup * More code cleanup * More code cleanup * Cleaned up BaseHouse * Enforces styling * Converts foreach to linq where possible. * Dont need that * Goals/Readme updates * Removes 32bit support at the highest level. Turns on HRT by default. * Code cleanup. Fixes extended features packet. * Fixes various bugs * Code cleanup * Code cleanup * Code cleanup. Fixes gump X/Y assignment. * Code cleanup using |= operator * More code cleanup * Cleanup * Fixes spacing issues. Thanks Visual Studio. You suck. * Compiler error * Fixes NPE from RunUO 2.7 * Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README * Fixes more packets. Stupid trailing nulls. * Fixes various bugs. * Fixes for gumps * Fixes more gump stuff. Going to split it out later since it is getting insane * Recoded the gump writing * WIP * *Added output path of scripts project to dev branch *Activated debugging in code
This commit is contained in:
parent
7aa8fd3df1
commit
179cb50557
588 changed files with 10843 additions and 16177 deletions
|
|
@ -26,14 +26,13 @@ using System.IO;
|
|||
using System.IO.Pipelines;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Server.Accounting;
|
||||
using Server.Diagnostics;
|
||||
using Server.Gumps;
|
||||
using Server.HuePickers;
|
||||
using Server.Items;
|
||||
using Server.Menus;
|
||||
using NetworkPackets = Server.Network.Packets;
|
||||
|
||||
namespace Server.Network
|
||||
{
|
||||
|
|
@ -93,7 +92,6 @@ namespace Server.Network
|
|||
{
|
||||
private string m_ToString;
|
||||
private ClientVersion m_Version;
|
||||
private SendQueue<Packet> m_SendQueue = new SendQueue<Packet>();
|
||||
|
||||
public DateTime ConnectedOn { get; }
|
||||
|
||||
|
|
@ -111,6 +109,8 @@ namespace Server.Network
|
|||
|
||||
private static AsyncState m_AsyncState = m_ResumeState;
|
||||
|
||||
public bool UseCompression { get; set; }
|
||||
|
||||
public IPacketEncoder PacketEncoder { get; set; }
|
||||
|
||||
public static NetStateCreatedCallback CreatedCallback { get; set; }
|
||||
|
|
@ -158,7 +158,8 @@ namespace Server.Network
|
|||
ProtocolChanges = ProtocolChanges.Version500a;
|
||||
else if (value >= m_Version407a)
|
||||
ProtocolChanges = ProtocolChanges.Version407a;
|
||||
else if (value >= m_Version400a) ProtocolChanges = ProtocolChanges.Version400a;
|
||||
else if (value >= m_Version400a)
|
||||
ProtocolChanges = ProtocolChanges.Version400a;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -272,9 +273,7 @@ namespace Server.Network
|
|||
|
||||
public Socket Socket { get; private set; }
|
||||
|
||||
public bool CompressionEnabled { get; set; }
|
||||
|
||||
public int Sequence { get; set; }
|
||||
public byte Sequence { get; set; }
|
||||
|
||||
public List<Gump> Gumps { get; private set; }
|
||||
|
||||
|
|
@ -300,8 +299,7 @@ namespace Server.Network
|
|||
|
||||
public void AddMenu(IMenu menu)
|
||||
{
|
||||
if (Menus == null)
|
||||
Menus = new List<IMenu>();
|
||||
Menus ??= new List<IMenu>();
|
||||
|
||||
if (Menus.Count < MenuCap)
|
||||
Menus.Add(menu);
|
||||
|
|
@ -329,8 +327,7 @@ namespace Server.Network
|
|||
|
||||
public void AddHuePicker(HuePicker huePicker)
|
||||
{
|
||||
if (HuePickers == null)
|
||||
HuePickers = new List<HuePicker>();
|
||||
HuePickers ??= new List<HuePicker>();
|
||||
|
||||
if (HuePickers.Count < HuePickerCap)
|
||||
HuePickers.Add(huePicker);
|
||||
|
|
@ -358,8 +355,7 @@ namespace Server.Network
|
|||
|
||||
public void AddGump(Gump gump)
|
||||
{
|
||||
if (Gumps == null)
|
||||
Gumps = new List<Gump>();
|
||||
Gumps ??= new List<Gump>();
|
||||
|
||||
if (Gumps.Count < GumpCap)
|
||||
Gumps.Add(gump);
|
||||
|
|
@ -387,8 +383,8 @@ namespace Server.Network
|
|||
|
||||
public void LaunchBrowser(string url)
|
||||
{
|
||||
Send(new MessageLocalized(Serial.MinusOne, -1, MessageType.Label, 0x35, 3, 501231, "", ""));
|
||||
Send(new LaunchBrowser(url));
|
||||
NetworkPackets.SendMessageLocalized(this, Serial.MinusOne, -1, MessageType.Label, 0x35, 3, 501231);
|
||||
NetworkPackets.SendLaunchBrowser(this, url);
|
||||
}
|
||||
|
||||
public CityInfo[] CityInfo { get; set; }
|
||||
|
|
@ -446,17 +442,6 @@ namespace Server.Network
|
|||
m_AsyncState = Interlocked.Exchange(ref m_AsyncState, m_ResumeState);
|
||||
}
|
||||
|
||||
public virtual void Send(Packet p)
|
||||
{
|
||||
if (Socket == null || BlockAllPackets)
|
||||
{
|
||||
p.OnSend();
|
||||
return;
|
||||
}
|
||||
|
||||
m_SendQueue.Enqueue(p);
|
||||
}
|
||||
|
||||
public bool CheckEncrypted(int packetID)
|
||||
{
|
||||
if (!SentFirstPacket && packetID != 0xF0 && packetID != 0xF1 && packetID != 0xCF && packetID != 0x80 &&
|
||||
|
|
@ -470,32 +455,35 @@ namespace Server.Network
|
|||
return false;
|
||||
}
|
||||
|
||||
private Pipe m_RecvdPipe;
|
||||
public Pipe RecvdPipe { get; private set; }
|
||||
public Pipe SendPipe { get; private set; }
|
||||
|
||||
private async Task Start(MessagePump pump)
|
||||
{
|
||||
m_RecvdPipe = new Pipe();
|
||||
RecvdPipe = new Pipe();
|
||||
SendPipe = new Pipe();
|
||||
Running = true;
|
||||
|
||||
await Task.WhenAll(ProcessSends(), ProcessRecvs(), HandlePackets(pump)).ConfigureAwait(false);
|
||||
await Task.WhenAll(HandlePackets(pump), ProcessSends(), ProcessRecvs());
|
||||
}
|
||||
|
||||
private async Task ProcessRecvs()
|
||||
{
|
||||
PipeWriter w = m_RecvdPipe.Writer;
|
||||
PipeWriter w = RecvdPipe.Writer;
|
||||
|
||||
while (true)
|
||||
while (!Core.Closing)
|
||||
{
|
||||
if (m_AsyncState.Paused)
|
||||
{
|
||||
await Timer.Pause(50).ConfigureAwait(false);
|
||||
Interlocked.Exchange(ref m_NextCheckActivity, Core.TickCount + 90000);
|
||||
await Timer.Pause(50);
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Memory<byte> memory = w.GetMemory();
|
||||
int bytesRead = await Socket.ReceiveAsync(memory, SocketFlags.None).ConfigureAwait(false);
|
||||
int bytesRead = await Socket.ReceiveAsync(memory, SocketFlags.None);
|
||||
if (bytesRead == 0)
|
||||
break;
|
||||
|
||||
|
|
@ -503,7 +491,7 @@ namespace Server.Network
|
|||
|
||||
w.Advance(bytesRead);
|
||||
|
||||
FlushResult result = await w.FlushAsync().ConfigureAwait(false);
|
||||
FlushResult result = await w.FlushAsync();
|
||||
if (result.IsCompleted || result.IsCanceled)
|
||||
break;
|
||||
}
|
||||
|
|
@ -517,7 +505,7 @@ namespace Server.Network
|
|||
Dispose();
|
||||
}
|
||||
|
||||
private async Task ProcessSends()
|
||||
private async Task HandlePackets(MessagePump pump)
|
||||
{
|
||||
while (true)
|
||||
try
|
||||
|
|
@ -526,26 +514,31 @@ namespace Server.Network
|
|||
if (p == null)
|
||||
break;
|
||||
|
||||
ReadOnlyMemory<byte> buffer = p.Compile(CompressionEnabled, out int length);
|
||||
long pos = PacketHandlers.ProcessPacket(pump, this, seq);
|
||||
|
||||
if (buffer.Length <= 0 || length <= 0)
|
||||
{
|
||||
p.OnSend();
|
||||
return;
|
||||
}
|
||||
if (pos <= 0)
|
||||
break;
|
||||
|
||||
buffer = buffer.Slice(0, length);
|
||||
pr.AdvanceTo(seq.GetPosition(pos, seq.Start));
|
||||
|
||||
PacketSendProfile prof = null;
|
||||
if (result.IsCompleted || result.IsCanceled)
|
||||
break;
|
||||
}
|
||||
|
||||
if (Core.Profiling)
|
||||
prof = PacketSendProfile.Acquire(p.GetType());
|
||||
pr.Complete();
|
||||
}
|
||||
|
||||
prof?.Start();
|
||||
public async Task Flush(int bytesWritten)
|
||||
{
|
||||
if (IsDisposing || BlockAllPackets)
|
||||
return;
|
||||
|
||||
await Socket.SendAsync(buffer, SocketFlags.None).ConfigureAwait(false);
|
||||
SendPipe.Writer.Advance(bytesWritten);
|
||||
FlushResult result = await SendPipe.Writer.FlushAsync();
|
||||
|
||||
p.OnSend();
|
||||
if (result.IsCompleted || result.IsCanceled)
|
||||
Dispose();
|
||||
}
|
||||
|
||||
prof?.Finish(length);
|
||||
}
|
||||
|
|
@ -562,29 +555,44 @@ namespace Server.Network
|
|||
}
|
||||
}
|
||||
|
||||
private async Task HandlePackets(MessagePump pump)
|
||||
private async Task ProcessSends()
|
||||
{
|
||||
PipeReader pr = m_RecvdPipe.Reader;
|
||||
PipeReader pr = SendPipe.Reader;
|
||||
|
||||
while (true)
|
||||
while (!Core.Closing)
|
||||
{
|
||||
if (m_AsyncState.Paused)
|
||||
{
|
||||
await Timer.Pause(50);
|
||||
continue;
|
||||
}
|
||||
|
||||
ReadResult result = await pr.ReadAsync();
|
||||
ReadOnlySequence<byte> seq = result.Buffer;
|
||||
if (seq.Length == 0)
|
||||
break;
|
||||
|
||||
long pos = PacketHandlers.ProcessPacket(pump, this, seq);
|
||||
|
||||
if (pos <= 0)
|
||||
if (!SequenceMarshal.TryGetReadOnlyMemory(seq, out ReadOnlyMemory<byte> memory))
|
||||
break;
|
||||
|
||||
pr.AdvanceTo(seq.GetPosition(pos, seq.Start));
|
||||
try
|
||||
{
|
||||
int bytesWritten = await Socket.SendAsync(memory, SocketFlags.None);
|
||||
|
||||
pr.AdvanceTo(seq.GetPosition(bytesWritten));
|
||||
}
|
||||
catch (SocketException ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
TraceException(ex);
|
||||
break;
|
||||
}
|
||||
|
||||
if (result.IsCompleted || result.IsCanceled)
|
||||
break;
|
||||
}
|
||||
|
||||
pr.Complete();
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public PacketHandler GetHandler(int packetID) =>
|
||||
|
|
@ -639,17 +647,17 @@ namespace Server.Network
|
|||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
m_RecvdPipe.Reader.CancelPendingRead();
|
||||
m_RecvdPipe.Reader.Complete();
|
||||
await m_RecvdPipe.Writer.FlushAsync().ConfigureAwait(false);
|
||||
m_RecvdPipe.Writer.Complete();
|
||||
RecvdPipe.Reader.CancelPendingRead();
|
||||
RecvdPipe.Reader.Complete();
|
||||
await SendPipe.Writer.FlushAsync();
|
||||
SendPipe.Writer.Complete();
|
||||
|
||||
try { Socket.Shutdown(SocketShutdown.Both); } catch (Exception ex) { TraceException(ex); }
|
||||
try { Socket.Close(); } catch (Exception ex) { TraceException(ex); }
|
||||
|
||||
Socket = null;
|
||||
m_RecvdPipe = null;
|
||||
m_SendQueue = null;
|
||||
RecvdPipe = null;
|
||||
SendPipe = null;
|
||||
m_Disposed.Enqueue(this);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue