Skip to content

Commit

Permalink
Merge pull request ddnet#9403 from heinrich5991/pr_str_startswith_return
Browse files Browse the repository at this point in the history
Remove use of magic strings
  • Loading branch information
def- authored Dec 19, 2024
2 parents 0662eb7 + 6ab23ed commit 6bf7653
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2176,29 +2176,22 @@ void CGameContext::OnSayNetMessage(const CNetMsg_Cl_Say *pMsg, int ClientId, con

if(pMsg->m_pMessage[0] == '/')
{
if(str_startswith_nocase(pMsg->m_pMessage + 1, "w "))
const char *pWhisper;
if((pWhisper = str_startswith_nocase(pMsg->m_pMessage + 1, "w ")))
{
char aWhisperMsg[256];
str_copy(aWhisperMsg, pMsg->m_pMessage + sizeof("w "));
Whisper(pPlayer->GetCid(), aWhisperMsg);
Whisper(pPlayer->GetCid(), const_cast<char *>(pWhisper));
}
else if(str_startswith_nocase(pMsg->m_pMessage + 1, "whisper "))
else if((pWhisper = str_startswith_nocase(pMsg->m_pMessage + 1, "whisper ")))
{
char aWhisperMsg[256];
str_copy(aWhisperMsg, pMsg->m_pMessage + sizeof("whisper "));
Whisper(pPlayer->GetCid(), aWhisperMsg);
Whisper(pPlayer->GetCid(), const_cast<char *>(pWhisper));
}
else if(str_startswith_nocase(pMsg->m_pMessage + 1, "c "))
else if((pWhisper = str_startswith_nocase(pMsg->m_pMessage + 1, "c ")))
{
char aWhisperMsg[256];
str_copy(aWhisperMsg, pMsg->m_pMessage + sizeof("c "));
Converse(pPlayer->GetCid(), aWhisperMsg);
Converse(pPlayer->GetCid(), const_cast<char *>(pWhisper));
}
else if(str_startswith_nocase(pMsg->m_pMessage + 1, "converse "))
else if((pWhisper = str_startswith_nocase(pMsg->m_pMessage + 1, "converse ")))
{
char aWhisperMsg[256];
str_copy(aWhisperMsg, pMsg->m_pMessage + sizeof("converse "));
Converse(pPlayer->GetCid(), aWhisperMsg);
Converse(pPlayer->GetCid(), const_cast<char *>(pWhisper));
}
else
{
Expand Down

0 comments on commit 6bf7653

Please sign in to comment.