From 05db3d28ee4350e1d3609336ad8fd09aa8d3d348 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Mon, 30 Dec 2024 20:00:12 +0100 Subject: [PATCH] Add new events - Game ended - Peer connected --- Fika.Core/Coop/GameMode/CoopGame.cs | 2 ++ Fika.Core/Modding/Events/FikaGameEndedEvent.cs | 12 ++++++++++++ Fika.Core/Modding/Events/PeerConnectedEvent.cs | 17 +++++++++++++++++ Fika.Core/Networking/FikaClient.cs | 2 ++ Fika.Core/Networking/FikaServer.cs | 2 ++ 5 files changed, 35 insertions(+) create mode 100644 Fika.Core/Modding/Events/FikaGameEndedEvent.cs create mode 100644 Fika.Core/Modding/Events/PeerConnectedEvent.cs diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 7b226789..ae5ad308 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -2065,6 +2065,8 @@ private async void HealthController_DiedEvent(EDamageType damageType) /// public override void Stop(string profileId, ExitStatus exitStatus, string exitName, float delay = 0f) { + FikaEventDispatcher.DispatchEvent(new FikaGameEndedEvent(isServer)); + if (exitStatus < ExitStatus.Transit) { FikaBackendUtils.IsTransit = false; diff --git a/Fika.Core/Modding/Events/FikaGameEndedEvent.cs b/Fika.Core/Modding/Events/FikaGameEndedEvent.cs new file mode 100644 index 00000000..b2397369 --- /dev/null +++ b/Fika.Core/Modding/Events/FikaGameEndedEvent.cs @@ -0,0 +1,12 @@ +namespace Fika.Core.Modding.Events +{ + public class FikaGameEndedEvent : FikaEvent + { + public bool IsServer { get; } + + internal FikaGameEndedEvent(bool isServer) + { + IsServer = isServer; + } + } +} diff --git a/Fika.Core/Modding/Events/PeerConnectedEvent.cs b/Fika.Core/Modding/Events/PeerConnectedEvent.cs new file mode 100644 index 00000000..11f11dcb --- /dev/null +++ b/Fika.Core/Modding/Events/PeerConnectedEvent.cs @@ -0,0 +1,17 @@ +using Fika.Core.Networking; +using LiteNetLib; + +namespace Fika.Core.Modding.Events +{ + public class PeerConnectedEvent : FikaEvent + { + public NetPeer Peer { get; } + public IFikaNetworkManager NetworkManager { get; } + + internal PeerConnectedEvent(NetPeer peer, IFikaNetworkManager networkManager) + { + Peer = peer; + NetworkManager = networkManager; + } + } +} diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index 58ba81f0..e4af66ab 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -1297,6 +1297,8 @@ public void OnPeerConnected(NetPeer peer) Profiles = profiles }; SendData(ref profilePacket, DeliveryMethod.ReliableOrdered); + + FikaEventDispatcher.DispatchEvent(new PeerConnectedEvent(peer, this)); } public void OnNetworkError(IPEndPoint endPoint, SocketError socketErrorCode) diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index d00da767..c56e05e2 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -1311,6 +1311,8 @@ public void OnPeerConnected(NetPeer peer) NetworkSettingsPacket packet = new(sendRate); SendDataToPeer(peer, ref packet, DeliveryMethod.ReliableOrdered); + + FikaEventDispatcher.DispatchEvent(new PeerConnectedEvent(peer, this)); } public void OnNetworkError(IPEndPoint endPoint, SocketError socketErrorCode)