fix(core): Converts BB packets (#406)

- [X] Organizes and splits up bulletin boards
- [X] Converts packets
This commit is contained in:
Kamron Batman 2021-01-13 22:28:31 -08:00 • committed by GitHub
parent bae568d856
commit c58aad733d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 952 additions and 737 deletions

View file

@ -284,7 +284,7 @@ namespace Server.Network
}
else
{
index = _second.Slice(0, remaining).IndexOfTerminator(sizeT);
index = _second.SliceToLength(remaining).IndexOfTerminator(sizeT);
int secondLength = index < 0 ? remaining : index;
int length = firstLength + secondLength;
@ -292,7 +292,7 @@ namespace Server.Network
// Assume no strings should be too long for the stack
Span<byte> bytes = stackalloc byte[length];
_first.Slice(Position).CopyTo(bytes);
_second.Slice(0, secondLength).CopyTo(bytes.Slice(firstLength));
_second.SliceToLength(secondLength).CopyTo(bytes.Slice(firstLength));
Position += length + (index >= 0 ? sizeT : 0);
return TextEncoding.GetString(bytes, encoding, safeString);
@ -309,7 +309,7 @@ namespace Server.Network
if (index >= 0)
{
span = span.Slice(0, index);
span = span.SliceToLength(index);
}
else
{

View file

@ -18,6 +18,7 @@ using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using Server;
using Server.Network;
using Server.Text;
namespace System.Buffers
@ -363,7 +364,7 @@ namespace System.Buffers
if (Position < _first.Length)
{
var sz = Math.Min(buffer.Length, _first.Length - Position);
buffer.Slice(0, sz).CopyTo(_first.Slice(Position));
buffer.SliceToLength(sz).CopyTo(_first.Slice(Position));
if (sz < buffer.Length)
{
buffer.Slice(sz).CopyTo(_second);
@ -398,7 +399,7 @@ namespace System.Buffers
if (Position < _first.Length)
{
count = Math.Min(_first.Length - Position, byteCount);
bytes.Slice(0, count).CopyTo(_first.Slice(Position));
bytes.SliceToLength(count).CopyTo(_first.Slice(Position));
byteCount -= count;
Position += count;
}

View file

@ -21,6 +21,7 @@ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using Server;
using Server.Network;
using Server.Text;
namespace System.Buffers
@ -50,7 +51,7 @@ namespace System.Buffers
public int Capacity => _buffer.Length;
public ReadOnlySpan<byte> Span => _buffer.Slice(0, Position);
public ReadOnlySpan<byte> Span => _buffer.SliceToLength(Position);
public Span<byte> RawBuffer => _buffer;
@ -78,7 +79,7 @@ namespace System.Buffers
var newSize = Math.Max(BytesWritten + additionalCapacity, _buffer.Length * 2);
byte[] poolArray = ArrayPool<byte>.Shared.Rent(newSize);
_buffer.Slice(0, BytesWritten).CopyTo(poolArray);
_buffer.SliceToLength(BytesWritten).CopyTo(poolArray);
byte[]? toReturn = _arrayToReturnToPool;
_buffer = _arrayToReturnToPool = poolArray;

View file

@ -5,6 +5,7 @@ using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Server.Network;
namespace Server.Buffers
{
@ -63,7 +64,7 @@ namespace Server.Buffers
public ref char this[int index] => ref _chars[index];
public override string ToString() => _chars.Slice(0, Length).ToString();
public override string ToString() => _chars.SliceToLength(Length).ToString();
/// <summary>Returns the underlying storage of the builder.</summary>
public Span<char> RawChars => _chars;
@ -79,16 +80,16 @@ namespace Server.Buffers
EnsureCapacity(Length + 1);
_chars[Length] = '\0';
}
return _chars.Slice(0, Length);
return _chars.SliceToLength(Length);
}
public ReadOnlySpan<char> AsSpan() => _chars.Slice(0, Length);
public ReadOnlySpan<char> AsSpan() => _chars.SliceToLength(Length);
public ReadOnlySpan<char> AsSpan(int start) => _chars.Slice(start, Length - start);
public ReadOnlySpan<char> AsSpan(int start, int length) => _chars.Slice(start, length);
public bool TryCopyTo(Span<char> destination, out int charsWritten)
{
if (_chars.Slice(0, Length).TryCopyTo(destination))
if (_chars.SliceToLength(Length).TryCopyTo(destination))
{
charsWritten = Length;
return true;
@ -275,7 +276,7 @@ namespace Server.Buffers
{
char[] poolArray = ArrayPool<char>.Shared.Rent(Math.Max(Length + additionalCapacityBeyondPos, _chars.Length * 2));
_chars.Slice(0, Length).CopyTo(poolArray);
_chars.SliceToLength(Length).CopyTo(poolArray);
char[]? toReturn = _arrayToReturnToPool;
_chars = _arrayToReturnToPool = poolArray;
@ -349,7 +350,7 @@ namespace Server.Buffers
}
else if (startIndex + length == Length)
{
_chars = _chars.Slice(0, startIndex);
_chars = _chars.SliceToLength(startIndex);
}
else
{