Merge branch 'feat/antibot-system' of https://github.com/Bohicatv/ModernUO into feat/antibot-system
This commit is contained in:
commit
d56e6b0377
24 changed files with 1409 additions and 339 deletions
|
|
@ -3,7 +3,7 @@
|
|||
"isRoot": true,
|
||||
"tools": {
|
||||
"modernuoschemagenerator": {
|
||||
"version": "2.12.20",
|
||||
"version": "2.13.0",
|
||||
"commands": [
|
||||
"ModernUOSchemaGenerator"
|
||||
]
|
||||
|
|
|
|||
17
.github/workflows/build-test.yml
vendored
17
.github/workflows/build-test.yml
vendored
|
|
@ -23,7 +23,7 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
|
||||
- name: Install .NET 9
|
||||
- name: Install .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
global-json-file: global.json
|
||||
|
|
@ -54,20 +54,11 @@ jobs:
|
|||
- container: ubuntu:jammy
|
||||
name: Ubuntu 22
|
||||
packageManager: apt
|
||||
- container: ubuntu:focal
|
||||
name: Ubuntu 20
|
||||
packageManager: apt
|
||||
- container: debian:bookworm
|
||||
name: Debian 12
|
||||
packageManager: apt
|
||||
- container: debian:bullseye
|
||||
name: Debian 11
|
||||
packageManager: apt
|
||||
- container: fedora:39
|
||||
name: Fedora 39
|
||||
packageManager: dnf
|
||||
- container: fedora:40
|
||||
name: Fedora 40
|
||||
- container: fedora:42
|
||||
name: Fedora 42
|
||||
packageManager: dnf
|
||||
- container: quay.io/centos/centos:stream9
|
||||
name: CentOS 9 Stream
|
||||
|
|
@ -86,7 +77,7 @@ jobs:
|
|||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
|
||||
- name: Install .NET 9
|
||||
- name: Install .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
global-json-file: global.json
|
||||
|
|
|
|||
2
.github/workflows/create-release.yml
vendored
2
.github/workflows/create-release.yml
vendored
|
|
@ -14,7 +14,7 @@ jobs:
|
|||
with:
|
||||
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
|
||||
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
|
||||
- name: Install .NET 9
|
||||
- name: Install .NET
|
||||
uses: actions/setup-dotnet@v4
|
||||
with:
|
||||
global-json-file: global.json
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
<PropertyGroup>
|
||||
<Authors>Kamron Batman</Authors>
|
||||
<Company>ModernUO</Company>
|
||||
<Copyright>2019-2024</Copyright>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<LangVersion>13</LangVersion>
|
||||
<Copyright>2019-2025</Copyright>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<LangVersion>14</LangVersion>
|
||||
<PublicRelease>true</PublicRelease>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<NoWarn>NU1603</NoWarn>
|
||||
|
|
@ -64,9 +64,9 @@
|
|||
<ItemGroup>
|
||||
<PackageReference Include="Serilog" Version="4.3.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
|
||||
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
|
||||
<Version>3.7.115</Version>
|
||||
<Version>3.9.50</Version>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<AdditionalFiles Include="..\..\Rules.ruleset" />
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@
|
|||
<RootNamespace>Server.Tests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
|||
597
Projects/Server.Tests/Tests/Buffers/SpanReaderTests.cs
Normal file
597
Projects/Server.Tests/Tests/Buffers/SpanReaderTests.cs
Normal file
|
|
@ -0,0 +1,597 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests;
|
||||
|
||||
public class SpanReaderTests
|
||||
{
|
||||
[Fact]
|
||||
public void TestReadByte()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x12, reader.ReadByte());
|
||||
Assert.Equal(0x34, reader.ReadByte());
|
||||
Assert.Equal(2, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadByteAtEnd()
|
||||
{
|
||||
Assert.Throws<EndOfStreamException>(
|
||||
() =>
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12];
|
||||
var reader = new SpanReader(buffer);
|
||||
reader.ReadByte();
|
||||
reader.ReadByte();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadBoolean()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0, 1, 2, 255];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.False(reader.ReadBoolean());
|
||||
Assert.True(reader.ReadBoolean());
|
||||
Assert.True(reader.ReadBoolean());
|
||||
Assert.True(reader.ReadBoolean());
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadSByte()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0xFF, 0x7F];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(-1, reader.ReadSByte());
|
||||
Assert.Equal(127, reader.ReadSByte());
|
||||
Assert.Equal(2, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadInt16BigEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x1234, reader.ReadInt16());
|
||||
Assert.Equal(2, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadInt16LittleEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x34, 0x12];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x1234, reader.ReadInt16LE());
|
||||
Assert.Equal(2, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadInt16AtEnd()
|
||||
{
|
||||
Assert.Throws<EndOfStreamException>(
|
||||
() =>
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12];
|
||||
var reader = new SpanReader(buffer);
|
||||
reader.ReadInt16();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadUInt16BigEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal((ushort)0x1234, reader.ReadUInt16());
|
||||
Assert.Equal(2, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadUInt16LittleEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x34, 0x12];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal((ushort)0x1234, reader.ReadUInt16LE());
|
||||
Assert.Equal(2, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadInt32BigEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34, 0x56, 0x78];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x12345678, reader.ReadInt32());
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadInt32AtEnd()
|
||||
{
|
||||
Assert.Throws<EndOfStreamException>(
|
||||
() =>
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34, 0x56];
|
||||
var reader = new SpanReader(buffer);
|
||||
reader.ReadInt32();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadUInt32BigEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34, 0x56, 0x78];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x12345678u, reader.ReadUInt32());
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadUInt32LittleEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x78, 0x56, 0x34, 0x12];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x12345678u, reader.ReadUInt32LE());
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadInt64BigEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x123456789ABCDEF0L, reader.ReadInt64());
|
||||
Assert.Equal(8, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadInt64AtEnd()
|
||||
{
|
||||
Assert.Throws<EndOfStreamException>(
|
||||
() =>
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE];
|
||||
var reader = new SpanReader(buffer);
|
||||
reader.ReadInt64();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadUInt64BigEndian()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0x123456789ABCDEF0UL, reader.ReadUInt64());
|
||||
Assert.Equal(8, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadAsciiString()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "Hello"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadAscii();
|
||||
|
||||
Assert.Equal("Hello", result);
|
||||
Assert.Equal(5, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadAsciiStringWithNull()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "Hel\0o"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadAscii();
|
||||
|
||||
Assert.Equal("Hel", result);
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadAsciiStringFixedLength()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "Hello\0\0\0\0\0"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadAscii(10);
|
||||
|
||||
Assert.Equal("Hello", result);
|
||||
Assert.Equal(10, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadAsciiStringFixedLengthTooLarge()
|
||||
{
|
||||
Assert.Throws<EndOfStreamException>(
|
||||
() =>
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "Hel"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
reader.ReadAscii(10);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadAsciiSafe()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [(byte)'H', (byte)'e', 0xFF, (byte)'l', (byte)'o'];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadAsciiSafe();
|
||||
|
||||
Assert.Equal("He?lo", result);
|
||||
Assert.Equal(5, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadUTF8String()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "Hello"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadUTF8();
|
||||
|
||||
Assert.Equal("Hello", result);
|
||||
Assert.Equal(5, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadUTF8StringWithNull()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "Hi\0Bye"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadUTF8();
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(3, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadLittleUniString()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "H\0i\0"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadLittleUni();
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadLittleUniStringWithNull()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "H\0i\0\0\0X\0"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadLittleUni();
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(5, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadLittleUniStringFixedLength()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "H\0i\0\0\0\0\0"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadLittleUni(4);
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(8, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadLittleUniSafe()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [(byte)'H', 0, 0xFF, 0xD8, (byte)'i', 0];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadLittleUniSafe();
|
||||
|
||||
Assert.Equal("H\uFFFDi", result);
|
||||
Assert.Equal(6, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadBigUniString()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "\0H\0i"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadBigUni();
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadBigUniStringWithNull()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "\0H\0i\0\0\0X"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadBigUni();
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(5, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadBigUniStringFixedLength()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "\0H\0i\0\0\0\0"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadBigUni(4);
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(8, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadBigUniSafe()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0, (byte)'H', 0xD8, 0xFF, 0, (byte)'i'];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadBigUniSafe();
|
||||
|
||||
Assert.Equal("H\uFFFDi", result);
|
||||
Assert.Equal(6, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekBegin()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03, 0x04, 0x05];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
reader.ReadByte();
|
||||
reader.ReadByte();
|
||||
|
||||
var pos = reader.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
Assert.Equal(0, pos);
|
||||
Assert.Equal(0, reader.Position);
|
||||
Assert.Equal(0x01, reader.ReadByte());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekCurrent()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03, 0x04, 0x05];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
reader.ReadByte();
|
||||
var pos = reader.Seek(2, SeekOrigin.Current);
|
||||
|
||||
Assert.Equal(3, pos);
|
||||
Assert.Equal(3, reader.Position);
|
||||
Assert.Equal(0x04, reader.ReadByte());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekEnd()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03, 0x04, 0x05];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var pos = reader.Seek(-2, SeekOrigin.End);
|
||||
|
||||
Assert.Equal(3, pos);
|
||||
Assert.Equal(3, reader.Position);
|
||||
Assert.Equal(0x04, reader.ReadByte());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekNegativeThrows()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(
|
||||
() =>
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
reader.Seek(-1, SeekOrigin.Begin);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekBeyondEndThrows()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(
|
||||
() =>
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
reader.Seek(10, SeekOrigin.Begin);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRead()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03, 0x04, 0x05];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Span<byte> dest = stackalloc byte[3];
|
||||
var bytesRead = reader.Read(dest);
|
||||
|
||||
Assert.Equal(3, bytesRead);
|
||||
Assert.Equal(3, reader.Position);
|
||||
AssertThat.Equal(dest, [0x01, 0x02, 0x03]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadPartial()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Span<byte> dest = stackalloc byte[5];
|
||||
var bytesRead = reader.Read(dest);
|
||||
|
||||
Assert.Equal(3, bytesRead);
|
||||
Assert.Equal(3, reader.Position);
|
||||
AssertThat.Equal(dest[..3], [0x01, 0x02, 0x03]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadEmpty()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Span<byte> dest = [];
|
||||
var bytesRead = reader.Read(dest);
|
||||
|
||||
Assert.Equal(0, bytesRead);
|
||||
Assert.Equal(0, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadAtEnd()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
reader.Seek(3, SeekOrigin.Begin);
|
||||
|
||||
Span<byte> dest = stackalloc byte[5];
|
||||
var bytesRead = reader.Read(dest);
|
||||
|
||||
Assert.Equal(0, bytesRead);
|
||||
Assert.Equal(3, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestLength()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03, 0x04, 0x05];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(5, reader.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestPosition()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(0, reader.Position);
|
||||
|
||||
reader.ReadByte();
|
||||
Assert.Equal(1, reader.Position);
|
||||
|
||||
reader.ReadUInt16();
|
||||
Assert.Equal(3, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRemaining()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03, 0x04, 0x05];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal(5, reader.Remaining);
|
||||
|
||||
reader.ReadByte();
|
||||
Assert.Equal(4, reader.Remaining);
|
||||
|
||||
reader.ReadUInt16();
|
||||
Assert.Equal(2, reader.Remaining);
|
||||
|
||||
reader.ReadUInt16();
|
||||
Assert.Equal(0, reader.Remaining);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBuffer()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var bufferProperty = reader.Buffer;
|
||||
|
||||
Assert.Equal(3, bufferProperty.Length);
|
||||
AssertThat.Equal(bufferProperty, buffer);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadStringEmptyFixedLength()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = [0x01, 0x02, 0x03];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadAscii(0);
|
||||
|
||||
Assert.Equal("", result);
|
||||
Assert.Equal(0, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadMultipleStringsWithNullTerminators()
|
||||
{
|
||||
ReadOnlySpan<byte> buffer = "AB\0CD\0EF"u8;
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
Assert.Equal("AB", reader.ReadAscii());
|
||||
Assert.Equal("CD", reader.ReadAscii());
|
||||
Assert.Equal("EF", reader.ReadAscii());
|
||||
Assert.Equal(8, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadLittleUniOddByteCount()
|
||||
{
|
||||
// If buffer has odd number of bytes, the last byte should be ignored
|
||||
ReadOnlySpan<byte> buffer = [(byte)'H', 0, (byte)'i', 0, 0xFF];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadLittleUni();
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestReadBigUniOddByteCount()
|
||||
{
|
||||
// If buffer has odd number of bytes, the last byte should be ignored
|
||||
ReadOnlySpan<byte> buffer = [0, (byte)'H', 0, (byte)'i', 0xFF];
|
||||
var reader = new SpanReader(buffer);
|
||||
|
||||
var result = reader.ReadBigUni();
|
||||
|
||||
Assert.Equal("Hi", result);
|
||||
Assert.Equal(4, reader.Position);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +1,591 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using Xunit;
|
||||
|
||||
namespace Server.Tests
|
||||
namespace Server.Tests;
|
||||
|
||||
public class SpanWriterTests
|
||||
{
|
||||
public class SpanWriterTests
|
||||
[Fact]
|
||||
public unsafe void TestSpanWriterResizes()
|
||||
{
|
||||
[Fact]
|
||||
public unsafe void TestSpanWriterResizes()
|
||||
{
|
||||
Span<byte> smallStack = stackalloc byte[8];
|
||||
using var writer = new SpanWriter(smallStack, true);
|
||||
writer.Write(0x1024L);
|
||||
writer.Write(0x1024L);
|
||||
Span<byte> smallStack = stackalloc byte[8];
|
||||
var writer = new SpanWriter(smallStack, true);
|
||||
writer.Write(0x1024L);
|
||||
writer.Write(0x1024L);
|
||||
|
||||
var span = writer.RawBuffer;
|
||||
fixed (byte* spanPtr = span)
|
||||
var span = writer.RawBuffer;
|
||||
fixed (byte* spanPtr = span)
|
||||
{
|
||||
fixed (byte* stackPtr = smallStack)
|
||||
{
|
||||
fixed (byte* stackPtr = smallStack)
|
||||
{
|
||||
Assert.True(spanPtr != stackPtr);
|
||||
}
|
||||
Assert.True(spanPtr != stackPtr);
|
||||
}
|
||||
|
||||
Assert.True(span.Length > smallStack.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public unsafe void TestSpanWriterOnlyStackAlloc()
|
||||
{
|
||||
Span<byte> smallStack = stackalloc byte[8];
|
||||
using var writer = new SpanWriter(smallStack, true);
|
||||
writer.Write(0x1024L);
|
||||
Assert.True(span.Length > smallStack.Length);
|
||||
writer.Dispose();
|
||||
}
|
||||
|
||||
var span = writer.RawBuffer;
|
||||
fixed (byte* spanPtr = span)
|
||||
[Fact]
|
||||
public unsafe void TestSpanWriterOnlyStackAlloc()
|
||||
{
|
||||
Span<byte> smallStack = stackalloc byte[8];
|
||||
var writer = new SpanWriter(smallStack, true);
|
||||
writer.Write(0x1024L);
|
||||
|
||||
var span = writer.RawBuffer;
|
||||
fixed (byte* spanPtr = span)
|
||||
{
|
||||
fixed (byte* stackPtr = smallStack)
|
||||
{
|
||||
fixed (byte* stackPtr = smallStack)
|
||||
{
|
||||
Assert.True(spanPtr == stackPtr);
|
||||
}
|
||||
Assert.True(spanPtr == stackPtr);
|
||||
}
|
||||
|
||||
Assert.True(span.Length == smallStack.Length);
|
||||
AssertThat.Equal(smallStack, stackalloc byte[] { 0, 0, 0, 0, 0, 0, 0x10, 0x24 });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSpanWriterNoResizeThrows()
|
||||
{
|
||||
Assert.Throws<OutOfMemoryException>(
|
||||
() =>
|
||||
{
|
||||
Span<byte> smallStack = stackalloc byte[8];
|
||||
using var writer = new SpanWriter(smallStack);
|
||||
writer.Write(0x1024L);
|
||||
writer.Write(0x1024L);
|
||||
}
|
||||
);
|
||||
}
|
||||
Assert.Equal(8, span.Length);
|
||||
AssertThat.Equal(smallStack, [0, 0, 0, 0, 0, 0, 0x10, 0x24]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSpanWriterNoResizeThrows()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(
|
||||
() =>
|
||||
{
|
||||
Span<byte> smallStack = stackalloc byte[8];
|
||||
var writer = new SpanWriter(smallStack);
|
||||
writer.Write(0x1024L);
|
||||
writer.Write(0x1024L);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteBool()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write(true);
|
||||
writer.Write(false);
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [1, 0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteByte()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x12);
|
||||
writer.Write((byte)0x34);
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x12, 0x34]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteSByte()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((sbyte)-1);
|
||||
writer.Write((sbyte)127);
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0xFF, 0x7F]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteInt16BigEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((short)0x1234);
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x12, 0x34]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteInt16LittleEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteLE((short)0x1234);
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x34, 0x12]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteUInt16BigEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((ushort)0x1234);
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x12, 0x34]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteUInt16LittleEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteLE((ushort)0x1234);
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x34, 0x12]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteInt32BigEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write(0x12345678);
|
||||
|
||||
Assert.Equal(4, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x12, 0x34, 0x56, 0x78]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteInt32LittleEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteLE(0x12345678);
|
||||
|
||||
Assert.Equal(4, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x78, 0x56, 0x34, 0x12]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteUInt32BigEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write(0x12345678u);
|
||||
|
||||
Assert.Equal(4, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x12, 0x34, 0x56, 0x78]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteUInt32LittleEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteLE(0x12345678u);
|
||||
|
||||
Assert.Equal(4, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x78, 0x56, 0x34, 0x12]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteInt64BigEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write(0x123456789ABCDEF0L);
|
||||
|
||||
Assert.Equal(8, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteUInt64BigEndian()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write(0x123456789ABCDEF0UL);
|
||||
|
||||
Assert.Equal(8, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteSpan()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[6];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
ReadOnlySpan<byte> data = [0x01, 0x02, 0x03];
|
||||
writer.Write(data);
|
||||
writer.Write(data);
|
||||
|
||||
Assert.Equal(6, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x01, 0x02, 0x03, 0x01, 0x02, 0x03]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteAsciiChar()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteAscii('A');
|
||||
writer.WriteAscii('B');
|
||||
|
||||
Assert.Equal(2, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "AB"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteAsciiString()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[5];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteAscii("Hello");
|
||||
|
||||
Assert.Equal(5, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "Hello"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteAsciiStringNull()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[6];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteAsciiNull("Hello");
|
||||
|
||||
Assert.Equal(6, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "Hello\0"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteAsciiStringFixedLength()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteAscii("Hello", 10);
|
||||
|
||||
Assert.Equal(10, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "Hello\0\0\0\0\0"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteUTF8String()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[5];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteUTF8("Hello");
|
||||
|
||||
Assert.Equal(5, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "Hello"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteUTF8StringNull()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[6];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteUTF8Null("Hello");
|
||||
|
||||
Assert.Equal(6, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "Hello\0"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteLittleUniString()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteLittleUni("Hello");
|
||||
|
||||
Assert.Equal(10, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "H\0e\0l\0l\0o\0"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteLittleUniStringNull()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[12];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteLittleUniNull("Hello");
|
||||
|
||||
Assert.Equal(12, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "H\0e\0l\0l\0o\0\0\0"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteBigUniString()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteBigUni("Hello");
|
||||
|
||||
Assert.Equal(10, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "\0H\0e\0l\0l\0o"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestWriteBigUniStringNull()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[12];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.WriteBigUniNull("Hello");
|
||||
|
||||
Assert.Equal(12, writer.Position);
|
||||
AssertThat.Equal(writer.Span, "\0H\0e\0l\0l\0o\0\0"u8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestClear()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
buffer.Fill(0xFF);
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
writer.Clear(5);
|
||||
writer.Write((byte)0x02);
|
||||
|
||||
Assert.Equal(7, writer.Position);
|
||||
AssertThat.Equal(writer.Span, [0x01, 0, 0, 0, 0, 0, 0x02]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekBegin()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
writer.Write((byte)0x02);
|
||||
writer.Write((byte)0x03);
|
||||
|
||||
var pos = writer.Seek(1, SeekOrigin.Begin);
|
||||
|
||||
Assert.Equal(1, pos);
|
||||
Assert.Equal(1, writer.Position);
|
||||
Assert.Equal(3, writer.BytesWritten);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekCurrent()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
writer.Write((byte)0x02);
|
||||
|
||||
var pos = writer.Seek(2, SeekOrigin.Current);
|
||||
|
||||
Assert.Equal(4, pos);
|
||||
Assert.Equal(4, writer.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekEnd()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
writer.Write((byte)0x02);
|
||||
writer.Write((byte)0x03);
|
||||
|
||||
var pos = writer.Seek(-1, SeekOrigin.End);
|
||||
|
||||
Assert.Equal(2, pos);
|
||||
Assert.Equal(2, writer.Position);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekNegativeThrows()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(
|
||||
() =>
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Seek(-1, SeekOrigin.Begin);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekBeyondCapacityNoResizeThrows()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(
|
||||
() =>
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.Seek(20, SeekOrigin.Begin);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSeekBeyondCapacityWithResize()
|
||||
{
|
||||
var writer = new SpanWriter(10, true);
|
||||
|
||||
var pos = writer.Seek(20, SeekOrigin.Begin);
|
||||
|
||||
Assert.Equal(20, pos);
|
||||
Assert.True(writer.Capacity >= 20);
|
||||
writer.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEnsureCapacityNoResize()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.EnsureCapacity(10);
|
||||
Assert.Equal(10, writer.Capacity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEnsureCapacityNoResizeThrows()
|
||||
{
|
||||
Assert.Throws<InvalidOperationException>(
|
||||
() =>
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
writer.EnsureCapacity(20);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestEnsureCapacityWithResize()
|
||||
{
|
||||
var writer = new SpanWriter(10, true);
|
||||
|
||||
writer.EnsureCapacity(50);
|
||||
|
||||
Assert.True(writer.Capacity >= 50);
|
||||
writer.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestToSpanWithStackAlloc()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
writer.Write((byte)0x02);
|
||||
writer.Write((byte)0x03);
|
||||
|
||||
using var owner = writer.ToSpan();
|
||||
|
||||
Assert.Equal(3, owner.Span.Length);
|
||||
AssertThat.Equal(owner.Span, [0x01, 0x02, 0x03]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestToSpanWithRentedBuffer()
|
||||
{
|
||||
var writer = new SpanWriter(10);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
writer.Write((byte)0x02);
|
||||
writer.Write((byte)0x03);
|
||||
|
||||
using var owner = writer.ToSpan();
|
||||
|
||||
Assert.Equal(3, owner.Span.Length);
|
||||
AssertThat.Equal(owner.Span, [0x01, 0x02, 0x03]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestToSpanEmpty()
|
||||
{
|
||||
var writer = new SpanWriter(10);
|
||||
|
||||
using var owner = writer.ToSpan();
|
||||
|
||||
Assert.Equal(0, owner.Span.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBytesWritten()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
Assert.Equal(0, writer.BytesWritten);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
Assert.Equal(1, writer.BytesWritten);
|
||||
|
||||
writer.Write((ushort)0x0203);
|
||||
Assert.Equal(3, writer.BytesWritten);
|
||||
|
||||
writer.Seek(1, SeekOrigin.Begin);
|
||||
Assert.Equal(3, writer.BytesWritten);
|
||||
|
||||
writer.Write((byte)0xFF);
|
||||
Assert.Equal(3, writer.BytesWritten);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestCapacity()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
Assert.Equal(10, writer.Capacity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRawBuffer()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
|
||||
var raw = writer.RawBuffer;
|
||||
Assert.Equal(10, raw.Length);
|
||||
Assert.Equal(0x01, raw[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestSpan()
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[10];
|
||||
var writer = new SpanWriter(buffer);
|
||||
|
||||
writer.Write((byte)0x01);
|
||||
writer.Write((byte)0x02);
|
||||
|
||||
var span = writer.Span;
|
||||
Assert.Equal(2, span.Length);
|
||||
AssertThat.Equal(span, [0x01, 0x02]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2025 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: SpanReader.cs *
|
||||
* *
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
|
@ -45,7 +44,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (Position >= Length)
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
return _buffer[Position++];
|
||||
|
|
@ -62,7 +61,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadInt16BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 2;
|
||||
|
|
@ -74,7 +73,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadInt16LittleEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 2;
|
||||
|
|
@ -86,7 +85,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadUInt16BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 2;
|
||||
|
|
@ -98,7 +97,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadUInt16LittleEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 2;
|
||||
|
|
@ -110,7 +109,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadInt32BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 4;
|
||||
|
|
@ -122,7 +121,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadUInt32BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 4;
|
||||
|
|
@ -134,7 +133,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadUInt32LittleEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 4;
|
||||
|
|
@ -146,7 +145,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadInt64BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 8;
|
||||
|
|
@ -158,7 +157,7 @@ public ref struct SpanReader
|
|||
{
|
||||
if (!BinaryPrimitives.TryReadUInt64BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
|
||||
Position += 8;
|
||||
|
|
@ -173,9 +172,9 @@ public ref struct SpanReader
|
|||
return "";
|
||||
}
|
||||
|
||||
int byteLength = encoding.GetByteLengthForEncoding();
|
||||
var byteLength = encoding.GetByteLengthForEncoding();
|
||||
|
||||
bool isFixedLength = fixedLength > -1;
|
||||
var isFixedLength = fixedLength > -1;
|
||||
|
||||
var remaining = Remaining;
|
||||
int size;
|
||||
|
|
@ -184,7 +183,7 @@ public ref struct SpanReader
|
|||
size = fixedLength * byteLength;
|
||||
if (size > Remaining)
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new EndOfStreamException("Cannot read past the end of the buffer.");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -255,46 +254,28 @@ public ref struct SpanReader
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Seek(int offset, SeekOrigin origin)
|
||||
{
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.End || offset <= 0,
|
||||
"Attempting to seek to a position beyond capacity using SeekOrigin.End"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.End || offset >= -_buffer.Length,
|
||||
"Attempting to seek to a negative position using SeekOrigin.End"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Begin || offset >= 0,
|
||||
"Attempting to seek to a negative position using SeekOrigin.Begin"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Begin || offset <= _buffer.Length,
|
||||
"Attempting to seek to a position beyond the capacity using SeekOrigin.Begin"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Current || Position + offset >= 0,
|
||||
"Attempting to seek to a negative position using SeekOrigin.Current"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Current || Position + offset <= _buffer.Length,
|
||||
"Attempting to seek to a position beyond the capacity using SeekOrigin.Current"
|
||||
);
|
||||
|
||||
return Position = Math.Max(0, origin switch
|
||||
var newPosition = origin switch
|
||||
{
|
||||
SeekOrigin.Current => Position + offset,
|
||||
SeekOrigin.End => _buffer.Length + offset,
|
||||
_ => offset // Begin
|
||||
});
|
||||
};
|
||||
|
||||
if (newPosition < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset), "Seek operation would result in a negative position.");
|
||||
}
|
||||
|
||||
if (newPosition > _buffer.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset), $"Cannot seek to position {newPosition} beyond buffer length {_buffer.Length}.");
|
||||
}
|
||||
|
||||
return Position = newPosition;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Read(Span<byte> bytes)
|
||||
public int Read(scoped Span<byte> bytes)
|
||||
{
|
||||
if (bytes.Length == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2025 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: SpanWriter.cs *
|
||||
* *
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
|
@ -56,14 +55,14 @@ public ref struct SpanWriter
|
|||
public Span<byte> RawBuffer => _buffer;
|
||||
|
||||
/**
|
||||
* Converts the writer to a Span<byte> using a SpanOwner.
|
||||
* If the buffer was stackalloc, it will be copied to a rented buffer.
|
||||
* Otherwise the existing rented buffer is used.
|
||||
*
|
||||
* Note:
|
||||
* Do not use the SpanWriter after calling this method.
|
||||
* This method will effectively dispose of the SpanWriter and is therefore considered terminal.
|
||||
*/
|
||||
* Converts the writer to a Span<byte> using a SpanOwner.
|
||||
* If the buffer was stackalloc, it will be copied to a rented buffer.
|
||||
* Otherwise the existing rented buffer is used.
|
||||
*
|
||||
* Note:
|
||||
* Do not use the SpanWriter after calling this method.
|
||||
* This method will effectively dispose of the SpanWriter and is therefore considered terminal.
|
||||
*/
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public SpanOwner ToSpan()
|
||||
{
|
||||
|
|
@ -117,11 +116,11 @@ public ref struct SpanWriter
|
|||
private void Grow(int additionalCapacity)
|
||||
{
|
||||
var newSize = Math.Max(BytesWritten + additionalCapacity, _buffer.Length * 2);
|
||||
byte[] poolArray = STArrayPool<byte>.Shared.Rent(newSize);
|
||||
var poolArray = STArrayPool<byte>.Shared.Rent(newSize);
|
||||
|
||||
_buffer[..BytesWritten].CopyTo(poolArray);
|
||||
|
||||
byte[] toReturn = _arrayToReturnToPool;
|
||||
var toReturn = _arrayToReturnToPool;
|
||||
_buffer = _arrayToReturnToPool = poolArray;
|
||||
if (toReturn != null)
|
||||
{
|
||||
|
|
@ -136,7 +135,7 @@ public ref struct SpanWriter
|
|||
{
|
||||
if (!_resize)
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new InvalidOperationException("Buffer is full and resizing is disabled.");
|
||||
}
|
||||
|
||||
Grow(count);
|
||||
|
|
@ -151,7 +150,7 @@ public ref struct SpanWriter
|
|||
{
|
||||
if (!_resize)
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
throw new InvalidOperationException("Buffer is full and resizing is disabled.");
|
||||
}
|
||||
|
||||
Grow(capacity - BytesWritten);
|
||||
|
|
@ -400,46 +399,25 @@ public ref struct SpanWriter
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Seek(int offset, SeekOrigin origin)
|
||||
{
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.End || _resize || offset <= 0,
|
||||
"Attempting to seek to a position beyond capacity using SeekOrigin.End without resize"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.End || offset >= -_buffer.Length,
|
||||
|
||||
"Attempting to seek to a negative position using SeekOrigin.End"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Begin || offset >= 0,
|
||||
"Attempting to seek to a negative position using SeekOrigin.Begin"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Begin || _resize || offset <= _buffer.Length,
|
||||
"Attempting to seek to a position beyond the capacity using SeekOrigin.Begin without resize"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Current || _position + offset >= 0,
|
||||
"Attempting to seek to a negative position using SeekOrigin.Current"
|
||||
);
|
||||
|
||||
Debug.Assert(
|
||||
origin != SeekOrigin.Current || _resize || _position + offset <= _buffer.Length,
|
||||
"Attempting to seek to a position beyond the capacity using SeekOrigin.Current without resize"
|
||||
);
|
||||
|
||||
var newPosition = Math.Max(0, origin switch
|
||||
var newPosition = origin switch
|
||||
{
|
||||
SeekOrigin.Current => _position + offset,
|
||||
SeekOrigin.End => BytesWritten + offset,
|
||||
_ => offset // Begin
|
||||
});
|
||||
};
|
||||
|
||||
if (newPosition < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(offset), "Seek operation would result in a negative position.");
|
||||
}
|
||||
|
||||
if (newPosition > _buffer.Length)
|
||||
{
|
||||
if (!_resize)
|
||||
{
|
||||
throw new InvalidOperationException($"Cannot seek to position {newPosition} beyond buffer capacity {_buffer.Length} when resizing is disabled.");
|
||||
}
|
||||
|
||||
Grow(newPosition - _buffer.Length + 1);
|
||||
}
|
||||
|
||||
|
|
@ -449,7 +427,7 @@ public ref struct SpanWriter
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Dispose()
|
||||
{
|
||||
byte[] toReturn = _arrayToReturnToPool;
|
||||
var toReturn = _arrayToReturnToPool;
|
||||
this = default; // for safety, to avoid using pooled array if this instance is erroneously appended to again
|
||||
if (toReturn != null)
|
||||
{
|
||||
|
|
@ -478,7 +456,7 @@ public ref struct SpanWriter
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Dispose()
|
||||
{
|
||||
byte[] toReturn = _arrayToReturnToPool;
|
||||
var toReturn = _arrayToReturnToPool;
|
||||
this = default;
|
||||
if (_length > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: SecureRandom.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Server;
|
||||
|
||||
public static class BuiltInSecureRng
|
||||
{
|
||||
public static RandomNumberGenerator Generator { get; } = RandomNumberGenerator.Create();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void NextBytes(Span<byte> buffer) => Generator.GetBytes(buffer);
|
||||
}
|
||||
|
|
@ -37,10 +37,10 @@
|
|||
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
|
||||
<PackageReference Include="LibDeflate.Bindings" Version="1.0.2.120" />
|
||||
<PackageReference Include="PollGroup" Version="1.6.1" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="9.0.7" />
|
||||
<PackageReference Include="System.IO.Hashing" Version="10.0.0" />
|
||||
|
||||
<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.9.1" />
|
||||
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.12.20" />
|
||||
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.13.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="Migrations/*.v*.json" />
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
<Configurations>Debug;Release;Analyze</Configurations>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2025 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: AccountSecurity.cs *
|
||||
* *
|
||||
|
|
@ -15,56 +15,55 @@
|
|||
|
||||
using System;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
{
|
||||
public enum PasswordProtectionAlgorithm
|
||||
{
|
||||
// Obsolete algorithms from RunUO. These are not secure!
|
||||
// They are included for password upgrades only.
|
||||
None,
|
||||
MD5,
|
||||
SHA1,
|
||||
namespace Server.Accounting.Security;
|
||||
|
||||
// Supported algorithms
|
||||
SHA2, // ServUO compatibility
|
||||
PBKDF2,
|
||||
Argon2 // Recommended algorithm for real security.
|
||||
public enum PasswordProtectionAlgorithm
|
||||
{
|
||||
// Obsolete algorithms from RunUO. These are not secure!
|
||||
// They are included for password upgrades only.
|
||||
None,
|
||||
MD5,
|
||||
SHA1,
|
||||
|
||||
// Supported algorithms
|
||||
SHA2, // ServUO compatibility
|
||||
PBKDF2,
|
||||
Argon2 // Recommended algorithm for real security.
|
||||
}
|
||||
|
||||
public static class AccountSecurity
|
||||
{
|
||||
public static PasswordProtectionAlgorithm CurrentAlgorithm { get; set; }
|
||||
|
||||
public static IPasswordProtection CurrentPasswordProtection => GetPasswordProtection(CurrentAlgorithm);
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
CurrentAlgorithm =
|
||||
ServerConfiguration.GetOrUpdateSetting(
|
||||
"accountSecurity.encryptionAlgorithm",
|
||||
PasswordProtectionAlgorithm.Argon2
|
||||
);
|
||||
|
||||
if (CurrentAlgorithm < PasswordProtectionAlgorithm.SHA2)
|
||||
{
|
||||
throw new Exception($"Security: {CurrentAlgorithm} is obsolete and not secure. Do not use it.");
|
||||
}
|
||||
}
|
||||
|
||||
public static class AccountSecurity
|
||||
public static IPasswordProtection GetPasswordProtection(PasswordProtectionAlgorithm algorithm)
|
||||
{
|
||||
public static PasswordProtectionAlgorithm CurrentAlgorithm { get; set; }
|
||||
|
||||
public static IPasswordProtection CurrentPasswordProtection => GetPasswordProtection(CurrentAlgorithm);
|
||||
|
||||
public static void Configure()
|
||||
var passwordProtection = algorithm switch
|
||||
{
|
||||
CurrentAlgorithm =
|
||||
ServerConfiguration.GetOrUpdateSetting(
|
||||
"accountSecurity.encryptionAlgorithm",
|
||||
PasswordProtectionAlgorithm.Argon2
|
||||
);
|
||||
PasswordProtectionAlgorithm.MD5 => HashAlgorithmPasswordProtection.MD5Instance,
|
||||
PasswordProtectionAlgorithm.SHA1 => HashAlgorithmPasswordProtection.SHA1Instance,
|
||||
PasswordProtectionAlgorithm.SHA2 => HashAlgorithmPasswordProtection.SHA2Instance,
|
||||
PasswordProtectionAlgorithm.PBKDF2 => PBKDF2PasswordProtection.Instance,
|
||||
PasswordProtectionAlgorithm.Argon2 => Argon2PasswordProtection.Instance,
|
||||
PasswordProtectionAlgorithm.None => throw new Exception("Do not use PasswordProtectionAlgorithm.None"),
|
||||
_ => throw new Exception("No algorithm")
|
||||
};
|
||||
|
||||
if (CurrentAlgorithm < PasswordProtectionAlgorithm.SHA2)
|
||||
{
|
||||
throw new Exception($"Security: {CurrentAlgorithm} is obsolete and not secure. Do not use it.");
|
||||
}
|
||||
}
|
||||
|
||||
public static IPasswordProtection GetPasswordProtection(PasswordProtectionAlgorithm algorithm)
|
||||
{
|
||||
var passwordProtection = algorithm switch
|
||||
{
|
||||
PasswordProtectionAlgorithm.MD5 => HashAlgorithmPasswordProtection.MD5Instance,
|
||||
PasswordProtectionAlgorithm.SHA1 => HashAlgorithmPasswordProtection.SHA1Instance,
|
||||
PasswordProtectionAlgorithm.SHA2 => HashAlgorithmPasswordProtection.SHA2Instance,
|
||||
PasswordProtectionAlgorithm.PBKDF2 => PBKDF2PasswordProtection.Instance,
|
||||
PasswordProtectionAlgorithm.Argon2 => Argon2PasswordProtection.Instance,
|
||||
PasswordProtectionAlgorithm.None => throw new Exception("Do not use PasswordProtectionAlgorithm.None"),
|
||||
_ => throw new Exception("No algorithm")
|
||||
};
|
||||
|
||||
return passwordProtection;
|
||||
}
|
||||
return passwordProtection;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2025 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: Argon2PasswordProtection.cs *
|
||||
* *
|
||||
|
|
@ -15,18 +15,17 @@
|
|||
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
namespace Server.Accounting.Security;
|
||||
|
||||
public class Argon2PasswordProtection : IPasswordProtection
|
||||
{
|
||||
public class Argon2PasswordProtection : IPasswordProtection
|
||||
{
|
||||
public static IPasswordProtection Instance = new Argon2PasswordProtection();
|
||||
public static IPasswordProtection Instance = new Argon2PasswordProtection();
|
||||
|
||||
private readonly Argon2PasswordHasher m_PasswordHasher = new(rng: BuiltInSecureRng.Generator);
|
||||
private readonly Argon2PasswordHasher m_PasswordHasher = new(rng: RandomNumberGenerator.Create());
|
||||
|
||||
public string EncryptPassword(string plainPassword) =>
|
||||
m_PasswordHasher.Hash(plainPassword);
|
||||
public string EncryptPassword(string plainPassword) =>
|
||||
m_PasswordHasher.Hash(plainPassword);
|
||||
|
||||
public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
|
||||
m_PasswordHasher.Verify(encryptedPassword, plainPassword);
|
||||
}
|
||||
public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
|
||||
m_PasswordHasher.Verify(encryptedPassword, plainPassword);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2025 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: HashAlgorithmPasswordProtection.cs *
|
||||
* *
|
||||
|
|
@ -17,24 +17,23 @@ using System;
|
|||
using System.Security.Cryptography;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
namespace Server.Accounting.Security;
|
||||
|
||||
public class HashAlgorithmPasswordProtection : IPasswordProtection
|
||||
{
|
||||
public class HashAlgorithmPasswordProtection : IPasswordProtection
|
||||
public static IPasswordProtection MD5Instance = new HashAlgorithmPasswordProtection(MD5.Create());
|
||||
public static IPasswordProtection SHA1Instance = new HashAlgorithmPasswordProtection(SHA1.Create());
|
||||
public static IPasswordProtection SHA2Instance = new HashAlgorithmPasswordProtection(SHA512.Create());
|
||||
private readonly HashAlgorithm _hashAlgorithm;
|
||||
|
||||
public HashAlgorithmPasswordProtection(HashAlgorithm hashAlgorithm) => _hashAlgorithm = hashAlgorithm;
|
||||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
public static IPasswordProtection MD5Instance = new HashAlgorithmPasswordProtection(MD5.Create());
|
||||
public static IPasswordProtection SHA1Instance = new HashAlgorithmPasswordProtection(SHA1.Create());
|
||||
public static IPasswordProtection SHA2Instance = new HashAlgorithmPasswordProtection(SHA512.Create());
|
||||
private readonly HashAlgorithm _hashAlgorithm;
|
||||
|
||||
public HashAlgorithmPasswordProtection(HashAlgorithm hashAlgorithm) => _hashAlgorithm = hashAlgorithm;
|
||||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
byte[] bytes = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length)).GetBytesAscii();
|
||||
return _hashAlgorithm.ComputeHash(bytes).ToHexString();
|
||||
}
|
||||
|
||||
public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
|
||||
EncryptPassword(plainPassword) == encryptedPassword;
|
||||
byte[] bytes = plainPassword.AsSpan(0, Math.Min(256, plainPassword.Length)).GetBytesAscii();
|
||||
return _hashAlgorithm.ComputeHash(bytes).ToHexString();
|
||||
}
|
||||
|
||||
public bool ValidatePassword(string encryptedPassword, string plainPassword) =>
|
||||
EncryptPassword(plainPassword) == encryptedPassword;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2023 - ModernUO Development Team *
|
||||
* Copyright 2019-2025 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: PBKDF2PasswordProtection.cs *
|
||||
* *
|
||||
|
|
@ -18,42 +18,43 @@ using System.Buffers.Binary;
|
|||
using System.Security.Cryptography;
|
||||
using Server.Text;
|
||||
|
||||
namespace Server.Accounting.Security
|
||||
namespace Server.Accounting.Security;
|
||||
|
||||
public class PBKDF2PasswordProtection : IPasswordProtection
|
||||
{
|
||||
public class PBKDF2PasswordProtection : IPasswordProtection
|
||||
private const ushort m_MinIterations = 1024;
|
||||
private const ushort m_MaxIterations = 1536;
|
||||
private const int m_SaltSize = 8;
|
||||
private const int m_HashSize = 32;
|
||||
private const int m_OutputSize = 2 + m_SaltSize + m_HashSize;
|
||||
public static readonly IPasswordProtection Instance = new PBKDF2PasswordProtection();
|
||||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
private const ushort m_MinIterations = 1024;
|
||||
private const ushort m_MaxIterations = 1536;
|
||||
private const int m_SaltSize = 8;
|
||||
private const int m_HashSize = 32;
|
||||
private const int m_OutputSize = 2 + m_SaltSize + m_HashSize;
|
||||
public static readonly IPasswordProtection Instance = new PBKDF2PasswordProtection();
|
||||
Span<byte> output = stackalloc byte[m_OutputSize];
|
||||
var iterations = Utility.RandomMinMax(m_MinIterations, m_MaxIterations);
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(output[..2], (ushort)iterations);
|
||||
|
||||
public string EncryptPassword(string plainPassword)
|
||||
{
|
||||
Span<byte> output = stackalloc byte[m_OutputSize];
|
||||
var iterations = Utility.RandomMinMax(m_MinIterations, m_MaxIterations);
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(output[..2], (ushort)iterations);
|
||||
var salt = output.Slice(2, m_SaltSize);
|
||||
RandomNumberGenerator.Fill(salt);
|
||||
|
||||
var rfc2898 = new Rfc2898DeriveBytes(plainPassword, m_SaltSize, iterations, HashAlgorithmName.SHA256);
|
||||
rfc2898.Salt.CopyTo(output.Slice(2, m_SaltSize));
|
||||
rfc2898.GetBytes(m_HashSize).CopyTo(output[(m_SaltSize + 2)..]);
|
||||
var hash = output.Slice(2 + m_SaltSize, m_HashSize);
|
||||
Rfc2898DeriveBytes.Pbkdf2(plainPassword, salt, hash, iterations, HashAlgorithmName.SHA256);
|
||||
|
||||
return output.ToHexString();
|
||||
}
|
||||
return output.ToHexString();
|
||||
}
|
||||
|
||||
public bool ValidatePassword(string encryptedPassword, string plainPassword)
|
||||
{
|
||||
Span<byte> encryptedBytes = stackalloc byte[m_OutputSize];
|
||||
encryptedPassword.GetBytes(encryptedBytes);
|
||||
public bool ValidatePassword(string encryptedPassword, string plainPassword)
|
||||
{
|
||||
Span<byte> encryptedBytes = stackalloc byte[m_OutputSize];
|
||||
encryptedPassword.GetBytes(encryptedBytes);
|
||||
|
||||
var iterations = BinaryPrimitives.ReadUInt16LittleEndian(encryptedBytes[..2]);
|
||||
var salt = encryptedBytes.Slice(2, m_SaltSize);
|
||||
var iterations = BinaryPrimitives.ReadUInt16LittleEndian(encryptedBytes[..2]);
|
||||
var salt = encryptedBytes.Slice(2, m_SaltSize);
|
||||
|
||||
ReadOnlySpan<byte> hash =
|
||||
new Rfc2898DeriveBytes(plainPassword, salt.ToArray(), iterations, HashAlgorithmName.SHA256).GetBytes(m_HashSize);
|
||||
Span<byte> hash = stackalloc byte[m_HashSize];
|
||||
Rfc2898DeriveBytes.Pbkdf2(plainPassword, salt, hash, iterations, HashAlgorithmName.SHA256);
|
||||
|
||||
return hash.SequenceEqual(encryptedBytes[(m_SaltSize + 2)..]);
|
||||
}
|
||||
return hash.SequenceEqual(encryptedBytes[(m_SaltSize + 2)..]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -320,7 +320,10 @@ namespace Server.Engines.Plants
|
|||
}
|
||||
|
||||
[SerializableFieldSaveFlag(17)]
|
||||
private bool ShouldSerializeLeftSeeds() => _leftSeeds != 0;
|
||||
private bool ShouldSerializeLeftSeeds() => _leftSeeds != 8;
|
||||
|
||||
[SerializableFieldDefault(17)]
|
||||
private int LeftSeedsDefaultValue() => 8;
|
||||
|
||||
[SerializableProperty(18)]
|
||||
public int AvailableResources
|
||||
|
|
@ -340,7 +343,10 @@ namespace Server.Engines.Plants
|
|||
}
|
||||
|
||||
[SerializableFieldSaveFlag(19)]
|
||||
private bool ShouldSerializeLeftResources() => _leftResources != 0;
|
||||
private bool ShouldSerializeLeftResources() => _leftResources != 8;
|
||||
|
||||
[SerializableFieldDefault(19)]
|
||||
private int LeftResourcesDefaultValue() => 8;
|
||||
|
||||
public void Reset(bool potions)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ public abstract partial class BaseCamp : BaseMulti
|
|||
|
||||
private TimeSpan _decayDelay;
|
||||
private Timer _decayTimer;
|
||||
private Timer _initTimer;
|
||||
|
||||
public BaseCamp(int multiID) : base(multiID)
|
||||
{
|
||||
|
|
@ -31,7 +32,7 @@ public abstract partial class BaseCamp : BaseMulti
|
|||
_decayDelay = TimeSpan.FromMinutes(30.0);
|
||||
RefreshDecay(true);
|
||||
|
||||
Timer.StartTimer(CheckAddComponents);
|
||||
_initTimer = Timer.DelayCall(TimeSpan.Zero, CheckAddComponents);
|
||||
}
|
||||
|
||||
public virtual int EventRange => 10;
|
||||
|
|
@ -50,6 +51,8 @@ public abstract partial class BaseCamp : BaseMulti
|
|||
|
||||
public void CheckAddComponents()
|
||||
{
|
||||
_initTimer = null;
|
||||
|
||||
if (Deleted)
|
||||
{
|
||||
return;
|
||||
|
|
@ -138,16 +141,16 @@ public abstract partial class BaseCamp : BaseMulti
|
|||
|
||||
for (var i = 0; i < _items.Count; ++i)
|
||||
{
|
||||
_items[i].Delete();
|
||||
_items[i]?.Delete();
|
||||
}
|
||||
|
||||
for (var i = 0; i < _mobiles.Count; ++i)
|
||||
{
|
||||
var mob = _mobiles[i];
|
||||
|
||||
if (mob.CantWalk || (mob as BaseCreature)?.IsPrisoner == false)
|
||||
if (mob != null && (mob.CantWalk || (mob as BaseCreature)?.IsPrisoner == false))
|
||||
{
|
||||
_mobiles[i].Delete();
|
||||
mob.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,6 +159,9 @@ public abstract partial class BaseCamp : BaseMulti
|
|||
|
||||
_decayTimer?.Stop();
|
||||
_decayTimer = null;
|
||||
|
||||
_initTimer?.Stop();
|
||||
_initTimer = null;
|
||||
}
|
||||
|
||||
private void Deserialize(IGenericReader reader, int version)
|
||||
|
|
@ -168,7 +174,20 @@ public abstract partial class BaseCamp : BaseMulti
|
|||
[AfterDeserialization]
|
||||
private void AfterDeserialization()
|
||||
{
|
||||
RefreshDecay(false);
|
||||
var remaining = _decayTime - Core.Now;
|
||||
|
||||
if (remaining > TimeSpan.Zero)
|
||||
{
|
||||
_decayDelay = remaining;
|
||||
RefreshDecay(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Timer.DelayCall(TimeSpan.Zero, Delete);
|
||||
return;
|
||||
}
|
||||
|
||||
_initTimer = Timer.DelayCall(TimeSpan.Zero, CheckAddComponents);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,16 +39,16 @@
|
|||
<IncludeInPackage>false</IncludeInPackage>
|
||||
</ProjectReference>
|
||||
<PackageReference Include="LibDeflate.Bindings" Version="1.0.2.120" />
|
||||
<PackageReference Include="MailKit" Version="4.13.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="9.0.7" />
|
||||
<PackageReference Include="MailKit" Version="4.14.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="10.0.0" />
|
||||
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.0" />
|
||||
<PackageReference Include="Argon2.Bindings" Version="1.16.1" />
|
||||
<PackageReference Include="ModernUO.CodeGeneratedEvents.Annotations" Version="1.0.0" />
|
||||
<PackageReference Include="ModernUO.CodeGeneratedEvents.Generator" Version="1.0.3.2" PrivateAssets="all" />
|
||||
<PackageReference Include="Zstd.Binaries" Version="1.6.0" />
|
||||
|
||||
<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.9.1" />
|
||||
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.12.20" />
|
||||
<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.13.0" />
|
||||
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.13.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AdditionalFiles Include="Migrations/*.v*.json" />
|
||||
|
|
|
|||
44
README.md
44
README.md
|
|
@ -15,38 +15,38 @@ ModernUO [](https://www.microsoft.com/en-US/evalcenter/evaluate-windows-server-2022)
|
||||

|
||||
[](https://www.microsoft.com/en-US/evalcenter/evaluate-windows-server-2022)
|
||||

|
||||
[](https://www.debian.org/distrib/)
|
||||
[](https://ubuntu.com/download/server)
|
||||
<br/>
|
||||
[](https://alpinelinux.org/downloads/)
|
||||
[](https://getfedora.org/en/server/download/)
|
||||
[](https://access.redhat.com/downloads)
|
||||
[](https://www.centos.org/download/)
|
||||
[](https://get.opensuse.org/)
|
||||
[](https://www.suse.com/download/sles/)
|
||||
[](https://linuxmint.com/download.php)
|
||||
[](https://alpinelinux.org/downloads/)
|
||||
[](https://getfedora.org/en/server/download/)
|
||||
[](https://access.redhat.com/downloads)
|
||||
[](https://www.centos.org/download/)
|
||||
[](https://get.opensuse.org/)
|
||||
[](https://www.suse.com/download/sles/)
|
||||
[](https://linuxmint.com/download.php)
|
||||
[](https://archlinux.org/download/)
|
||||
|
||||
#### Required Frameworks
|
||||
##### All Operating Systems
|
||||
[](https://dotnet.microsoft.com/download/dotnet/9.0)
|
||||
[](https://dotnet.microsoft.com/download/dotnet/10.0)
|
||||
|
||||
##### Windows
|
||||
[](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#visual-studio-2015-2017-2019-and-2022)
|
||||
[](https://aka.ms/vc14/vc_redist.x64.exe)
|
||||
|
||||
#### Development
|
||||
[](https://git-scm.com/downloads)
|
||||
[](https://dotnet.microsoft.com/download/dotnet/9.0)
|
||||
[](https://dotnet.microsoft.com/download/dotnet/10.0)
|
||||
|
||||
#### Supported IDEs
|
||||
<p align="left">
|
||||
<a href="https://www.jetbrains.com/rider/download"><img height="64" title="Jetbrains Rider 2025+" alt="Jetbrains Rider 2025+" src="https://github.com/user-attachments/assets/456dc87e-a7e7-467b-81b6-ba9c8e227f86"></a>
|
||||
<a href="https://www.jetbrains.com/rider/download"><img height="64" title="Jetbrains Rider 2025.3+" alt="Jetbrains Rider 2025.3+" src="https://github.com/user-attachments/assets/456dc87e-a7e7-467b-81b6-ba9c8e227f86"></a>
|
||||
<img alt="space" width="32" src="https://user-images.githubusercontent.com/3953314/200151935-3c1521ec-16cb-487b-85a2-7454d347c585.png">
|
||||
<a href="https://code.visualstudio.com/download"><img height="64" title="VSCode" alt="VSCode" src="https://user-images.githubusercontent.com/3953314/200161017-7697171f-8f13-4829-95d0-8a25b59ee4c9.png"></a>
|
||||
<img alt="space" width="32" src="https://user-images.githubusercontent.com/3953314/200151935-3c1521ec-16cb-487b-85a2-7454d347c585.png">
|
||||
<a href="https://visualstudio.microsoft.com/vs/community/"><img height="64" title="Visual Studio 2022 v17.12+" alt="Visual Studio 2022 v17.12+" src="https://user-images.githubusercontent.com/3953314/133473556-35fd48b4-6460-49b1-b7c5-b4a8c529cc04.png"></a>
|
||||
<a href="https://visualstudio.microsoft.com/vs/community/"><img height="64" title="Visual Studio 2026" alt="Visual Studio 2026" src="https://github.com/user-attachments/assets/4cb26751-56bb-4ea1-97e6-afe31d2dc9d7"></a>
|
||||
</p>
|
||||
|
||||
## Getting Started
|
||||
|
|
@ -57,13 +57,13 @@ ModernUO [] [os] [arch (default: x64)]`
|
||||
- `os` - [Supported operating systems](https://github.com/dotnet/core/blob/main/release-notes/9.0/supported-os.md)
|
||||
- `win` - Windows 10/11/2019/2022/2025
|
||||
- `osx` - MacOS 13/14/15 (Sequoia, Sonoma, Big Sur)
|
||||
- `linux` - Linux
|
||||
- `os` - [Supported operating systems](https://github.com/dotnet/core/blob/main/release-notes/10.0/supported-os.md)
|
||||
- `win` - [Windows](https://learn.microsoft.com/en-us/dotnet/core/install/windows)
|
||||
- `osx` - [MacOS](https://learn.microsoft.com/en-us/dotnet/core/install/macos)
|
||||
- `linux` - [Linux](https://learn.microsoft.com/en-us/dotnet/core/install/linux)
|
||||
- `arch`
|
||||
- `x64` - Intel 64-bit
|
||||
- `arm64` - ARM 64-bit (Windows Arm64 not supported)
|
||||
- `x64` - Intel/AMD 64-bit
|
||||
- `arm64` - ARM 64-bit (Windows not supported)
|
||||
|
||||
## Linux Prerequisites
|
||||
### Fedora, CentOS, RHEL, etc
|
||||
|
|
@ -86,8 +86,8 @@ brew install icu4c libdeflate zstd argon2
|
|||
```
|
||||
|
||||
## Running the Server
|
||||
- Follow the [publish](https://github.com/modernuo/ModernUO#publishing-builds) instructions
|
||||
- Run `ModernUO.exe` or `dotnet ModernUO.dll` from the `Distribution` directory on the
|
||||
- Follow the [publish](https://github.com/modernuo/ModernUO#buildingpublishing) instructions
|
||||
- Run `ModernUO.exe` or `dotnet ModernUO.dll` from the `Distribution` directory
|
||||
|
||||
## Troubleshooting / FAQ
|
||||
- See [FAQ](./FAQ.md)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- task: UseDotNet@2
|
||||
displayName: 'Install .NET 9'
|
||||
displayName: 'Install .NET'
|
||||
inputs:
|
||||
useGlobalJson: true
|
||||
- task: NuGetAuthenticate@1
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ title: Installation
|
|||
|
||||
=== "Windows"
|
||||
### Prerequisites
|
||||
1. Download and install the latest [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0)
|
||||
1. Download and install the latest [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0)
|
||||
1. Download and install from [here](https://git-scm.com/download/win)
|
||||
|
||||
!!! Tip
|
||||
|
|
@ -22,7 +22,7 @@ title: Installation
|
|||
|
||||
=== "OSX"
|
||||
### Prerequisites
|
||||
1. Download and install the latest [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0).
|
||||
1. Download and install the latest [.NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0).
|
||||
1. Using _terminal_, install [homebrew](https://brew.sh) and git:
|
||||
```bash
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
|
||||
|
|
@ -37,7 +37,7 @@ title: Installation
|
|||
|
||||
=== "Linux"
|
||||
### Prerequisites
|
||||
1. Download and install the latest [.NET 8 SDK](https://docs.microsoft.com/en-us/dotnet/core/install/linux).
|
||||
1. Download and install the latest [.NET 10 SDK](https://docs.microsoft.com/en-us/dotnet/core/install/linux).
|
||||
1. Using _bash_, install git:
|
||||
```bash
|
||||
sudo apt update && sudo apt install git
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version": "9.0.100",
|
||||
"version": "10.0.100",
|
||||
"rollForward": "latestMajor",
|
||||
"allowPrerelease": false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
|
||||
"version": "0.15.1"
|
||||
"version": "0.15.2"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue