5461: add penatly to the whole team r=def- a=BloodWod-513

this should fix it #5460

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: BloodWod-513 <dayn_2013@mail.ru>
This commit is contained in:
bors[bot] 2022-06-20 22:20:32 +00:00 committed by GitHub
commit 29be9a79fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View file

@ -852,9 +852,9 @@ void CGameTeams::RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, int T
m_LastSwap[Team] = Server()->Tick(); 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; return;
char aBuf[128]; 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.", "You have to wait %d seconds until you can swap.",
g_Config.m_SvSaveSwapGamesDelay - Since); g_Config.m_SvSaveSwapGamesDelay - Since);
GameServer()->SendChatTarget(pPlayer->GetCID(), aBuf); GameServer()->SendChatTarget(pPrimaryPlayer->GetCID(), aBuf);
return; 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.", "Your swap request timed out %d seconds ago. Use /swap again to re-initiate it.",
Since - g_Config.m_SvSwapTimeout); Since - g_Config.m_SvSwapTimeout);
GameServer()->SendChatTarget(pPlayer->GetCID(), aBuf); GameServer()->SendChatTarget(pPrimaryPlayer->GetCID(), aBuf);
return; return;
} }
CSaveTee PrimarySavedTee; CSaveTee PrimarySavedTee;
PrimarySavedTee.Save(pPlayer->GetCharacter()); PrimarySavedTee.Save(pPrimaryPlayer->GetCharacter());
CSaveTee SecondarySavedTee; CSaveTee SecondarySavedTee;
SecondarySavedTee.Save(pTargetPlayer->GetCharacter()); SecondarySavedTee.Save(pTargetPlayer->GetCharacter());
PrimarySavedTee.Load(pTargetPlayer->GetCharacter(), Team, true); 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()]); if(Team >= 1)
std::swap(m_TeeFinished[pPlayer->GetCID()], m_TeeFinished[pTargetPlayer->GetCID()]); {
std::swap(pPlayer->GetCharacter()->GetRescueTeeRef(), pTargetPlayer->GetCharacter()->GetRescueTeeRef()); 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()) if(GameServer()->TeeHistorianActive())
{ {
GameServer()->TeeHistorian()->RecordPlayerSwap(pPlayer->GetCID(), pTargetPlayer->GetCID()); GameServer()->TeeHistorian()->RecordPlayerSwap(pPrimaryPlayer->GetCID(), pTargetPlayer->GetCID());
} }
str_format(aBuf, sizeof(aBuf), str_format(aBuf, sizeof(aBuf),
"%s has swapped with %s.", "%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); GameServer()->SendChatTeam(Team, aBuf);
} }

View file

@ -121,7 +121,7 @@ public:
void KillSavedTeam(int ClientID, int Team); void KillSavedTeam(int ClientID, int Team);
void ResetSavedTeam(int ClientID, int Team); void ResetSavedTeam(int ClientID, int Team);
void RequestTeamSwap(CPlayer *pPlayer, CPlayer *pTargetPlayer, 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(); void ProcessSaveTeam();
int GetFirstEmptyTeam() const; int GetFirstEmptyTeam() const;