Skip to content

Commit

Permalink
Fixes rtv issues with rank/point requirement (#15)
Browse files Browse the repository at this point in the history
-added option for vips to bypass rank/points requirement
-players outside rank/points requirement are not counted towards votes needed
-added one player bypass
-version++
  • Loading branch information
qawery-just-sad authored Apr 12, 2021
1 parent 94cc6bf commit b3683fb
Show file tree
Hide file tree
Showing 5 changed files with 405 additions and 57 deletions.
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This is a edit of the default SourceMod mapchooser and nomination plugin, it pro

* Sourcemod 1.8+
* MySQL 5.7 / 8+ / MariaDB supported
* SurfTimer from [Olokos](https://github.com/surftimer/Surftimer-olokos)
* [SurfTimer](https://github.com/surftimer/Surftimer-Official)
<br><sup>I mean it works with any fork as long as the layout of ck_maptier and ck_zones are the same as in [Fluffys](https://github.com/fluffyst/Surftimer) archived repo :wink:</sup>

**Compilation Requirements (Includes):**
Expand All @@ -22,18 +22,6 @@ This is a edit of the default SourceMod mapchooser and nomination plugin, it pro

* Get latest plugin files from **[Release Page](https://github.com/qawery-just-sad/surftimer-mapchooser/releases)**
* Copy files over to `csgo/addons/sourcemod/plugins`
* Make sure that `csgo/addons/sourcemod/configs/databases.cfg` points to the surftimer database (You have to use the same database as the SurfTimer)
```
"surftimer"
{
"driver" "mysql"
"host" "localhost" // The ip address to the database server
"database" "surftimerdb" // The database name that surftimer uses
"user" "dbuser" // The user name that has access to that database
"pass" "dbuserpassword" // The password for user specified above
"port" "3306" // The port to the database server
}
```
* Set `sm_server_tier` in `csgo/cfg/sourcemod/mapchooser.cfg` to the tier of maps you want appearing the nominate list. Example, for a tier 1-3 server, set it to `sm_server_tier 1.3`, a tier 1 only server would be `sm_server_tier 1.0` and if you want all tiers `sm_server_tier 0`

<br><sup>This plugin is broken, trust me, it only works on my server :smile:</sup>
<br><sup>This plugin is broken, trust me, it only works on my server 😝</sup>
200 changes: 185 additions & 15 deletions addons/sourcemod/scripting/mapchooser.sp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public Plugin myinfo =
name = "SurfTimer MapChooser",
author = "AlliedModders LLC & SurfTimer Contributors",
description = "Automated Map Voting",
version = "1.8",
version = "1.8.3",
url = "https://github.com/qawery-just-sad/surftimer-mapchooser"
};

Expand Down Expand Up @@ -75,6 +75,8 @@ ConVar g_Cvar_RunOffPercent;
ConVar g_Cvar_ServerTier;
ConVar g_Cvar_PointsRequirement;
ConVar g_Cvar_RankRequirement;
ConVar g_Cvar_VIPOverwriteRequirements;
ConVar g_PlayerOne;

// Chat prefix
char g_szChatPrefix[256];
Expand Down Expand Up @@ -103,6 +105,10 @@ bool g_ChangeMapAtRoundEnd;
bool g_ChangeMapInProgress;
// int g_mapFileSerial = -1;

bool g_PointsREQ[MAXPLAYERS+1] = {false, ...};
bool g_RankREQ[MAXPLAYERS+1] = {false, ...};
int g_Voters;

MapChange g_ChangeTime;

Handle g_NominationsResetForward = null;
Expand All @@ -116,6 +122,8 @@ Handle g_hDb = null;
char sql_SelectMapListSpecific[] = "SELECT ck_zones.mapname, tier, count(ck_zones.mapname), bonus FROM `ck_zones` INNER JOIN ck_maptier on ck_zones.mapname = ck_maptier.mapname LEFT JOIN ( SELECT mapname as map_2, MAX(ck_zones.zonegroup) as bonus FROM ck_zones GROUP BY mapname ) as a on ck_zones.mapname = a.map_2 WHERE (zonegroup = 0 AND zonetype = 1 or zonetype = 3) AND tier = %s GROUP BY mapname, tier, bonus ORDER BY mapname ASC";
char sql_SelectMapListRange[] = "SELECT ck_zones.mapname, tier, count(ck_zones.mapname), bonus FROM `ck_zones` INNER JOIN ck_maptier on ck_zones.mapname = ck_maptier.mapname LEFT JOIN ( SELECT mapname as map_2, MAX(ck_zones.zonegroup) as bonus FROM ck_zones GROUP BY mapname ) as a on ck_zones.mapname = a.map_2 WHERE (zonegroup = 0 AND zonetype = 1 or zonetype = 3) AND tier >= %s AND tier <= %s GROUP BY mapname, tier, bonus ORDER BY mapname ASC";
char sql_SelectMapList[] = "SELECT ck_zones.mapname, tier, count(ck_zones.mapname), bonus FROM `ck_zones` INNER JOIN ck_maptier on ck_zones.mapname = ck_maptier.mapname LEFT JOIN ( SELECT mapname as map_2, MAX(ck_zones.zonegroup) as bonus FROM ck_zones GROUP BY mapname ) as a on ck_zones.mapname = a.map_2 WHERE (zonegroup = 0 AND zonetype = 1 or zonetype = 3) GROUP BY mapname, tier, bonus ORDER BY mapname ASC";
char sql_SelectRank[] = "SELECT COUNT(*) FROM ck_playerrank WHERE style = 0 AND points >= (SELECT points FROM ck_playerrank WHERE steamid = '%s' AND style = 0);";
char sql_SelectPoints[] = "SELECT points FROM ck_playerrank WHERE steamid = '%s' AND style = 0";

/* Upper bound of how many team there could be */
#define MAXTEAMS 10
Expand Down Expand Up @@ -246,6 +254,7 @@ public void OnConfigsExecuted()
// }
// }


g_ChatPrefix = FindConVar("ck_chat_prefix");
GetConVarString(g_ChatPrefix, g_szChatPrefix, sizeof(g_szChatPrefix));

Expand Down Expand Up @@ -296,7 +305,25 @@ public void OnMapEnd()
if (g_OldMapList.Length > g_Cvar_ExcludeMaps.IntValue)
{
g_OldMapList.Erase(0);
}
}

for ( int i=1 ; i<=MAXPLAYERS ; i++ )
{
g_RankREQ[i] = false;
g_PointsREQ[i] = false;
}
g_Voters = 0;
}

public void OnClientPostAdminCheck(int client)
{
if (IsFakeClient(client))
{
return;
}
g_Voters++;
GetPlayerRank(client);
GetPlayerPoints(client);
}

public void OnClientDisconnect(int client)
Expand All @@ -317,6 +344,14 @@ public void OnClientDisconnect(int client)

g_NominateOwners.Erase(index);
g_NominateList.Erase(index);

if (IsFakeClient(client))
{
return;
}
g_RankREQ[client] = false;
g_PointsREQ[client] = false;
g_Voters--;
}

public Action Command_SetNextmap(int client, int args)
Expand Down Expand Up @@ -1360,32 +1395,167 @@ public void GetMapDisplayNameTier(char[] szMapName, char szBuffer[PLATFORM_MAX_P

public bool DisplayVoteToPros(int time, int flags, Menu menu)
{
g_PlayerOne = FindConVar("sm_rtv_oneplayer");
int total = 0;
int[] players = new int[MaxClients];
g_Cvar_PointsRequirement = FindConVar("sm_rtv_point_requirement");
g_Cvar_RankRequirement = FindConVar("sm_rtv_rank_requirement");
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
continue;

if (g_Cvar_PointsRequirement != null && GetConVarInt(g_Cvar_PointsRequirement) > 0)
if (g_Voters == 1 && GetConVarBool(g_PlayerOne))
{
for (int i = 1; i <= MaxClients; i++)
{
if (surftimer_GetPlayerPoints(i) < GetConVarInt(g_Cvar_PointsRequirement))
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}
}

if (g_Cvar_RankRequirement != null && GetConVarInt(g_Cvar_RankRequirement) > 0)
players[total++] = i;
}
}
else
{
for (int i = 1; i <= MaxClients; i++)
{
if (surftimer_GetPlayerRank(i) > GetConVarInt(g_Cvar_RankRequirement) || surftimer_GetPlayerRank(i) == 0)
if (!IsClientInGame(i) || IsFakeClient(i))
{
continue;
}

if (GetConVarInt(g_Cvar_RankRequirement) > 0 && !g_RankREQ[i])
{
continue;
}

if (GetConVarInt(g_Cvar_PointsRequirement) > 0 && !g_PointsREQ[i])
{
continue;
}
}

players[total++] = i;
players[total++] = i;
}
}
menu.DisplayVote(players, total, time, flags);
}

stock bool VIPBypass(int client)
{
g_Cvar_VIPOverwriteRequirements = FindConVar("sm_rtv_vipoverwrite");
if (surftimer_IsClientVip(client) && GetConVarBool(g_Cvar_VIPOverwriteRequirements))
{
return true;
}
else
{
return false;
}
}

stock bool IsValidClient(int client)
{
if (client >= 1 && client <= MaxClients && IsValidEntity(client) && IsClientConnected(client) && IsClientInGame(client))
return true;
return false;
}

void GetPlayerRank(int client)
{
g_Cvar_RankRequirement = FindConVar("sm_rtv_rank_requirement");
if (!(GetConVarInt(g_Cvar_RankRequirement) > 0))
{
return;
}

char szQuery[256], steamid[32];
GetClientAuthId(client, AuthId_Steam2, steamid, MAX_NAME_LENGTH, true);

FormatEx(szQuery, sizeof(szQuery), sql_SelectRank, steamid);
SQL_TQuery(g_hDb, GetPlayerRankCallBack, szQuery, client, DBPrio_Normal);
}

void GetPlayerRankCallBack(Handle owner, Handle hndl, const char[] error, any client)
{
if (hndl == null){
LogError("[RTV] SQL Error (GetPlayerRankCallBack): %s", error);
return;
}

if(!IsValidClient(client))
{
return;
}

if (SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
{
int rank = SQL_FetchInt(hndl,0);
if(rank <= 0)
{
g_RankREQ[client] = false;
return;
}

if(rank < GetConVarInt(g_Cvar_RankRequirement))
{
g_RankREQ[client] = true;
}
else if (VIPBypass(client))
{
g_RankREQ[client] = true;
}
else
{
g_RankREQ[client] = false;
}

}
}

void GetPlayerPoints(int client)
{
g_Cvar_PointsRequirement = FindConVar("sm_rtv_point_requirement");
if (!(GetConVarInt(g_Cvar_PointsRequirement) > 0))
{
return;
}

char szQuery[256], steamid[32];
GetClientAuthId(client, AuthId_Steam2, steamid, MAX_NAME_LENGTH, true);

FormatEx(szQuery, sizeof(szQuery), sql_SelectPoints, steamid);
SQL_TQuery(g_hDb, GetPlayerPointsCallBack, szQuery, client, DBPrio_Normal);
}

void GetPlayerPointsCallBack(Handle owner, Handle hndl, const char[] error, any client)
{
if (hndl == null){
LogError("[RTV] SQL Error (GetPlayerPointsCallBack): %s", error);
return;
}

if(!IsValidClient(client))
{
return;
}

if (SQL_HasResultSet(hndl) && SQL_FetchRow(hndl))
{
int points = SQL_FetchInt(hndl,0);
if(points <= 0)
{
g_PointsREQ[client] = false;
return;
}

if(points > GetConVarInt(g_Cvar_PointsRequirement))
{
g_PointsREQ[client] = true;
}
else if (VIPBypass(client))
{
g_PointsREQ[client] = true;
}
else
{
g_PointsREQ[client] = false;
}

}
}
2 changes: 1 addition & 1 deletion addons/sourcemod/scripting/nominations.sp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Plugin myinfo =
name = "SurfTimer Nominations",
author = "AlliedModders LLC & SurfTimer Contributors",
description = "Provides Map Nominations",
version = "1.8",
version = "1.8.3",
url = "https://github.com/qawery-just-sad/surftimer-mapchooser"
};

Expand Down
Loading

0 comments on commit b3683fb

Please sign in to comment.