diff --git a/RaceTimer/scripting/unloze_racetimer_redux.sp b/RaceTimer/scripting/unloze_racetimer_redux.sp index 1ee5d98a..35fb3436 100644 --- a/RaceTimer/scripting/unloze_racetimer_redux.sp +++ b/RaceTimer/scripting/unloze_racetimer_redux.sp @@ -23,6 +23,7 @@ static char g_sConfigzones[PLATFORM_MAX_PATH]; float g_fStartTime[MAXPLAYERS + 1]; char g_csTime_record[MAXPLAYERS + 1][65]; float g_fClientVectors[MAXPLAYERS + 1][3]; +float g_fClient_End_time[MAXPLAYERS + 1]; int g_iClientFrames[MAXPLAYERS + 1]; int g_iClientSpeedInterval[MAXPLAYERS + 1]; int g_iClientChecking[MAXPLAYERS + 1]; @@ -30,8 +31,8 @@ bool g_bDisplaySpecial; bool g_bHumansAllowedTime[MAXPLAYERS + 1]; bool g_bhumans_finished[MAXPLAYERS + 1]; bool g_bHideTimer[MAXPLAYERS + 1]; -int g_bAllowToLeave[MAXPLAYERS + 1]; bool g_bEventBool = false; +bool g_bClient_allowed_to_leave_again[MAXPLAYERS + 1]; Handle g_hClientCookie = INVALID_HANDLE; Database g_dDatabase; Handle hText; @@ -86,6 +87,13 @@ public void OnPluginStart() g_bDisplaySpecial = unloze_gBSpecialMapDisplay(); } +public Action allow_leaving_again(Handle hTimer, int client) +{ + if (IsValidClient(client)) + { + g_bClient_allowed_to_leave_again[client] = true; + } +} public Action Timer_alter_tables(Handle hTimer) { if (!g_dDatabase) @@ -105,12 +113,12 @@ public void trigger_teleport(const char[] output, int entity_index, int client, //if its surf maps there most likely are needed teleports if (StrContains(g_cMapname, "surf", false) == -1) { - g_bHumansAllowedTime[client] = false; - resetClientVectors(client); - if (GetClientTeam(client) == 3) - { - PrintToChat(client, "Disabled timer due to potential teleport abuse"); - } + g_bHumansAllowedTime[client] = false; + g_bhumans_finished[client] = false; + resetClientVectors(client); + g_bClient_allowed_to_leave_again[client] = false; + PrintToChat(client, "Disabled timer due to potential teleport abuse, type 1."); + CreateTimer(1.0, allow_leaving_again, client); } } } @@ -122,13 +130,15 @@ public void Trigger_Multiple(const char[] output, int entity_index, int client, if (StrContains(g_cMapname, "surf", false) == -1) { g_bHumansAllowedTime[client] = false; + g_bhumans_finished[client] = false; resetClientVectors(client); - PrintToChat(client, "Disabled timer due to potential teleport abuse"); + g_bClient_allowed_to_leave_again[client] = false; + PrintToChat(client, "Disabled timer due to potential teleport abuse, type 1."); + CreateTimer(1.0, allow_leaving_again, client); } } } - public bool origin_command_check(int entity_index) { int count_trigger = GetOutputCount(entity_index, "m_OnTrigger"); @@ -198,7 +208,6 @@ public void MYSQLCheckMapEntry() int l_iRaceCount; int l_iZoneCount = unloze_zoneCount(); char sQuery[g_dLength]; - char l_cZoneIndexName[g_dIndex][g_dLength]; if (l_iZoneCount == 1) { Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` ADD COLUMN IF NOT EXISTS `%s` REAL DEFAULT 0.000 NOT NULL", g_cMapname); @@ -210,7 +219,9 @@ public void MYSQLCheckMapEntry() { for (int iterator = 0; iterator <= l_iZoneCount; iterator++) { - if (IsCorrectZone(iterator, l_cZoneIndexName[iterator][g_dLength -1], "ZONE_PREFIX_RACE")) + char zoneIndexName[512]; + ZoneNameBasedOnIndex(iterator, zoneIndexName); + if (StrContains(zoneIndexName, "ZONE_PREFIX_RACE") > -1) { l_iRaceCount++; Format(sQuery, sizeof(sQuery), "ALTER TABLE `zetimer_table_new` ADD COLUMN IF NOT EXISTS `%sS%i` REAL DEFAULT 0.000 NOT NULL", g_cMapname, l_iRaceCount); @@ -370,17 +381,18 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast if (IsValidClient(i) && !IsFakeClient(i)) { g_bhumans_finished[i] = false; + g_fClient_End_time[i] = 0.0; resetClientVectors(i); - g_bAllowToLeave[i] = 0; char first_zone[512]; ZoneNameBasedOnIndex(0, first_zone); + g_bClient_allowed_to_leave_again[i] = true; if (race_zone_count != 1) g_bHumansAllowedTime[i] = false; else if (StrContains(first_zone, "ZONE_PREFIX_RACE") > -1) //ensures only one zone in total and that its the actual end zone { - mysql_get_player_time(i, 0); g_bHumansAllowedTime[i] = true; g_fStartTime[i] = GetEngineTime(); + mysql_get_player_time(i, 0); } else { @@ -421,8 +433,9 @@ public void resetClient(int client) { g_iClientChecking[client] = 0; g_bHumansAllowedTime[client] = false; - g_bAllowToLeave[client] = 0; g_bhumans_finished[client] = false; + g_fClient_End_time[client] = 0.0; + g_bClient_allowed_to_leave_again[client] = false; resetClientVectors(client); g_fStartTime[client] = 0.0; player_stage[client] = 0; @@ -444,29 +457,36 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float g_bHumansAllowedTime[client] = false; return; } - if (GetClientTeam(client) == CS_TEAM_CT && IsPlayerAlive(client)) + if (!IsPlayerAlive(client)) { + g_bHumansAllowedTime[client] = false; + g_bhumans_finished[client] = false; + resetClientVectors(client); + PrintToChat(client, "Disabled timer due to dying."); + return; + } + if (GetClientTeam(client) == CS_TEAM_CT) + { + float clientVectors[3]; + GetClientAbsOrigin(client, clientVectors); + if (checkClientOrigin(g_fClientVectors[client], clientVectors, client)) + { + g_bHumansAllowedTime[client] = false; + g_bhumans_finished[client] = false; + resetClientVectors(client); + g_bClient_allowed_to_leave_again[client] = false; + PrintToChat(client, "Disabled timer due to potential teleport abuse, type 2."); + CreateTimer(1.0, allow_leaving_again, client); + return; + } int frameCap = 11; if (g_bhumans_finished[client]) g_iClientFrames[client] = 11; if (g_iClientFrames[client] >= frameCap) { g_iClientFrames[client] = 0; - float clientVectors[3]; - GetClientAbsOrigin(client, clientVectors); - if (checkClientOrigin(g_fClientVectors[client], clientVectors, client)) - { - g_bHumansAllowedTime[client] = false; - g_bhumans_finished[client] = false; - //called if teleported to some place far away or teleported from inside start zone to end zone - CreateTimer(1.0, reset_permissions_for_leave, client); - resetClientVectors(client); - PrintToChat(client, "Disabled timer due to potential teleport abuse"); - return; - } if (g_bhumans_finished[client]) { - CreateTimer(1.0, reset_permissions_for_leave, client); resetClientVectors(client); g_bhumans_finished[client] = false; g_bHumansAllowedTime[client] = false; @@ -525,6 +545,16 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float } g_iClientFrames[client]++; } + else + { + //is zm + g_bHumansAllowedTime[client] = false; + g_bhumans_finished[client] = false; + //called if teleported to some place far away or teleported from inside start zone to end zone + resetClientVectors(client); + PrintToChat(client, "Disabled timer due to ZM infection."); + return; + } return; } @@ -557,7 +587,6 @@ public bool checkClientOrigin(float oldVals[3], float newVals[3], int client) float teleport_range = 1090450.0; int velocityCap = 625; float distance = GetVectorDistance(oldVals, newVals, true); - //PrintToChatAll("distance: %f", distance); bool bInAir = (GetEntPropEnt(client, Prop_Send, "m_hGroundEntity") == -1); if (distance > teleport_range) { @@ -592,32 +621,13 @@ public void unloze_zoneEntry(int client, char[] zone) player_stage[client] = 0; if (player_stage[client] == (zoneIndex / 2) || l_iZoneCount < 2) { - g_bAllowToLeave[client] = 1; g_bhumans_finished[client] = true; + g_fClient_End_time[client] = client_current_race_time(client); } } } } -public Action reset_permissions_for_leave(Handle timer, int i) -{ - if (IsValidClient(i)) - { - //if you start the timer and run inside the start zone again there are 3 options: - //you leave the zone normally by running out of it which is fine - //you get teleported out of the zone to a certain distance away by something like afk teleport, in that case your timer gets disabled - //due to detected teleport abuse - - //Third option is you get teleported out of spawn zone to a end zone which after triggering Entry forward triggers Leave forward again - //Therefore we need a cooldown when teleporting from inside of start zone to an entry zone as Leave forward is called right after again - //which is a errornous way of starting the timer from the end zone, by having a second delay we ensure its not a problem when teleported from spawn - //to a random place thats not an entry zone as this is handled seemingly correctly by the teleport abuse detection. Meanwhile to stop the timer from - //starting when teleported from spawn to an Entry zone we need a cooldown - g_bAllowToLeave[i] = 0; - } - return Plugin_Continue; -} - //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -625,13 +635,11 @@ public void unloze_zoneLeave(int client, char[] zone) { //only maps with multiple zones need ZONE_PREFIX_START int race_zone_count = GetTotalRaceZones(); - //if zone has special name like in mako dont return despite g_bAllowToLeave being false or there being no normally named zone - if (!(StrEqual(zone, g_cSpecialMapStart)) && (!race_zone_count || g_bAllowToLeave[client])) + if (!(StrEqual(zone, g_cSpecialMapStart)) && !race_zone_count) return; if (GetClientTeam(client) == CS_TEAM_CT) { - //PrintToChatAll("Equal: %i", StrEqual(zone, g_cSpecialMapStart)); if ((StrContains(zone, "ZONE_PREFIX_START") > -1) || StrEqual(zone, g_cSpecialMapStart)) { char sAuthID[32]; @@ -641,13 +649,17 @@ public void unloze_zoneLeave(int client, char[] zone) PrintToChat(client, "Not starting timer due to being listed as nosteamer"); return; } + if (!g_bClient_allowed_to_leave_again[client]) + { + return; + } g_fStartTime[client] = GetEngineTime(); float notRounded = float(RetrieveZoneIndex(zone)); player_stage[client] = RoundToCeil(notRounded / 2); - mysql_get_player_time(client, player_stage[client]); - g_bHumansAllowedTime[client] = true; CPrintToChat(client, "Timer started for Course: %i", player_stage[client]); + g_bHumansAllowedTime[client] = true; + mysql_get_player_time(client, player_stage[client]); } } } @@ -706,7 +718,7 @@ public void FinishedStageRaceZone(int client) } int l_iZoneCount = unloze_zoneCount(); - float client_time = client_current_race_time(client); + float client_time = g_fClient_End_time[client]; if (client_time == -1.0) { //if client disconnected we dont want to cary timer over to other client @@ -898,7 +910,6 @@ public void mysql_select_lowest_ordered(int client, int index, int length_increa public void CheckTop(int client, int index, int autismstate) { int l_iZoneCount = unloze_zoneCount(); - //PrintToChatAll("checktop l_iZoneCount: %i", l_iZoneCount); if (l_iZoneCount < 1) { PrintToChat(client, "No zones active on this map"); @@ -1023,52 +1034,51 @@ public Action cmd_timerCheckStage(int client, int args) //---------------------------------------------------------------------------------------------------- public void CheckStagesOnMap(int client, int state) { - int l_iCount; - int l_iZoneCount = unloze_zoneCount(); - Menu StageMenu = CreateMenu(Stage_menu); - char l_cZoneIndexName[g_dIndex][g_dLength]; - char l_cMenuContent[g_dLength]; - if (!l_iZoneCount) - { - CPrintToChat(client, "[UNLOZE] Map does not support racestage timer"); - return; - } - //state 0 == toptime, state 1 == own time - g_iClientChecking[client] = state; - StageMenu.SetTitle("Stages on: %s", g_cMapname); - if (g_bDisplaySpecial) - { - l_iCount++; - Format(l_cMenuContent, sizeof(l_cMenuContent), "Stage: %i", l_iCount); - StageMenu.AddItem("", l_cMenuContent); - } - else - { - for (int Iterator = 0; Iterator <= l_iZoneCount; Iterator++) - { - if (IsCorrectZone(Iterator, l_cZoneIndexName[Iterator][g_dLength -1], "ZONE_PREFIX_RACE")) - { - l_iCount++; - Format(l_cMenuContent, sizeof(l_cMenuContent), "Stage: %i", l_iCount); - StageMenu.AddItem("", l_cMenuContent); - } - } - } - StageMenu.ExitButton = true; - StageMenu.Display(client, 0); -} -//---------------------------------------------------------------------------------------------------- -// Purpose: -//---------------------------------------------------------------------------------------------------- -public bool IsCorrectZone(int index, char[] zoneIndexName, char[] zone_prefix) -{ - ZoneNameBasedOnIndex(index, zoneIndexName); - if (StrContains(zoneIndexName, zone_prefix) > -1) - { - return true; - } - return false; + int l_iCount; + int l_iZoneCount = unloze_zoneCount(); + Menu StageMenu = CreateMenu(Stage_menu); + char l_cMenuContent[g_dLength]; + if (!l_iZoneCount) + { + CPrintToChat(client, "[UNLOZE] Map does not support racestage timer"); + return; + } + //state 0 == toptime, state 1 == own time + g_iClientChecking[client] = state; + StageMenu.SetTitle("Stages on: %s", g_cMapname); + if (g_bDisplaySpecial) + { + l_iCount++; + Format(l_cMenuContent, sizeof(l_cMenuContent), "Stage: %i", l_iCount); + StageMenu.AddItem("", l_cMenuContent); + } + else + { + int zone_reached = 0; + for (int Iterator = 0; Iterator <= l_iZoneCount; Iterator++) + { + char zoneIndexName[512]; + ZoneNameBasedOnIndex(Iterator, zoneIndexName); + if (StrContains(zoneIndexName, "ZONE_PREFIX_RACE") > -1) + { + char local_c[g_dLength]; + Format(local_c, sizeof(local_c), "%s", zoneIndexName[strlen("ZONE_PREFIX_RACE") + 1]); + int prev = zone_reached; + zone_reached = StringToInt(local_c); + if (zone_reached == prev) + { + continue; + } + l_iCount++; + Format(l_cMenuContent, sizeof(l_cMenuContent), "Stage: %i", l_iCount); + StageMenu.AddItem("", l_cMenuContent); + } + } + } + StageMenu.ExitButton = true; + StageMenu.Display(client, 0); } + //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- @@ -1119,25 +1129,25 @@ public void deleteClientTime(char[] steam2, int stage) //---------------------------------------------------------------------------------------------------- public void Checkself(int client) { - int l_iZoneCount = unloze_zoneCount(); - char l_cQuery[g_dLength]; - char l_cSID[g_dIndex]; - GetClientAuthId(client, AuthId_Steam2, l_cSID, sizeof(l_cSID)); - if (l_iZoneCount < 1) - { - PrintToChat(client, "No zones active on this map"); - return; - } - if (l_iZoneCount < 2) - { - Format(l_cQuery, sizeof(l_cQuery), "SELECT name, `%s` FROM `zetimer_table_new` WHERE steam_auth = '%s'", g_cMapname, l_cSID); - DataPack hDataPack = new DataPack(); - hDataPack.WriteCell(GetClientSerial(client)); - hDataPack.WriteString(l_cQuery); - g_dDatabase.Query(SQL_CheckSelf, l_cQuery, hDataPack); - } - else - CheckStagesOnMap(client, 1); + int l_iZoneCount = unloze_zoneCount(); + char l_cQuery[g_dLength]; + char l_cSID[g_dIndex]; + GetClientAuthId(client, AuthId_Steam2, l_cSID, sizeof(l_cSID)); + if (l_iZoneCount < 1) + { + PrintToChat(client, "No zones active on this map"); + return; + } + if (l_iZoneCount < 2) + { + Format(l_cQuery, sizeof(l_cQuery), "SELECT name, `%s` FROM `zetimer_table_new` WHERE steam_auth = '%s'", g_cMapname, l_cSID); + DataPack hDataPack = new DataPack(); + hDataPack.WriteCell(GetClientSerial(client)); + hDataPack.WriteString(l_cQuery); + g_dDatabase.Query(SQL_CheckSelf, l_cQuery, hDataPack); + } + else + CheckStagesOnMap(client, 1); } //---------------------------------------------------------------------------------------------------- // Purpose: