From 0b14a794826cf922d3350df14d5cef58feaf1bb7 Mon Sep 17 00:00:00 2001 From: jenz Date: Sun, 17 Sep 2023 15:53:15 +0200 Subject: [PATCH] updated mapchooser to avoid bug caused by calling rockthevote native or by calling SetupTimeleftTimer without g_WaitingForVote check --- .../scripting/mapchooser_extended_avg.sp | 451 +++++++++--------- 1 file changed, 233 insertions(+), 218 deletions(-) diff --git a/mapchooser_extended/scripting/mapchooser_extended_avg.sp b/mapchooser_extended/scripting/mapchooser_extended_avg.sp index 94c0f0e1..9b7a88ff 100755 --- a/mapchooser_extended/scripting/mapchooser_extended_avg.sp +++ b/mapchooser_extended/scripting/mapchooser_extended_avg.sp @@ -138,7 +138,6 @@ bool g_ChangeMapInProgress; bool g_HasIntermissionStarted = false; int g_mapFileSerial = -1; -bool prevent_rare_map_vote_bug_2023 = false; //this is not very cool -jenz int g_NominateCount = 0; int g_NominateReservedCount = 0; @@ -400,7 +399,6 @@ public void OnPluginStart() g_MapVoteWarningTickForward = CreateGlobalForward("OnMapVoteWarningTick", ET_Ignore, Param_Cell); g_MapVoteRunoffStartForward = CreateGlobalForward("OnMapVoteRunnoffWarningStart", ET_Ignore); - prevent_rare_map_vote_bug_2023 = false; InternalRestoreMapCooldowns(); } @@ -557,7 +555,6 @@ public void OnMapEnd() g_WarningTimer = INVALID_HANDLE; g_RunoffCount = 0; - prevent_rare_map_vote_bug_2023 = false; static char map[PLATFORM_MAX_PATH]; int Cooldown; @@ -688,55 +685,63 @@ public Action Command_ExtendsLeft(int client, int args) public void OnMapTimeLeftChanged() { - if(GetArraySize(g_MapList)) - SetupTimeleftTimer(); + if(GetArraySize(g_MapList)) + { + //LogMessage("Mapchooser_extended_avg OnMapTimeLeftChanged call."); + SetupTimeleftTimer(); + } } void SetupTimeleftTimer() { - int time; - if(GetMapTimeLeft(time) && time > 0) - { - int startTime; - if(GetConVarBool(g_Cvar_StartTimePercentEnable)) - { - int timeLimit; - if(GetMapTimeLimit(timeLimit) && timeLimit > 0) - { - startTime = GetConVarInt(g_Cvar_StartTimePercent) * (timeLimit * 60) / 100; - } - } - else - startTime = GetConVarInt(g_Cvar_StartTime) * 60; + int time; + if(GetMapTimeLeft(time) && time > 0) + { + int startTime; + if(GetConVarBool(g_Cvar_StartTimePercentEnable)) + { + int timeLimit; + if(GetMapTimeLimit(timeLimit) && timeLimit > 0) + { + startTime = GetConVarInt(g_Cvar_StartTimePercent) * (timeLimit * 60) / 100; + } + } + else + startTime = GetConVarInt(g_Cvar_StartTime) * 60; - if(time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted) - { - SetupWarningTimer(WarningType_Vote); - } - else - { - if(g_WarningTimer == INVALID_HANDLE) - { - if(g_VoteTimer != INVALID_HANDLE) - { - KillTimer(g_VoteTimer); - g_VoteTimer = INVALID_HANDLE; - } + if(time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted && !g_WaitingForVote) + { + SetupWarningTimer(WarningType_Vote); + //LogMessage("Mapchooser_extended_avg SetupWarningTimer call 2"); + } + else + { + if(g_WarningTimer == INVALID_HANDLE) + { + if(g_VoteTimer != INVALID_HANDLE) + { + KillTimer(g_VoteTimer); + g_VoteTimer = INVALID_HANDLE; + } - //g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVoteTimer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE); - g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartWarningTimer, _, TIMER_FLAG_NO_MAPCHANGE); - } - } - } + //g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartMapVoteTimer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE); + //LogMessage("Mapchooser_extended_avg g_VoteTimer Timer_StartWarningTimer"); + g_VoteTimer = CreateTimer(float(time - startTime), Timer_StartWarningTimer, _, TIMER_FLAG_NO_MAPCHANGE); + } + } + } } public Action Timer_StartWarningTimer(Handle timer) { - g_VoteTimer = INVALID_HANDLE; + g_VoteTimer = INVALID_HANDLE; - if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) - SetupWarningTimer(WarningType_Vote); - return Plugin_Stop; + if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) + { + //LogMessage("Mapchooser_extended_avg SetupWarningTimer call 3"); + SetupWarningTimer(WarningType_Vote); + } + return Plugin_Stop; } public Action Timer_StartMapVote(Handle timer, Handle data) @@ -747,6 +752,7 @@ public Action Timer_StartMapVote(Handle timer, Handle data) if(!GetArraySize(g_MapList) || !GetConVarBool(g_Cvar_EndOfMapVote) || g_MapVoteCompleted || g_HasVoteStarted) { g_WarningTimer = INVALID_HANDLE; + //LogMessage("Mapchooser_extended_avg Timer_Start MapVote Plugin_Stop"); return Plugin_Stop; } @@ -785,6 +791,7 @@ public Action Timer_StartMapVote(Handle timer, Handle data) } } + //LogMessage("timePassed: %i \n warningMaxTime: %i", timePassed, warningMaxTime); if(timePassed++ >= warningMaxTime) { if(timer == g_RetryTimer) @@ -798,12 +805,8 @@ public Action Timer_StartMapVote(Handle timer, Handle data) timePassed = 0; MapChange mapChange = view_as(ReadPackCell(data)); Handle hndl = view_as(ReadPackCell(data)); - - if (!prevent_rare_map_vote_bug_2023) - { - InitiateVote(mapChange, hndl); - } - + //LogMessage("Mapchooser_extended_avg calling InitiateVote()"); + InitiateVote(mapChange, hndl); return Plugin_Stop; } @@ -908,40 +911,42 @@ public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast) public void CheckWinLimit(int winner_score) { - int winlimit = GetConVarInt(g_Cvar_Winlimit); - if(winlimit) - { - if(winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds))) - { - if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) - { - SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); - } - } - } + int winlimit = GetConVarInt(g_Cvar_Winlimit); + if(winlimit) + { + if(winner_score >= (winlimit - GetConVarInt(g_Cvar_StartRounds))) + { + if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) + { + SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); + //LogMessage("Mapchooser_extended_avg SetupWarningTimer call 4"); + } + } + } } public void CheckMaxRounds(int roundcount) { - int maxrounds = 0; + int maxrounds = 0; - if(g_RoundCounting == RoundCounting_ArmsRace) - maxrounds = GameRules_GetProp("m_iNumGunGameProgressiveWeaponsCT"); - else if(g_RoundCounting == RoundCounting_MvM) - maxrounds = GetEntProp(g_ObjectiveEnt, Prop_Send, "m_nMannVsMachineMaxWaveCount"); - else - return; + if(g_RoundCounting == RoundCounting_ArmsRace) + maxrounds = GameRules_GetProp("m_iNumGunGameProgressiveWeaponsCT"); + else if(g_RoundCounting == RoundCounting_MvM) + maxrounds = GetEntProp(g_ObjectiveEnt, Prop_Send, "m_nMannVsMachineMaxWaveCount"); + else + return; - if(maxrounds) - { - if(roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds))) - { - if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) - { - SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); - } - } - } + if(maxrounds) + { + if(roundcount >= (maxrounds - GetConVarInt(g_Cvar_StartRounds))) + { + if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) + { + SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); + //LogMessage("Mapchooser_extended_avg SetupWarningTimer call 5"); + } + } + } } public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast) @@ -965,6 +970,7 @@ public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadc if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE) { SetupWarningTimer(WarningType_Vote, MapChange_MapEnd); + //LogMessage("Mapchooser_extended_avg SetupWarningTimer call 6"); } } return Plugin_Continue; @@ -972,11 +978,12 @@ public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadc public Action Command_Mapvote(int client, int args) { - ShowActivity2(client, "[MCE] ", "%t", "Initiated Vote Map"); + ShowActivity2(client, "[MCE] ", "%t", "Initiated Vote Map"); - SetupWarningTimer(WarningType_Vote, MapChange_MapEnd, INVALID_HANDLE, true); + SetupWarningTimer(WarningType_Vote, MapChange_MapEnd, INVALID_HANDLE, true); + //LogMessage("Mapchooser_extended_avg SetupWarningTimer call 7"); - return Plugin_Handled; + return Plugin_Handled; } public Handle get_most_nominated_maps() @@ -1103,6 +1110,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE) CPrintToChatAll("[MCE] %t", "Cannot Start Vote", FAILURE_TIMER_LENGTH); Handle data; g_RetryTimer = CreateDataTimer(1.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT); + //LogMessage("Mapchooser_extended_avg: called Timer_StartMapVote"); /* Mapchooser Extended */ WritePackCell(data, FAILURE_TIMER_LENGTH); @@ -1121,16 +1129,17 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE) /* If the main map vote has completed (and chosen result) and its currently changing (not a delayed change) we block further attempts */ if(g_MapVoteCompleted && g_ChangeMapInProgress) + { + //LogMessage("Mapchooser_extended_avg ended here: g_MapVoteCompleted: %i \n g_ChangeMapInProgress: %i", g_MapVoteCompleted, g_ChangeMapInProgress); return; + } - prevent_rare_map_vote_bug_2023 = true; CheckMapRestrictions(true, true); CreateNextVote(); g_ChangeTime = when; - g_WaitingForVote = false; g_HasVoteStarted = true; @@ -1446,14 +1455,15 @@ public void Handler_MapVoteFinished(Handle menu, const int[][] item_info) { // Implement revote logic - Only run this` block if revotes are enabled and this isn't the last revote' - prevent_rare_map_vote_bug_2023 = false; + //LogMessage("Mapchooser_extended_avg Handler_MapVoteFinished."); + //LogMessage("Mapchooser_extended_avg g_Cvar_RunOff: %i num_items: %i g_RunoffCount %i g_Cvar_MaxRunOffs %i", GetConVarBool(g_Cvar_RunOff), num_items, g_RunoffCount, GetConVarInt(g_Cvar_MaxRunOffs)); if(GetConVarBool(g_Cvar_RunOff) && num_items > 1 && g_RunoffCount < GetConVarInt(g_Cvar_MaxRunOffs)) { + //LogMessage("Mapchooser_extended_avg Handler_MapVoteFinished passed check1."); g_RunoffCount++; int highest_votes = item_info[0][VOTEINFO_ITEM_VOTES]; int required_percent = GetConVarInt(g_Cvar_RunOffPercent); int required_votes = RoundToCeil(float(num_votes) * float(required_percent) / 100.0); - if(highest_votes == item_info[1][VOTEINFO_ITEM_VOTES]) { g_HasVoteStarted = false; @@ -1476,6 +1486,7 @@ public void Handler_MapVoteFinished(Handle menu, } CPrintToChatAll("[MCE] %t", "Tie Vote", GetArraySize(mapList)); + //LogMessage("Mapchooser_extended_avg reached WarningType_Revote 1"); SetupWarningTimer(WarningType_Revote, view_as(g_ChangeTime), mapList); return; } @@ -1506,122 +1517,125 @@ public void Handler_MapVoteFinished(Handle menu, } CPrintToChatAll("[MCE] %t", "Revote Is Needed", required_percent); + //LogMessage("Mapchooser_extended_avg reached WarningType_Revote 2"); SetupWarningTimer(WarningType_Revote, view_as(g_ChangeTime), mapList); return; } } + g_WaitingForVote = false; + //LogMessage("Mapchooser_extended_avg no revote needed, continue as normal."); // No revote needed, continue as normal. Handler_VoteFinishedGeneric(menu, num_votes, num_clients, client_info, num_items, item_info); } public int Handler_MapVoteMenu(Handle menu, MenuAction action, int param1, int param2) { - switch(action) - { - case MenuAction_End: - { - g_VoteMenu = INVALID_HANDLE; - delete menu; - } + switch(action) + { + case MenuAction_End: + { + g_VoteMenu = INVALID_HANDLE; + delete menu; + } - case MenuAction_Display: - { - static char buffer[255]; - Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1); - Handle panel = view_as(param2); - SetPanelTitle(panel, buffer); - DrawPanelText(panel, "Warning: The Position of the Maps are different for each Player."); - } + case MenuAction_Display: + { + static char buffer[255]; + Format(buffer, sizeof(buffer), "%T", "Vote Nextmap", param1); + Handle panel = view_as(param2); + SetPanelTitle(panel, buffer); + DrawPanelText(panel, "Warning: The Position of the Maps are different for each Player."); + } - case MenuAction_DisplayItem: - { - char map[PLATFORM_MAX_PATH]; - char buffer[255]; - int mark = GetConVarInt(g_Cvar_MarkCustomMaps); + case MenuAction_DisplayItem: + { + char map[PLATFORM_MAX_PATH]; + char buffer[255]; + int mark = GetConVarInt(g_Cvar_MarkCustomMaps); - GetMenuItem(menu, param2, map, PLATFORM_MAX_PATH, _, _, _, param1); + GetMenuItem(menu, param2, map, PLATFORM_MAX_PATH, _, _, _, param1); - if(StrEqual(map, VOTE_EXTEND, false)) - { - Format(buffer, sizeof(buffer), "%T", "Extend Map", param1); - } - else if(StrEqual(map, VOTE_DONTCHANGE, false)) - { - Format(buffer, sizeof(buffer), "%T", "Dont Change", param1); - } - // Mapchooser Extended - else if(StrEqual(map, LINE_ONE, false)) - { - Format(buffer, sizeof(buffer),"%T", "Line One", param1); - } - else if(StrEqual(map, LINE_TWO, false)) - { - Format(buffer, sizeof(buffer),"%T", "Line Two", param1); - } - // Note that the first part is to discard the spacer line - else if(!StrEqual(map, LINE_SPACER, false)) - { - if(mark == 1 && !InternalIsMapOfficial(map)) - { - Format(buffer, sizeof(buffer), "%T", "Custom Marked", param1, map); - } - else if(mark == 2 && !InternalIsMapOfficial(map)) - { - Format(buffer, sizeof(buffer), "%T", "Custom", param1, map); - } - else if(InternalGetMapVIPRestriction(map)) - { - Format(buffer, sizeof(buffer), "%s (%T)", map, "VIP Nomination", param1); - } - } + if(StrEqual(map, VOTE_EXTEND, false)) + { + Format(buffer, sizeof(buffer), "%T", "Extend Map", param1); + } + else if(StrEqual(map, VOTE_DONTCHANGE, false)) + { + Format(buffer, sizeof(buffer), "%T", "Dont Change", param1); + } + // Mapchooser Extended + else if(StrEqual(map, LINE_ONE, false)) + { + Format(buffer, sizeof(buffer),"%T", "Line One", param1); + } + else if(StrEqual(map, LINE_TWO, false)) + { + Format(buffer, sizeof(buffer),"%T", "Line Two", param1); + } + // Note that the first part is to discard the spacer line + else if(!StrEqual(map, LINE_SPACER, false)) + { + if(mark == 1 && !InternalIsMapOfficial(map)) + { + Format(buffer, sizeof(buffer), "%T", "Custom Marked", param1, map); + } + else if(mark == 2 && !InternalIsMapOfficial(map)) + { + Format(buffer, sizeof(buffer), "%T", "Custom", param1, map); + } + else if(InternalGetMapVIPRestriction(map)) + { + Format(buffer, sizeof(buffer), "%s (%T)", map, "VIP Nomination", param1); + } + } - if(buffer[0] != '\0') - { - return RedrawMenuItem(buffer); - } - // End Mapchooser Extended - } + if(buffer[0] != '\0') + { + return RedrawMenuItem(buffer); + } + // End Mapchooser Extended + } - case MenuAction_VoteCancel: - { - // If we receive 0 votes, pick at random. - if(param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode)) - { - int count = GetMenuItemCount(menu); + case MenuAction_VoteCancel: + { + // If we receive 0 votes, pick at random. + if(param1 == VoteCancel_NoVotes && GetConVarBool(g_Cvar_NoVoteMode)) + { + int count = GetMenuItemCount(menu); - int item; - static char map[PLATFORM_MAX_PATH]; + int item; + static char map[PLATFORM_MAX_PATH]; - do - { - int startInt = 0; - if(g_BlockedSlots) - { - if(g_AddNoVote) - { - startInt = 2; - } - else - { - startInt = 3; - } - } - item = GetRandomInt(startInt, count - 1); + do + { + int startInt = 0; + if(g_BlockedSlots) + { + if(g_AddNoVote) + { + startInt = 2; + } + else + { + startInt = 3; + } + } + item = GetRandomInt(startInt, count - 1); - GetMenuItem(menu, item, map, PLATFORM_MAX_PATH, _, _, _, param1); - } - while(strcmp(map, VOTE_EXTEND, false) == 0); + GetMenuItem(menu, item, map, PLATFORM_MAX_PATH, _, _, _, param1); + } + while(strcmp(map, VOTE_EXTEND, false) == 0); - SetNextMap(map); - g_MapVoteCompleted = true; - } - - g_HasVoteStarted = false; - } - } - - return 0; + SetNextMap(map); + g_MapVoteCompleted = true; + } + g_WaitingForVote = false; + g_HasVoteStarted = false; + g_RunoffCount = 0; + } + } + return 0; } public Action Timer_ChangeMap(Handle hTimer, Handle dp) @@ -1977,6 +1991,7 @@ public int Native_InitiateVote(Handle plugin, int numParams) LogAction(-1, -1, "Starting map vote because outside request"); SetupWarningTimer(WarningType_Vote, when, inputarray); + //LogMessage("Mapchooser_extended_avg SetupWarningTimer call 1"); return 0; } @@ -2048,54 +2063,54 @@ public int Native_GetNominatedMapList(Handle plugin, int numParams) // Functions new to Mapchooser Extended stock void SetupWarningTimer(WarningType type, MapChange when=MapChange_MapEnd, Handle mapList=INVALID_HANDLE, bool force=false) { - if(!GetArraySize(g_MapList) || g_ChangeMapInProgress || g_HasVoteStarted || (!force && ((when == MapChange_MapEnd && !GetConVarBool(g_Cvar_EndOfMapVote)) || g_MapVoteCompleted))) - return; + if(!GetArraySize(g_MapList) || g_ChangeMapInProgress || g_HasVoteStarted || (!force && ((when == MapChange_MapEnd && !GetConVarBool(g_Cvar_EndOfMapVote)) || g_MapVoteCompleted))) + return; - bool interrupted = false; - if(g_WarningInProgress && g_WarningTimer != INVALID_HANDLE) - { - interrupted = true; - KillTimer(g_WarningTimer); - } + bool interrupted = false; + if(g_WarningInProgress && g_WarningTimer != INVALID_HANDLE) + { + interrupted = true; + KillTimer(g_WarningTimer); + } - g_WarningInProgress = true; + g_WarningInProgress = true; - Handle forwardVote; - Handle cvarTime; - static char translationKey[64]; + Handle forwardVote; + Handle cvarTime; + static char translationKey[64]; - switch(type) - { - case WarningType_Vote: - { - forwardVote = g_MapVoteWarningStartForward; - cvarTime = g_Cvar_WarningTime; - strcopy(translationKey, sizeof(translationKey), "Vote Warning"); + switch(type) + { + case WarningType_Vote: + { + forwardVote = g_MapVoteWarningStartForward; + cvarTime = g_Cvar_WarningTime; + strcopy(translationKey, sizeof(translationKey), "Vote Warning"); + //LogMessage("Mapchooser_extended_avg WarningType_Vote"); + } - } + case WarningType_Revote: + { + forwardVote = g_MapVoteRunoffStartForward; + cvarTime = g_Cvar_RunOffWarningTime; + strcopy(translationKey, sizeof(translationKey), "Revote Warning"); + //LogMessage("Mapchooser_extended_avg WarningType_Revote. cvarTime: %i", GetConVarInt(cvarTime)); + } + } - case WarningType_Revote: - { - forwardVote = g_MapVoteRunoffStartForward; - cvarTime = g_Cvar_RunOffWarningTime; - strcopy(translationKey, sizeof(translationKey), "Revote Warning"); + if(!interrupted) + { + Call_StartForward(forwardVote); + Call_Finish(); + } - } - } - - if(!interrupted) - { - Call_StartForward(forwardVote); - Call_Finish(); - } - - Handle data; - g_WarningTimer = CreateDataTimer(1.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT); - WritePackCell(data, GetConVarInt(cvarTime)); - WritePackString(data, translationKey); - WritePackCell(data, view_as(when)); - WritePackCell(data, view_as(mapList)); - ResetPack(data); + Handle data; + g_WarningTimer = CreateDataTimer(1.0, Timer_StartMapVote, data, TIMER_FLAG_NO_MAPCHANGE | TIMER_REPEAT); + WritePackCell(data, GetConVarInt(cvarTime)); + WritePackString(data, translationKey); + WritePackCell(data, view_as(when)); + WritePackCell(data, view_as(mapList)); + ResetPack(data); } stock void InitializeOfficialMapList()