Skip to content

Commit

Permalink
Never send sounds to sixup that are played on the client side
Browse files Browse the repository at this point in the history
Closed ddnet#2523
  • Loading branch information
ChillerDragon committed Aug 21, 2024
1 parent 00b9eab commit dcd1fef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/game/server/entities/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/game/server/teams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/game/server/teams.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CGameTeams

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;

Expand Down

0 comments on commit dcd1fef

Please sign in to comment.