From b64fe824e1a08418658dfc44d0e3935b94971252 Mon Sep 17 00:00:00 2001 From: dark room danny <115037920+followingthefasciaplane@users.noreply.github.com> Date: Sat, 25 May 2024 04:07:12 +1200 Subject: [PATCH 1/3] reliablestream overflow client disconnect fix --- shavit-bash2.sp | 128 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 115 insertions(+), 13 deletions(-) diff --git a/shavit-bash2.sp b/shavit-bash2.sp index 7462e39..c65b6a9 100644 --- a/shavit-bash2.sp +++ b/shavit-bash2.sp @@ -1043,22 +1043,111 @@ public Action Hook_GroundFlags(int entity, const char[] PropName, int &iValue, i #endif } +//this fixes client disconnects due to QueryForCvars overflowing the reliable stream during network interruption +#define MAX_CONVARS 12 + +enum QueryConVars +{ + CONVAR_YAWSPEED, + CONVAR_YAW, + CONVAR_FILTER, + CONVAR_CUSTOMACCEL, + CONVAR_CUSTOMACCEL_MAX, + CONVAR_CUSTOMACCEL_SCALE, + CONVAR_CUSTOMACCEL_EXPONENT, + CONVAR_RAWINPUT, + CONVAR_SENSITIVITY, + CONVAR_YAWSENSITIVITY, + CONVAR_JOYSTICK, + CONVAR_ZOOMSENSITIVITY +}; + +bool g_bQueryPending[MAXPLAYERS + 1][MAX_CONVARS]; // track pending queries... void QueryForCvars(int client) { - if(g_Engine == Engine_CSS) QueryClientConVar(client, "cl_yawspeed", OnYawSpeedRetrieved); - QueryClientConVar(client, "m_yaw", OnYawRetrieved); - QueryClientConVar(client, "m_filter", OnFilterRetrieved); - QueryClientConVar(client, "m_customaccel", OnCustomAccelRetrieved); - QueryClientConVar(client, "m_customaccel_max", OnCustomAccelMaxRetrieved); - QueryClientConVar(client, "m_customaccel_scale", OnCustomAccelScaleRetrieved); - QueryClientConVar(client, "m_customaccel_exponent", OnCustomAccelExRetrieved); - QueryClientConVar(client, "m_rawinput", OnRawInputRetrieved); - QueryClientConVar(client, "sensitivity", OnSensitivityRetrieved); - QueryClientConVar(client, "joy_yawsensitivity", OnYawSensitivityRetrieved); - QueryClientConVar(client, "joystick", OnJoystickRetrieved); - if(g_Engine == Engine_CSGO) QueryClientConVar(client, "zoom_sensitivity_ratio_mouse", OnZoomSensitivityRetrieved); - if(g_Engine == Engine_CSS) QueryClientConVar(client, "zoom_sensitivity_ratio", OnZoomSensitivityRetrieved); + if (g_Engine == Engine_CSS && !g_bQueryPending[client][CONVAR_YAWSPEED]) + { + QueryClientConVar(client, "cl_yawspeed", OnYawSpeedRetrieved); + g_bQueryPending[client][CONVAR_YAWSPEED] = true; + } + + if (!g_bQueryPending[client][CONVAR_YAW]) + { + QueryClientConVar(client, "m_yaw", OnYawRetrieved); + g_bQueryPending[client][CONVAR_YAW] = true; + } + + if (!g_bQueryPending[client][CONVAR_FILTER]) + { + QueryClientConVar(client, "m_filter", OnFilterRetrieved); + g_bQueryPending[client][CONVAR_FILTER] = true; + } + + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL]) + { + QueryClientConVar(client, "m_customaccel", OnCustomAccelRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL] = true; + } + + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_MAX]) + { + QueryClientConVar(client, "m_customaccel_max", OnCustomAccelMaxRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL_MAX] = true; + } + + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_SCALE]) + { + QueryClientConVar(client, "m_customaccel_scale", OnCustomAccelScaleRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL_SCALE] = true; + } + + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_EXPONENT]) + { + QueryClientConVar(client, "m_customaccel_exponent", OnCustomAccelExRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL_EXPONENT] = true; + } + + if (!g_bQueryPending[client][CONVAR_RAWINPUT]) + { + QueryClientConVar(client, "m_rawinput", OnRawInputRetrieved); + g_bQueryPending[client][CONVAR_RAWINPUT] = true; + } + + if (!g_bQueryPending[client][CONVAR_SENSITIVITY]) + { + QueryClientConVar(client, "sensitivity", OnSensitivityRetrieved); + g_bQueryPending[client][CONVAR_SENSITIVITY] = true; + } + + if (!g_bQueryPending[client][CONVAR_YAWSENSITIVITY]) + { + QueryClientConVar(client, "joy_yawsensitivity", OnYawSensitivityRetrieved); + g_bQueryPending[client][CONVAR_YAWSENSITIVITY] = true; + } + + if (!g_bQueryPending[client][CONVAR_JOYSTICK]) + { + QueryClientConVar(client, "joystick", OnJoystickRetrieved); + g_bQueryPending[client][CONVAR_JOYSTICK] = true; + } + + if (g_Engine == Engine_CSGO && !g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY]) + { + QueryClientConVar(client, "zoom_sensitivity_ratio_mouse", OnZoomSensitivityRetrieved); + g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY] = true; + } + + if (g_Engine == Engine_CSS && !g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY]) + { + QueryClientConVar(client, "zoom_sensitivity_ratio", OnZoomSensitivityRetrieved); + g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY] = true; + } +} + +public void SimulateConVarQueryCompleted(int client, int convar) +{ + g_bQueryPending[client][convar] = false; } public void OnYawSpeedRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1069,6 +1158,8 @@ public void OnYawSpeedRetrieved(QueryCookie cookie, int client, ConVarQueryResul { KickClient(client, "cl_yawspeed cannot be negative"); } + + SimulateConVarQueryCompleted(client, CONVAR_YAWSPEED); } public void OnYawRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1087,6 +1178,7 @@ public void OnYawRetrieved(QueryCookie cookie, int client, ConVarQueryResult res } g_mYawCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_YAW); } public void OnFilterRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1105,6 +1197,7 @@ public void OnFilterRetrieved(QueryCookie cookie, int client, ConVarQueryResult } g_mFilterCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_FILTER); } public void OnCustomAccelRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1124,6 +1217,7 @@ public void OnCustomAccelRetrieved(QueryCookie cookie, int client, ConVarQueryRe } g_mCustomAccelCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_CUSTOMACCEL); } public void OnCustomAccelMaxRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1142,6 +1236,7 @@ public void OnCustomAccelMaxRetrieved(QueryCookie cookie, int client, ConVarQuer } g_mCustomAccelMaxCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_CUSTOMACCEL_MAX); } public void OnCustomAccelScaleRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1161,6 +1256,7 @@ public void OnCustomAccelScaleRetrieved(QueryCookie cookie, int client, ConVarQu } g_mCustomAccelScaleCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_CUSTOMACCEL_SCALE); } public void OnCustomAccelExRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1180,6 +1276,7 @@ public void OnCustomAccelExRetrieved(QueryCookie cookie, int client, ConVarQuery } g_mCustomAccelExponentCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_CUSTOMACCEL_EXPONENT); } public void OnRawInputRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1198,6 +1295,7 @@ public void OnRawInputRetrieved(QueryCookie cookie, int client, ConVarQueryResul } g_mRawInputCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_RAWINPUT); } public void OnSensitivityRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1216,6 +1314,7 @@ public void OnSensitivityRetrieved(QueryCookie cookie, int client, ConVarQueryRe } g_SensitivityCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_SENSITIVITY); } public void OnYawSensitivityRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1234,6 +1333,7 @@ public void OnYawSensitivityRetrieved(QueryCookie cookie, int client, ConVarQuer } g_JoySensitivityCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_YAWSENSITIVITY); } public void OnZoomSensitivityRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1252,6 +1352,7 @@ public void OnZoomSensitivityRetrieved(QueryCookie cookie, int client, ConVarQue } g_ZoomSensitivityCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_ZOOMSENSITIVITY); } public void OnJoystickRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1270,6 +1371,7 @@ public void OnJoystickRetrieved(QueryCookie cookie, int client, ConVarQueryResul } g_JoyStickCheckedCount[client]++; + SimulateConVarQueryCompleted(client, CONVAR_JOYSTICK); } From 5b9fbef2dc7b7586f64c232bf0276eed3199e443 Mon Sep 17 00:00:00 2001 From: dark room danny <115037920+followingthefasciaplane@users.noreply.github.com> Date: Sat, 25 May 2024 04:21:52 +1200 Subject: [PATCH 2/3] Update shavit-bash2.sp --- shavit-bash2.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shavit-bash2.sp b/shavit-bash2.sp index c65b6a9..1ca86c5 100644 --- a/shavit-bash2.sp +++ b/shavit-bash2.sp @@ -1046,7 +1046,7 @@ public Action Hook_GroundFlags(int entity, const char[] PropName, int &iValue, i //this fixes client disconnects due to QueryForCvars overflowing the reliable stream during network interruption #define MAX_CONVARS 12 -enum QueryConVars +enum { CONVAR_YAWSPEED, CONVAR_YAW, From 7cd7ca845ca41a2b13ebee26aecb6c53fca0fae8 Mon Sep 17 00:00:00 2001 From: dark room danny <115037920+followingthefasciaplane@users.noreply.github.com> Date: Mon, 5 Aug 2024 22:52:38 +1200 Subject: [PATCH 3/3] Reduce unnecessary queries Do we need to be querying cvars that have no effect with m_rawinput 1 or joystick 0? Does this break anything? --- shavit-bash2.sp | 223 +++++++++++++++++++++++++----------------------- 1 file changed, 117 insertions(+), 106 deletions(-) diff --git a/shavit-bash2.sp b/shavit-bash2.sp index 1ca86c5..bca36b0 100644 --- a/shavit-bash2.sp +++ b/shavit-bash2.sp @@ -1066,83 +1066,56 @@ bool g_bQueryPending[MAXPLAYERS + 1][MAX_CONVARS]; // track pending queries... void QueryForCvars(int client) { - if (g_Engine == Engine_CSS && !g_bQueryPending[client][CONVAR_YAWSPEED]) - { - QueryClientConVar(client, "cl_yawspeed", OnYawSpeedRetrieved); - g_bQueryPending[client][CONVAR_YAWSPEED] = true; - } - - if (!g_bQueryPending[client][CONVAR_YAW]) - { - QueryClientConVar(client, "m_yaw", OnYawRetrieved); - g_bQueryPending[client][CONVAR_YAW] = true; - } - - if (!g_bQueryPending[client][CONVAR_FILTER]) - { - QueryClientConVar(client, "m_filter", OnFilterRetrieved); - g_bQueryPending[client][CONVAR_FILTER] = true; - } - - if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL]) - { - QueryClientConVar(client, "m_customaccel", OnCustomAccelRetrieved); - g_bQueryPending[client][CONVAR_CUSTOMACCEL] = true; - } - - if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_MAX]) - { - QueryClientConVar(client, "m_customaccel_max", OnCustomAccelMaxRetrieved); - g_bQueryPending[client][CONVAR_CUSTOMACCEL_MAX] = true; - } - - if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_SCALE]) - { - QueryClientConVar(client, "m_customaccel_scale", OnCustomAccelScaleRetrieved); - g_bQueryPending[client][CONVAR_CUSTOMACCEL_SCALE] = true; - } - - if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_EXPONENT]) - { - QueryClientConVar(client, "m_customaccel_exponent", OnCustomAccelExRetrieved); - g_bQueryPending[client][CONVAR_CUSTOMACCEL_EXPONENT] = true; - } - - if (!g_bQueryPending[client][CONVAR_RAWINPUT]) - { - QueryClientConVar(client, "m_rawinput", OnRawInputRetrieved); - g_bQueryPending[client][CONVAR_RAWINPUT] = true; - } - - if (!g_bQueryPending[client][CONVAR_SENSITIVITY]) - { - QueryClientConVar(client, "sensitivity", OnSensitivityRetrieved); - g_bQueryPending[client][CONVAR_SENSITIVITY] = true; - } - - if (!g_bQueryPending[client][CONVAR_YAWSENSITIVITY]) - { - QueryClientConVar(client, "joy_yawsensitivity", OnYawSensitivityRetrieved); - g_bQueryPending[client][CONVAR_YAWSENSITIVITY] = true; - } - - if (!g_bQueryPending[client][CONVAR_JOYSTICK]) - { - QueryClientConVar(client, "joystick", OnJoystickRetrieved); - g_bQueryPending[client][CONVAR_JOYSTICK] = true; - } - - if (g_Engine == Engine_CSGO && !g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY]) - { - QueryClientConVar(client, "zoom_sensitivity_ratio_mouse", OnZoomSensitivityRetrieved); - g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY] = true; - } - - if (g_Engine == Engine_CSS && !g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY]) - { - QueryClientConVar(client, "zoom_sensitivity_ratio", OnZoomSensitivityRetrieved); - g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY] = true; - } + // Always query these cvars + if (!g_bQueryPending[client][CONVAR_YAW]) + { + QueryClientConVar(client, "m_yaw", OnYawRetrieved); + g_bQueryPending[client][CONVAR_YAW] = true; + } + + if (!g_bQueryPending[client][CONVAR_SENSITIVITY]) + { + QueryClientConVar(client, "sensitivity", OnSensitivityRetrieved); + g_bQueryPending[client][CONVAR_SENSITIVITY] = true; + } + + if (!g_bQueryPending[client][CONVAR_JOYSTICK]) + { + QueryClientConVar(client, "joystick", OnJoystickRetrieved); + g_bQueryPending[client][CONVAR_JOYSTICK] = true; + } + + if (!g_bQueryPending[client][CONVAR_RAWINPUT]) + { + QueryClientConVar(client, "m_rawinput", OnRawInputRetrieved); + g_bQueryPending[client][CONVAR_RAWINPUT] = true; + } + + if (g_Engine == Engine_CSS) + { + if (!g_bQueryPending[client][CONVAR_YAWSPEED]) + { + QueryClientConVar(client, "cl_yawspeed", OnYawSpeedRetrieved); + g_bQueryPending[client][CONVAR_YAWSPEED] = true; + } + + if (!g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY]) + { + QueryClientConVar(client, "zoom_sensitivity_ratio", OnZoomSensitivityRetrieved); + g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY] = true; + } + } + else if (g_Engine == Engine_CSGO) + { + if (!g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY]) + { + QueryClientConVar(client, "zoom_sensitivity_ratio_mouse", OnZoomSensitivityRetrieved); + g_bQueryPending[client][CONVAR_ZOOMSENSITIVITY] = true; + } + } + + // Note: m_ queries that do nothing with m_rawinput 1 are now only called if m_rawinput is 0, and are handled in the OnRawInputRetrieved callback. + // joy_yawsensitivity is only queried if joystick is not 0 and it is handled in the OnJoystickRetrieved callback. } public void SimulateConVarQueryCompleted(int client, int convar) @@ -1281,21 +1254,50 @@ public void OnCustomAccelExRetrieved(QueryCookie cookie, int client, ConVarQuery public void OnRawInputRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) { - bool mRawInput = (0.0 <= StringToFloat(cvarValue) < 1.0)?false:true; - if(mRawInput != g_mRawInput[client]) - { - g_mRawInputChangedCount[client]++; - g_mRawInput[client] = mRawInput; - - if(g_mRawInputChangedCount[client] > 1) - { - PrintToAdmins("%N changed their m_rawinput ConVar to %d", client, mRawInput); - //AnticheatLog(client, "%L changed their m_rawinput ConVar to %d", mRawInput); - } - } - - g_mRawInputCheckedCount[client]++; - SimulateConVarQueryCompleted(client, CONVAR_RAWINPUT); + bool mRawInput = (0.0 <= StringToFloat(cvarValue) < 1.0) ? false : true; + if (mRawInput != g_mRawInput[client]) + { + g_mRawInputChangedCount[client]++; + g_mRawInput[client] = mRawInput; + + if (g_mRawInputChangedCount[client] > 1) + { + PrintToAdmins("%N changed their m_rawinput ConVar to %d", client, mRawInput); + } + } + + g_mRawInputCheckedCount[client]++; + g_bQueryPending[client][CONVAR_RAWINPUT] = false; + + // If m_rawinput is 0, query additional cvars + if (!mRawInput) + { + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL]) + { + QueryClientConVar(client, "m_customaccel", OnCustomAccelRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL] = true; + } + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_MAX]) + { + QueryClientConVar(client, "m_customaccel_max", OnCustomAccelMaxRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL_MAX] = true; + } + if (!g_bQueryPending[client][CONVAR_FILTER]) + { + QueryClientConVar(client, "m_filter", OnFilterRetrieved); + g_bQueryPending[client][CONVAR_FILTER] = true; + } + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_SCALE]) + { + QueryClientConVar(client, "m_customaccel_scale", OnCustomAccelScaleRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL_SCALE] = true; + } + if (!g_bQueryPending[client][CONVAR_CUSTOMACCEL_EXPONENT]) + { + QueryClientConVar(client, "m_customaccel_exponent", OnCustomAccelExRetrieved); + g_bQueryPending[client][CONVAR_CUSTOMACCEL_EXPONENT] = true; + } + } } public void OnSensitivityRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1357,21 +1359,30 @@ public void OnZoomSensitivityRetrieved(QueryCookie cookie, int client, ConVarQue public void OnJoystickRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) { - bool joyStick = (0.0 <= StringToFloat(cvarValue) < 1.0)?false:true; - if(joyStick != g_JoyStick[client]) - { - g_JoyStickChangedCount[client]++; - g_JoyStick[client] = joyStick; + bool joyStick = (0.0 <= StringToFloat(cvarValue) < 1.0) ? false : true; + if (joyStick != g_JoyStick[client]) + { + g_JoyStickChangedCount[client]++; + g_JoyStick[client] = joyStick; - if(g_JoyStickChangedCount[client] > 1) - { - PrintToAdmins("%N changed their joystick ConVar to %d", client, joyStick); - //AnticheatLog("%L changed their joystick ConVar to %d", client, joyStick); - } - } + if (g_JoyStickChangedCount[client] > 1) + { + PrintToAdmins("%N changed their joystick ConVar to %d", client, joyStick); + } + } + + g_JoyStickCheckedCount[client]++; + g_bQueryPending[client][CONVAR_JOYSTICK] = false; - g_JoyStickCheckedCount[client]++; - SimulateConVarQueryCompleted(client, CONVAR_JOYSTICK); + // If joystick is 1, query joy_yawsensitivity + if (joyStick) + { + if (!g_bQueryPending[client][CONVAR_YAWSENSITIVITY]) + { + QueryClientConVar(client, "joy_yawsensitivity", OnYawSensitivityRetrieved); + g_bQueryPending[client][CONVAR_YAWSENSITIVITY] = true; + } + } } @@ -1949,7 +1960,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3 Shavit_GetStyleStrings(style, sSpecialString, sSpecial, 128); if(StrContains(sSpecial, "bash_bypass", false) != -1) { - bCheck = false; + bCheck = false; } #endif