Skip to content

Commit

Permalink
internal war list tracking working
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrc6 committed Dec 5, 2024
1 parent 6549668 commit f8b6d41
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
13 changes: 11 additions & 2 deletions src/game/client/components/tclient/bindwheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,24 @@ void CBindWheel::ExecuteHover()
if(m_SelectedBind >= 0)
Console()->ExecuteLine(m_vBinds[m_SelectedBind].m_aCommand);
}
static void EscapeParam(char *pDst, const char *pSrc, int Size)
{
str_escape(&pDst, pSrc, pDst + Size);
}

void CBindWheel::ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData)
{
CBindWheel *pThis = (CBindWheel *)pUserData;

char aBuf[128] = {};
char aBuf[2048];
char aEscapeName[BINDWHEEL_MAX_NAME + 256];
char aEscapeCommand[BINDWHEEL_MAX_CMD + 256];

for(SBind &Bind : pThis->m_vBinds)
{
str_format(aBuf, sizeof(aBuf), "add_bindwheel \"%s\" \"%s\"", Bind.m_aName, Bind.m_aCommand);
EscapeParam(aEscapeName, Bind.m_aName, sizeof(aEscapeName));
EscapeParam(aEscapeCommand, Bind.m_aCommand, sizeof(aEscapeCommand));
str_format(aBuf, sizeof(aBuf), "add_bindwheel \"%s\" \"%s\"", aEscapeName, aEscapeCommand);
pConfigManager->WriteLine(aBuf);
}
}
41 changes: 33 additions & 8 deletions src/game/client/components/tclient/warlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

void CWarList::OnNewSnapshot()
{
UpdateWarPlayers();
}

void CWarList::OnConsoleInit()
Expand All @@ -20,7 +21,13 @@ void CWarList::OnConsoleInit()
if(pConfigManager)
pConfigManager->RegisterTCallback(ConfigSaveCallback, this);

// TODO: PUT CON COMMANDS HERE
Console()->Register("update_war_type", "s[type] s[name] i[color]", CFGFLAG_CLIENT, ConUpsertWarType, this, "Update or add a specific war entry");
Console()->Register("add_war_entry", "s[type] s[name] s[clan] r[reason]", CFGFLAG_CLIENT, ConAddWarEntry, this, "Adds a specific war entry");

Console()->Register("war_name", "s[type] s[name] r[reason]", CFGFLAG_CLIENT, ConName, this, "Add a name war entry");
Console()->Register("war_clan", "s[type] s[clan] r[reason]", CFGFLAG_CLIENT, ConClan, this, "Add a clan war entry");
Console()->Register("remove_war_name", "s[type] s[name]", CFGFLAG_CLIENT, ConRemoveName, this, "Remove a name war entry");
Console()->Register("remove_war_clan", "s[type] s[clan]", CFGFLAG_CLIENT, ConRemoveClan, this, "Remove a clan war entry");

m_pStorage = Kernel()->RequestInterface<IStorage>();
IOHANDLE File = m_pStorage->OpenFile(WARLIST_FILE, IOFLAG_READ, IStorage::TYPE_ALL);
Expand Down Expand Up @@ -65,7 +72,7 @@ void CWarList::ConRemoveName(IConsole::IResult *pResult, void *pUserData)
CWarList *pThis = static_cast<CWarList *>(pUserData);
pThis->RemoveWarEntry(pName, "", pType);
}
void CWarList::ConRemoveClan(IConsole::IResult *pResult, void *pUserData)
void CWarList::ConRemoveClan(IConsole::IResult *pResult, void *pUserData)
{
const char *pType = pResult->GetString(0);
const char *pClan = pResult->GetString(1);
Expand All @@ -74,7 +81,7 @@ void CWarList::ConRemoveClan(IConsole::IResult *pResult, void *pUserData)
}

// Backend Commands for config file
void CWarList::ConAddWarEntry(IConsole::IResult *pResult, void *pUserData)
void CWarList::ConAddWarEntry(IConsole::IResult *pResult, void *pUserData)
{
const char *pType = pResult->GetString(0);
const char *pName = pResult->GetString(1);
Expand All @@ -83,7 +90,7 @@ void CWarList::ConAddWarEntry(IConsole::IResult *pResult, void *pUserData)
CWarList *pThis = static_cast<CWarList *>(pUserData);
pThis->AddWarEntry(pName, pClan, pReason, pType);
}
void CWarList::ConUpsertWarType(IConsole::IResult *pResult, void *pUserData)
void CWarList::ConUpsertWarType(IConsole::IResult *pResult, void *pUserData)
{
int Index = pResult->GetInteger(0);
const char *pType = pResult->GetString(1);
Expand Down Expand Up @@ -126,9 +133,9 @@ void CWarList::AddWarEntry(const char *pName, const char *pClan, const char *pRe
CWarEntry Entry(WarType);
str_copy(Entry.m_aReason, pReason);

if(pClan)
if(str_comp(pClan, "") != 0)
str_copy(Entry.m_aClan, pClan);
else if(pName)
else if(str_comp(pName, "") != 0)
str_copy(Entry.m_aName, pName);
else
return;
Expand Down Expand Up @@ -264,6 +271,11 @@ void CWarList::WriteLine(const char *pLine)
return;
}

static void EscapeParam(char *pDst, const char *pSrc, int Size)
{
str_escape(&pDst, pSrc, pDst + Size);
}

void CWarList::ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData)
{
CWarList *pThis = (CWarList *)pUserData;
Expand All @@ -286,7 +298,11 @@ void CWarList::ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserDat
if(WarType.m_Imported)
continue;

str_format(aBuf, sizeof(aBuf), "update_war_type %d \"%s\" %d", i, WarType.m_aWarType, WarType.m_Color.Pack());
char aEscapeType[MAX_WARLIST_TYPE_LENGTH * 2];
EscapeParam(aEscapeType, WarType.m_aWarType, sizeof(aEscapeType));
ColorHSLA Color = color_cast<ColorHSLA>(WarType.m_Color);

str_format(aBuf, sizeof(aBuf), "update_war_type %d \"%s\" %d", i, aEscapeType, Color.Pack(false));
pThis->WriteLine(aBuf);
}
for(CWarEntry &Entry : pThis->m_WarEntries)
Expand All @@ -295,7 +311,16 @@ void CWarList::ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserDat
if(Entry.m_Imported)
continue;

str_format(aBuf, sizeof(aBuf), "add_war_entry \"%s\" \"%s\" \"%s\" \"%s\"", Entry.m_pWarType->m_aWarType, Entry.m_aName, Entry.m_aClan, Entry.m_aReason);
char aEscapeType[MAX_WARLIST_TYPE_LENGTH * 2];
char aEscapeName[MAX_NAME_LENGTH * 2];
char aEscapeClan[MAX_CLAN_LENGTH * 2];
char aEscapeReason[MAX_WARLIST_REASON_LENGTH * 2];
EscapeParam(aEscapeType, Entry.m_pWarType->m_aWarType, sizeof(aEscapeType));
EscapeParam(aEscapeName, Entry.m_aName, sizeof(aEscapeName));
EscapeParam(aEscapeClan, Entry.m_aClan, sizeof(aEscapeClan));
EscapeParam(aEscapeReason, Entry.m_aReason, sizeof(aEscapeReason));

str_format(aBuf, sizeof(aBuf), "add_war_entry \"%s\" \"%s\" \"%s\" \"%s\"", aEscapeType, aEscapeName, aEscapeClan, aEscapeReason);
pThis->WriteLine(aBuf);
}

Expand Down
1 change: 1 addition & 0 deletions src/game/client/gameclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void CGameClient::OnConsoleInit()
&m_Spectator,
&m_Emoticon,
&m_Bindwheel,
&m_WarList,
&m_InfoMessages,
&m_Chat,
&m_Broadcast,
Expand Down
16 changes: 10 additions & 6 deletions src/game/client/gameclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "components/tclient/skinprofiles.h"
#include "components/tclient/tater.h"
#include "components/tclient/verify.h"
#include "components/tclient/warlist.h"
#include "components/voting.h"

class CGameInfo
Expand Down Expand Up @@ -138,7 +139,6 @@ class CGameClient : public IGameClient
CBroadcast m_Broadcast;
CGameConsole m_GameConsole;
CBinds m_Binds;
CSkinProfiles m_SkinProfiles;
CParticles m_Particles;
CMenus m_Menus;
CSkins m_Skins;
Expand All @@ -153,16 +153,12 @@ class CGameClient : public IGameClient
CStatboard m_Statboard;
CSounds m_Sounds;
CEmoticon m_Emoticon;
CBindWheel m_Bindwheel;
CTater m_Tater;
CDamageInd m_DamageInd;
CVoting m_Voting;
CVerify m_Verify;
CSpectator m_Spectator;

CPlayers m_Players;
CPlayerIndicator m_PlayerIndicator;
COutlines m_Outlines;
CNamePlates m_NamePlates;
CFreezeBars m_FreezeBars;
CItems m_Items;
Expand All @@ -176,11 +172,19 @@ class CGameClient : public IGameClient
CMapSounds m_MapSounds;

CRaceDemo m_RaceDemo;
CRainbow m_Rainbow;
CGhost m_Ghost;

CTooltips m_Tooltips;

// TClient Components
CSkinProfiles m_SkinProfiles;
CBindWheel m_Bindwheel;
CTater m_Tater;
CPlayerIndicator m_PlayerIndicator;
COutlines m_Outlines;
CRainbow m_Rainbow;
CWarList m_WarList;

private:
std::vector<class CComponent *> m_vpAll;
std::vector<class CComponent *> m_vpInput;
Expand Down

0 comments on commit f8b6d41

Please sign in to comment.