Skip to content

Commit

Permalink
Merge pull request #267 from project-fika/add-new-events
Browse files Browse the repository at this point in the history
Add new events
  • Loading branch information
Lacyway authored Dec 30, 2024
2 parents fe87d92 + 05db3d2 commit 1ac82d3
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,6 +2065,8 @@ private async void HealthController_DiedEvent(EDamageType damageType)
/// <param name="delay"></param>
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;
Expand Down
12 changes: 12 additions & 0 deletions Fika.Core/Modding/Events/FikaGameEndedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Fika.Core.Modding.Events
{
public class FikaGameEndedEvent : FikaEvent
{
public bool IsServer { get; }

internal FikaGameEndedEvent(bool isServer)
{
IsServer = isServer;
}
}
}
17 changes: 17 additions & 0 deletions Fika.Core/Modding/Events/PeerConnectedEvent.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
2 changes: 2 additions & 0 deletions Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions Fika.Core/Networking/FikaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ac82d3

Please sign in to comment.