diff --git a/shavit-bash2.sp b/shavit-bash2.sp index 7462e39..bca36b0 100644 --- a/shavit-bash2.sp +++ b/shavit-bash2.sp @@ -1043,22 +1043,84 @@ 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 +{ + 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); + // 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) +{ + g_bQueryPending[client][convar] = false; } public void OnYawSpeedRetrieved(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue) @@ -1069,6 +1131,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 +1151,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 +1170,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 +1190,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 +1209,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 +1229,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,24 +1249,55 @@ 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) { - 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]++; + 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) @@ -1216,6 +1316,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 +1335,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,24 +1354,35 @@ 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) { - 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]++; + // 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; + } + } } @@ -1847,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