Added UWorld
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
using Prospect.Unreal.Net;
|
using Prospect.Unreal.Core;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
namespace Prospect.Server.Game;
|
namespace Prospect.Server.Game;
|
||||||
@@ -10,9 +10,9 @@ internal static class Program
|
|||||||
private static readonly ILogger Logger = Log.ForContext(typeof(Program));
|
private static readonly ILogger Logger = Log.ForContext(typeof(Program));
|
||||||
private static readonly PeriodicTimer Tick = new PeriodicTimer(TimeSpan.FromSeconds(TickRate));
|
private static readonly PeriodicTimer Tick = new PeriodicTimer(TimeSpan.FromSeconds(TickRate));
|
||||||
|
|
||||||
public static async Task Main(string[] args)
|
public static async Task Main()
|
||||||
{
|
{
|
||||||
Console.CancelKeyPress += (s, e) =>
|
Console.CancelKeyPress += (_, e) =>
|
||||||
{
|
{
|
||||||
Tick.Dispose();
|
Tick.Dispose();
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
@@ -26,22 +26,18 @@ internal static class Program
|
|||||||
|
|
||||||
Logger.Information("Starting Prospect.Server.Game");
|
Logger.Information("Starting Prospect.Server.Game");
|
||||||
|
|
||||||
await using (var driver = new UIpNetDriver())
|
var worldUrl = new FUrl
|
||||||
{
|
{
|
||||||
driver.Init();
|
Map = "/Game/ThirdPersonCPP/Maps/ThirdPersonExampleMap"
|
||||||
|
};
|
||||||
|
|
||||||
|
await using (var world = new ProspectWorld(worldUrl))
|
||||||
|
{
|
||||||
|
world.Listen();
|
||||||
|
|
||||||
// Tick all components.
|
|
||||||
while (await Tick.WaitForNextTickAsync())
|
while (await Tick.WaitForNextTickAsync())
|
||||||
{
|
{
|
||||||
var deltaTime = TickRate;
|
world.Tick(TickRate);
|
||||||
|
|
||||||
driver.TickDispatch(deltaTime);
|
|
||||||
// driver.PostTickDispatch();
|
|
||||||
|
|
||||||
if (driver.ConnectionlessHandler != null)
|
|
||||||
{
|
|
||||||
driver.ConnectionlessHandler.Tick(deltaTime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Prospect.Unreal.Core;
|
||||||
|
using Prospect.Unreal.Runtime;
|
||||||
|
|
||||||
|
namespace Prospect.Server.Game;
|
||||||
|
|
||||||
|
public class ProspectWorld : UWorld
|
||||||
|
{
|
||||||
|
public ProspectWorld(FUrl url) : base(url)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Prospect.Unreal.Core;
|
|
||||||
|
|
||||||
public class FURL
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace Prospect.Unreal.Core;
|
||||||
|
|
||||||
|
public class FUrl
|
||||||
|
{
|
||||||
|
public string Protocol { get; init; } = "unreal";
|
||||||
|
public IPAddress Host { get; init; } = IPAddress.Any;
|
||||||
|
public int Port { get; init; } = 7777;
|
||||||
|
public string Map { get; init; } = "GearStart";
|
||||||
|
public string RedirectUrl { get; init; } = string.Empty;
|
||||||
|
public List<string> Options { get; init; } = new List<string>();
|
||||||
|
public string Portal { get; init; } = string.Empty;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace Prospect.Unreal.Exceptions;
|
||||||
|
|
||||||
|
public class UnrealNetException : UnrealException
|
||||||
|
{
|
||||||
|
public UnrealNetException()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected UnrealNetException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnrealNetException(string? message) : base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnrealNetException(string? message, Exception? innerException) : base(message, innerException)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,17 +6,17 @@ namespace Prospect.Unreal.Net;
|
|||||||
|
|
||||||
public class UIpConnection : UNetConnection
|
public class UIpConnection : UNetConnection
|
||||||
{
|
{
|
||||||
public override void InitBase(UNetDriver inDriver, UdpClient inSocket, FURL inURL, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0)
|
public override void InitBase(UNetDriver inDriver, UdpClient inSocket, FUrl inURL, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitRemoteConnection(UNetDriver inDriver, UdpClient inSocket, FURL inURL, IPEndPoint inRemoteAddr, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0)
|
public override void InitRemoteConnection(UNetDriver inDriver, UdpClient inSocket, FUrl inURL, IPEndPoint inRemoteAddr, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void InitLocalConnection(UNetDriver inDriver, UdpClient inSocket, FURL inURL, EConnectionState inState,
|
public override void InitLocalConnection(UNetDriver inDriver, UdpClient inSocket, FUrl inURL, EConnectionState inState,
|
||||||
int inMaxPacket = 0, int inPacketOverhead = 0)
|
int inMaxPacket = 0, int inPacketOverhead = 0)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ public class UIpNetDriver : UNetDriver
|
|||||||
|
|
||||||
private bool _isDisposed;
|
private bool _isDisposed;
|
||||||
|
|
||||||
public UIpNetDriver()
|
public UIpNetDriver(IPAddress host, int port)
|
||||||
{
|
{
|
||||||
ServerIp = new IPEndPoint(IPAddress.Any, 7777);
|
ServerIp = new IPEndPoint(host, port);
|
||||||
Socket = new UdpClient(ServerIp);
|
Socket = new UdpClient(ServerIp);
|
||||||
ReceiveThread = new FReceiveThreadRunnable(this);
|
ReceiveThread = new FReceiveThreadRunnable(this);
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,7 @@ public class UIpNetDriver : UNetDriver
|
|||||||
public UdpClient Socket { get; }
|
public UdpClient Socket { get; }
|
||||||
public FReceiveThreadRunnable ReceiveThread { get; }
|
public FReceiveThreadRunnable ReceiveThread { get; }
|
||||||
|
|
||||||
public bool Init()
|
public override bool Init()
|
||||||
{
|
{
|
||||||
// Initialize connectionless packet handler.
|
// Initialize connectionless packet handler.
|
||||||
InitConnectionlessHandler();
|
InitConnectionlessHandler();
|
||||||
@@ -119,8 +119,7 @@ public class UIpNetDriver : UNetDriver
|
|||||||
returnVal.InitSequence(clientSequence, serverSequence);
|
returnVal.InitSequence(clientSequence, serverSequence);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: World url
|
returnVal.InitRemoteConnection(this, Socket, World != null ? World.Url : new FUrl(), address, EConnectionState.USOCK_Open);
|
||||||
returnVal.InitRemoteConnection(this, Socket, null, address, EConnectionState.USOCK_Open);
|
|
||||||
|
|
||||||
// if (returnVal.Handler)
|
// if (returnVal.Handler)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ public abstract class UNetConnection
|
|||||||
public const int ReliableBuffer = 256;
|
public const int ReliableBuffer = 256;
|
||||||
public const int MaxPacketId = 16384;
|
public const int MaxPacketId = 16384;
|
||||||
|
|
||||||
public abstract void InitBase(UNetDriver inDriver, UdpClient inSocket, FURL inURL, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0);
|
public abstract void InitBase(UNetDriver inDriver, UdpClient inSocket, FUrl inURL, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0);
|
||||||
public abstract void InitRemoteConnection(UNetDriver inDriver, UdpClient inSocket, FURL inURL, IPEndPoint inRemoteAddr, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0);
|
public abstract void InitRemoteConnection(UNetDriver inDriver, UdpClient inSocket, FUrl inURL, IPEndPoint inRemoteAddr, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0);
|
||||||
public abstract void InitLocalConnection(UNetDriver inDriver, UdpClient inSocket, FURL inURL, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0);
|
public abstract void InitLocalConnection(UNetDriver inDriver, UdpClient inSocket, FUrl inURL, EConnectionState inState, int inMaxPacket = 0, int inPacketOverhead = 0);
|
||||||
public abstract void LowLevelSend(byte[] data, int countBits, FOutPacketTraits traits);
|
public abstract void LowLevelSend(byte[] data, int countBits, FOutPacketTraits traits);
|
||||||
public abstract string LowLevelGetRemoteAddress(bool bAppendPort = false);
|
public abstract string LowLevelGetRemoteAddress(bool bAppendPort = false);
|
||||||
public abstract string LowLevelDescribe();
|
public abstract string LowLevelDescribe();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using Prospect.Unreal.Runtime;
|
||||||
|
|
||||||
namespace Prospect.Unreal.Net;
|
namespace Prospect.Unreal.Net;
|
||||||
|
|
||||||
@@ -12,6 +13,11 @@ public abstract class UNetDriver : IAsyncDisposable
|
|||||||
MappedClientConnections = new ConcurrentDictionary<IPEndPoint, UNetConnection>();
|
MappedClientConnections = new ConcurrentDictionary<IPEndPoint, UNetConnection>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// World this net driver is associated with
|
||||||
|
/// </summary>
|
||||||
|
public UWorld? World { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Map of <see cref="IPEndPoint"/> to <see cref="UNetConnection"/>.
|
/// Map of <see cref="IPEndPoint"/> to <see cref="UNetConnection"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -38,6 +44,11 @@ public abstract class UNetDriver : IAsyncDisposable
|
|||||||
ConnectionlessHandler.InitializeComponents();
|
ConnectionlessHandler.InitializeComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual bool Init()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void TickDispatch(float deltaTime)
|
public virtual void TickDispatch(float deltaTime)
|
||||||
{
|
{
|
||||||
_elapsedTime += deltaTime;
|
_elapsedTime += deltaTime;
|
||||||
@@ -50,6 +61,21 @@ public abstract class UNetDriver : IAsyncDisposable
|
|||||||
|
|
||||||
public abstract bool IsNetResourceValid();
|
public abstract bool IsNetResourceValid();
|
||||||
|
|
||||||
|
public void SetWorld(UWorld? inWorld)
|
||||||
|
{
|
||||||
|
if (World != null)
|
||||||
|
{
|
||||||
|
World = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inWorld != null)
|
||||||
|
{
|
||||||
|
World = inWorld;
|
||||||
|
|
||||||
|
// TODO: AddInitialObjects?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public double GetElapsedTime()
|
public double GetElapsedTime()
|
||||||
{
|
{
|
||||||
return _elapsedTime;
|
return _elapsedTime;
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
using Prospect.Unreal.Core;
|
||||||
|
using Prospect.Unreal.Net;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace Prospect.Unreal.Runtime;
|
||||||
|
|
||||||
|
public abstract class UWorld : IAsyncDisposable
|
||||||
|
{
|
||||||
|
private static readonly ILogger Logger = Log.ForContext<UWorld>();
|
||||||
|
|
||||||
|
public UWorld(FUrl url)
|
||||||
|
{
|
||||||
|
Url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FUrl Url { get; }
|
||||||
|
public UNetDriver? NetDriver { get; private set; }
|
||||||
|
|
||||||
|
public void Tick(float deltaTime)
|
||||||
|
{
|
||||||
|
if (NetDriver != null)
|
||||||
|
{
|
||||||
|
NetDriver.TickDispatch(deltaTime);
|
||||||
|
NetDriver.ConnectionlessHandler?.Tick(deltaTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Listen()
|
||||||
|
{
|
||||||
|
if (NetDriver != null)
|
||||||
|
{
|
||||||
|
Logger.Error("NetDriver already exists");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NetDriver = new UIpNetDriver(Url.Host, Url.Port);
|
||||||
|
NetDriver.SetWorld(this);
|
||||||
|
|
||||||
|
if (!NetDriver.Init())
|
||||||
|
{
|
||||||
|
Logger.Error("Failed to listen");
|
||||||
|
NetDriver = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async ValueTask DisposeAsync()
|
||||||
|
{
|
||||||
|
if (NetDriver != null)
|
||||||
|
{
|
||||||
|
await NetDriver.DisposeAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user