From a31b2747ac7e05270a903cdf2e7807b0778e873d Mon Sep 17 00:00:00 2001 From: Des Date: Mon, 25 Nov 2024 09:04:05 -0300 Subject: [PATCH] Detect broken .defragcp files and flag them to be recreated on map completion. --- qcsrc/server/race.qc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index ee68144ae..f4c72eb32 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -937,6 +937,7 @@ void trigger_race_checkpoint_verify(entity this) // check if a defragcp file already exists, then read it and apply the checkpoint order float fh; float len; + bool broken_defragcp = false; string l; defragcpexists = fh = fopen(strcat("maps/", GetMapname(), ".defragcp"), FILE_READ); @@ -944,16 +945,29 @@ void trigger_race_checkpoint_verify(entity this) while ((l = fgets(fh))) { len = tokenize_console(l); if (len != 2) { - defragcpexists = -1; // something's wrong in the defrag cp file, set defragcpexists to -1 so that it will be rewritten when someone finishes - continue; + broken_defragcp = true; + break; } for (entity cp = NULL; (cp = find(cp, classname, "target_checkpoint"));) { if (argv(0) == cp.targetname) { + if(cp.race_checkpoint != -2 && cp.race_checkpoint != stof(argv(1))) { // cp had been previously set with diff order nr defragcp file is broken + broken_defragcp = true; + break; + } cp.race_checkpoint = stof(argv(1)); } } + if(broken_defragcp) break; // no point to keep going we'll rebuild the whole order } fclose(fh); + if(broken_defragcp) { + // something's wrong in the defrag cp file, set defragcpexists to -1 so that it will be rewritten when someone finishes + // also clear any set cp order to make sure map is completable + defragcpexists = -1; + for (entity cp = NULL; (cp = find(cp, classname, "target_checkpoint"));) { + cp.race_checkpoint = -2; + } + } } } -- 2.39.2