Skip to content

Commit

Permalink
Merge pull request #229 from MrDave1999/support/YSF-plugin
Browse files Browse the repository at this point in the history
feat: Add support for YSF Server Functions
  • Loading branch information
MrDave1999 authored Nov 14, 2024
2 parents 6df2aa7 + 72b758c commit ccf2492
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Add plugins to server.cfg file
run: |
echo "" >> ctf-gamemode-windows/server.cfg
echo "plugins SampSharp streamer" >> ctf-gamemode-windows/server.cfg
echo "plugins SampSharp streamer YSF" >> ctf-gamemode-windows/server.cfg
- name: Build game mode
run: dotnet publish src/Host -c Release -o bin --framework=net8.0
- name: Copy artifacts
Expand Down
41 changes: 41 additions & 0 deletions plugins/YSF.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Turning this on disables all hooks and custom processing, as well as natives that rely on that
PassiveMode 0

# Protection against fake pickup ids
PickupProtection 0

# Protection against fakekill
DeathProtection 0

# Protection against sproofed dialog ids
DialogProtection 0

# Use redirected YSF's own RPC for spawning
UseCustomSpawn 0

# Set it to 1 when you want to use per player gangzones
UsePerPlayerGangZones 0

# Allowing remote RCON connections with banned IPs (its very good to enable when you need to unban yourself)
AllowRemoteRCONWithBannedIPs 0

# Use this if you want to use SetMaxPlayers to increase your server slots at runtime
# DANGER: With enabling this option server will allow to connect 1000 players, doesn't matter what is your "maxplayers" value in server.cfg!
IncreaseRakNetInternalPlayers 0

# If the option above isn't enabled this option won't have any effect
# Change raknet internal threads sleeping time, lowering the value migh result in smoother sync - by default is 5ms
RakNetInternalSleepTime 5

# Delay im ms - object will be attached to player after this delay passed, lowering this delay might result in crashes
AttachObjectDelay 2000

# SA-MP by default doesn't store material info for per-player objects, which made GetPlayerObjectMaterial/MaterialText broken
# If you just use streamer for objects and you don't wanna use those two natives below, then disable this option
StorePlayerObjectsMaterial 1

# With this option you can load YSF on whatever server version, but it can result unwanted behavior
SkipVersionCheck 0

# This option makes newly created player objects prioritize IDs used by other existing player objects.
GroupPlayerObjects 0
Binary file added plugins/YSF.dll
Binary file not shown.
Binary file added plugins/YSF.so
Binary file not shown.
2 changes: 1 addition & 1 deletion server.cfg.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
echo Executing Server Config...
gamemode0 empty
skip_empty_check true
plugins libSampSharp.so streamer.so
plugins libSampSharp.so streamer.so YSF.so
filterscripts
rcon_password password
port 7777
Expand Down
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 ccf2492

Please sign in to comment.