Skip to content

Commit

Permalink
chore: Add support for YSF Server Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 committed Nov 14, 2024
1 parent ab71baa commit 75540b5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Host/Extensions/HostEcsBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public static IEcsBuilder EnableExceptionHandler(this IEcsBuilder builder)
"OnPlayerPickUpPickup",
"OnPlayerSpawn",
"OnPlayerRequestClass",
"OnPlayerRequestSpawn"
"OnPlayerRequestSpawn",
"OnPlayerPauseStateChange"
];

foreach (string @event in events)
Expand All @@ -33,4 +34,13 @@ public static IEcsBuilder EnableExceptionHandler(this IEcsBuilder builder)

return builder;
}

public static IEcsBuilder EnableYsfEvents(this IEcsBuilder builder)
{
builder
.EnableEvent<int, bool>("OnPlayerPauseStateChange");

builder.UseMiddleware<PlayerPauseStateChangeMiddleware>("OnPlayerPauseStateChange");
return builder;
}
}
15 changes: 15 additions & 0 deletions src/Host/Middlewares/PlayerPauseStateChangeMiddleware.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace CTF.Host.Middlewares;

public class PlayerPauseStateChangeMiddleware(EventDelegate next)
{
public object Invoke(EventContext context, IEntityManager entityManager)
{
var playerEntity = SampEntities.GetPlayerId((int)context.Arguments[0]);

if (!entityManager.Exists(playerEntity))
return null;

context.Arguments[0] = playerEntity;
return next(context);
}
}
3 changes: 2 additions & 1 deletion src/Host/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public void Configure(IEcsBuilder builder)
.EnableSampEvents()
.EnablePlayerCommands()
.EnableRconCommands()
.EnableStreamerEvents();
.EnableStreamerEvents()
.EnableYsfEvents();
}
}

0 comments on commit 75540b5

Please sign in to comment.