diff --git a/src/game/server/teams.cpp b/src/game/server/teams.cpp index d098d2a35..5299cb2dc 100644 --- a/src/game/server/teams.cpp +++ b/src/game/server/teams.cpp @@ -852,9 +852,9 @@ void CGameTeams::RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int T m_LastSwap[Team] = Server()->Tick(); } -void CGameTeams::SwapTeamCharacters(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team) +void CGameTeams::SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPlayer, int Team) { - if(!pPlayer || !pTargetPlayer) + if(!pPrimaryPlayer || !pTargetPlayer) return; char aBuf[128]; @@ -866,7 +866,7 @@ void CGameTeams::SwapTeamCharacters(CPlayer *pPlayer, CPlayer *pTargetPlayer, in "You have to wait %d seconds until you can swap.", g_Config.m_SvSaveSwapGamesDelay - Since); - GameServer()->SendChatTarget(pPlayer->GetCID(), aBuf); + GameServer()->SendChatTarget(pPrimaryPlayer->GetCID(), aBuf); return; } @@ -886,34 +886,43 @@ void CGameTeams::SwapTeamCharacters(CPlayer *pPlayer, CPlayer *pTargetPlayer, in "Your swap request timed out %d seconds ago. Use /swap again to re-initiate it.", Since - g_Config.m_SvSwapTimeout); - GameServer()->SendChatTarget(pPlayer->GetCID(), aBuf); + GameServer()->SendChatTarget(pPrimaryPlayer->GetCID(), aBuf); return; } CSaveTee PrimarySavedTee; - PrimarySavedTee.Save(pPlayer->GetCharacter()); + PrimarySavedTee.Save(pPrimaryPlayer->GetCharacter()); CSaveTee SecondarySavedTee; SecondarySavedTee.Save(pTargetPlayer->GetCharacter()); PrimarySavedTee.Load(pTargetPlayer->GetCharacter(), Team, true); - SecondarySavedTee.Load(pPlayer->GetCharacter(), Team, true); + SecondarySavedTee.Load(pPrimaryPlayer->GetCharacter(), Team, true); - std::swap(m_TeeStarted[pPlayer->GetCID()], m_TeeStarted[pTargetPlayer->GetCID()]); - std::swap(m_TeeFinished[pPlayer->GetCID()], m_TeeFinished[pTargetPlayer->GetCID()]); - std::swap(pPlayer->GetCharacter()->GetRescueTeeRef(), pTargetPlayer->GetCharacter()->GetRescueTeeRef()); + if(Team >= 1) + { + for(const auto &pPlayer : GameServer()->m_apPlayers) + { + CCharacter *pChar = pPlayer ? pPlayer->GetCharacter() : nullptr; + if(pChar && pChar->Team() == Team && pChar != pPrimaryPlayer->GetCharacter() && pChar != pTargetPlayer->GetCharacter()) + pChar->m_StartTime = pPrimaryPlayer->GetCharacter()->m_StartTime; + } + } + std::swap(m_TeeStarted[pPrimaryPlayer->GetCID()], m_TeeStarted[pTargetPlayer->GetCID()]); + std::swap(m_TeeFinished[pPrimaryPlayer->GetCID()], m_TeeFinished[pTargetPlayer->GetCID()]); + std::swap(pPrimaryPlayer->GetCharacter()->GetRescueTeeRef(), pTargetPlayer->GetCharacter()->GetRescueTeeRef()); - GameServer()->m_World.SwapClients(pPlayer->GetCID(), pTargetPlayer->GetCID()); + GameServer()->m_World.SwapClients(pPrimaryPlayer->GetCID(), pTargetPlayer->GetCID()); if(GameServer()->TeeHistorianActive()) { - GameServer()->TeeHistorian()->RecordPlayerSwap(pPlayer->GetCID(), pTargetPlayer->GetCID()); + GameServer()->TeeHistorian()->RecordPlayerSwap(pPrimaryPlayer->GetCID(), pTargetPlayer->GetCID()); } str_format(aBuf, sizeof(aBuf), "%s has swapped with %s.", - Server()->ClientName(pPlayer->GetCID()), Server()->ClientName(pTargetPlayer->GetCID())); + Server()->ClientName(pPrimaryPlayer->GetCID()), Server()->ClientName(pTargetPlayer->GetCID())); GameServer()->SendChatTeam(Team, aBuf); } diff --git a/src/game/server/teams.h b/src/game/server/teams.h index 86470a667..9ff2c4471 100644 --- a/src/game/server/teams.h +++ b/src/game/server/teams.h @@ -121,7 +121,7 @@ public: void KillSavedTeam(int ClientID, int Team); void ResetSavedTeam(int ClientID, int Team); void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team); - void SwapTeamCharacters(CPlayer *pPlayer, CPlayer *pTargetPlayer, int Team); + void SwapTeamCharacters(CPlayer *pPrimaryPlayer, CPlayer *pTargetPlayer, int Team); void ProcessSaveTeam(); int GetFirstEmptyTeam() const;