Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions progs/ssqc.src
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ gamemodes/core.qc
tests/test_math.qc
tests/test_perksacola.qc
tests/test_weapons.qc
tests/test_rounds.qc
tests/test_misc_model.qc
tests/test_score.qc
tests/test_ai.qc
Expand Down
2 changes: 1 addition & 1 deletion source/server/player/player_core.qc
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ void() PlayerSpawn =

#endif // FTE

rounds = cvar("sv_startround") - 1;
if (rounds < cvar("sv_startround")) rounds = cvar("sv_startround") - 1;
if (rounds < 0) rounds = 0;

// Make sure players joining after game start are still allowed
Expand Down
3 changes: 2 additions & 1 deletion source/server/tests/test_module.qc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ var struct {
{ Test_AddScore_MysteryBoxLeave, "Test_AddScore_MysteryBoxLeave" },
{ Test_AI_HellhoundsDetected, "Test_AI_HellhoundsDetected" },
{ Test_Power_HandleResetOnRestart, "Test_Power_HandleResetOnRestart" },
{ Test_EndGame_CounterResetsOnRestart, "Test_EndGame_CounterResetsOnRestart" }
{ Test_EndGame_CounterResetsOnRestart, "Test_EndGame_CounterResetsOnRestart" },
{ Test_Round_PlayerSpawnSetsRoundProperly, "Test_Round_PlayerSpawnSetsRoundProperly" }
};

void() Test_RunAllTests =
Expand Down
58 changes: 58 additions & 0 deletions source/server/tests/test_rounds.qc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
server/tests/test_rounds.qc

Unit tests related to rounds.

Copyright (C) 2021-2025 NZ:P Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to:

Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA

*/
float(float condition, string message) Test_Assert;
void(string message) Test_Skip;

//
// Test_Round_PlayerSpawnSetsRoundProperly()
// Validate that PlayerSpawn() only sets the round when needed (at the game start).
// This prevents the round resetting whenever a player joins the game.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this line because this isn't fixing or preventing anything, just testing its behaviors

// (https://github.com/nzp-team/nzportable/issues/1185)
//
void() Test_Round_PlayerSpawnSetsRoundProperly =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you confirm that this test functioned properly (failed) before writing your fix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I hadn't. The test still passes when the change is reverted. I'll need to go back and revise the test (and the code).

{
float backup_round, backup_startround;

// Backup our rounds / start round, and then set them.
backup_round = rounds;
backup_startround = cvar("sv_startround");
rounds = 21;
cvar_set("sv_startround", "0");

// Make sure that our rounds value is still 21.
PlayerSpawn();
Test_Assert(rounds == 21, "Rounds value is being incorrectly reset!");

// Make sure that a negative round value properly sets as well.
rounds = -3;
PlayerSpawn();
Test_Assert(rounds == 0, "Rounds value is not being correctly reset!");

// Restore original values.
rounds = backup_round;
cvar_set("sv_startround", ftos(backup_startround));
};