mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Add logs for moderators
This commit is contained in:
parent
d45b84f18c
commit
36939475e2
|
@ -58,6 +58,7 @@ CONSOLE_COMMAND("mutes", "", CFGFLAG_SERVER, ConMutes, this, "")
|
|||
CONSOLE_COMMAND("moderate", "", CFGFLAG_SERVER, ConModerate, this, "Enables/disables active moderator mode for the player")
|
||||
CONSOLE_COMMAND("vote_no", "", CFGFLAG_SERVER, ConVoteNo, this, "Same as \"vote no\"")
|
||||
CONSOLE_COMMAND("save_dry", "", CFGFLAG_SERVER, ConDrySave, this, "Dump the current savestring")
|
||||
CONSOLE_COMMAND("dump_log", "?i[seconds]", CFGFLAG_SERVER, ConDumpLog, this, "Show logs of the last i seconds")
|
||||
|
||||
CONSOLE_COMMAND("freezehammer", "v[id]", CFGFLAG_SERVER | CMDFLAG_TEST, ConFreezeHammer, this, "Gives a player Freeze Hammer")
|
||||
CONSOLE_COMMAND("unfreezehammer", "v[id]", CFGFLAG_SERVER | CMDFLAG_TEST, ConUnFreezeHammer, this, "Removes Freeze Hammer from a player")
|
||||
|
|
|
@ -827,3 +827,52 @@ void CGameContext::ConDumpAntibot(IConsole::IResult *pResult, void *pUserData)
|
|||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
pSelf->Antibot()->Dump();
|
||||
}
|
||||
|
||||
void CGameContext::ConDumpLog(IConsole::IResult *pResult, void *pUserData)
|
||||
{
|
||||
CGameContext *pSelf = (CGameContext *)pUserData;
|
||||
int LimitSecs = MAX_LOG_SECONDS;
|
||||
if(pResult->NumArguments() > 0)
|
||||
LimitSecs = pResult->GetInteger(0);
|
||||
|
||||
if(LimitSecs < 0)
|
||||
return;
|
||||
|
||||
for(int i = pSelf->m_FirstLog; i != pSelf->m_LastLog; i = (i + 1) % pSelf->MAX_LOGS)
|
||||
{
|
||||
CLog *pEntry = &pSelf->m_aLogs[i];
|
||||
|
||||
if(!pEntry->m_Timestamp)
|
||||
continue;
|
||||
|
||||
int Seconds = (time_get() - pEntry->m_Timestamp) / time_freq();
|
||||
if(Seconds > LimitSecs)
|
||||
continue;
|
||||
|
||||
char aBuf[256];
|
||||
if(pEntry->m_FromServer)
|
||||
str_format(aBuf, sizeof aBuf, "%s, %d seconds ago", pEntry->m_aDescription, Seconds);
|
||||
else
|
||||
str_format(aBuf, sizeof aBuf, "%s, %d seconds ago < addr=<{%s}> name='%s' client=%d",
|
||||
pEntry->m_aDescription, Seconds, pEntry->m_aClientAddrStr, pEntry->m_aClientName, pEntry->m_ClientVersion);
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "log", aBuf);
|
||||
}
|
||||
}
|
||||
|
||||
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++;
|
||||
|
||||
pNewEntry->m_Timestamp = time_get();
|
||||
str_copy(pNewEntry->m_aDescription, Description);
|
||||
pNewEntry->m_FromServer = ClientID < 0;
|
||||
if(!pNewEntry->m_FromServer)
|
||||
{
|
||||
pNewEntry->m_ClientVersion = Server()->GetClientVersion(ClientID);
|
||||
Server()->GetClientAddr(ClientID, pNewEntry->m_aClientAddrStr, sizeof(pNewEntry->m_aClientAddrStr));
|
||||
str_copy(pNewEntry->m_aClientName, Server()->ClientName(ClientID));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,6 +93,9 @@ void CGameContext::Construct(int Resetting)
|
|||
m_NumMutes = 0;
|
||||
m_NumVoteMutes = 0;
|
||||
|
||||
m_LastLog = 0;
|
||||
m_FirstLog = 0;
|
||||
|
||||
if(Resetting == NO_RESET)
|
||||
{
|
||||
m_NonEmptySince = 0;
|
||||
|
@ -472,6 +475,9 @@ void CGameContext::SendChat(int ChatterClientID, int Team, const char *pText, in
|
|||
if(!m_apPlayers[i]->m_DND && Send)
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, i);
|
||||
}
|
||||
|
||||
str_format(aBuf, sizeof aBuf, "Chat: %s", aText);
|
||||
LogEvent(aBuf, ChatterClientID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1060,6 +1066,14 @@ 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)
|
||||
{
|
||||
|
@ -1462,6 +1476,8 @@ void CGameContext::OnClientEnter(int ClientID)
|
|||
Server()->GetClientAddr(ClientID, &Addr);
|
||||
Mute(&Addr, g_Config.m_SvChatInitialDelay, Server()->ClientName(ClientID), "Initial chat delay", true);
|
||||
}
|
||||
|
||||
LogEvent("Connect", ClientID);
|
||||
}
|
||||
|
||||
bool CGameContext::OnClientDataPersist(int ClientID, void *pData)
|
||||
|
@ -1524,6 +1540,8 @@ void CGameContext::OnClientConnected(int ClientID, void *pData)
|
|||
|
||||
void CGameContext::OnClientDrop(int ClientID, const char *pReason)
|
||||
{
|
||||
LogEvent("Disconnect", ClientID);
|
||||
|
||||
AbortVoteKickOnDisconnect(ClientID);
|
||||
m_pController->OnPlayerDisconnect(m_apPlayers[ClientID], pReason);
|
||||
delete m_apPlayers[ClientID];
|
||||
|
@ -2347,6 +2365,8 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
|||
Score()->LoadPlayerData(ClientID);
|
||||
|
||||
SixupNeedsUpdate = true;
|
||||
|
||||
LogEvent("Name change", ClientID);
|
||||
}
|
||||
|
||||
if(str_comp(Server()->ClientClan(ClientID), pMsg->m_pClan))
|
||||
|
|
|
@ -117,6 +117,7 @@ class CGameContext : public IGameServer
|
|||
static void ConDrySave(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConDumpAntibot(IConsole::IResult *pResult, void *pUserData);
|
||||
static void ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
|
||||
static void ConDumpLog(IConsole::IResult *pResult, void *pUserData);
|
||||
|
||||
void Construct(int Resetting);
|
||||
void Destruct(int Resetting);
|
||||
|
@ -449,6 +450,26 @@ private:
|
|||
bool IsVersionBanned(int Version);
|
||||
void UnlockTeam(int ClientID, int Team);
|
||||
|
||||
enum
|
||||
{
|
||||
MAX_LOG_SECONDS = 240,
|
||||
MAX_LOGS = 256,
|
||||
};
|
||||
struct CLog
|
||||
{
|
||||
int64_t m_Timestamp;
|
||||
bool m_FromServer;
|
||||
char m_aDescription[128];
|
||||
int m_ClientVersion;
|
||||
char m_aClientName[MAX_NAME_LENGTH];
|
||||
char m_aClientAddrStr[NETADDR_MAXSTRSIZE];
|
||||
};
|
||||
CLog m_aLogs[MAX_LOGS];
|
||||
int m_FirstLog;
|
||||
int m_LastLog;
|
||||
|
||||
void LogEvent(const char *Description, int ClientID);
|
||||
|
||||
public:
|
||||
CLayers *Layers() { return &m_Layers; }
|
||||
CScore *Score() { return m_pScore; }
|
||||
|
|
Loading…
Reference in a new issue