Skip to content

Commit cff65cb

Browse files
authored
Merge pull request #91 from NosCoreIO/claude/upgrade-dotnet-10-01BcetFyyVBD62HhVeqkRVdU
Upgrade Project to .NET 10
2 parents 0bc64ae + 1622ccb commit cff65cb

33 files changed

+526
-47
lines changed

.github/workflows/dotnet.yml

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ jobs:
1212
build:
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/checkout@v2
16-
- name: Setup .NET
17-
uses: actions/setup-dotnet@v3
15+
- uses: actions/checkout@v4
16+
- name: Setup .NET 10
17+
uses: actions/setup-dotnet@v4
1818
with:
19-
dotnet-version: 8.0.x
19+
dotnet-version: '10.0.0'
20+
continue-on-error: true
21+
- name: Fallback - Install .NET 10 manually
22+
if: failure()
23+
run: |
24+
wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
25+
chmod +x dotnet-install.sh
26+
./dotnet-install.sh --channel 10.0 --install-dir $HOME/.dotnet
27+
echo "$HOME/.dotnet" >> $GITHUB_PATH
2028
2129
- name: Check Tag
2230
id: check-tag
2331
run: |
2432
if [[ v${{ github.event.ref }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
25-
echo ::set-output name=match::true
33+
echo "match=true" >> $GITHUB_OUTPUT
2634
fi
2735
2836
- name: Run Unit Tests
@@ -39,23 +47,13 @@ jobs:
3947
dotnet build -c Release
4048
dotnet pack -c Release -o /tmp/nupkgs -v m -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
4149
dotnet nuget push /tmp/nupkgs/NosCore.Networking.${{github.event.ref}}.nupkg -s https://api.nuget.org/v3/index.json -k ${{secrets.NUGET_API_KEY}}
42-
echo ::set-output name=ARTIFACT_PATH::/tmp/nupkgs/NosCore.Networking.${{github.event.ref}}.nupkg
43-
echo ::set-output name=ARTIFACT_NAME::NosCore.Networking.${{github.event.ref}}.nupkg
44-
45-
- name: Gets Latest Release
46-
if: steps.check-tag.outputs.match == 'true'
47-
id: latest_release_info
48-
uses: jossef/[email protected]
49-
env:
50-
GITHUB_TOKEN: ${{ github.token }}
50+
echo "ARTIFACT_PATH=/tmp/nupkgs/NosCore.Networking.${{github.event.ref}}.nupkg" >> $GITHUB_OUTPUT
51+
echo "ARTIFACT_NAME=NosCore.Networking.${{github.event.ref}}.nupkg" >> $GITHUB_OUTPUT
5152
5253
- name: Upload Release Asset
5354
if: steps.check-tag.outputs.match == 'true'
54-
uses: actions/upload-release-asset@v1
55-
env:
56-
GITHUB_TOKEN: ${{ github.token }}
55+
uses: softprops/action-gh-release@v2
5756
with:
58-
upload_url: ${{ steps.latest_release_info.outputs.upload_url }}
59-
asset_path: ${{ steps.build_artifact.outputs.ARTIFACT_PATH }}
60-
asset_name: ${{ steps.build_artifact.outputs.ARTIFACT_NAME }}
61-
asset_content_type: application/zip
57+
files: ${{ steps.build_artifact.outputs.ARTIFACT_PATH }}
58+
env:
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/NosCore.Networking/BroadcastableExtension.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,41 @@
1313

1414
namespace NosCore.Networking
1515
{
16+
/// <summary>
17+
/// Provides extension methods for broadcasting packets to <see cref="IBroadcastable"/> instances.
18+
/// </summary>
1619
public static class IBroadcastableExtension
1720
{
21+
/// <summary>
22+
/// Sends a single packet to all sessions in the broadcastable group.
23+
/// </summary>
24+
/// <param name="channelGroup">The broadcastable group to send the packet to.</param>
25+
/// <param name="packet">The packet to send.</param>
26+
/// <returns>A task representing the asynchronous send operation.</returns>
1827
public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet)
1928
{
2029
return channelGroup.SendPacketsAsync(new[] { packet });
2130
}
2231

32+
/// <summary>
33+
/// Sends a single packet to matching sessions in the broadcastable group.
34+
/// </summary>
35+
/// <param name="channelGroup">The broadcastable group to send the packet to.</param>
36+
/// <param name="packet">The packet to send.</param>
37+
/// <param name="matcher">The channel matcher to filter recipients.</param>
38+
/// <returns>A task representing the asynchronous send operation.</returns>
2339
public static Task SendPacketAsync(this IBroadcastable channelGroup, IPacket packet, IChannelMatcher matcher)
2440
{
2541
return channelGroup.SendPacketsAsync(new[] { packet }, matcher);
2642
}
2743

28-
44+
/// <summary>
45+
/// Sends multiple packets to matching sessions in the broadcastable group.
46+
/// </summary>
47+
/// <param name="channelGroup">The broadcastable group to send the packets to.</param>
48+
/// <param name="packets">The collection of packets to send.</param>
49+
/// <param name="matcher">The optional channel matcher to filter recipients.</param>
50+
/// <returns>A task representing the asynchronous send operation.</returns>
2951
public static async Task SendPacketsAsync(this IBroadcastable channelGroup, IEnumerable<IPacket> packets,
3052
IChannelMatcher? matcher)
3153
{
@@ -51,6 +73,12 @@ public static async Task SendPacketsAsync(this IBroadcastable channelGroup, IEnu
5173
}
5274

5375

76+
/// <summary>
77+
/// Sends multiple packets to all sessions in the broadcastable group.
78+
/// </summary>
79+
/// <param name="channelGroup">The broadcastable group to send the packets to.</param>
80+
/// <param name="packets">The collection of packets to send.</param>
81+
/// <returns>A task representing the asynchronous send operation.</returns>
5482
public static Task SendPacketsAsync(this IBroadcastable channelGroup, IEnumerable<IPacket> packets)
5583
{
5684
return channelGroup.SendPacketsAsync(packets, null);

src/NosCore.Networking/Encoding/Filter/RequestFilter.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,25 @@
1212

1313
namespace NosCore.Networking.Encoding.Filter
1414
{
15+
/// <summary>
16+
/// Abstract base class for request filters that process incoming byte data.
17+
/// </summary>
1518
public abstract class RequestFilter : MessageToMessageDecoder<IByteBuffer>
1619
{
20+
/// <summary>
21+
/// Filters incoming request data.
22+
/// </summary>
23+
/// <param name="context">The channel handler context.</param>
24+
/// <param name="message">The incoming message bytes.</param>
25+
/// <returns>The filtered byte array, or null if the request should be blocked.</returns>
1726
public abstract byte[]? Filter(IChannelHandlerContext context, Span<byte> message);
1827

28+
/// <summary>
29+
/// Decodes the incoming byte buffer through the filter.
30+
/// </summary>
31+
/// <param name="context">The channel handler context.</param>
32+
/// <param name="message">The byte buffer to decode.</param>
33+
/// <param name="output">The output list to add filtered results to.</param>
1934
protected override void Decode(IChannelHandlerContext context, IByteBuffer message, List<object> output)
2035
{
2136
var result = Filter(context, ((Span<byte>)message.Array).Slice(message.ArrayOffset, message.ReadableBytes));

src/NosCore.Networking/Encoding/Filter/SpamRequestFilter.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,41 @@
1515

1616
namespace NosCore.Networking.Encoding.Filter
1717
{
18+
/// <summary>
19+
/// Filters spam requests by rate-limiting connections from the same IP address.
20+
/// </summary>
1821
public class SpamRequestFilter : RequestFilter
1922
{
2023
private readonly Dictionary<EndPoint, Instant> _connectionsByIp = new();
2124
private readonly TimeSpan _timeBetweenConnection = TimeSpan.FromMilliseconds(1000);
2225
private readonly IClock _clock;
2326
private readonly ILogger<SpamRequestFilter> _logger;
2427
private readonly ILogLanguageLocalizer<LogLanguageKey> _logLanguage;
28+
29+
/// <summary>
30+
/// Gets a value indicating whether this handler can be shared across multiple channels.
31+
/// </summary>
2532
public override bool IsSharable => true;
2633

34+
/// <summary>
35+
/// Initializes a new instance of the <see cref="SpamRequestFilter"/> class.
36+
/// </summary>
37+
/// <param name="clock">The clock instance for time tracking.</param>
38+
/// <param name="logger">The logger instance.</param>
39+
/// <param name="logLanguage">The localized log language provider.</param>
2740
public SpamRequestFilter(IClock clock, ILogger<SpamRequestFilter> logger, ILogLanguageLocalizer<LogLanguageKey> logLanguage)
2841
{
2942
_clock = clock;
3043
_logger = logger;
3144
_logLanguage = logLanguage;
3245
}
3346

47+
/// <summary>
48+
/// Filters incoming requests based on connection rate from the same IP address.
49+
/// </summary>
50+
/// <param name="context">The channel handler context.</param>
51+
/// <param name="message">The incoming message bytes.</param>
52+
/// <returns>The message bytes if allowed, or null if blocked by the spam filter.</returns>
3453
public override byte[]? Filter(IChannelHandlerContext context, Span<byte> message)
3554
{
3655
if (_connectionsByIp.TryGetValue(context.Channel.RemoteAddress, out var date))

src/NosCore.Networking/Encoding/FrameDelimiter.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,28 @@
1313

1414
namespace NosCore.Networking.Encoding;
1515

16+
/// <summary>
17+
/// Delimits incoming byte streams into frames based on session-specific delimiters.
18+
/// </summary>
1619
public class FrameDelimiter : ByteToMessageDecoder
1720
{
1821
private readonly ISessionRefHolder _sessionRefHolder;
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="FrameDelimiter"/> class.
25+
/// </summary>
26+
/// <param name="sessionRefHolder">The session reference holder.</param>
1927
public FrameDelimiter(ISessionRefHolder sessionRefHolder)
2028
{
2129
_sessionRefHolder = sessionRefHolder;
2230
}
2331

24-
32+
/// <summary>
33+
/// Decodes the incoming byte buffer into frames based on delimiters.
34+
/// </summary>
35+
/// <param name="context">The channel handler context.</param>
36+
/// <param name="input">The input byte buffer.</param>
37+
/// <param name="output">The output list to add decoded frames to.</param>
2538
protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
2639
{
2740
var sessionId = context.Channel.Id.AsLongText();
@@ -45,6 +58,12 @@ protected override void Decode(IChannelHandlerContext context, IByteBuffer input
4558
}
4659
}
4760

61+
/// <summary>
62+
/// Gets the delimiter byte for a specific session.
63+
/// </summary>
64+
/// <param name="session">The session identifier.</param>
65+
/// <param name="isFirstPacket">Whether this is the first packet in the session.</param>
66+
/// <returns>The delimiter byte for the session.</returns>
4867
public static byte GetDelimiter(int session, bool isFirstPacket = false)
4968
{
5069
int stype = !isFirstPacket ? (session >> 6) & 3 : -1;

src/NosCore.Networking/Encoding/IDecoder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@
1111

1212
namespace NosCore.Networking.Encoding
1313
{
14+
/// <summary>
15+
/// Defines a packet decoder that converts byte data into packets.
16+
/// </summary>
1417
public interface IDecoder : IChannelHandler
1518
{
19+
/// <summary>
20+
/// Decodes a byte span into a collection of packets.
21+
/// </summary>
22+
/// <param name="clientSessionId">The client session identifier.</param>
23+
/// <param name="message">The byte span containing the encoded packet data.</param>
24+
/// <returns>A collection of decoded packets.</returns>
1625
IEnumerable<IPacket> Decode(string clientSessionId, Span<byte> message);
1726
}
1827
}

src/NosCore.Networking/Encoding/IEncoder.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@
1111

1212
namespace NosCore.Networking.Encoding
1313
{
14+
/// <summary>
15+
/// Defines a packet encoder that converts packets to byte arrays for transmission.
16+
/// </summary>
1417
public interface IEncoder : IChannelHandler
1518
{
19+
/// <summary>
20+
/// Encodes a collection of packets into a byte array.
21+
/// </summary>
22+
/// <param name="clientSessionId">The client session identifier.</param>
23+
/// <param name="packets">The packets to encode.</param>
24+
/// <returns>A byte array containing the encoded packet data.</returns>
1625
byte[] Encode(string clientSessionId, IEnumerable<IPacket> packets);
1726
}
1827
}

src/NosCore.Networking/Encoding/LoginDecoder.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@
1919

2020
namespace NosCore.Networking.Encoding
2121
{
22+
/// <summary>
23+
/// Decodes packets from login server communication using region-specific decoding.
24+
/// </summary>
2225
public class LoginDecoder : MessageToMessageDecoder<IByteBuffer>, IDecoder
2326
{
2427
private readonly IDeserializer _deserializer;
2528
private readonly ILogger<LoginDecoder> _logger;
2629
private readonly ISessionRefHolder _sessionRefHolder;
2730
private readonly ILogLanguageLocalizer<LogLanguageKey> _logLanguage;
2831

32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="LoginDecoder"/> class.
34+
/// </summary>
35+
/// <param name="logger">The logger instance.</param>
36+
/// <param name="deserializer">The packet deserializer.</param>
37+
/// <param name="sessionRefHolder">The session reference holder.</param>
38+
/// <param name="logLanguage">The localized log language provider.</param>
2939
public LoginDecoder(ILogger<LoginDecoder> logger, IDeserializer deserializer, ISessionRefHolder sessionRefHolder, ILogLanguageLocalizer<LogLanguageKey> logLanguage)
3040
{
3141
_logger = logger;
@@ -34,6 +44,12 @@ public LoginDecoder(ILogger<LoginDecoder> logger, IDeserializer deserializer, IS
3444
_logLanguage = logLanguage;
3545
}
3646

47+
/// <summary>
48+
/// Decodes a byte span into a collection of packets using login server decoding.
49+
/// </summary>
50+
/// <param name="clientSessionId">The client session identifier.</param>
51+
/// <param name="message">The byte span containing the encoded packet data.</param>
52+
/// <returns>A collection of decoded packets.</returns>
3753
public IEnumerable<IPacket> Decode(string clientSessionId, Span<byte> message)
3854
{
3955
try
@@ -75,6 +91,12 @@ public IEnumerable<IPacket> Decode(string clientSessionId, Span<byte> message)
7591
return Array.Empty<IPacket>();
7692
}
7793

94+
/// <summary>
95+
/// Decodes a byte buffer into packets.
96+
/// </summary>
97+
/// <param name="context">The channel handler context.</param>
98+
/// <param name="message">The byte buffer containing encoded packet data.</param>
99+
/// <param name="output">The output list to add decoded packets to.</param>
78100
protected override void Decode(IChannelHandlerContext context, IByteBuffer message, List<object> output)
79101
{
80102
var packets = Decode(context.Channel.Id.AsLongText(),

src/NosCore.Networking/Encoding/LoginEncoder.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@
1919

2020
namespace NosCore.Networking.Encoding
2121
{
22+
/// <summary>
23+
/// Encodes packets for login server communication using region-specific encoding.
24+
/// </summary>
2225
public class LoginEncoder : MessageToMessageEncoder<IEnumerable<IPacket>>, IEncoder
2326
{
2427
private readonly ILogger<LoginEncoder> _logger;
2528
private readonly ISerializer _serializer;
2629
private readonly ISessionRefHolder _sessionRefHolder;
2730
private readonly ILogLanguageLocalizer<LogLanguageKey> _logLanguage;
2831

32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="LoginEncoder"/> class.
34+
/// </summary>
35+
/// <param name="logger">The logger instance.</param>
36+
/// <param name="serializer">The packet serializer.</param>
37+
/// <param name="sessionRefHolder">The session reference holder.</param>
38+
/// <param name="logLanguage">The localized log language provider.</param>
2939
public LoginEncoder(ILogger<LoginEncoder> logger, ISerializer serializer, ISessionRefHolder sessionRefHolder, ILogLanguageLocalizer<LogLanguageKey> logLanguage)
3040
{
3141
_logger = logger;
@@ -34,12 +44,24 @@ public LoginEncoder(ILogger<LoginEncoder> logger, ISerializer serializer, ISessi
3444
_logLanguage = logLanguage;
3545
}
3646

47+
/// <summary>
48+
/// Encodes packets into a byte buffer for transmission.
49+
/// </summary>
50+
/// <param name="context">The channel handler context.</param>
51+
/// <param name="message">The packets to encode.</param>
52+
/// <param name="output">The output list to add the encoded buffer to.</param>
3753
protected override void Encode(IChannelHandlerContext context, IEnumerable<IPacket> message,
3854
List<object> output)
3955
{
4056
output.Add(Unpooled.WrappedBuffer(Encode(context.Channel.Id.AsLongText(), message)));
4157
}
4258

59+
/// <summary>
60+
/// Encodes a collection of packets into a byte array using login server encoding.
61+
/// </summary>
62+
/// <param name="clientSessionId">The client session identifier.</param>
63+
/// <param name="packets">The packets to encode.</param>
64+
/// <returns>A byte array containing the encoded packet data.</returns>
4365
public byte[] Encode(string clientSessionId, IEnumerable<IPacket> packets)
4466
{
4567
try

0 commit comments

Comments
 (0)