Klayeryt / Welcome

CS2 Plugin C#
30 stars 3 forks source link

[Bug] Stacktrace if user gets kicked, before the timer ends #9

Open danir-de opened 7 months ago

danir-de commented 7 months ago

If the timer is set ("Timer": 5,) and the user gets kicked or disconnects before the welcome message is sent, the plugin sends a stacktrace to the log:

[#979216412 UDP steamid:xxx@123.123.123.123:49685 'userName'] closed by app, linger requested but not needed (2039) NETWORK_DISCONNECT_KICKED
Removing Steam Net Connection for 123.123.123.123:49685, handle #979216412
19:51:08 [EROR] (cssharp:Core) Error invoking callback
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidOperationException: Entity is not valid
   at CounterStrikeSharp.API.Guard.IsValidEntity(CEntityInstance ent) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Guard.cs:line 8
   at CounterStrikeSharp.API.Core.CCSPlayerController.PrintToChat(String message) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/Model/CCSPlayerController.cs:line 51
   at Main.Main.<>c__DisplayClass12_0.<OnPlayerConnectFull>b__0() in D:\cs2server\steamapps\common\Counter-Strike Global Offensive\game\csgo\addons\counterstrikesharp\source\Welcome\Main.cs:line 82
   at InvokeStub_Action.Invoke(Object, Object, IntPtr*)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at CounterStrikeSharp.API.Core.FunctionReference.<CreateWrappedCallback>b__18_0(fxScriptContext* context) in /home/runner/work/CounterStrikeSharp/CounterStrikeSharp/managed/CounterStrikeSharp.API/Core/FunctionReference.cs:line 100

This seems to come from the plugin trying to fetch user data once the timer ends, but by then he has already disconnected, leading to this error.

Klayeryt commented 7 months ago

Can you post the config?

danir-de commented 3 months ago

The config looks like this:

// This configuration was automatically generated by CounterStrikeSharp for plugin 'Welcome', at 2024.03.09 05:25:53
{
  "PluginName": "[CHRONICALSde][Welcome] | ",
  "Timer": 5,
  "WelcomePlayerOneEnable": "true",
  "WelcomePlayerAllEnable": "true",
  "DisconnectPlayerAllEnable": "true",
  "WelcomeText": "\u0001[\u000bCHRONICALS\u0008de\u0001] \u0008============== \u000bWILLKOMMEN \u0008============== {ENTER}\u0001[\u000bCHRONICALS\u0008de\u0001] Willkommen bei \u000bCHRONICALS\u0008de\u0001, \u000b{PLAYERNAME}\u0001! {ENTER} \u0001[\u000bCHRONICALS\u0008de\u0001] Mode: \u000bRetakes\u0001 - Map: \u000b{MAP}\u0001 - Online: \u000b{PLAYERS}\u0001/\u000b{MAXPLAYERS}\u0001{ENTER} \u0001[\u000bCHRONICALS\u0008de\u0001] TeamSpeak, CS2 Server & mehr: \u0009CHRONICALS.de{ENTER} \u0001[\u000bCHRONICALS\u0008de\u0001] \u0008=========== \u0001Good Luck, Have fun! \u0008=========== {ENTER} {ENTER}",
  "disconnectAllText": " \u0001[{RED}-\u0001] {PLAYERNAME} ({REASON}) ",
  "WelcomeAllText": " \u0001[{GREEN}+\u0001] {PLAYERNAME} ",
  "ConfigVersion": 1
}
Klayeryt commented 3 months ago

"WelcomeText": " ...(example text) "

danir-de commented 3 months ago

What do you mean? "WelcomeText": ... included in my snippet :)

The error occurs if the user gets kicked (by Whitelist, another plugin, etc.) or leaves while joining.

Klayeryt commented 3 months ago

{ "PluginName": "[CHRONICALSde][Welcome] | ", "Timer": 5, "WelcomePlayerOneEnable": "true", "WelcomePlayerAllEnable": "true", "DisconnectPlayerAllEnable": "true", "WelcomeText": " \u0001[\u000bCHRONICALS\u0008de\u0001] \u0008============== \u000bWILLKOMMEN \u0008============== {ENTER}\u0001[\u000bCHRONICALS\u0008de\u0001] Willkommen bei \u000bCHRONICALS\u0008de\u0001, \u000b{PLAYERNAME}\u0001! {ENTER} \u0001[\u000bCHRONICALS\u0008de\u0001] Mode: \u000bRetakes\u0001 - Map: \u000b{MAP}\u0001 - Online: \u000b{PLAYERS}\u0001/\u000b{MAXPLAYERS}\u0001{ENTER} \u0001[\u000bCHRONICALS\u0008de\u0001] TeamSpeak, CS2 Server & mehr: \u0009CHRONICALS.de{ENTER} \u0001[\u000bCHRONICALS\u0008de\u0001] \u0008=========== \u0001Good Luck, Have fun! \u0008=========== {ENTER} {ENTER} ", "disconnectAllText": " \u0001[{RED}-\u0001] {PLAYERNAME} ({REASON}) ", "WelcomeAllText": " \u0001[{GREEN}+\u0001] {PLAYERNAME} ", "ConfigVersion": 1 }