Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions addons/sourcemod/scripting/include/nativevotes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ enum NativeVotesOverride
NativeVotesOverride_AutoBalance,
NativeVotesOverride_ClassLimits,
NativeVotesOverride_Extend,
NativeVotesOverride_Count,
}

methodmap NativeVote < KeyValues
Expand Down Expand Up @@ -1282,7 +1283,8 @@ stock void NativeVotes_DisplayRawFailToAll(NativeVotesFailType reason=NativeVote
players[total++] = i;
}

return NativeVotes_DisplayRawFail(players, total, reason, team);
NativeVotes_DisplayRawFail(players, total, reason, team);
return;
}

/**
Expand All @@ -1301,7 +1303,9 @@ stock void NativeVotes_DisplayRawFailToOne(int client, NativeVotesFailType reaso

players[0] = client;

return NativeVotes_DisplayRawFail(players, 1, reason, team);

NativeVotes_DisplayRawFail(players, 1, reason, team);
return;
}

/**
Expand Down
127 changes: 72 additions & 55 deletions addons/sourcemod/scripting/nativevotes.sp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ EngineVersion g_EngineVersion = Engine_Unknown;

#include "nativevotes/data-keyvalues.sp"

#define VERSION "1.1.0 beta 8"
#define VERSION "1.1.1fix"

#define LOGTAG "NV"

Expand All @@ -72,7 +72,7 @@ EngineVersion g_EngineVersion = Engine_Unknown;

#define MAX_CALLVOTE_SIZE 128

//#define LOG
#define LOG

//----------------------------------------------------------------------------
// Global Variables
Expand Down Expand Up @@ -112,6 +112,8 @@ int g_ClientVotes[MAXPLAYERS+1];
bool g_bRevoting[MAXPLAYERS+1];
char g_LeaderList[1024];

ConVar sv_vote_holder_may_vote_no;

// Map list stuffs

#define STRINGTABLE_NAME "ServerMapCycle"
Expand All @@ -124,19 +126,19 @@ StringMap g_MapOverrides;
bool g_OverridesSet;
bool g_OverrideNextCallVote[MAXPLAYERS + 1];

enum CallVoteForwards
enum struct CallVoteForwards
{
Handle:CallVote_Forward,
Handle:CallVote_Vis,
Handle CallVote_Forward;
Handle CallVote_Vis;
}

enum CallVoteListData
enum struct CallVoteListData
{
NativeVotesOverride:CallVoteList_VoteType,
bool:CallVoteList_VoteEnabled,
NativeVotesOverride CallVoteList_VoteType;
bool CallVoteList_VoteEnabled;
}

int g_CallVotes[NativeVotesOverride][CallVoteForwards];
CallVoteForwards g_CallVotes[NativeVotesOverride_Count];

#include "nativevotes/game.sp"

Expand Down Expand Up @@ -262,6 +264,8 @@ public void OnPluginStart()

AddCommandListener(Command_Vote, "vote"); // All games, command listeners aren't case sensitive

sv_vote_holder_may_vote_no = FindConVar("sv_vote_holder_may_vote_no");

// The new version of the CallVote system is TF2 only
if (Game_AreVoteCommandsSupported())
{
Expand All @@ -271,8 +275,8 @@ public void OnPluginStart()
// As of 2015-09-28, there are 10 votes for a total of 20 private forwards created here.
for (int i = 1; i < sizeof(g_CallVotes); i++)
{
g_CallVotes[i][CallVote_Forward] = CreateForward(ET_Hook, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell);
g_CallVotes[i][CallVote_Vis] = CreateForward(ET_Hook, Param_Cell, Param_Cell);
g_CallVotes[i].CallVote_Forward = CreateForward(ET_Hook, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell);
g_CallVotes[i].CallVote_Vis = CreateForward(ET_Hook, Param_Cell, Param_Cell);
}

g_OverrideMaps = CreateGlobalForward("NativeVotes_OverrideMaps", ET_Hook, Param_Cell);
Expand Down Expand Up @@ -416,40 +420,40 @@ public Action Command_CallVote(int client, const char[] command, int argc)
return Plugin_Handled;
}

ArrayList hVoteTypes = new ArrayList(view_as<int>(CallVoteListData)); // Stores arrays of CallVoteListData
ArrayList hVoteTypes = new ArrayList(sizeof(CallVoteListData)); // Stores arrays of CallVoteListData

Game_AddDefaultVotes(hVoteTypes);

// Add our overridden votes to the system
bool overridesPresent = false;
for (int i = 1; i < sizeof(g_CallVotes); i++)
{
if (GetForwardFunctionCount(g_CallVotes[i][CallVote_Forward]) > 0)
if (GetForwardFunctionCount(g_CallVotes[i].CallVote_Forward) > 0)
{
#if defined LOG
LogMessage("Found overrides for vote type: %d", i);
#endif
overridesPresent = true;
int voteType[CallVoteListData];
CallVoteListData voteType;

int pos = FindVoteInArray(hVoteTypes, view_as<NativeVotesOverride>(i));
if (pos > -1)
{
hVoteTypes.GetArray(pos, voteType[0], sizeof(voteType));
voteType[CallVoteList_VoteEnabled] = true;
hVoteTypes.GetArray(pos, voteType, sizeof(CallVoteListData));
voteType.CallVoteList_VoteEnabled = true;
#if defined LOG
LogMessage("Forcing vote type to visible: %d", i);
#endif
hVoteTypes.SetArray(pos, voteType[0], sizeof(voteType));
hVoteTypes.SetArray(pos, voteType);
}
else
{
#if defined LOG
LogMessage("Creating override for vote type: %d", i);
#endif
voteType[CallVoteList_VoteType] = view_as<NativeVotesOverride>(i);
voteType[CallVoteList_VoteEnabled] = true;
hVoteTypes.PushArray(voteType[0], sizeof(voteType));
voteType.CallVoteList_VoteType = view_as<NativeVotesOverride>(i);
voteType.CallVoteList_VoteEnabled = true;
hVoteTypes.PushArray(voteType);
}
}
}
Expand Down Expand Up @@ -484,7 +488,7 @@ public Action Command_CallVote(int client, const char[] command, int argc)

char argument[PLATFORM_MAX_PATH];

if (GetForwardFunctionCount(g_CallVotes[overrideType][CallVote_Forward]) == 0)
if (GetForwardFunctionCount(g_CallVotes[overrideType].CallVote_Forward) == 0)
{

if (g_MapOverrides != null &&
Expand All @@ -511,7 +515,7 @@ public Action Command_CallVote(int client, const char[] command, int argc)
#if defined LOG
LogMessage("Calling visForward for %s", voteCommand);
#endif
Call_StartForward(g_CallVotes[overrideType][CallVote_Vis]);
Call_StartForward(g_CallVotes[overrideType].CallVote_Vis);
Call_PushCell(client);
Call_PushCell(overrideType);
Call_Finish(result);
Expand Down Expand Up @@ -570,7 +574,7 @@ public Action Command_CallVote(int client, const char[] command, int argc)
LogMessage("Calling callVoteForward for %s", voteCommand);
#endif

Call_StartForward(g_CallVotes[overrideType][CallVote_Forward]);
Call_StartForward(g_CallVotes[overrideType].CallVote_Forward);
Call_PushCell(client);
Call_PushCell(overrideType);
Call_PushString(argument);
Expand All @@ -590,10 +594,10 @@ stock int FindVoteInArray(ArrayList myArray, NativeVotesOverride value)
int size = myArray.Length;
for (int i = 0; i < size; i++)
{
int voteData[CallVoteListData];
myArray.GetArray(i, voteData[0]);
CallVoteListData voteData;
myArray.GetArray(i, voteData, sizeof(CallVoteListData));

if (voteData[CallVoteList_VoteType] == value)
if (voteData.CallVoteList_VoteType == value)
{
return i;
}
Expand All @@ -607,9 +611,9 @@ stock bool IsVoteEnabled(ArrayList myArray, NativeVotesOverride value)
int pos = FindVoteInArray(myArray, value);
if (pos > -1)
{
int voteType[CallVoteListData];
myArray.GetArray(pos, voteType[0], sizeof(voteType));
if (voteType[CallVoteList_VoteEnabled])
CallVoteListData voteType;
myArray.GetArray(pos, voteType, sizeof(CallVoteListData));
if (voteType.CallVoteList_VoteEnabled)
return true;
}
return false;
Expand Down Expand Up @@ -655,33 +659,36 @@ public void OnMapEnd()

public Action Command_Vote(int client, const char[] command, int argc)
{
#if defined LOG
char voteString[128];
GetCmdArgString(voteString, sizeof(voteString));
LogMessage("Client %N ran a vote command: %s", client, voteString);
#endif

// If we're not running a vote, return the vote control back to the server
if (!Internal_IsVoteInProgress() || g_ClientVotes[client] != VOTE_PENDING)
{
return Plugin_Continue;
}

char option[32];
GetCmdArg(1, option, sizeof(option));
char option[64];
GetCmdArgString(option, sizeof(option));

int item = Game_ParseVote(option);

bool cancel;

if (item == NATIVEVOTES_VOTE_INVALID)
// Make sure we don't go out of bounds on the vote
if (item == NATIVEVOTES_VOTE_INVALID || item > g_Items)
{
cancel = true;
return Plugin_Handled;
}

bool cancel;

if (Data_GetFlags(g_hCurVote) & MENUFLAG_BUTTON_NOVOTE && item == 0)
{
cancel = true;
}

/*
* If they choose no vote or the vote is invalid (typed command), then
* treat it as no vote and adjust the numbers.
*/
if (cancel)
{
OnCancel(g_hCurVote, client, MenuCancel_Exit);
Expand Down Expand Up @@ -709,6 +716,8 @@ void OnVoteSelect(NativeVote vote, int client, int item)
g_hVotes.Set(item, g_hVotes.Get(item) + 1);
g_NumVotes++;

PrintToChatAll("OnVoteSelect hit");
Game_UpdateClientCount(g_TotalClients);
Game_UpdateVoteCounts(g_hVotes, g_TotalClients);

if (g_Cvar_VoteChat.BoolValue || g_Cvar_VoteConsole.BoolValue || g_Cvar_VoteClientConsole.BoolValue)
Expand Down Expand Up @@ -821,7 +830,7 @@ Action DoAction(NativeVote vote, MenuAction action, int param1, int param2, Acti
{
Action res = def_res;

Handle handler = Data_GetHandler(vote);
Handle handler = CloneHandle(Data_GetHandler(vote));
#if defined LOG
LogMessage("Calling Menu forward for vote: %d, handler: %d, action: %d, param1: %d, param2: %d", vote, handler, action, param1, param2);
#endif
Expand All @@ -831,6 +840,7 @@ Action DoAction(NativeVote vote, MenuAction action, int param1, int param2, Acti
Call_PushCell(param1);
Call_PushCell(param2);
Call_Finish(res);
delete handler;
return res;
}

Expand Down Expand Up @@ -1118,6 +1128,10 @@ void EndVoting()
NativeVote vote = g_hCurVote;
Internal_Reset();

#if defined LOG
LogMessage("Voting done");
#endif

/* Send vote info */
OnVoteResults(vote, votes, num_votes, num_items, client_list, num_clients);
OnEnd(vote, MenuEnd_VotingDone);
Expand Down Expand Up @@ -1279,7 +1293,7 @@ void StartVoting()
{
int initiator = Data_GetInitiator(g_hCurVote);

if (initiator > 0 && initiator <= MaxClients && IsClientConnected(initiator) && Internal_IsClientInVotePool(initiator))
if (initiator > 0 && initiator <= MaxClients && IsClientConnected(initiator) && Internal_IsClientInVotePool(initiator) && !sv_vote_holder_may_vote_no)
{
Game_VoteYes(initiator);
}
Expand Down Expand Up @@ -1486,22 +1500,22 @@ void PerformVisChecks(int client, ArrayList hVoteTypes)
// Iterate backwards so we can safely remove items
for (int i = hVoteTypes.Length - 1; i >= 0; i--)
{
int voteData[CallVoteListData];
hVoteTypes.GetArray(i, voteData[0]);
CallVoteListData voteData;
hVoteTypes.GetArray(i, voteData, sizeof(CallVoteListData));

Action hide = Plugin_Continue;

#if defined LOG
LogMessage("Checking visibility forward for %d: %d", voteData[CallVoteList_VoteType], g_CallVotes[voteData[CallVoteList_VoteType]][CallVote_Vis]);
//LogMessage("Checking visibility forward for %d: %d", voteData.CallVoteList_VoteType., g_CallVotes[voteData.CallVoteList_VoteType].CallVote_Vis);
#endif
Call_StartForward(g_CallVotes[voteData[CallVoteList_VoteType]][CallVote_Vis]);
Call_StartForward(g_CallVotes[voteData.CallVoteList_VoteType].CallVote_Vis);
Call_PushCell(client);
Call_PushCell(voteData[CallVoteList_VoteType]);
Call_PushCell(voteData.CallVoteList_VoteType);
Call_Finish(hide);
if (hide >= Plugin_Handled)
{
#if defined LOG
LogMessage("Hiding vote type %d", voteData[CallVoteList_VoteType]);
LogMessage("Hiding vote type %d", voteData.CallVoteList_VoteType);
#endif
if (Game_AreDisabledIssuesHidden())
{
Expand All @@ -1511,7 +1525,7 @@ void PerformVisChecks(int client, ArrayList hVoteTypes)
else
{
// Arrays are pass by ref, so this should update the one inside the ArrayList
voteData[CallVoteList_VoteEnabled] = false;
voteData.CallVoteList_VoteEnabled = false;
}
}
}
Expand Down Expand Up @@ -2005,7 +2019,10 @@ public int Native_RedrawClientVote(Handle plugin, int numParams)

if (!Internal_IsVoteInProgress())
{
ThrowNativeError(SP_ERROR_NATIVE, "No vote is in progress");
// When revoting in TF2, NativeVotes_IsVoteInProgress always gets skipped because of Game_IsVoteInProgress()
// TF2s vote controller will stay alive a few seconds after the vote is complete
// If one tries to revote right as a vote completes, it will throw an error
LogError("No vote is in progress");
return false;
}

Expand Down Expand Up @@ -2412,7 +2429,7 @@ public int Native_RegisterVoteCommand(Handle plugin, int numParams)

// This tosses an error so use the simplified version
// if (view_as<int>(overrideType) > sizeof(g_CallVotes))
if (overrideType > NativeVotesOverride)
if (overrideType > NativeVotesOverride_Count)
{
ThrowNativeError(SP_ERROR_NATIVE, "Override Type %d is not supported by this version of NativeVotes", overrideType);
return;
Expand All @@ -2424,11 +2441,11 @@ public int Native_RegisterVoteCommand(Handle plugin, int numParams)
return;
}

AddToForward(g_CallVotes[overrideType][CallVote_Forward], plugin, callVoteHandler);
AddToForward(g_CallVotes[overrideType].CallVote_Forward, plugin, callVoteHandler);

if (visHandler != INVALID_FUNCTION)
{
AddToForward(g_CallVotes[overrideType][CallVote_Vis], plugin, visHandler);
AddToForward(g_CallVotes[overrideType].CallVote_Vis, plugin, visHandler);
}
}

Expand All @@ -2439,7 +2456,7 @@ public int Native_UnregisterVoteCommand(Handle plugin, int numParams)
Function callVoteHandler = GetNativeFunction(2);
Function visHandler = GetNativeFunction(3);

if (overrideType > NativeVotesOverride)
if (overrideType > NativeVotesOverride_Count)
{
ThrowNativeError(SP_ERROR_NATIVE, "Override Type %d is not supported by this version of NativeVotes", overrideType);
return;
Expand All @@ -2451,11 +2468,11 @@ public int Native_UnregisterVoteCommand(Handle plugin, int numParams)
return;
}

RemoveFromForward(g_CallVotes[overrideType][CallVote_Forward], plugin, callVoteHandler);
RemoveFromForward(g_CallVotes[overrideType].CallVote_Forward, plugin, callVoteHandler);

if (visHandler != INVALID_FUNCTION)
{
RemoveFromForward(g_CallVotes[overrideType][CallVote_Vis], plugin, visHandler);
RemoveFromForward(g_CallVotes[overrideType].CallVote_Vis, plugin, visHandler);
}
}

Expand Down
Loading