Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
TitleHHHH authored and TitleHHHH committed Sep 22, 2024
1 parent 8e4bd33 commit b5d13a8
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNext" Version="5.7.0" />
<PackageReference Include="DotNext" Version="5.13.0" />
</ItemGroup>

</Project>
9 changes: 6 additions & 3 deletions src/McProtoNet/McProtoNet.NBT/McProtoNet.NBT.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand All @@ -12,7 +12,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ConfigureAwait.Fody" Version="3.3.2"/>
<PackageReference Include="DotNext" Version="5.7.0" />
<PackageReference Include="MinVer" Version="5.0.0"/>
<PackageReference Include="DotNext" Version="5.13.0" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/McProtoNet/McProtoNet.NBT/NbtSpanReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public NbtSpanReader(ReadOnlySpan<byte> data)
}


public T ReadAsTag<T>(bool readRootName = true) where T : NbtTag
public T ReadAsTag<T>(bool readRootName) where T : NbtTag
{
NbtTagType type = ReadTagType();
string? rootName = readRootName ? ReadString() : null;
if (_reader.RemainingCount >= 512) // Recursive
if (_reader.RemainingCount <= 512) // Recursive
{
return ReadRecursive(type, rootName) as T ?? throw new InvalidOperationException($"Error cast to {typeof(T)}");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
14 changes: 10 additions & 4 deletions src/McProtoNet/McProtoNet.Protocol/Protocols/MultiProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class MultiProtocol : ProtocolBase
{
private Subject<KeepAlivePacket> _onKeepAlive = new Subject<KeepAlivePacket>();
private static readonly byte[] bitset = new byte[3];

public Subject<Unit> OnJoinGame { get; } = new();
public MultiProtocol(IPacketBroker client) : base(client)
{
//SupportedVersion = 755;
Expand Down Expand Up @@ -65,11 +65,16 @@ protected override void OnPacketReceived(InputPacket packet)
>= 764 and <= 765 => 0x1B,
>= 766 and <= 767 => 0x1D,
};

if (packet.Id == 0x2B)
{
OnJoinGame.OnNext(Unit.Default);
return;
}
if (keepAlive == packet.Id)
{
scoped var reader = new MinecraftPrimitiveReaderSlim(packet.Data);
_onKeepAlive.OnNext(new KeepAlivePacket(reader.ReadSignedLong()));
//_onKeepAlive.OnNext(new KeepAlivePacket(reader.ReadSignedLong()));
_ = SendKeepAlive(reader.ReadSignedLong());
}
else if (disconnect == packet.Id)
{
Expand All @@ -79,7 +84,8 @@ protected override void OnPacketReceived(InputPacket packet)
// var reason = reader.ReadNbt();
NbtSpanReader nbtReader = new NbtSpanReader(packet.Data.Span);

var nbt = nbtReader.ReadAsTag<NbtTag>();
var nbt = nbtReader.ReadAsTag<NbtTag>(false);
Console.WriteLine($"{nbt} ThreadName: {Thread.CurrentThread.Name}");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNext" Version="5.7.0" />
<PackageReference Include="DotNext.IO" Version="5.7.0" />
<PackageReference Include="DotNext.Unsafe" Version="5.7.0" />
<PackageReference Include="DotNext" Version="5.13.0" />
<PackageReference Include="DotNext.IO" Version="5.13.0" />
<PackageReference Include="DotNext.Unsafe" Version="5.13.0" />
<PackageReference Include="ZString" Version="2.6.0"/>
<PackageReference Include="MinVer" Version="5.0.0"/>
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/McProtoNet/McProtoNet.Tests/McProtoNet.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>12</LangVersion>
<IsPackable>false</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion src/McProtoNet/McProtoNet.Utils/McProtoNet.Utils.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand Down
13 changes: 8 additions & 5 deletions src/McProtoNet/McProtoNet/Client/MinecraftClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Net.Sockets;
using DotNext;
using DotNext.Threading;
using Fody;
using LibDeflate;
using McProtoNet.Abstractions;
using McProtoNet.Protocol;
Expand Down Expand Up @@ -117,8 +118,10 @@ public async Task Start()


var result = await minecraftLogin.Login(mainStream, loginOptions, CTS.Token);

_ = MainLoop(result, CTS.Token);

_ = MainLoop(result, CTS.Token);


}
catch (OperationCanceledException ex)
{
Expand Down Expand Up @@ -147,6 +150,7 @@ private void OnException(Exception ex)
StateChanged?.Invoke(this, new StateEventArgs(ex, _state));
}

[ConfigureAwait(true)]
private async Task MainLoop(LoginizationResult loginizationResult, CancellationToken cancellationToken)
{
_packetSender = new MinecraftPacketSender();
Expand All @@ -162,7 +166,8 @@ private async Task MainLoop(LoginizationResult loginizationResult, CancellationT
{
while (!cancellationToken.IsCancellationRequested)
{
var packet = await _packetReader.ReadNextPacketAsync(cancellationToken);
var packet = await _packetReader
.ReadNextPacketAsync(cancellationToken);
try
{
PacketReceived?.Invoke(this, packet);
Expand Down Expand Up @@ -208,8 +213,6 @@ private async ValueTask ConnectAsync(CancellationToken cancellationToken)
}
else
{


await newTcp.ConnectAsync(Host, Port, cancellationToken);
mainStream = newTcp.GetStream();
}
Expand Down
13 changes: 8 additions & 5 deletions src/McProtoNet/McProtoNet/McProtoNet.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>preview</LangVersion>
Expand All @@ -12,10 +12,13 @@

<ItemGroup>
<PackageReference Include="ConfigureAwait.Fody" Version="3.3.2"/>
<PackageReference Include="DotNext.IO" Version="5.7.0" />
<PackageReference Include="DotNext.Threading" Version="5.7.0" />
<PackageReference Include="MinVer" Version="5.0.0"/>
<PackageReference Include="DotNext" Version="5.7.0" />
<PackageReference Include="DotNext.IO" Version="5.13.0" />
<PackageReference Include="DotNext.Threading" Version="5.13.0" />
<PackageReference Include="MinVer" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="DotNext" Version="5.13.0" />
<PackageReference Include="LibDeflate.NET" Version="1.19.0"/>
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0"/>

Expand Down
72 changes: 61 additions & 11 deletions src/Sandbox/SandBoxMcProtoNet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// See https://aka.ms/new-console-template for more information

using System.Collections.Concurrent;
using System.Diagnostics;
using System.Reactive.Linq;
using System.Text;
using DotNext.Collections.Generic;
using McProtoNet.Client;
Expand All @@ -14,22 +16,70 @@ public static async Task Main(string[] args)
Console.WriteLine("Start");
try
{
MinecraftClient client = new MinecraftClient()
var list = new List<MinecraftClient>();
var listProtocols = new List<MultiProtocol>();
for (int i = 0; i < 300; i++)
{
ConnectTimeout = TimeSpan.FromSeconds(30),
Host = "192.168.0.7",
Port = 25565,
Username = "TestBot",
Version = MinecraftVersion.Latest
};

var protoTest = new MultiProtocol(client);
await client.Start();
MinecraftClient client = new MinecraftClient()
{
ConnectTimeout = TimeSpan.FromSeconds(30),
Host = "192.168.0.7",
Port = 25565,
Username = $"TitleBot_{i + 1:D3}",
Version = MinecraftVersion.Latest
};

var protoTest = new MultiProtocol(client);
listProtocols.Add(protoTest);
list.Add(client);
}

List<Task> tasks = new List<Task>();
int index = 0;
await foreach (var minecraftClient in list)
{
static async Task RunBot(MinecraftClient client, MultiProtocol proto)
{
for (int i = 0; i < 10; i++)
{
try
{
await client.Start();
await proto.OnJoinGame.FirstOrDefaultAsync();
break;
}
catch (Exception e)
{
// Console.WriteLine(e);
}
}
}

tasks.Add(RunBot(minecraftClient, listProtocols[index++]));
}

await Task.WhenAll(tasks);
//while (true)
{
await Task.Delay(5000);
var sends = listProtocols.Select(async b =>
{
try
{
await b.SendChatPacket("Hello from Minecraft Holy Client");
}
catch
{
// ignored
}
});
await Task.WhenAll(sends);
}
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
// throw;
}

await Task.Delay(-1);
Expand Down
2 changes: 1 addition & 1 deletion src/Sandbox/SandBoxMcProtoNet/SandBoxMcProtoNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down

0 comments on commit b5d13a8

Please sign in to comment.