Skip to content

Commit

Permalink
Auto record demo on match start at client side
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileYzn committed Jan 29, 2025
1 parent f5b9d1a commit c16148d
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MatchBot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ OBJECTS = *.cpp
LINKER =

# C flags
CFLAGS = -std=c++11 -Wall -Wno-switch -Wno-unknown-pragmas -Wno-strict-aliasing -shared -m32 -mtune=generic -msse3 -msse4.1 -pipe -g0 -O3 -s -funroll-loops -fno-stack-protector -g -DNDEBUG -Dlinux -D__linux__ -DGLIBCXX_USE_CXX11_ABI=0 -U_FORTIFY_SOURCE
CFLAGS = -std=gnu++11 -Wall -Wno-switch -Wno-unknown-pragmas -Wno-strict-aliasing -shared -m32 -mtune=generic -msse3 -msse4.1 -pipe -g0 -O3 -s -funroll-loops -fno-stack-protector -flto -fPIC -g -DNDEBUG -Dlinux -D__linux__ -DGLIBCXX_USE_CXX11_ABI=0 -U_FORTIFY_SOURCE

# Include directory
INCLUDE = -I. -I$(CSSDK)/common -I$(CSSDK)/dlls -I$(CSSDK)/engine -I$(CSSDK)/game_shared -I$(CSSDK)/pm_shared -I$(CSSDK)/public -I$(METAMOD)
Expand Down
36 changes: 36 additions & 0 deletions MatchBot/MatchBot.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "precompiled.h"
#include "MatchBot.h"

CMatchBot gMatchBot;

Expand Down Expand Up @@ -143,6 +144,9 @@ void CMatchBot::ServerActivate()
// Extra Smokegranade explosion fix (0 to disable fix, or the number of extra smoke puffs)
this->m_ExtraSmokeCount = gMatchUtil.CvarRegister("mb_extra_smoke_count", "2");

// Auto demo record on client side while match is started or running (0 Disable, 1 Enable)
this->m_AutoDemoRecord = gMatchUtil.CvarRegister("mb_auto_demo_record", "0");

// Amount of seconds to pause match (0 Disable, or number of seconds to pause the match)
this->m_PauseTime = gMatchUtil.CvarRegister("mb_pause_time", "60.0");

Expand Down Expand Up @@ -823,6 +827,13 @@ bool CMatchBot::PlayerJoinTeam(CBasePlayer* Player, int Slot)
}
}

// If match is running
if (this->m_State >= STATE_FIRST_HALF && this->m_State <= STATE_OVERTIME)
{
// Try to record demo on client side
this->RecordDemo(Player->edict());
}

// Allow any thing
return false;
}
Expand Down Expand Up @@ -1206,6 +1217,31 @@ void CMatchBot::UpdateGameName()
}
}

// Record demo on client side
void CMatchBot::RecordDemo(edict_t *pEntity)
{
// If is enabled
if (this->m_AutoDemoRecord->value > 0.0f)
{
struct tm* tm_info = localtime(NULL);

if (tm_info)
{
char Date[32] = { 0 };

strftime(Date, sizeof(Date), "%F-%H-%M-%S", tm_info);

char Name[64] = { 0 };

Q_sprintf(Name, "match-%s", Date);

gMatchUtil.ClientCommand(pEntity, "record \"%s\";", Name);

gMatchUtil.SayText(pEntity, PRINT_TEAM_DEFAULT, _T("Recording demo to ^3%s.dem^1 in your client."), Name);
}
}
}

// Start vote map
void CMatchBot::StartVoteMap(CBasePlayer* Player)
{
Expand Down
4 changes: 4 additions & 0 deletions MatchBot/MatchBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class CMatchBot
// Update game description
void UpdateGameName();

// Record demo on client side
void RecordDemo(edict_t* pEntity);

// Start vote map
void StartVoteMap(CBasePlayer* Player);

Expand Down Expand Up @@ -227,6 +230,7 @@ class CMatchBot
cvar_t* m_RoundGrenadeCount = nullptr;
cvar_t* m_RoundSmokeCount = nullptr;
cvar_t* m_RoundFlashCount = nullptr;
cvar_t* m_AutoDemoRecord = nullptr;
cvar_t* m_HelpFile = nullptr;
cvar_t* m_HelpFileAdmin = nullptr;
};
Expand Down
2 changes: 2 additions & 0 deletions MatchBot/MatchLO3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ void CMatchLO3::Start()
CSGameRules()->m_bGameStarted = true;
}

gMatchBot.RecordDemo(nullptr);

g_engfuncs.pfnCvar_DirectSet(gMatchBot.m_SvRestart, std::to_string(this->m_Restart).c_str());

gMatchUtil.SayText(nullptr, PRINT_TEAM_RED, _T("Live in three restarts! ^3Get Ready!!"));
Expand Down
47 changes: 47 additions & 0 deletions MatchBot/MatchUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "precompiled.h"
#include "MatchUtil.h"

CMatchUtil gMatchUtil;

Expand Down Expand Up @@ -194,6 +195,52 @@ void CMatchUtil::ClientPrint(edict_t* pEntity, int msg_dest, const char* Format,
}
}

void CMatchUtil::ClientCommand(edict_t *pEntity, const char *Format, ...)
{
static char Command[256] = { 0 };

va_list ArgList;

va_start(ArgList, Format);

vsnprintf(Command, sizeof(Command), Format, ArgList);

va_end(ArgList);

strcat(Command, "\n");

if (!FNullEnt(pEntity))
{
g_engfuncs.pfnClientCommand(pEntity, Command);
}
else
{
for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
pEntity = INDEXENT(i);

if (!FNullEnt(pEntity))
{
if ((pEntity->v.flags & FL_DORMANT) == FL_DORMANT)
{
continue;
}

if ((pEntity->v.flags & FL_PROXY) == FL_PROXY)
{
continue;
}

if ((pEntity->v.flags & FL_FAKECLIENT) == FL_FAKECLIENT)
{
continue;
}

g_engfuncs.pfnClientCommand(pEntity, Command);
}
}
}
}
int CMatchUtil::GetCount(TeamName Team)
{
int Result = 0;
Expand Down
3 changes: 3 additions & 0 deletions MatchBot/MatchUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class CMatchUtil
// Print client text message
void ClientPrint(edict_t* pEntity, int msg_dest, const char* Format, ...);

// Send client console commands
void ClientCommand(edict_t *pEntity, const char *Format, ...);

// Get player count in team
int GetCount(TeamName Team);

Expand Down
3 changes: 0 additions & 3 deletions MatchBot/MatchVoteMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ void CMatchVoteMap::ChangeRandomMap()
}
}

// Try to change to a random map until this function returns true
this->ChangeRandomMap();

// Return Result
return;
}
16 changes: 8 additions & 8 deletions MatchBot/MatchVoteMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ struct P_MAP_ITEM
class CMatchVoteMap
{
public:
//
// Init vote map
void Init(int VoteMapType, int VoteMapFail);

//
// Return loaded map list
std::vector<P_MAP_ITEM> Load();

//
// Stop vote map
static void Stop(int VoteFailType);

//
// Increment vote
void AddVote(int Item, int Vote);

//
// Vote menu handler
static void MenuHandle(int EntityIndex, P_MENU_ITEM Item);

//
// Updte vote hud list message task
static void UpdateVoteList(int PlayerCount);

//
// Updte vote hud list message
void VoteList();

//
// Get map winner of vote map
P_MAP_ITEM GetWinner();

// Change to a random map
Expand Down
8 changes: 8 additions & 0 deletions cstrike/addons/matchbot/cfg/matchbot.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ mb_restrict_weapons "000000000000000000000000000000000000000"
// Default "2"
mb_extra_smoke_count "2"

// Auto demo record on client side while match is started or running
//
// 0 Disable
// 1 Enable
//
// Default "0"
mb_auto_demo_record "0"

// Amount of seconds to pause match
//
// 0 Disable
Expand Down

0 comments on commit c16148d

Please sign in to comment.