Implement handshake Hello NetControlMessage, recv and send

This commit is contained in:
AeonLucid
2022-01-12 07:26:25 +01:00
parent 0a27bdd3c0
commit 65a28b32ef
50 changed files with 2768 additions and 156 deletions
+59 -2
View File
@@ -1,7 +1,9 @@
using Prospect.Unreal.Core;
using Prospect.Unreal.Exceptions;
using Prospect.Unreal.Net;
using Prospect.Unreal.Net.Channels;
using Prospect.Unreal.Net.Packets.Bunch;
using Prospect.Unreal.Net.Packets.Control;
using Serilog;
namespace Prospect.Unreal.Runtime;
@@ -60,7 +62,12 @@ public abstract class UWorld : FNetworkNotify, IAsyncDisposable
public bool NotifyAcceptingChannel(UChannel channel)
{
var driver = channel.Connection.Driver!;
if (channel.Connection?.Driver == null)
{
throw new UnrealNetException();
}
var driver = channel.Connection.Driver;
if (!driver.IsServer())
{
throw new NotSupportedException("Client code");
@@ -81,9 +88,59 @@ public abstract class UWorld : FNetworkNotify, IAsyncDisposable
}
}
public void NotifyControlMessage(UNetConnection connection, byte messageType, FInBunch bunch)
public void NotifyControlMessage(UNetConnection connection, NMT messageType, FInBunch bunch)
{
if (NetDriver == null)
{
throw new UnrealNetException();
}
if (!NetDriver.IsServer())
{
throw new NotSupportedException("Client code");
}
else
{
Logger.Verbose("Level server received: {MessageType}", messageType);
if (!connection.IsClientMsgTypeValid(messageType))
{
Logger.Error("IsClientMsgTypeValid FAILED ({MessageType}): Remote Address = {Address}", (int)messageType, connection.LowLevelGetRemoteAddress());
bunch.SetError();
return;
}
switch (messageType)
{
case NMT.Hello:
{
if (NMT_Hello.Receive(bunch, out var isLittleEndian, out var remoteNetworkVersion, out var encryptionToken))
{
// TODO: Version check.
if (string.IsNullOrEmpty(encryptionToken))
{
connection.SendChallengeControlMessage();
}
else
{
throw new NotImplementedException("Encryption");
}
}
break;
}
case NMT.Login:
{
throw new NotImplementedException();
}
default:
{
throw new NotImplementedException($"Unhandled control message {messageType}");
}
}
}
}
public async ValueTask DisposeAsync()