diff --git a/Engine.Systems/Network/NetworkBehaviour.cs b/Engine.Systems/Network/NetworkBehaviour.cs new file mode 100644 index 0000000..21d6683 --- /dev/null +++ b/Engine.Systems/Network/NetworkBehaviour.cs @@ -0,0 +1,40 @@ +using Engine.Core; + +namespace Engine.Systems.Network; + +/// +/// Basic network behaviour that supports both client & server behaviour. Finds both +/// the and the +/// in the universe in it's first active frame. Recommended to use or +///
+/// Disclaimer: It implements and in virtual methods. +///
+public class NetworkBehaviour : Behaviour, IFirstFrameUpdate, ILastFrameUpdate +{ + protected INetworkCommunicatorServer? server = null!; + protected INetworkCommunicatorClient? client = null!; + + protected bool IsServer { get; private set; } = false; + protected bool IsClient { get; private set; } = false; + + public INetworkCommunicatorServer Server => server ?? throw new Core.Exceptions.NotFoundException($"Universe does not contain a {nameof(INetworkCommunicatorServer)}"); + public INetworkCommunicatorClient Client => client ?? throw new Core.Exceptions.NotFoundException($"Universe does not contain a {nameof(INetworkCommunicatorClient)}"); + + public virtual void FirstActiveFrame() + { + client = Universe.FindBehaviour(); + server = Universe.FindBehaviour(); + + IsServer = server is not null; + IsClient = client is not null; + } + + public virtual void LastActiveFrame() + { + client = null!; + server = null!; + + IsServer = false; + IsClient = false; + } +}