mirror of
https://github.com/ddnet/ddnet.git
synced 2024-09-20 01:24:18 +00:00
Merge #2861
2861: Implement censoring words on server r=heinrich5991 a=def- Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
commit
8b399ba1be
|
@ -740,6 +740,7 @@ set(EXPECTED_DATA
|
|||
audio/wp_switch-03.wv
|
||||
blob.png
|
||||
browse_icons.png
|
||||
censorlist.txt
|
||||
console.png
|
||||
console_bar.png
|
||||
countryflags/AD.png
|
||||
|
|
0
data/censorlist.txt
Normal file
0
data/censorlist.txt
Normal file
|
@ -1607,6 +1607,18 @@ void *CGameContext::PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID
|
|||
return m_NetObjHandler.SecureUnpackMsg(*MsgID, pUnpacker);
|
||||
}
|
||||
|
||||
void CGameContext::CensorMessage(char *pCensoredMessage, const char *pMessage, int Size)
|
||||
{
|
||||
str_copy(pCensoredMessage, pMessage, Size);
|
||||
|
||||
for(int i = 0; i < m_aCensorlist.size(); i++)
|
||||
{
|
||||
char *pNeedle = (char *)str_find(pCensoredMessage, m_aCensorlist[i].cstr());
|
||||
if(pNeedle)
|
||||
memset(pNeedle, '*', str_length(m_aCensorlist[i].cstr()));
|
||||
}
|
||||
}
|
||||
|
||||
void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
||||
{
|
||||
if(m_TeeHistorianActive)
|
||||
|
@ -1748,7 +1760,11 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
|
|||
}
|
||||
}
|
||||
else
|
||||
SendChat(ClientID, Team, pMsg->m_pMessage, ClientID);
|
||||
{
|
||||
char aCensoredMessage[256];
|
||||
CensorMessage(aCensoredMessage, pMsg->m_pMessage, sizeof(aCensoredMessage));
|
||||
SendChat(ClientID, Team, aCensoredMessage, ClientID);
|
||||
}
|
||||
}
|
||||
else if(MsgID == NETMSGTYPE_CL_CALLVOTE)
|
||||
{
|
||||
|
@ -3078,6 +3094,24 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
|
|||
m_pController = new CGameControllerDDRace(this);
|
||||
((CGameControllerDDRace*)m_pController)->m_Teams.Reset();
|
||||
|
||||
const char *pCensorFilename = "censorlist.txt";
|
||||
IOHANDLE File = Storage()->OpenFile(pCensorFilename, IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
if(!File)
|
||||
{
|
||||
dbg_msg("censorlist", "failed to open '%s'", pCensorFilename);
|
||||
}
|
||||
else
|
||||
{
|
||||
CLineReader LineReader;
|
||||
LineReader.Init(File);
|
||||
char *pLine;
|
||||
while((pLine = LineReader.Get()))
|
||||
{
|
||||
m_aCensorlist.add(pLine);
|
||||
}
|
||||
io_close(File);
|
||||
}
|
||||
|
||||
m_TeeHistorianActive = g_Config.m_SvTeeHistorian;
|
||||
if(m_TeeHistorianActive)
|
||||
{
|
||||
|
@ -3790,6 +3824,9 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
|
|||
if(m_apPlayers[ClientID])
|
||||
m_apPlayers[ClientID]->m_LastWhisperTo = VictimID;
|
||||
|
||||
char aCensoredMessage[256];
|
||||
CensorMessage(aCensoredMessage, pMessage, sizeof(aCensoredMessage));
|
||||
|
||||
char aBuf[256];
|
||||
|
||||
if(Server()->IsSixup(ClientID))
|
||||
|
@ -3797,7 +3834,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
|
|||
protocol7::CNetMsg_Sv_Chat Msg;
|
||||
Msg.m_ClientID = ClientID;
|
||||
Msg.m_Mode = protocol7::CHAT_WHISPER;
|
||||
Msg.m_pMessage = pMessage;
|
||||
Msg.m_pMessage = aCensoredMessage;
|
||||
Msg.m_TargetID = VictimID;
|
||||
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID);
|
||||
|
@ -3807,7 +3844,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
|
|||
CNetMsg_Sv_Chat Msg;
|
||||
Msg.m_Team = CHAT_WHISPER_SEND;
|
||||
Msg.m_ClientID = VictimID;
|
||||
Msg.m_pMessage = pMessage;
|
||||
Msg.m_pMessage = aCensoredMessage;
|
||||
if(g_Config.m_SvDemoChat)
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
|
||||
else
|
||||
|
@ -3815,7 +3852,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
|
|||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "[→ %s] %s", Server()->ClientName(VictimID), pMessage);
|
||||
str_format(aBuf, sizeof(aBuf), "[→ %s] %s", Server()->ClientName(VictimID), aCensoredMessage);
|
||||
SendChatTarget(ClientID, aBuf);
|
||||
}
|
||||
|
||||
|
@ -3824,7 +3861,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
|
|||
protocol7::CNetMsg_Sv_Chat Msg;
|
||||
Msg.m_ClientID = ClientID;
|
||||
Msg.m_Mode = protocol7::CHAT_WHISPER;
|
||||
Msg.m_pMessage = pMessage;
|
||||
Msg.m_pMessage = aCensoredMessage;
|
||||
Msg.m_TargetID = VictimID;
|
||||
|
||||
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, VictimID);
|
||||
|
@ -3834,7 +3871,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
|
|||
CNetMsg_Sv_Chat Msg2;
|
||||
Msg2.m_Team = CHAT_WHISPER_RECV;
|
||||
Msg2.m_ClientID = ClientID;
|
||||
Msg2.m_pMessage = pMessage;
|
||||
Msg2.m_pMessage = aCensoredMessage;
|
||||
if(g_Config.m_SvDemoChat)
|
||||
Server()->SendPackMsg(&Msg2, MSGFLAG_VITAL, VictimID);
|
||||
else
|
||||
|
@ -3842,7 +3879,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
|
|||
}
|
||||
else
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "[← %s] %s", Server()->ClientName(ClientID), pMessage);
|
||||
str_format(aBuf, sizeof(aBuf), "[← %s] %s", Server()->ClientName(ClientID), aCensoredMessage);
|
||||
SendChatTarget(VictimID, aBuf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
#include <game/mapbugs.h>
|
||||
#include <game/voting.h>
|
||||
|
||||
#include <base/tl/array.h>
|
||||
#include <base/tl/string.h>
|
||||
|
||||
#include "eventhandler.h"
|
||||
#include "gamecontroller.h"
|
||||
#include "gameworld.h"
|
||||
|
@ -73,6 +76,7 @@ class CGameContext : public IGameServer
|
|||
CNetObjHandler m_NetObjHandler;
|
||||
CTuningParams m_Tuning;
|
||||
CTuningParams m_aTuningList[NUM_TUNEZONES];
|
||||
array<string> m_aCensorlist;
|
||||
|
||||
bool m_TeeHistorianActive;
|
||||
CTeeHistorian m_TeeHistorian;
|
||||
|
@ -236,6 +240,7 @@ public:
|
|||
virtual void OnPostSnap();
|
||||
|
||||
void *PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID);
|
||||
void CensorMessage(char *pCensoredMessage, const char *pMessage, int Size);
|
||||
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID);
|
||||
|
||||
virtual void OnClientConnected(int ClientID);
|
||||
|
|
Loading…
Reference in a new issue