CounterStrikeSharp
CounterStrikeSharp copied to clipboard
`VirtualFunctions.ClientPrint` causes server to crash
Reporting for version v1.0.337 but it has been happening over a few versions now. Metamod build 1365.
Minimal example to reproduce issue:
[ConsoleCommand("send_message", "Send message to all clients")]
[CommandHelper(minArgs: 1, usage: "[text]", whoCanExecute: CommandUsage.SERVER_ONLY)]
public void OnSendMessage(CCSPlayerController? player, CommandInfo command)
{
if (command.ArgCount < 2)
{
command.ReplyToCommand("Please provide a message to send");
return;
}
var text = command.GetArg(1);
var players = Utilities.GetPlayers()
.Where(p => p.IsValid && !p.IsBot);
foreach (var p in players)
{
Console.WriteLine($"Sending message to {p.PlayerName}: \"{text}\"");
// p.PrintToChat(text); // this works
VirtualFunctions.ClientPrint(p.Handle, HudDestination.Chat, text, 0, 0, 0, 0); // this crashes the server
}
}
I think this should be replaced by the implementation in NativeAPI, which just sends a usermessage. This relies on a signature, and I think it should be deprecated or aliased at least.