Tons of minor fixes

This commit is contained in:
derek.holloway committed 2026-08-03 10:01:31 -07:00
1 parent 873a6fa455
commit 37a6b5d59b
12 files changed
+219 -147

No files matched your search

+13 -13
View File
@@ -1,17 +1,16 @@
using System;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
namespace Mistox.Client {
public class UDPReceiver : IDisposable {
MistoxClient _parent;
private readonly MistoxClient _parent;
public UDPReceiver( MistoxClient parent) {
_parent = parent;
Thread Client = new Thread(async() => { await ReceiveThread(); });
Client.Start();
// Start the receive thread
Task.Run(ReceiveThread);
}
async Task ReceiveThread() {
@@ -21,25 +20,26 @@ namespace Mistox.Client {
// As UDP reads the whole next packet then drops. Im guaranteed to receive 1 packet at a time
UdpReceiveResult udpPacket = await _parent.ClientSocket.ReceiveAsync();
// Compute the connectionKey
UInt128 ConnectionKey = mUDPClient.GetConnectionKey(udpPacket.RemoteEndPoint.Address);
// Try find the user
mUDPClient client = null;
bool clientExists = _parent.clientConnections.TryGetValue(ConnectionKey, out client);
bool clientExists = _parent.clientConnections.TryGetValue(udpPacket.RemoteEndPoint, out client);
if (clientExists) {
// Create the data readers
ReadOnlyMemory<byte> dataMemory = udpPacket.Buffer.AsMemory();
ReadOnlySpan<byte> dataPacket = dataMemory.Span;
// Split apart the packet
byte dataType = dataPacket[0];
ushort DataLength = (ushort)((dataPacket[1] << 8) | dataPacket[2]);
ReadOnlyMemory<byte> data = dataMemory.Slice(DataPacket.HeaderLength, DataLength);
// Create the packet header
DataPacketHeader Header = new DataPacketHeader {
Type = dataPacket[0],
DataLength = (ushort)((dataPacket[1] << 8) | dataPacket[2])
};
// Slice out the data part of the packet
ReadOnlyMemory<byte> data = dataMemory.Slice(DataPacket.HeaderLength, Header.DataLength);
// Extract the object
dynamic buildObj = DataPacket.Deserialize( dataType, DataLength, data );
dynamic buildObj = DataPacket.Deserialize( Header, data );
// Return the object
_parent.InvokeOnReceived( buildObj, client );