Skip to content

Commit

Permalink
Add cl_silent_chat_commands to not send cmds to chat
Browse files Browse the repository at this point in the history
Closed #166
  • Loading branch information
ChillerDragon committed Oct 12, 2024
1 parent 55d8a0d commit fb5101b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ You can use those commands in chat to color names:
- ``!team <name>``
- ``!delteam <name>``

The commands will end up in public chat by default. They can be hidden with the following console command: ``cl_silent_chat_commands 1``

![warlist simple preview](https://raw.githubusercontent.com/ChillerDragon/cdn/master/chillerbot_warlist_basic.gif)

**Advanced warlist (not recommended for beginners):**
Expand Down
1 change: 1 addition & 0 deletions src/engine/shared/chillerbot/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ MACRO_CONFIG_INT(ClDbgIntersect, cl_dbg_intersect, 0, 0, 1, CFGFLAG_CLIENT, "Sho
MACRO_CONFIG_INT(ClReleaseMouse, cl_release_mouse, 0, 0, 1, CFGFLAG_CLIENT, "Release the mouse (you probably do not want this)")
MACRO_CONFIG_STR(ClRunOnVoteStart, cl_run_on_vote_start, 512, "", CFGFLAG_CLIENT | CFGFLAG_SAVE, "console command to run when a vote is called")
MACRO_CONFIG_INT(ClMineTeeEditor, cl_mine_tee_editor, 0, 0, 1, CFGFLAG_CLIENT, "send modify map packets to the server while brushing in the editor")
MACRO_CONFIG_INT(ClSilentChatCommands, cl_silent_chat_commands, 0, 0, 1, CFGFLAG_CLIENT, "do not send internal chat commands like !help to the server")

#if defined(CONF_CURSES_CLIENT)
MACRO_CONFIG_INT(ClTermHistory, cl_term_history, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Persist input history in filesystem for curses client")
Expand Down
5 changes: 3 additions & 2 deletions src/game/client/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,9 @@ void CChat::SendChat(int Team, const char *pLine)
if(*str_utf8_skip_whitespaces(pLine) == '\0')
return;

if(!m_pClient->m_ChillerBotUX.OnSendChat(Team, pLine))
return;

m_LastChatSend = time();

if(m_pClient->Client()->IsSixup())
Expand All @@ -1332,8 +1335,6 @@ void CChat::SendChat(int Team, const char *pLine)
Msg.m_Team = Team;
Msg.m_pMessage = pLine;
Client()->SendPackMsgActive(&Msg, MSGFLAG_VITAL);

m_pClient->m_ChillerBotUX.ReturnFromAfk(pLine);
}

void CChat::SendChatQueued(const char *pLine)
Expand Down
21 changes: 15 additions & 6 deletions src/game/client/components/chillerbot/chatcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ void CChatCommand::OnServerMsg(const char *pMsg)
{
}

void CChatCommand::OnChatMsg(int ClientId, int Team, const char *pMsg)
bool CChatCommand::OnChatMsg(int ClientId, int Team, const char *pMsg)
{
if(!pMsg[1])
return;
return false;
if(pMsg[0] == '.' || pMsg[0] == ':' || pMsg[0] == '!' || pMsg[0] == '#' || pMsg[0] == '$' || pMsg[0] == '/')
if(ParseChatCmd(pMsg[0], ClientId, Team, pMsg + 1))
return;
return true;

OnNoChatCommandMatches(ClientId, Team, pMsg);
return false;
}

void CChatCommand::OnNoChatCommandMatches(int ClientId, int Team, const char *pMsg)
Expand Down Expand Up @@ -152,9 +153,17 @@ void CChatCommand::OnMessage(int MsgType, void *pRawMsg)
if(MsgType == NETMSGTYPE_SV_CHAT)
{
CNetMsg_Sv_Chat *pMsg = (CNetMsg_Sv_Chat *)pRawMsg;
if(pMsg->m_ClientId == -1 && pMsg->m_Team < 2)
int ClientId = pMsg->m_ClientId;
if(ClientId == -1 && pMsg->m_Team < 2)
{
OnServerMsg(pMsg->m_pMessage);
else
OnChatMsg(pMsg->m_ClientId, pMsg->m_Team, pMsg->m_pMessage);
}
// ignore own messages
// they get processed on send
// if the server spoofs us we drop it
else if(ClientId != m_pClient->m_aLocalIds[0] && (!m_pClient->Client()->DummyConnected() || ClientId != m_pClient->m_aLocalIds[1]))
{
OnChatMsg(ClientId, pMsg->m_Team, pMsg->m_pMessage);
}
}
}
6 changes: 5 additions & 1 deletion src/game/client/components/chillerbot/chatcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class CChatCommand : public CComponent
virtual void OnMessage(int MsgType, void *pRawMsg) override;

void OnServerMsg(const char *pMsg);
void OnChatMsg(int ClientId, int Team, const char *pMsg);
bool ParseChatCmd(char Prefix, int ClientId, int Team, const char *pCmdWithArgs);

/*
Expand Down Expand Up @@ -36,6 +35,11 @@ class CChatCommand : public CComponent

public:
virtual int Sizeof() const override { return sizeof(*this); }

// will be called on send of our on messages
// and on receive of all other messages
// returns true if a valid chat command was matched
bool OnChatMsg(int ClientId, int Team, const char *pMsg);
};

#endif
15 changes: 15 additions & 0 deletions src/game/client/components/chillerbot/chillerbotux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <engine/engine.h>
#include <engine/graphics.h>
#include <engine/keys.h>
#include <engine/shared/config.h>
#include <engine/shared/json.h>
#include <engine/shared/protocol.h>
#include <engine/textrender.h>
Expand Down Expand Up @@ -132,6 +133,20 @@ void CChillerBotUX::OnRender()
m_LastForceDir = m_ForceDir;
}

bool CChillerBotUX::OnSendChat(int Team, const char *pLine)
{
ReturnFromAfk(pLine);

int ClientId = m_pClient->m_aLocalIds[g_Config.m_ClDummy];
if(m_pClient->m_ChatCommand.OnChatMsg(ClientId, Team, pLine))
{
if(g_Config.m_ClSilentChatCommands)
return false;
}

return true;
}

void CChillerBotUX::OnStateChange(int NewState, int OldState)
{
if(NewState == IClient::STATE_OFFLINE && m_pClient->Client()->ReconnectTime() == 0)
Expand Down
3 changes: 3 additions & 0 deletions src/game/client/components/chillerbot/chillerbotux.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class CChillerBotUX : public CComponent
virtual int Sizeof() const override { return sizeof(*this); }
int m_IgnoreChatAfk;

// return false to drop the message
bool OnSendChat(int Team, const char *pLine);

void ReturnFromAfk(const char *pChatMessage = 0);
int64_t GetAfkTime() { return m_AfkTill; }
const char *GetAfkMessage() { return m_aAfkMessage; }
Expand Down

0 comments on commit fb5101b

Please sign in to comment.