MCPcopy Create free account
hub / github.com/ddnet/ddnet / SendChat

Method SendChat

src/game/server/gamecontext.cpp:637–718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

635}
636
637void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText, int SpamProtectionClientId, int VersionFlags)
638{
639 dbg_assert(ChatterClientId >= -1 && ChatterClientId < MAX_CLIENTS, "ChatterClientId invalid: %d", ChatterClientId);
640
641 if(SpamProtectionClientId >= 0 && SpamProtectionClientId < MAX_CLIENTS)
642 if(ProcessSpamProtection(SpamProtectionClientId))
643 return;
644
645 char aText[256];
646 str_copy(aText, pText, sizeof(aText));
647 const char *pTeamString = Team == TEAM_ALL ? "chat" : "teamchat";
648 if(ChatterClientId == -1)
649 {
650 log_info(pTeamString, "*** %s", aText);
651 }
652 else
653 {
654 log_info(pTeamString, "%d:%d:%s: %s", ChatterClientId, Team, Server()->ClientName(ChatterClientId), aText);
655 }
656
657 if(Team == TEAM_ALL)
658 {
659 CNetMsg_Sv_Chat Msg;
660 Msg.m_Team = 0;
661 Msg.m_ClientId = ChatterClientId;
662 Msg.m_pMessage = aText;
663
664 // pack one for the recording only
665 if(g_Config.m_SvDemoChat)
666 Server()->SendPackMsg(&Msg, MSGFLAG_NOSEND, SERVER_DEMO_CLIENT);
667
668 // send to the clients
669 for(int i = 0; i < Server()->MaxClients(); i++)
670 {
671 if(!m_apPlayers[i])
672 continue;
673 bool Send = (Server()->IsSixup(i) && (VersionFlags & FLAG_SIXUP)) ||
674 (!Server()->IsSixup(i) && (VersionFlags & FLAG_SIX));
675
676 if(!m_apPlayers[i]->m_DND && Send)
677 Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, i);
678 }
679
680 char aBuf[sizeof(aText) + 8];
681 str_format(aBuf, sizeof(aBuf), "Chat: %s", aText);
682 LogEvent(aBuf, ChatterClientId);
683 }
684 else
685 {
686 CTeamsCore *pTeams = &m_pController->Teams().m_Core;
687 CNetMsg_Sv_Chat Msg;
688 Msg.m_Team = 1;
689 Msg.m_ClientId = ChatterClientId;
690 Msg.m_pMessage = aText;
691
692 // pack one for the recording only
693 if(g_Config.m_SvDemoChat)
694 Server()->SendPackMsg(&Msg, MSGFLAG_NOSEND, SERVER_DEMO_CLIENT);

Callers 15

ConKillPlayerMethod · 0.45
ConModerateMethod · 0.45
OnTeamFinishMethod · 0.45
OnFinishMethod · 0.45
ConSayTimeAllMethod · 0.45
OnPlayerDisconnectMethod · 0.45
DoTeamChangeMethod · 0.45
ConSayMethod · 0.45
ConSetTeamAllMethod · 0.45
TickMethod · 0.45
PauseMethod · 0.45

Calls 10

str_formatFunction · 0.85
ClientNameMethod · 0.80
GetTeamMethod · 0.80
str_copyFunction · 0.50
ServerClass · 0.50
SendPackMsgMethod · 0.45
MaxClientsMethod · 0.45
IsSixupMethod · 0.45
TeamsMethod · 0.45
TeamMethod · 0.45

Tested by

no test coverage detected