Skip to content

Commit

Permalink
Add RTV and Extend votes (#79)
Browse files Browse the repository at this point in the history
* Add V1 of RTV and Extend vote systems

* Add !timeleft and admin !extend commands
  • Loading branch information
Faramour authored Oct 29, 2023
1 parent 47be731 commit 57efafb
Show file tree
Hide file tree
Showing 9 changed files with 570 additions and 2 deletions.
1 change: 1 addition & 0 deletions AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ for sdk_name in MMSPlugin.sdks:
'src/ctimer.cpp',
'src/playermanager.cpp',
'src/gameconfig.cpp',
'src/votemanager.cpp',
'src/httpmanager.cpp',
]

Expand Down
2 changes: 2 additions & 0 deletions CS2Fixes.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
<ClCompile Include="src\mempatch.cpp" />
<ClCompile Include="src\patches.cpp" />
<ClCompile Include="src\playermanager.cpp" />
<ClCompile Include="src\votemanager.cpp" />
<ClCompile Include="sdk\tier1\convar.cpp" />
<ClCompile Include="src\utils\entity.cpp" />
<ClCompile Include="src\utils\plat_unix.cpp" />
Expand Down Expand Up @@ -215,6 +216,7 @@
<ClInclude Include="src\addresses.h" />
<ClInclude Include="src\playermanager.h" />
<ClInclude Include="src\recipientfilters.h" />
<ClInclude Include="src\votemanager.h" />
<ClInclude Include="src\utils\entity.h" />
<ClInclude Include="src\utils\module.h" />
<ClInclude Include="src\utils\plat.h" />
Expand Down
6 changes: 6 additions & 0 deletions CS2Fixes.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<ClCompile Include="src\httpmanager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\votemanager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\mempatch.h">
Expand Down Expand Up @@ -196,5 +199,8 @@
<ClInclude Include="src\httpmanager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\votemanager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
37 changes: 35 additions & 2 deletions src/adminsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ CAdminSystem* g_pAdminSystem = nullptr;

CUtlMap<uint32, CChatCommand *> g_CommandList(0, 0, DefLessFunc(uint32));

#define ADMIN_PREFIX "Admin %s has "

void PrintSingleAdminAction(const char *pszAdminName, const char *pszTargetName, const char *pszAction, const char *pszAction2 = "")
{
ClientPrintAll(HUD_PRINTTALK, CHAT_PREFIX ADMIN_PREFIX "%s %s%s.", pszAdminName, pszAction, pszTargetName, pszAction2);
Expand Down Expand Up @@ -839,6 +837,41 @@ CON_COMMAND_CHAT_FLAGS(rcon, "send a command to server console", ADMFLAG_RCON)
g_pEngineServer2->ServerCommand(args.ArgS());
}

CON_COMMAND_CHAT_FLAGS(extend, "extend current map (negative value reduces map duration)", ADMFLAG_CHANGEMAP)
{
if (args.ArgC() < 3)
{
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Usage: !extend <minutes>");
return;
}

int iExtendTime = V_StringToInt32(args[1], 0);

// CONVAR_TODO
ConVar* cvar = g_pCVar->GetConVar(g_pCVar->FindConVar("mp_timelimit"));

float flTimelimit;
memcpy(&flTimelimit, &cvar->values, sizeof(flTimelimit));

if (gpGlobals->curtime - g_pGameRules->m_flGameStartTime > flTimelimit * 60)
flTimelimit = (gpGlobals->curtime - g_pGameRules->m_flGameStartTime) / 60.0f + iExtendTime;
else
{
if (flTimelimit == 1)
flTimelimit = 0;
flTimelimit += iExtendTime;
}

if (flTimelimit <= 0)
flTimelimit = 1;

char buf[32];
V_snprintf(buf, sizeof(buf), "mp_timelimit %.6f", flTimelimit);

// CONVAR_TODO
g_pEngineServer2->ServerCommand(buf);
}

bool CAdminSystem::LoadAdmins()
{
m_vecAdmins.Purge();
Expand Down
1 change: 1 addition & 0 deletions src/adminsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#define ADMFLAG_CUSTOM11 (1 << 24) // y
#define ADMFLAG_ROOT (1 << 25) // z

#define ADMIN_PREFIX "Admin %s has "

class CInfractionBase
{
Expand Down
19 changes: 19 additions & 0 deletions src/cs2fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "commands.h"
#include "eventlistener.h"
#include "gameconfig.h"
#include "votemanager.h"
#include "httpmanager.h"
#include "entity/cgamerules.h"

Expand Down Expand Up @@ -302,6 +303,24 @@ void CS2Fixes::Hook_StartupServer(const GameSessionConfiguration_t& config, ISou
g_bHasTicked = false;

RegisterEventListeners();

// Disable RTV and Extend votes after map has just started
g_RTVState = ERTVState::MAP_START;
g_ExtendState = EExtendState::MAP_START;

// Allow RTV and Extend votes after 2 minutes post map start
new CTimer(120.0f, false, []()
{
if (g_RTVState != ERTVState::BLOCKED_BY_ADMIN)
g_RTVState = ERTVState::RTV_ALLOWED;

if (g_ExtendState != EExtendState::NO_EXTENDS)
g_ExtendState = EExtendState::EXTEND_ALLOWED;
return -1.0f;
});

// Set amount of Extends left
g_ExtendsLeft = 1;
}

void CS2Fixes::Hook_GameServerSteamAPIActivated()
Expand Down
8 changes: 8 additions & 0 deletions src/playermanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class ZEPlayer
m_iHideDistance = 0;
m_bConnected = false;
m_iTotalDamage = 0;
m_bVotedRTV = false;
m_bVotedExtend = false;
}

bool IsFakeClient() { return m_bFakeClient; }
Expand All @@ -69,13 +71,17 @@ class ZEPlayer
void ClearTransmit() { m_shouldTransmit.ClearAll(); }
void SetHideDistance(int distance) { m_iHideDistance = distance; }
void SetTotalDamage(int damage) { m_iTotalDamage = damage; }
void SetRTVVote(bool bRTVVote) { m_bVotedRTV = bRTVVote; }
void SetExtendVote(bool bExtendVote) { m_bVotedExtend = bExtendVote; }

bool IsMuted() { return m_bMuted; }
bool IsGagged() { return m_bGagged; }
bool ShouldBlockTransmit(int index) { return m_shouldTransmit.Get(index); }
int GetHideDistance() { return m_iHideDistance; }
CPlayerSlot GetPlayerSlot() { return m_slot; }
int GetTotalDamage() { return m_iTotalDamage; }
bool GetRTVVote() { return m_bVotedRTV; }
bool GetExtendVote() { return m_bVotedExtend; }

void OnAuthenticated();
void CheckAdmin();
Expand All @@ -93,6 +99,8 @@ class ZEPlayer
int m_iHideDistance;
CBitVec<MAXPLAYERS> m_shouldTransmit;
int m_iTotalDamage;
bool m_bVotedRTV;
bool m_bVotedExtend;
};

class CPlayerManager
Expand Down
Loading

0 comments on commit 57efafb

Please sign in to comment.