Skip to content

Commit

Permalink
Merge pull request ddnet#8966 from furo321/reload-censorlist
Browse files Browse the repository at this point in the history
Add `reload_censorlist` to reread `censorlist.txt`
  • Loading branch information
Robyt3 authored Sep 16, 2024
2 parents 7dc6346 + e8e52a8 commit e69e7d8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/game/server/ddracecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,12 @@ void CGameContext::ConDrySave(IConsole::IResult *pResult, void *pUserData)
io_close(File);
}

void CGameContext::ConReloadCensorlist(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
pSelf->ReadCensorList();
}

void CGameContext::ConDumpAntibot(IConsole::IResult *pResult, void *pUserData)
{
CGameContext *pSelf = (CGameContext *)pUserData;
Expand Down
33 changes: 20 additions & 13 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3642,6 +3642,7 @@ void CGameContext::OnConsoleInit()
Console()->Register("set_team", "i[id] i[team-id] ?i[delay in minutes]", CFGFLAG_SERVER, ConSetTeam, this, "Set team of player to team");
Console()->Register("set_team_all", "i[team-id]", CFGFLAG_SERVER, ConSetTeamAll, this, "Set team of all players to team");
Console()->Register("hot_reload", "", CFGFLAG_SERVER | CMDFLAG_TEST, ConHotReload, this, "Reload the map while preserving the state of tees and teams");
Console()->Register("reload_censorlist", "", CFGFLAG_SERVER, ConReloadCensorlist, this, "Reload the censorlist");

Console()->Register("add_vote", "s[name] r[command]", CFGFLAG_SERVER, ConAddVote, this, "Add a voting option");
Console()->Register("remove_vote", "r[name]", CFGFLAG_SERVER, ConRemoveVote, this, "remove a voting option");
Expand Down Expand Up @@ -3933,19 +3934,7 @@ void CGameContext::OnInit(const void *pPersistentData)
else
m_pController = new CGameControllerDDRace(this);

const char *pCensorFilename = "censorlist.txt";
CLineReader LineReader;
if(LineReader.OpenFile(Storage()->OpenFile(pCensorFilename, IOFLAG_READ, IStorage::TYPE_ALL)))
{
while(const char *pLine = LineReader.Get())
{
m_vCensorlist.emplace_back(pLine);
}
}
else
{
dbg_msg("censorlist", "failed to open '%s'", pCensorFilename);
}
ReadCensorList();

m_TeeHistorianActive = g_Config.m_SvTeeHistorian;
if(m_TeeHistorianActive)
Expand Down Expand Up @@ -4989,3 +4978,21 @@ void CGameContext::OnUpdatePlayerServerInfo(CJsonStringWriter *pJSonWriter, int
pJSonWriter->WriteAttribute("team");
pJSonWriter->WriteIntValue(Team);
}

void CGameContext::ReadCensorList()
{
const char *pCensorFilename = "censorlist.txt";
CLineReader LineReader;
m_vCensorlist.clear();
if(LineReader.OpenFile(Storage()->OpenFile(pCensorFilename, IOFLAG_READ, IStorage::TYPE_ALL)))
{
while(const char *pLine = LineReader.Get())
{
m_vCensorlist.emplace_back(pLine);
}
}
else
{
dbg_msg("censorlist", "failed to open '%s'", pCensorFilename);
}
}
3 changes: 3 additions & 0 deletions src/game/server/gamecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class CGameContext : public IGameServer
bool RateLimitPlayerMapVote(int ClientId) const;

void OnUpdatePlayerServerInfo(CJsonStringWriter *pJSonWriter, int Id) override;
void ReadCensorList();

std::shared_ptr<CScoreRandomMapResult> m_SqlRandomMapResult;

Expand Down Expand Up @@ -514,6 +515,8 @@ class CGameContext : public IGameServer
static void ConFreezeHammer(IConsole::IResult *pResult, void *pUserData);
static void ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData);

static void ConReloadCensorlist(IConsole::IResult *pResult, void *pUserData);

CCharacter *GetPracticeCharacter(IConsole::IResult *pResult);

enum
Expand Down

0 comments on commit e69e7d8

Please sign in to comment.