From 027febcd84e1edccc2cee57ebf442f62ff17023f Mon Sep 17 00:00:00 2001 From: qawery-just-sad <53490397+qawery-just-sad@users.noreply.github.com> Date: Tue, 7 Jul 2020 14:49:50 +0200 Subject: [PATCH] v1.3 -Vote Extend is now here -RTV doesn't need db access -Check what db if not mysql then fuck it --- addons/sourcemod/scripting/mapchooser.sp | 17 +- addons/sourcemod/scripting/nominations.sp | 19 +- addons/sourcemod/scripting/rockthevote.sp | 87 +-------- addons/sourcemod/scripting/voteextend.sp | 206 ++++++++++++++++++++++ 4 files changed, 240 insertions(+), 89 deletions(-) create mode 100644 addons/sourcemod/scripting/voteextend.sp diff --git a/addons/sourcemod/scripting/mapchooser.sp b/addons/sourcemod/scripting/mapchooser.sp index ae42bbc..ca03cab 100644 --- a/addons/sourcemod/scripting/mapchooser.sp +++ b/addons/sourcemod/scripting/mapchooser.sp @@ -44,8 +44,8 @@ public Plugin myinfo = name = "SurfTimer MapChooser", author = "AlliedModders LLC & SurfTimer Contributors", description = "Automated Map Voting", - version = "1.2", - url = "http://www.sourcemod.net/" + version = "1.3", + url = "https://github.com/qawery-just-sad/surftimer-mapchooser" }; /* Valve ConVars */ @@ -1246,6 +1246,19 @@ public void db_setupDatabase() if (g_hDb == null) SetFailState("[Mapchooser] Unable to connect to database (%s)", szError); + char szIdent[8]; + SQL_ReadDriver(g_hDb, szIdent, 8); + + if (strcmp(szIdent, "mysql", false) == 0) + { + // https://github.com/nikooo777/ckSurf/pull/58 - eeeee that is an issue in a half || Also https://discordapp.com/channels/366959507764674560/379572504542445568/729723679541559336 + SQL_FastQuery(g_hDb, "SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"); + } + else + { + SetFailState("[Mapchooser] Invalid database type"); + return; + } return; } diff --git a/addons/sourcemod/scripting/nominations.sp b/addons/sourcemod/scripting/nominations.sp index 4e62057..1d2b1d5 100644 --- a/addons/sourcemod/scripting/nominations.sp +++ b/addons/sourcemod/scripting/nominations.sp @@ -41,8 +41,8 @@ public Plugin myinfo = name = "SurfTimer Nominations", author = "AlliedModders LLC & SurfTimer Contributors", description = "Provides Map Nominations", - version = "1.2", - url = "http://www.sourcemod.net/" + version = "1.3", + url = "https://github.com/qawery-just-sad/surftimer-mapchooser" }; ConVar g_Cvar_ExcludeOld; @@ -455,7 +455,20 @@ public void db_setupDatabase() if (g_hDb == null) SetFailState("[Nominations] Unable to connect to database (%s)", szError); - + + char szIdent[8]; + SQL_ReadDriver(g_hDb, szIdent, 8); + + if (strcmp(szIdent, "mysql", false) == 0) + { + // https://github.com/nikooo777/ckSurf/pull/58 - eeeee that is an issue in a half || Also https://discordapp.com/channels/366959507764674560/379572504542445568/729723679541559336 + SQL_FastQuery(g_hDb, "SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"); + } + else + { + SetFailState("[Nominations] Invalid database type"); + return; + } return; } diff --git a/addons/sourcemod/scripting/rockthevote.sp b/addons/sourcemod/scripting/rockthevote.sp index de7bace..512adc6 100644 --- a/addons/sourcemod/scripting/rockthevote.sp +++ b/addons/sourcemod/scripting/rockthevote.sp @@ -43,8 +43,8 @@ public Plugin myinfo = name = "SurfTimer Rock The Vote", author = "AlliedModders LLC & SurfTimer Contributors", description = "Provides RTV Map Voting", - version = "1.2", - url = "http://www.sourcemod.net/" + version = "1.3", + url = "https://github.com/qawery-just-sad/surftimer-mapchooser" }; ConVar g_Cvar_Needed; @@ -63,18 +63,13 @@ int g_VotesNeeded = 0; // Necessary votes before map vote begins. (voters * pe bool g_Voted[MAXPLAYERS+1] = {false, ...}; bool g_InChange = false; -bool g_bCanVote[MAXPLAYERS + 1]; -// SQL Connection -Handle g_hDb = null; -#define PERCENT 0x25 public void OnPluginStart() { LoadTranslations("common.phrases"); LoadTranslations("rockthevote.phrases"); - db_setupDatabase(); g_Cvar_Needed = CreateConVar("sm_rtv_needed", "0.60", "Percentage of players needed to rockthevote (Def 60%)", 0, true, 0.05, true, 1.0); g_Cvar_MinPlayers = CreateConVar("sm_rtv_minplayers", "0", "Number of players required before RTV will be enabled.", 0, true, 0.0, true, float(MAXPLAYERS)); @@ -119,15 +114,6 @@ public void OnClientPostAdminCheck(int client) { if (!IsFakeClient(client)) { - g_bCanVote[client] = false; - - if (GetConVarInt(g_Cvar_PointsRequirement) > 0 || GetConVarInt(g_Cvar_RankRequirement) > 0) - { - db_selectPlayerData(client); - return; - } - - g_bCanVote[client] = true; g_Voters++; g_VotesNeeded = RoundToCeil(float(g_Voters) * g_Cvar_Needed.FloatValue); } @@ -141,7 +127,7 @@ public void OnClientDisconnect(int client) g_Voted[client] = false; } - if (!IsFakeClient(client) && g_bCanVote[client]) + if (!IsFakeClient(client)) { g_Voters--; g_VotesNeeded = RoundToCeil(float(g_Voters) * g_Cvar_Needed.FloatValue); @@ -321,71 +307,4 @@ stock bool IsValidClient(int client) if (client >= 1 && client <= MaxClients && IsValidEntity(client) && IsClientConnected(client) && IsClientInGame(client)) return true; return false; -} - -public void db_setupDatabase() -{ - char szError[255]; - g_hDb = SQL_Connect("surftimer", false, szError, 255); - - if (g_hDb == null) - SetFailState("[Nominations] Unable to connect to database (%s)", szError); - - return; -} - -public void db_selectPlayerData(int client) -{ - if (!IsValidClient(client) || IsFakeClient(client)) - return; - - char szSteamID[32], szQuery[256]; - GetClientAuthId(client, AuthId_Steam2, szSteamID, sizeof(szSteamID), true); - - Format(szQuery, sizeof(szQuery), "SELECT name, points FROM ck_playerrank WHERE style = 0 AND points >= (SELECT points FROM ck_playerrank WHERE steamid = '%s' AND style = 0) ORDER BY points;", szSteamID); - SQL_TQuery(g_hDb, db_selectPlayersDataCallback, szQuery, client, DBPrio_Low); -} - -public void db_selectPlayersDataCallback(Handle owner, Handle hndl, const char[] error, any client) -{ - if (hndl == null) - { - LogError("[RockTheVote] SQL Error (db_selectPlayersDataCallback): %s", error); - return; - } - - int rank, points; - if (SQL_HasResultSet(hndl) && SQL_FetchRow(hndl)) - { - rank = SQL_GetRowCount(hndl); - points = SQL_FetchInt(hndl, 0); - } - else - rank = 99999; - - bool bNewVoter = true; - if (GetConVarInt(g_Cvar_PointsRequirement) > 0) - { - if (points < GetConVarInt(g_Cvar_PointsRequirement)) - { - bNewVoter = false; - g_bCanVote[client] = false; - } - } - - if (GetConVarInt(g_Cvar_RankRequirement) > 0) - { - if (rank > GetConVarInt(g_Cvar_RankRequirement)) - { - bNewVoter = false; - g_bCanVote[client] = false; - } - } - - if (bNewVoter) - { - g_bCanVote[client] = true; - g_Voters++; - g_VotesNeeded = RoundToCeil(float(g_Voters) * g_Cvar_Needed.FloatValue); - } } \ No newline at end of file diff --git a/addons/sourcemod/scripting/voteextend.sp b/addons/sourcemod/scripting/voteextend.sp new file mode 100644 index 0000000..9438dbf --- /dev/null +++ b/addons/sourcemod/scripting/voteextend.sp @@ -0,0 +1,206 @@ +/* + The credit goes to User LESAC4 - https://pastebin.com/u/lesac4 + Original Code - https://pastebin.com/6uWxRxkX + Found by - https://github.com/surftimer/Surftimer-olokos/issues/31#issuecomment-617615860 + Modified by SurfTimer Contributors +*/ + +#include +#include + +#pragma newdecls required +#pragma semicolon 1 + +ConVar g_hVoteExtendTime; // Extend time CVar +ConVar g_hMaxVoteExtends; // Extend max count CVar +ConVar g_fInitialVoteDelay; +ConVar g_bOneVotePerPlayer; +ConVar g_VipFeature; +ConVar g_fInterval; + +bool g_bVEAllowed = false; +int g_VoteExtends = 0; // How many extends have happened in current map +char g_szSteamID[MAXPLAYERS + 1][32]; // Client's steamID +char g_szUsedVoteExtend[MAXPLAYERS+1][32]; // SteamID's which triggered extend vote + +public Plugin myinfo = +{ + name = "SurfTimer Vote Extend", + author = "SurfTimer Contributors", + description = "Allows players to vote extend the map", + version = "1.3", + url = "https://github.com/qawery-just-sad/surftimer-mapchooser" +}; + +public void OnPluginStart() +{ + RegConsoleCmd("sm_ve", Command_VoteExtend, "SurfTimer | Vote to extend the map"); + RegConsoleCmd("sm_voteextend", Command_VoteExtend, "SurfTimer | Vote to extend the map"); + RegConsoleCmd("sm_extend", Command_VoteExtend, "SurfTimer | Vote to extend the map"); + + g_hMaxVoteExtends = CreateConVar("ck_max_vote_extends", "2", "The max number of VIP vote extends", FCVAR_NOTIFY, true, 0.0); + g_hVoteExtendTime = CreateConVar("ck_vote_extend_time", "10.0", "The time in minutes that is added to the remaining map time if a vote extend is successful.", FCVAR_NOTIFY, true, 0.0); + g_fInitialVoteDelay = CreateConVar("ck_ve_initialdelay", "300", "The time in seconds when first vote can take place", FCVAR_NOTIFY, true, 0.0); + g_fInterval = CreateConVar("ck_ve_interval", "240.0", "Time in seconds after a failed VE before another can be held", 0, true, 0.00); + g_bOneVotePerPlayer = CreateConVar("ck_ve_onevote", "0", "Can vote be started again from the same person. 0 - Yes, 1 - No.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + g_VipFeature = CreateConVar("ck_ve_vip", "1", "Is command only for vips? 1-Yes, 0-No.", FCVAR_NOTIFY, true, 0.0, true, 1.0); + + AutoExecConfig(true, "vote-extend"); +} + +public void OnMapEnd() +{ + g_bVEAllowed = false; + g_VoteExtends = 0; + + for (int i = 0; i < MAXPLAYERS+1; i++) + g_szUsedVoteExtend[i][0] = '\0'; +} + +public void OnClientPostAdminCheck(int client) +{ + GetClientAuthId(client, AuthId_Steam2, g_szSteamID[client], MAX_NAME_LENGTH, true); +} + +public void OnConfigsExecuted() +{ + CreateTimer(g_fInitialVoteDelay.FloatValue, Timer_Delay, _, TIMER_FLAG_NO_MAPCHANGE); +} + +public Action Timer_Delay(Handle timer) +{ + g_bVEAllowed = true; +} + +public Action Command_VoteExtend(int client, int args) +{ + if(!IsValidClient(client)) + return Plugin_Handled; + + if(g_VipFeature) + { + if(!surftimer_IsClientVip(client)) + { + ReplyToCommand(client, "SurfTimer | This is a VIP feature."); + return Plugin_Handled; + } + } + + if (IsVoteInProgress()) + { + ReplyToCommand(client, "SurfTimer | Please wait until the current vote has finished."); + return Plugin_Handled; + } + + if (g_VoteExtends >= GetConVarInt(g_hMaxVoteExtends)) + { + ReplyToCommand(client, "SurfTimer | There have been too many extends this map."); + return Plugin_Handled; + } + + if (!g_bVEAllowed) + { + ReplyToCommand(client, "SurfTimer | Vote Extend is not allowed yet."); + return Plugin_Handled; + } + + int timeleft; + GetMapTimeLeft(timeleft); + + // Here we go through and make sure this user has not already voted. This persists throughout map. + if (GetConVarBool(g_bOneVotePerPlayer)) + { + for (int i = 0; i < g_VoteExtends; i++) + { + if (StrEqual(g_szUsedVoteExtend[i], g_szSteamID[client], false)) + { + ReplyToCommand(client, "SurfTimer | You have already used your vote to extend this map."); + return Plugin_Handled; + } + } + } + + StartVoteExtend(client); + return Plugin_Handled; +} + + +public void StartVoteExtend(int client) +{ + char szPlayerName[MAX_NAME_LENGTH]; + GetClientName(client, szPlayerName, MAX_NAME_LENGTH); + PrintToChatAll("[SurfTimer] Vote to Extend started by %s", szPlayerName); + + g_szUsedVoteExtend[g_VoteExtends] = g_szSteamID[client]; // Add the user's steam ID to the list + g_VoteExtends++; // Increment the total number of vote extends so far + + Menu voteExtend = CreateMenu(H_VoteExtend); + SetVoteResultCallback(voteExtend, H_VoteExtendCallback); + char szMenuTitle[128]; + + char buffer[8]; + IntToString(RoundToFloor(GetConVarFloat(g_hVoteExtendTime)), buffer, sizeof(buffer)); + + Format(szMenuTitle, sizeof(szMenuTitle), "Extend map for %s minutes?", buffer); + SetMenuTitle(voteExtend, szMenuTitle); + + AddMenuItem(voteExtend, "", "Yes"); + AddMenuItem(voteExtend, "", "No"); + SetMenuExitButton(voteExtend, false); + VoteMenuToAll(voteExtend, 20); +} + +public void H_VoteExtendCallback(Menu menu, int num_votes, int num_clients, const int[][] client_info, int num_items, const int[][] item_info) +{ + int votesYes = 0; + int votesNo = 0; + + if (item_info[0][VOTEINFO_ITEM_INDEX] == 0) { // If the winner is Yes + votesYes = item_info[0][VOTEINFO_ITEM_VOTES]; + if (num_items > 1) { + votesNo = item_info[1][VOTEINFO_ITEM_VOTES]; + } + } + else { // If the winner is No + votesNo = item_info[0][VOTEINFO_ITEM_VOTES]; + if (num_items > 1) { + votesYes = item_info[1][VOTEINFO_ITEM_VOTES]; + } + } + + if (votesYes > votesNo) // A tie is a failure + { + PrintToChatAll("[SurfTimer] Vote to Extend succeeded - Votes Yes: %i | Votes No: %i", votesYes, votesNo); + ExtendMapTimeLimit(RoundToFloor(GetConVarFloat(g_hVoteExtendTime)*60)); + g_bVEAllowed = false; + CreateTimer(g_fInterval.FloatValue, Timer_Delay, _, TIMER_FLAG_NO_MAPCHANGE); + } + else + { + PrintToChatAll("[SurfTimer] Vote to Extend failed - Votes Yes: %i | Votes No: %i", votesYes, votesNo); + g_bVEAllowed = false; + CreateTimer(g_fInterval.FloatValue, Timer_Delay, _, TIMER_FLAG_NO_MAPCHANGE); + } +} + +public int H_VoteExtend(Menu tMenu, MenuAction action, int client, int item) +{ + if (action == MenuAction_End) + { + CloseHandle(tMenu); + } +} + +stock bool IsValidClient(int client) +{ + if (client <= 0) + return false; + + if (client > MaxClients) + return false; + + if ( !IsClientConnected(client) ) + return false; + + return IsClientInGame(client); +} \ No newline at end of file