Changes account packets to functional (#284)

- [X] Moved packets from objects to functions
- [X] Fixed bug where characters were showing up with their modded names in the character list

Bumps release version
This commit is contained in:
Kamron Batman 2020-10-25 23:47:29 -07:00 • committed by GitHub
parent 90220feb41
commit 0e02cf0821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 866 additions and 631 deletions

View file

@ -35,6 +35,10 @@ namespace Server.Network
{
}
public CircularBufferReader(CircularBuffer<byte> buffer) : this(buffer.GetSpan(0), buffer.GetSpan(1))
{
}
public CircularBufferReader(ReadOnlySpan<byte> first, ReadOnlySpan<byte> second)
{
_first = first;

View file

@ -29,6 +29,10 @@ namespace System.Buffers
public int Length { get; }
public int Position { get; private set; }
public CircularBufferWriter(CircularBuffer<byte> buffer) : this(buffer.GetSpan(0), buffer.GetSpan(1))
{
}
public CircularBufferWriter(Span<byte> first, Span<byte> second)
{
_first = first;
@ -153,6 +157,34 @@ namespace System.Buffers
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void WriteLE(int value)
{
if (Position < _first.Length)
{
if (!BinaryPrimitives.TryWriteInt32LittleEndian(_first.Slice(Position), value))
{
// Not enough space. Split the spans
Write((byte)(value >> 24));
Write((byte)(value >> 16));
Write((byte)(value >> 8));
Write((byte)value);
}
else
{
Position += 4;
}
}
else if (BinaryPrimitives.TryWriteInt32LittleEndian(_second.Slice(Position - _first.Length), value))
{
Position += 4;
}
else
{
throw new OutOfMemoryException();
}
}
/// <summary>
/// Writes a 4-byte unsigned integer value to the underlying stream.
/// </summary>

View file

@ -141,7 +141,7 @@ namespace System.Buffers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteAscii(this Span<byte> span, ref int pos, string value, int max)
{
var length = value.Length <= max ? value.Length : max;
var length = Math.Min(value.Length, max);
pos += Encoding.ASCII.GetBytes(value.AsSpan(0, length), span.Slice(pos, length));
}
@ -160,7 +160,7 @@ namespace System.Buffers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteAsciiNull(this Span<byte> span, ref int pos, string value, int max)
{
var length = value.Length < max ? value.Length : max - 1;
var length = Math.Min(value.Length, max - 1);
pos += Encoding.ASCII.GetBytes(value.AsSpan(0, length), span.Slice(pos, length));
#if NO_LOCAL_INIT
@ -172,7 +172,7 @@ namespace System.Buffers
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void WriteAsciiFixed(this Span<byte> span, ref int pos, string value, int amount)
{
var length = value.Length <= amount ? value.Length : amount;
var length = Math.Min(value.Length, amount);
#if NO_LOCAL_INIT
int bytesWritten = Encoding.ASCII.GetBytes(value.AsSpan(0, length), span.Slice(pos, length));