6227: Fix more issues with the `restart` command r=def- a=Robyt3

Closes #6168.

Not resetting the team when restarting requires too much effort for a feature that would only be active with the non-default `sv_rejoin_team_0 0` setting. If the `restart` command is used for testing a map or for tournaments, it would be easy enough as a workaround to create a bind to join a specific team after restarting, so I don't think this is necessary.

## 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 (especially base/) or added coverage to integration test
- [ ] 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: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2023-01-03 23:16:27 +00:00 committed by GitHub
commit 4ca0506690
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 17 deletions

View file

@ -810,18 +810,10 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dumm
for(i = 0; i < MAX_CLIENTS; i++) for(i = 0; i < MAX_CLIENTS; i++)
{ {
int Team = pUnpacker->GetInt(); const int Team = pUnpacker->GetInt();
bool WentWrong = false; if(!pUnpacker->Error() && Team >= TEAM_FLOCK && Team <= TEAM_SUPER)
if(pUnpacker->Error())
WentWrong = true;
if(!WentWrong && Team >= TEAM_FLOCK && Team <= TEAM_SUPER)
m_Teams.Team(i, Team); m_Teams.Team(i, Team);
else else
WentWrong = true;
if(WentWrong)
{ {
m_Teams.Team(i, 0); m_Teams.Team(i, 0);
break; break;
@ -883,6 +875,17 @@ void CGameClient::OnStartGame()
m_Statboard.OnReset(); m_Statboard.OnReset();
} }
void CGameClient::OnStartRound()
{
// In GamePaused or GameOver state RoundStartTick is updated on each tick
// hence no need to reset stats until player leaves GameOver
// and it would be a mistake to reset stats after or during the pause
m_Statboard.OnReset();
// Restart automatic race demo recording
m_RaceDemo.OnReset();
}
void CGameClient::OnFlagGrab(int TeamID) void CGameClient::OnFlagGrab(int TeamID)
{ {
if(TeamID == TEAM_RED) if(TeamID == TEAM_RED)
@ -1404,14 +1407,10 @@ void CGameClient::OnNewSnapshot()
OnGameOver(); OnGameOver();
else if(s_GameOver && !CurrentTickGameOver) else if(s_GameOver && !CurrentTickGameOver)
OnStartGame(); OnStartGame();
// Reset statboard when new round is started (RoundStartTick changed) // Handle case that a new round is started (RoundStartTick changed)
// New round is usually started after `restart` on server // New round is usually started after `restart` on server
if(m_Snap.m_pGameInfoObj->m_RoundStartTick != m_LastRoundStartTick if(m_Snap.m_pGameInfoObj->m_RoundStartTick != m_LastRoundStartTick && !(CurrentTickGameOver || m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED || s_GamePaused))
// In GamePaused or GameOver state RoundStartTick is updated on each tick OnStartRound();
// hence no need to reset stats until player leaves GameOver
// and it would be a mistake to reset stats after or during the pause
&& !(CurrentTickGameOver || m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED || s_GamePaused))
m_Statboard.OnReset();
m_LastRoundStartTick = m_Snap.m_pGameInfoObj->m_RoundStartTick; m_LastRoundStartTick = m_Snap.m_pGameInfoObj->m_RoundStartTick;
s_GameOver = CurrentTickGameOver; s_GameOver = CurrentTickGameOver;
s_GamePaused = (bool)(m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED); s_GamePaused = (bool)(m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED);

View file

@ -470,6 +470,7 @@ public:
void OnRconLine(const char *pLine) override; void OnRconLine(const char *pLine) override;
virtual void OnGameOver(); virtual void OnGameOver();
virtual void OnStartGame(); virtual void OnStartGame();
virtual void OnStartRound();
virtual void OnFlagGrab(int TeamID); virtual void OnFlagGrab(int TeamID);
void OnWindowResize(); void OnWindowResize();

View file

@ -24,6 +24,7 @@ void CGameTeams::Reset()
m_aTeeStarted[i] = false; m_aTeeStarted[i] = false;
m_aTeeFinished[i] = false; m_aTeeFinished[i] = false;
m_aLastChat[i] = 0; m_aLastChat[i] = 0;
SendTeamsState(i);
} }
for(int i = 0; i < NUM_TEAMS; ++i) for(int i = 0; i < NUM_TEAMS; ++i)