update: Hide Stealth Players from Spec List (untested)

fix: DefaultServerIP throws error if port not provided
This commit is contained in:
Sachin 2025-02-19 17:39:12 +05:30
parent bd7f4ed40f
commit bf4cd656be
4 changed files with 65 additions and 7 deletions

View file

@ -18,12 +18,16 @@ namespace CS2_SimpleAdmin;
public partial class CS2_SimpleAdmin
{
private bool _serverLoading;
public List<CCSPlayerController> CachedPlayers = new();
private void RegisterEvents()
{
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterListener<Listeners.OnClientConnect>(OnClientConnect);
RegisterListener<Listeners.OnGameServerSteamAPIActivated>(OnGameServerSteamAPIActivated);
if (Config.OtherSettings.HideStealthPlayersFromSpecList)
RegisterListener<Listeners.CheckTransmit>(CheckTransmitListener);
if (Config.OtherSettings.UserMessageGagChatType)
HookUserMessage(118, HookUmChat);
@ -59,6 +63,44 @@ public partial class CS2_SimpleAdmin
new ServerManager().LoadServerData();
}
private void CheckTransmitListener(CCheckTransmitInfoList infoList)
{
// Code taken from admin esp by aqua
foreach ((CCheckTransmitInfo info, CCSPlayerController? player) in infoList)
{
if (player is null || player.IsValid is not true) continue;
//itereate cached players
for (int i = 0; i < CachedPlayers.Count(); i++) {
//leave self's observerPawn so it can spectate and check if feature is enabled
//we are clearing the whole spectator list as it doesn't work relaibly per person basis
if (CachedPlayers[i] is null || CachedPlayers[i].IsValid is not true) continue;
//check if it 'us' in the current context and do the magic only if it's not
if (CachedPlayers[i].Slot != player.Slot) {
//get the target's pawn
var targetPawn = CachedPlayers[i].PlayerPawn.Value;
if (targetPawn is null || targetPawn.IsValid is not true) continue;
//get the target's observerpawn
var targetObserverPawn = CachedPlayers[i].ObserverPawn;
if (targetObserverPawn is null
|| targetObserverPawn.IsValid is not true
|| targetObserverPawn.Value is null
|| targetObserverPawn.Value.OriginalController.Value is null
|| !SilentPlayers.Contains(targetObserverPawn.Value.OriginalController.Value.Slot)) continue;
//we clear the spec list via clearing all of the observerTarget' pawns indexes
//from the Observer_services class that any cheat uses as a method to campare
//against current players in the server
info.TransmitEntities.Remove((int)targetObserverPawn.Index);
}
}
}
}
[GameEventHandler(HookMode.Pre)]
public HookResult OnClientDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
{
@ -97,6 +139,7 @@ public partial class CS2_SimpleAdmin
PlayerPenaltyManager.RemoveAllPenalties(player.Slot);
CachedPlayers.Remove(player);
SilentPlayers.Remove(player.Slot);
GodPlayers.Remove(player.Slot);
SpeedPlayers.Remove(player.Slot);
@ -155,6 +198,8 @@ public partial class CS2_SimpleAdmin
if (player == null || !player.IsValid || player.IsBot)
return HookResult.Continue;
CachedPlayers.Add(player);
if (player.UserId.HasValue && PlayersInfo.TryGetValue(player.UserId.Value, out PlayerInfo? value) &&
value.WaitingForKick)