From bfe7b8dda302e423cac5d012f1967d65424df4dd Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Mon, 25 Nov 2024 19:43:50 +0100 Subject: [PATCH] Consolidate events --- Fika.Core/Modding/Events/FikaClientCreatedEvent.cs | 14 -------------- .../Modding/Events/FikaClientDestroyedEvent.cs | 14 -------------- .../Events/FikaNetworkManagerCreatedEvent.cs | 14 ++++++++++++++ .../Events/FikaNetworkManagerDestroyedEvent.cs | 14 ++++++++++++++ Fika.Core/Modding/Events/FikaServerCreatedEvent.cs | 14 -------------- .../Modding/Events/FikaServerDestroyedEvent.cs | 14 -------------- Fika.Core/Networking/FikaClient.cs | 4 ++-- Fika.Core/Networking/FikaServer.cs | 4 ++-- 8 files changed, 32 insertions(+), 60 deletions(-) delete mode 100644 Fika.Core/Modding/Events/FikaClientCreatedEvent.cs delete mode 100644 Fika.Core/Modding/Events/FikaClientDestroyedEvent.cs create mode 100644 Fika.Core/Modding/Events/FikaNetworkManagerCreatedEvent.cs create mode 100644 Fika.Core/Modding/Events/FikaNetworkManagerDestroyedEvent.cs delete mode 100644 Fika.Core/Modding/Events/FikaServerCreatedEvent.cs delete mode 100644 Fika.Core/Modding/Events/FikaServerDestroyedEvent.cs diff --git a/Fika.Core/Modding/Events/FikaClientCreatedEvent.cs b/Fika.Core/Modding/Events/FikaClientCreatedEvent.cs deleted file mode 100644 index 24bce82f..00000000 --- a/Fika.Core/Modding/Events/FikaClientCreatedEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Fika.Core.Networking; - -namespace Fika.Core.Modding.Events -{ - public class FikaClientCreatedEvent : FikaEvent - { - public FikaClient Client { get; } - - internal FikaClientCreatedEvent(FikaClient client) - { - this.Client = client; - } - } -} diff --git a/Fika.Core/Modding/Events/FikaClientDestroyedEvent.cs b/Fika.Core/Modding/Events/FikaClientDestroyedEvent.cs deleted file mode 100644 index 2fbcf7ad..00000000 --- a/Fika.Core/Modding/Events/FikaClientDestroyedEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Fika.Core.Networking; - -namespace Fika.Core.Modding.Events -{ - public class FikaClientDestroyedEvent : FikaEvent - { - public FikaClient Client { get; } - - internal FikaClientDestroyedEvent(FikaClient client) - { - Client = client; - } - } -} diff --git a/Fika.Core/Modding/Events/FikaNetworkManagerCreatedEvent.cs b/Fika.Core/Modding/Events/FikaNetworkManagerCreatedEvent.cs new file mode 100644 index 00000000..66e736ae --- /dev/null +++ b/Fika.Core/Modding/Events/FikaNetworkManagerCreatedEvent.cs @@ -0,0 +1,14 @@ +using Fika.Core.Networking; + +namespace Fika.Core.Modding.Events +{ + public class FikaNetworkManagerCreatedEvent : FikaEvent + { + public IFikaNetworkManager Manager { get; } + + internal FikaNetworkManagerCreatedEvent(IFikaNetworkManager manager) + { + Manager = manager; + } + } +} diff --git a/Fika.Core/Modding/Events/FikaNetworkManagerDestroyedEvent.cs b/Fika.Core/Modding/Events/FikaNetworkManagerDestroyedEvent.cs new file mode 100644 index 00000000..ce212d01 --- /dev/null +++ b/Fika.Core/Modding/Events/FikaNetworkManagerDestroyedEvent.cs @@ -0,0 +1,14 @@ +using Fika.Core.Networking; + +namespace Fika.Core.Modding.Events +{ + public class FikaNetworkManagerDestroyedEvent : FikaEvent + { + public IFikaNetworkManager Manager { get; } + + public FikaNetworkManagerDestroyedEvent(IFikaNetworkManager server) + { + Manager = server; + } + } +} diff --git a/Fika.Core/Modding/Events/FikaServerCreatedEvent.cs b/Fika.Core/Modding/Events/FikaServerCreatedEvent.cs deleted file mode 100644 index fe2b9105..00000000 --- a/Fika.Core/Modding/Events/FikaServerCreatedEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Fika.Core.Networking; - -namespace Fika.Core.Modding.Events -{ - public class FikaServerCreatedEvent : FikaEvent - { - public FikaServer Server { get; } - - internal FikaServerCreatedEvent(FikaServer server) - { - Server = server; - } - } -} diff --git a/Fika.Core/Modding/Events/FikaServerDestroyedEvent.cs b/Fika.Core/Modding/Events/FikaServerDestroyedEvent.cs deleted file mode 100644 index 0c244c16..00000000 --- a/Fika.Core/Modding/Events/FikaServerDestroyedEvent.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Fika.Core.Networking; - -namespace Fika.Core.Modding.Events -{ - public class FikaServerDestroyedEvent : FikaEvent - { - public FikaServer Server { get; } - - internal FikaServerDestroyedEvent(FikaServer server) - { - Server = server; - } - } -} diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index a33d22ca..d9e559fd 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -206,7 +206,7 @@ public async void Init() ServerConnection = netClient.Connect(ip, port, "fika.core"); } - FikaEventDispatcher.DispatchEvent(new FikaClientCreatedEvent(this)); + FikaEventDispatcher.DispatchEvent(new FikaNetworkManagerCreatedEvent(this)); } private void OnLoadingProfilePacketReceived(LoadingProfilePacket packet) @@ -1208,7 +1208,7 @@ protected void OnDestroy() Destroy(fikaChat); } - FikaEventDispatcher.DispatchEvent(new FikaClientDestroyedEvent(this)); + FikaEventDispatcher.DispatchEvent(new FikaNetworkManagerDestroyedEvent(this)); } public void SendData(ref T packet, DeliveryMethod deliveryMethod) where T : INetSerializable diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 01512a92..9e908714 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -289,7 +289,7 @@ public async Task Init() SetHostRequest body = new(Ips, port, FikaPlugin.UseNatPunching.Value, FikaBackendUtils.IsDedicatedGame); FikaRequestHandler.UpdateSetHost(body); - FikaEventDispatcher.DispatchEvent(new FikaServerCreatedEvent(this)); + FikaEventDispatcher.DispatchEvent(new FikaNetworkManagerCreatedEvent(this)); } private void OnLoadingProfilePacketReceived(LoadingProfilePacket packet, NetPeer peer) @@ -1214,7 +1214,7 @@ protected void OnDestroy() Destroy(fikaChat); } - FikaEventDispatcher.DispatchEvent(new FikaServerDestroyedEvent(this)); + FikaEventDispatcher.DispatchEvent(new FikaNetworkManagerDestroyedEvent(this)); } public void SendDataToAll(ref T packet, DeliveryMethod deliveryMethod, NetPeer peerToExclude = null) where T : INetSerializable