Skip to content

Commit

Permalink
Fix bug, increase dump_log max seconds to 10min
Browse files Browse the repository at this point in the history
  • Loading branch information
Vy0x2 authored and def- committed Jul 15, 2023
1 parent aa817a8 commit 7f100e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/game/server/ddracecommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,11 @@ void CGameContext::ConDumpLog(IConsole::IResult *pResult, void *pUserData)
if(LimitSecs < 0)
return;

for(int i = pSelf->m_FirstLog; i != pSelf->m_LastLog; i = (i + 1) % pSelf->MAX_LOGS)
int Iterator = pSelf->m_LatestLog;
for(int i = 0; i < MAX_LOGS; i++)
{
CLog *pEntry = &pSelf->m_aLogs[i];
CLog *pEntry = &pSelf->m_aLogs[Iterator];
Iterator = (Iterator + 1) % MAX_LOGS;

if(!pEntry->m_Timestamp)
continue;
Expand All @@ -854,10 +856,8 @@ void CGameContext::ConDumpLog(IConsole::IResult *pResult, void *pUserData)

void CGameContext::LogEvent(const char *Description, int ClientID)
{
CLog *pNewEntry = &m_aLogs[m_LastLog];
m_LastLog = (m_LastLog + 1) % MAX_LOGS;
if(m_LastLog == m_FirstLog)
m_FirstLog++;
CLog *pNewEntry = &m_aLogs[m_LatestLog];
m_LatestLog = (m_LatestLog + 1) % MAX_LOGS;

pNewEntry->m_Timestamp = time_get();
str_copy(pNewEntry->m_aDescription, Description);
Expand Down
12 changes: 2 additions & 10 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ void CGameContext::Construct(int Resetting)
m_NumMutes = 0;
m_NumVoteMutes = 0;

m_LastLog = 0;
m_FirstLog = 0;
m_LatestLog = 0;
mem_zero(&m_aLogs, sizeof(m_aLogs));

if(Resetting == NO_RESET)
{
Expand Down Expand Up @@ -1150,14 +1150,6 @@ void CGameContext::OnTick()
m_aVoteMutes[i] = m_aVoteMutes[m_NumVoteMutes];
}
}
for(int i = 0; i < m_LastLog; i++)
{
if(m_aLogs[i].m_Timestamp && (time_get() - m_aLogs[i].m_Timestamp) / time_freq() > MAX_LOG_SECONDS)
{
m_FirstLog = (m_FirstLog + 1) % MAX_LOGS;
m_aLogs[m_FirstLog].m_Timestamp = 0;
}
}

if(Server()->Tick() % (g_Config.m_SvAnnouncementInterval * Server()->TickSpeed() * 60) == 0)
{
Expand Down
7 changes: 3 additions & 4 deletions src/game/server/gamecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ class CGameContext : public IGameServer

enum
{
MAX_LOG_SECONDS = 240,
MAX_LOGS = 256,
MAX_LOG_SECONDS = 600,
MAX_LOGS = 512,
};
struct CLog
{
Expand All @@ -488,8 +488,7 @@ class CGameContext : public IGameServer
char m_aClientAddrStr[NETADDR_MAXSTRSIZE];
};
CLog m_aLogs[MAX_LOGS];
int m_FirstLog;
int m_LastLog;
int m_LatestLog;

void LogEvent(const char *Description, int ClientID);

Expand Down

0 comments on commit 7f100e2

Please sign in to comment.