Skip to content

Commit 621b948

Browse files
committed
SERVER: Ensure PlayerSpawn() only resets rounds when appropriate
1 parent 41fe610 commit 621b948

4 files changed

Lines changed: 62 additions & 2 deletions

File tree

progs/ssqc.src

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ gamemodes/core.qc
8888
tests/test_math.qc
8989
tests/test_perksacola.qc
9090
tests/test_weapons.qc
91+
tests/test_rounds.qc
9192
tests/test_misc_model.qc
9293
tests/test_score.qc
9394
tests/test_ai.qc

source/server/player/player_core.qc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ void() PlayerSpawn =
10941094

10951095
#endif // FTE
10961096

1097-
rounds = cvar("sv_startround") - 1;
1097+
if (rounds < cvar("sv_startround")) rounds = cvar("sv_startround") - 1;
10981098
if (rounds < 0) rounds = 0;
10991099

11001100
// Make sure players joining after game start are still allowed

source/server/tests/test_module.qc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ var struct {
157157
{ Test_AddScore_MysteryBoxLeave, "Test_AddScore_MysteryBoxLeave" },
158158
{ Test_AI_HellhoundsDetected, "Test_AI_HellhoundsDetected" },
159159
{ Test_Power_HandleResetOnRestart, "Test_Power_HandleResetOnRestart" },
160-
{ Test_EndGame_CounterResetsOnRestart, "Test_EndGame_CounterResetsOnRestart" }
160+
{ Test_EndGame_CounterResetsOnRestart, "Test_EndGame_CounterResetsOnRestart" },
161+
{ Test_Round_PlayerSpawnSetsRoundProperly, "Test_Round_PlayerSpawnSetsRoundProperly" }
161162
};
162163

163164
void() Test_RunAllTests =

source/server/tests/test_rounds.qc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
server/tests/test_rounds.qc
3+
4+
Unit tests related to rounds.
5+
6+
Copyright (C) 2021-2025 NZ:P Team
7+
8+
This program is free software; you can redistribute it and/or
9+
modify it under the terms of the GNU General Public License
10+
as published by the Free Software Foundation; either version 2
11+
of the License, or (at your option) any later version.
12+
13+
This program is distributed in the hope that it will be useful,
14+
but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16+
17+
See the GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program; if not, write to:
21+
22+
Free Software Foundation, Inc.
23+
59 Temple Place - Suite 330
24+
Boston, MA 02111-1307, USA
25+
26+
*/
27+
float(float condition, string message) Test_Assert;
28+
void(string message) Test_Skip;
29+
30+
//
31+
// Test_Round_PlayerSpawnSetsRoundProperly()
32+
// Validate that PlayerSpawn() only sets the round when needed (at the game start).
33+
// This prevents the round resetting whenever a player joins the game.
34+
// (https://github.com/nzp-team/nzportable/issues/1185)
35+
//
36+
void() Test_Round_PlayerSpawnSetsRoundProperly =
37+
{
38+
float backup_round, backup_startround;
39+
40+
// Backup our rounds / start round, and then set them.
41+
backup_round = rounds;
42+
backup_startround = cvar("sv_startround");
43+
rounds = 21;
44+
cvar_set("sv_startround", "0");
45+
46+
// Make sure that our rounds value is still 21.
47+
PlayerSpawn();
48+
Test_Assert(rounds == 21, "Rounds value is being incorrectly reset!");
49+
50+
// Make sure that a negative round value properly sets as well.
51+
rounds = -3;
52+
PlayerSpawn();
53+
Test_Assert(rounds == 0, "Rounds value is not being correctly reset!");
54+
55+
// Restore original values.
56+
rounds = backup_round;
57+
cvar_set("sv_startround", ftos(backup_startround));
58+
};

0 commit comments

Comments
 (0)