2861: Implement censoring words on server r=heinrich5991 a=def-



Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2020-09-25 23:07:15 +00:00 committed by GitHub
commit 8b399ba1be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 7 deletions

View file

@ -740,6 +740,7 @@ set(EXPECTED_DATA
audio/wp_switch-03.wv audio/wp_switch-03.wv
blob.png blob.png
browse_icons.png browse_icons.png
censorlist.txt
console.png console.png
console_bar.png console_bar.png
countryflags/AD.png countryflags/AD.png

0
data/censorlist.txt Normal file
View file

View file

@ -1607,6 +1607,18 @@ void *CGameContext::PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID
return m_NetObjHandler.SecureUnpackMsg(*MsgID, pUnpacker); 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) void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
{ {
if(m_TeeHistorianActive) if(m_TeeHistorianActive)
@ -1748,7 +1760,11 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
} }
} }
else 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) else if(MsgID == NETMSGTYPE_CL_CALLVOTE)
{ {
@ -3078,6 +3094,24 @@ void CGameContext::OnInit(/*class IKernel *pKernel*/)
m_pController = new CGameControllerDDRace(this); m_pController = new CGameControllerDDRace(this);
((CGameControllerDDRace*)m_pController)->m_Teams.Reset(); ((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; m_TeeHistorianActive = g_Config.m_SvTeeHistorian;
if(m_TeeHistorianActive) if(m_TeeHistorianActive)
{ {
@ -3790,6 +3824,9 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
if(m_apPlayers[ClientID]) if(m_apPlayers[ClientID])
m_apPlayers[ClientID]->m_LastWhisperTo = VictimID; m_apPlayers[ClientID]->m_LastWhisperTo = VictimID;
char aCensoredMessage[256];
CensorMessage(aCensoredMessage, pMessage, sizeof(aCensoredMessage));
char aBuf[256]; char aBuf[256];
if(Server()->IsSixup(ClientID)) if(Server()->IsSixup(ClientID))
@ -3797,7 +3834,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
protocol7::CNetMsg_Sv_Chat Msg; protocol7::CNetMsg_Sv_Chat Msg;
Msg.m_ClientID = ClientID; Msg.m_ClientID = ClientID;
Msg.m_Mode = protocol7::CHAT_WHISPER; Msg.m_Mode = protocol7::CHAT_WHISPER;
Msg.m_pMessage = pMessage; Msg.m_pMessage = aCensoredMessage;
Msg.m_TargetID = VictimID; Msg.m_TargetID = VictimID;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID); 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; CNetMsg_Sv_Chat Msg;
Msg.m_Team = CHAT_WHISPER_SEND; Msg.m_Team = CHAT_WHISPER_SEND;
Msg.m_ClientID = VictimID; Msg.m_ClientID = VictimID;
Msg.m_pMessage = pMessage; Msg.m_pMessage = aCensoredMessage;
if(g_Config.m_SvDemoChat) if(g_Config.m_SvDemoChat)
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
else else
@ -3815,7 +3852,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
} }
else 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); SendChatTarget(ClientID, aBuf);
} }
@ -3824,7 +3861,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
protocol7::CNetMsg_Sv_Chat Msg; protocol7::CNetMsg_Sv_Chat Msg;
Msg.m_ClientID = ClientID; Msg.m_ClientID = ClientID;
Msg.m_Mode = protocol7::CHAT_WHISPER; Msg.m_Mode = protocol7::CHAT_WHISPER;
Msg.m_pMessage = pMessage; Msg.m_pMessage = aCensoredMessage;
Msg.m_TargetID = VictimID; Msg.m_TargetID = VictimID;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, 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; CNetMsg_Sv_Chat Msg2;
Msg2.m_Team = CHAT_WHISPER_RECV; Msg2.m_Team = CHAT_WHISPER_RECV;
Msg2.m_ClientID = ClientID; Msg2.m_ClientID = ClientID;
Msg2.m_pMessage = pMessage; Msg2.m_pMessage = aCensoredMessage;
if(g_Config.m_SvDemoChat) if(g_Config.m_SvDemoChat)
Server()->SendPackMsg(&Msg2, MSGFLAG_VITAL, VictimID); Server()->SendPackMsg(&Msg2, MSGFLAG_VITAL, VictimID);
else else
@ -3842,7 +3879,7 @@ void CGameContext::WhisperID(int ClientID, int VictimID, const char *pMessage)
} }
else 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); SendChatTarget(VictimID, aBuf);
} }
} }

View file

@ -12,6 +12,9 @@
#include <game/mapbugs.h> #include <game/mapbugs.h>
#include <game/voting.h> #include <game/voting.h>
#include <base/tl/array.h>
#include <base/tl/string.h>
#include "eventhandler.h" #include "eventhandler.h"
#include "gamecontroller.h" #include "gamecontroller.h"
#include "gameworld.h" #include "gameworld.h"
@ -73,6 +76,7 @@ class CGameContext : public IGameServer
CNetObjHandler m_NetObjHandler; CNetObjHandler m_NetObjHandler;
CTuningParams m_Tuning; CTuningParams m_Tuning;
CTuningParams m_aTuningList[NUM_TUNEZONES]; CTuningParams m_aTuningList[NUM_TUNEZONES];
array<string> m_aCensorlist;
bool m_TeeHistorianActive; bool m_TeeHistorianActive;
CTeeHistorian m_TeeHistorian; CTeeHistorian m_TeeHistorian;
@ -236,6 +240,7 @@ public:
virtual void OnPostSnap(); virtual void OnPostSnap();
void *PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID); 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 OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID);
virtual void OnClientConnected(int ClientID); virtual void OnClientConnected(int ClientID);