updated mapchooser to avoid bug caused by calling rockthevote native or by calling SetupTimeleftTimer without g_WaitingForVote check

This commit is contained in:
jenz 2023-09-17 15:53:15 +02:00
parent 59eb86fa23
commit 0b14a79482

View File

@ -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;
@ -689,7 +686,10 @@ public Action Command_ExtendsLeft(int client, int args)
public void OnMapTimeLeftChanged()
{
if(GetArraySize(g_MapList))
{
//LogMessage("Mapchooser_extended_avg OnMapTimeLeftChanged call.");
SetupTimeleftTimer();
}
}
void SetupTimeleftTimer()
@ -709,9 +709,10 @@ void SetupTimeleftTimer()
else
startTime = GetConVarInt(g_Cvar_StartTime) * 60;
if(time - startTime < 0 && GetConVarBool(g_Cvar_EndOfMapVote) && !g_MapVoteCompleted && !g_HasVoteStarted)
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
{
@ -724,6 +725,7 @@ void SetupTimeleftTimer()
}
//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);
}
}
@ -735,7 +737,10 @@ public Action Timer_StartWarningTimer(Handle timer)
g_VoteTimer = INVALID_HANDLE;
if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE)
{
//LogMessage("Mapchooser_extended_avg SetupWarningTimer call 3");
SetupWarningTimer(WarningType_Vote);
}
return Plugin_Stop;
}
@ -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<MapChange>(ReadPackCell(data));
Handle hndl = view_as<Handle>(ReadPackCell(data));
if (!prevent_rare_map_vote_bug_2023)
{
//LogMessage("Mapchooser_extended_avg calling InitiateVote()");
InitiateVote(mapChange, hndl);
}
return Plugin_Stop;
}
@ -916,6 +919,7 @@ public void CheckWinLimit(int winner_score)
if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE)
{
SetupWarningTimer(WarningType_Vote, MapChange_MapEnd);
//LogMessage("Mapchooser_extended_avg SetupWarningTimer call 4");
}
}
}
@ -939,6 +943,7 @@ public void CheckMaxRounds(int roundcount)
if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE)
{
SetupWarningTimer(WarningType_Vote, MapChange_MapEnd);
//LogMessage("Mapchooser_extended_avg SetupWarningTimer call 5");
}
}
}
@ -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;
@ -975,6 +981,7 @@ public Action Command_Mapvote(int client, int args)
ShowActivity2(client, "[MCE] ", "%t", "Initiated Vote Map");
SetupWarningTimer(WarningType_Vote, MapChange_MapEnd, INVALID_HANDLE, true);
//LogMessage("Mapchooser_extended_avg SetupWarningTimer call 7");
return Plugin_Handled;
}
@ -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<MapChange>(g_ChangeTime), mapList);
return;
}
@ -1506,11 +1517,14 @@ 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<MapChange>(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);
}
@ -1616,11 +1630,11 @@ public int Handler_MapVoteMenu(Handle menu, MenuAction action, int param1, int p
SetNextMap(map);
g_MapVoteCompleted = true;
}
g_WaitingForVote = false;
g_HasVoteStarted = false;
g_RunoffCount = 0;
}
}
return 0;
}
@ -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;
}
@ -2071,7 +2086,7 @@ stock void SetupWarningTimer(WarningType type, MapChange when=MapChange_MapEnd,
forwardVote = g_MapVoteWarningStartForward;
cvarTime = g_Cvar_WarningTime;
strcopy(translationKey, sizeof(translationKey), "Vote Warning");
//LogMessage("Mapchooser_extended_avg WarningType_Vote");
}
case WarningType_Revote:
@ -2079,7 +2094,7 @@ stock void SetupWarningTimer(WarningType type, MapChange when=MapChange_MapEnd,
forwardVote = g_MapVoteRunoffStartForward;
cvarTime = g_Cvar_RunOffWarningTime;
strcopy(translationKey, sizeof(translationKey), "Revote Warning");
//LogMessage("Mapchooser_extended_avg WarningType_Revote. cvarTime: %i", GetConVarInt(cvarTime));
}
}