From 00b9eab2ceeb6ca060bd13a2b7e2feb28893b79a Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 21 Aug 2024 21:33:34 +0800 Subject: [PATCH 1/2] Rename CHAT_SIX/SEVEN to more generic FLAG_SIX/SEVEN --- src/game/server/gamecontext.cpp | 30 ++++++++++++++-------------- src/game/server/gamecontext.h | 8 ++++---- src/game/server/gamecontroller.cpp | 2 +- src/game/server/gamemodes/DDRace.cpp | 2 +- src/game/server/teams.cpp | 10 +++++----- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index d119b26e5..884ef1e9e 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -546,7 +546,7 @@ void CGameContext::CallVote(int ClientId, const char *pDesc, const char *pCmd, c if(!pPlayer) return; - SendChat(-1, TEAM_ALL, pChatmsg, -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, pChatmsg, -1, FLAG_SIX); if(!pSixupDesc) pSixupDesc = pDesc; @@ -557,7 +557,7 @@ void CGameContext::CallVote(int ClientId, const char *pDesc, const char *pCmd, c pPlayer->m_LastVoteCall = Now; } -void CGameContext::SendChatTarget(int To, const char *pText, int Flags) const +void CGameContext::SendChatTarget(int To, const char *pText, int VersionFlags) const { CNetMsg_Sv_Chat Msg; Msg.m_Team = 0; @@ -571,8 +571,8 @@ void CGameContext::SendChatTarget(int To, const char *pText, int Flags) const { for(int i = 0; i < Server()->MaxClients(); i++) { - if(!((Server()->IsSixup(i) && (Flags & CHAT_SIXUP)) || - (!Server()->IsSixup(i) && (Flags & CHAT_SIX)))) + if(!((Server()->IsSixup(i) && (VersionFlags & FLAG_SIXUP)) || + (!Server()->IsSixup(i) && (VersionFlags & FLAG_SIX)))) continue; Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, i); @@ -580,8 +580,8 @@ void CGameContext::SendChatTarget(int To, const char *pText, int Flags) const } else { - if(!((Server()->IsSixup(To) && (Flags & CHAT_SIXUP)) || - (!Server()->IsSixup(To) && (Flags & CHAT_SIX)))) + if(!((Server()->IsSixup(To) && (VersionFlags & FLAG_SIXUP)) || + (!Server()->IsSixup(To) && (VersionFlags & FLAG_SIX)))) return; Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, To); @@ -595,7 +595,7 @@ void CGameContext::SendChatTeam(int Team, const char *pText) const SendChatTarget(i, pText); } -void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText, int SpamProtectionClientId, int Flags) +void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText, int SpamProtectionClientId, int VersionFlags) { if(SpamProtectionClientId >= 0 && SpamProtectionClientId < MAX_CLIENTS) if(ProcessSpamProtection(SpamProtectionClientId)) @@ -631,8 +631,8 @@ void CGameContext::SendChat(int ChatterClientId, int Team, const char *pText, in { if(!m_apPlayers[i]) continue; - bool Send = (Server()->IsSixup(i) && (Flags & CHAT_SIXUP)) || - (!Server()->IsSixup(i) && (Flags & CHAT_SIX)); + bool Send = (Server()->IsSixup(i) && (VersionFlags & FLAG_SIXUP)) || + (!Server()->IsSixup(i) && (VersionFlags & FLAG_SIX)); if(!m_apPlayers[i]->m_DND && Send) Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, i); @@ -1181,7 +1181,7 @@ void CGameContext::OnTick() Console()->ExecuteLine(m_aVoteCommand); Server()->SetRconCid(IServer::RCON_CID_SERV); EndVote(); - SendChat(-1, TEAM_ALL, "Vote passed", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote passed", -1, FLAG_SIX); if(m_apPlayers[m_VoteCreator] && !IsKickVote() && !IsSpecVote()) m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; @@ -1189,22 +1189,22 @@ void CGameContext::OnTick() else if(m_VoteEnforce == VOTE_ENFORCE_YES_ADMIN) { Console()->ExecuteLine(m_aVoteCommand, m_VoteEnforcer); - SendChat(-1, TEAM_ALL, "Vote passed enforced by authorized player", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote passed enforced by authorized player", -1, FLAG_SIX); EndVote(); } else if(m_VoteEnforce == VOTE_ENFORCE_NO_ADMIN) { EndVote(); - SendChat(-1, TEAM_ALL, "Vote failed enforced by authorized player", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote failed enforced by authorized player", -1, FLAG_SIX); } //else if(m_VoteEnforce == VOTE_ENFORCE_NO || time_get() > m_VoteCloseTime) else if(m_VoteEnforce == VOTE_ENFORCE_NO || (time_get() > m_VoteCloseTime && g_Config.m_SvVoteMajority)) { EndVote(); if(VetoStop || (m_VoteWillPass && Veto)) - SendChat(-1, TEAM_ALL, "Vote failed because of veto. Find an empty server instead", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote failed because of veto. Find an empty server instead", -1, FLAG_SIX); else - SendChat(-1, TEAM_ALL, "Vote failed", -1, CHAT_SIX); + SendChat(-1, TEAM_ALL, "Vote failed", -1, FLAG_SIX); } else if(m_VoteUpdate) { @@ -3345,7 +3345,7 @@ void CGameContext::ConForceVote(IConsole::IResult *pResult, void *pUserData) if(str_comp_nocase(pValue, pOption->m_aDescription) == 0) { str_format(aBuf, sizeof(aBuf), "authorized player forced server option '%s' (%s)", pValue, pReason); - pSelf->SendChatTarget(-1, aBuf, CHAT_SIX); + pSelf->SendChatTarget(-1, aBuf, FLAG_SIX); pSelf->Console()->ExecuteLine(pOption->m_aCommand); break; } diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 4cbd518ee..62e235cae 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -250,15 +250,15 @@ public: enum { - CHAT_SIX = 1 << 0, - CHAT_SIXUP = 1 << 1, + FLAG_SIX = 1 << 0, + FLAG_SIXUP = 1 << 1, }; // network void CallVote(int ClientId, const char *pDesc, const char *pCmd, const char *pReason, const char *pChatmsg, const char *pSixupDesc = 0); - void SendChatTarget(int To, const char *pText, int Flags = CHAT_SIX | CHAT_SIXUP) const; + void SendChatTarget(int To, const char *pText, int VersionFlags = FLAG_SIX | FLAG_SIXUP) const; void SendChatTeam(int Team, const char *pText) const; - void SendChat(int ClientId, int Team, const char *pText, int SpamProtectionClientId = -1, int Flags = CHAT_SIX | CHAT_SIXUP); + void SendChat(int ClientId, int Team, const char *pText, int SpamProtectionClientId = -1, int VersionFlags = FLAG_SIX | FLAG_SIXUP); void SendStartWarning(int ClientId, const char *pMessage); void SendEmoticon(int ClientId, int Emoticon, int TargetClientId) const; void SendWeaponPickup(int ClientId, int Weapon) const; diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 41c11a7c7..3ca74ba05 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -410,7 +410,7 @@ void IGameController::OnPlayerDisconnect(class CPlayer *pPlayer, const char *pRe str_format(aBuf, sizeof(aBuf), "'%s' has left the game (%s)", Server()->ClientName(ClientId), pReason); else str_format(aBuf, sizeof(aBuf), "'%s' has left the game", Server()->ClientName(ClientId)); - GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::FLAG_SIX); str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", ClientId, Server()->ClientName(ClientId)); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf); diff --git a/src/game/server/gamemodes/DDRace.cpp b/src/game/server/gamemodes/DDRace.cpp index 81a63507c..efbef3c52 100644 --- a/src/game/server/gamemodes/DDRace.cpp +++ b/src/game/server/gamemodes/DDRace.cpp @@ -127,7 +127,7 @@ void CGameControllerDDRace::OnPlayerConnect(CPlayer *pPlayer) { char aBuf[512]; str_format(aBuf, sizeof(aBuf), "'%s' entered and joined the %s", Server()->ClientName(ClientId), GetTeamName(pPlayer->GetTeam())); - GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::FLAG_SIX); GameServer()->SendChatTarget(ClientId, "DDraceNetwork Mod. Version: " GAME_VERSION); GameServer()->SendChatTarget(ClientId, "please visit DDNet.org or say /info and make sure to read our /rules"); diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index 5472bd9a1..6e255f653 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -711,9 +711,9 @@ void CGameTeams::OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp Server()->ClientName(ClientId), (int)Time / 60, Time - ((int)Time / 60 * 60)); if(g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores) - GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::CHAT_SIX); + GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::FLAG_SIX); else - GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1., CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1., CGameContext::FLAG_SIX); float Diff = absolute(Time - pData->m_BestTime); @@ -730,9 +730,9 @@ void CGameTeams::OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp str_format(aBuf, sizeof(aBuf), "New record: %5.2f second(s) better.", Diff); if(g_Config.m_SvHideScore || !g_Config.m_SvSaveWorseScores) - GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::CHAT_SIX); + GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::FLAG_SIX); else - GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::CHAT_SIX); + GameServer()->SendChat(-1, TEAM_ALL, aBuf, -1, CGameContext::FLAG_SIX); } else if(pData->m_BestTime != 0) // tee has already finished? { @@ -752,7 +752,7 @@ void CGameTeams::OnFinish(CPlayer *Player, int TimeTicks, const char *pTimestamp str_format(aBuf, sizeof(aBuf), "%5.2f second(s) worse, better luck next time.", Diff); - GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::CHAT_SIX); // this is private, sent only to the tee + GameServer()->SendChatTarget(ClientId, aBuf, CGameContext::FLAG_SIX); // this is private, sent only to the tee } } else From dcd1fefa7e99bd4ea3bb1f351a20a2096443a6da Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Wed, 21 Aug 2024 21:42:45 +0800 Subject: [PATCH 2/2] Never send sounds to sixup that are played on the client side Closed #2523 --- src/game/server/entities/character.cpp | 15 +++++++-------- src/game/server/teams.cpp | 5 ++++- src/game/server/teams.h | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index fd704d571..001b73fe2 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -851,24 +851,23 @@ void CCharacter::TickDeferred() int Events = m_Core.m_TriggeredEvents; int CID = m_pPlayer->GetCid(); - CClientMask TeamMask = Teams()->TeamMask(Team(), -1, CID); - // Some sounds are triggered client-side for the acting player + // Some sounds are triggered client-side for the acting player (or for all players on Sixup) // so we need to avoid duplicating them - CClientMask TeamMaskExceptSelf = Teams()->TeamMask(Team(), CID, CID); + CClientMask TeamMaskExceptSelfAndSixup = Teams()->TeamMask(Team(), -1, CID, CGameContext::FLAG_SIX); // Some are triggered client-side but only on Sixup - CClientMask TeamMaskExceptSelfIfSixup = Server()->IsSixup(CID) ? TeamMaskExceptSelf : TeamMask; + CClientMask TeamMaskExceptSixup = Teams()->TeamMask(Team(), -1, CID, CGameContext::FLAG_SIX); if(Events & COREEVENT_GROUND_JUMP) - GameServer()->CreateSound(m_Pos, SOUND_PLAYER_JUMP, TeamMaskExceptSelf); + GameServer()->CreateSound(m_Pos, SOUND_PLAYER_JUMP, TeamMaskExceptSelfAndSixup); if(Events & COREEVENT_HOOK_ATTACH_PLAYER) - GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_PLAYER, TeamMaskExceptSelfIfSixup); + GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_PLAYER, TeamMaskExceptSixup); if(Events & COREEVENT_HOOK_ATTACH_GROUND) - GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_GROUND, TeamMaskExceptSelf); + GameServer()->CreateSound(m_Pos, SOUND_HOOK_ATTACH_GROUND, TeamMaskExceptSelfAndSixup); if(Events & COREEVENT_HOOK_HIT_NOHOOK) - GameServer()->CreateSound(m_Pos, SOUND_HOOK_NOATTACH, TeamMaskExceptSelf); + GameServer()->CreateSound(m_Pos, SOUND_HOOK_NOATTACH, TeamMaskExceptSelfAndSixup); if(Events & COREEVENT_GROUND_JUMP) m_TriggeredEvents7 |= protocol7::COREEVENTFLAG_GROUND_JUMP; diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index 6e255f653..2f4b58bdf 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -507,7 +507,7 @@ bool CGameTeams::TeamFinished(int Team) return true; } -CClientMask CGameTeams::TeamMask(int Team, int ExceptId, int Asker) +CClientMask CGameTeams::TeamMask(int Team, int ExceptId, int Asker, int VersionFlags) { if(Team == TEAM_SUPER) { @@ -523,6 +523,9 @@ CClientMask CGameTeams::TeamMask(int Team, int ExceptId, int Asker) continue; // Explicitly excluded if(!GetPlayer(i)) continue; // Player doesn't exist + if(!((Server()->IsSixup(i) && (VersionFlags & CGameContext::FLAG_SIXUP)) || + (!Server()->IsSixup(i) && (VersionFlags & CGameContext::FLAG_SIX)))) + continue; if(!(GetPlayer(i)->GetTeam() == TEAM_SPECTATORS || GetPlayer(i)->IsPaused())) { // Not spectator diff --git a/src/game/server/teams.h b/src/game/server/teams.h index fec2af311..a836dc71e 100644 --- a/src/game/server/teams.h +++ b/src/game/server/teams.h @@ -97,7 +97,7 @@ public: void ChangeTeamState(int Team, int State); - CClientMask TeamMask(int Team, int ExceptId = -1, int Asker = -1); + CClientMask TeamMask(int Team, int ExceptId = -1, int Asker = -1, int VersionFlags = CGameContext::FLAG_SIX | CGameContext::FLAG_SIXUP); int Count(int Team) const;