Skip to content
Merged
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 common/proto10/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ int p10_decode_chat_broadcast(const uint8_t* data, size_t size, p10_chat_broadca
#define P10_GM_TEAM1_SCORE "team1-score"
#define P10_GM_TEAM2_SCORE "team2-score"
#define P10_GM_CAPTURE_LIMIT "capture-limit"
#define P10_GM_MATCH_TIME "match-time" /* seconds left of a timed match (absent: no time limit) */
#define P10_GM_TEAM1_INTEL "team1-intel"
#define P10_GM_TEAM2_INTEL "team2-intel"
/* The objectives' entities (12.2.3) have fixed ids: P10_OBJECTIVE_ID_BASE +
Expand Down
1 change: 1 addition & 0 deletions docs/protocol-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,7 @@ them, each within `int32`. Positions are **block cells** in map coordinates
| `team1-color`, `team2-color` | `r,g,b` (0..255) | team colours |
| `team1-score`, `team2-score` | decimal | team scores (CTF: captures) |
| `capture-limit` | decimal | CTF captures needed to win |
| `match-time` | decimal | Seconds left of the match's time limit, in the point-scored modes (CTF, ngCTF, Babel, TC, TDM, Koth: 20 min, 15 min for TDM and Koth by default, `match_seconds` in the mode's section of config.toml); absent in the others (Arena, Zombie and PtB play rounds, Creative has no end). A second apart in the last minute, to the next 10 s before it. When it reaches 0 the match ends by the score (a tie is a draw), `/extend` adds to it. A client may use it for a countdown or the closing music |
| `team1-intel`, `team2-intel` | `base`, `dropped`, `carried` | the state of the intel **belonging** to that team (team 1 defends `team1-intel`); where it is and who carries it are its `Flag` entity's (below) |
| `territory-count` | decimal `N` | TC: number of territories |
| `territory<i>` | `holder,capturing,permille,rate` | TC: territory `i` (`0` ≤ `i` < `N`, decimal without leading zeros: `territory0`, `territory12`): its holder (`0` team 1, `1` team 2, `2` nobody), the team that would take it, that team's share of the progress (0..1000) and its change a second (see below). Its place is its `Checkpoint` entity, id `P10_OBJECTIVE_ID_BASE + 5 + i` |
Expand Down
23 changes: 23 additions & 0 deletions server/Resources/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ spawn_near_min = 35.0 # a zombie's respawn, from a living survivor
spawn_near_max = 50.0


# The time limit of the point-scored modes: match_seconds in the mode's own
# section (30..86400). When it runs out the match ends by the score (a tie is
# a draw), and the clients hear the closing music in the last 5 seconds. A
# match never runs for ever; arena, ptb and zombie play rounds (their own
# round_seconds), creative has no end. /extend adds time.
[ctf]
match_seconds = 1200 # classic CTF

[ngctf]
match_seconds = 1200 # next gen CTF

[babel]
match_seconds = 1200

[tc]
match_seconds = 1200 # territory control

[tdm]
match_seconds = 900 # team deathmatch

[koth]
match_seconds = 900 # king of the hill

# Arena mode (rounds without respawns on Counter-Strike maps). All keys are
# optional; a map's own [arena] table and its .txt narrow them down for that
# map, and the mode's rounds are won by the map's capture_limit.
Expand Down
14 changes: 14 additions & 0 deletions server/Source/Server/ConfigCheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@ static void _net(char* out, size_t size, toml_table_t* root)
_int_in(out, size, "net", t, "connection_window_seconds", 1, 3600, 10);
}

static void _match(char* out, size_t size, toml_table_t* root)
{
static const struct { const char* section; int normal; } modes[] = {
{"ctf", 1200}, {"ngctf", 1200}, {"babel", 1200}, {"tc", 1200}, {"tdm", 900}, {"koth", 900},
};
for (size_t k = 0; k < sizeof modes / sizeof modes[0]; k++) {
toml_table_t* t = toml_table_in(root, modes[k].section);
if (t != NULL) {
_int_in(out, size, modes[k].section, t, "match_seconds", 30, 86400, modes[k].normal);
}
}
}

static void _zombie(char* out, size_t size, toml_table_t* root)
{
toml_table_t* t = toml_table_in(root, "zombie");
Expand Down Expand Up @@ -476,6 +489,7 @@ int config_check(const char* path, char* out, size_t size)
_server(out, size, root);
_teams(out, size, root);
_net(out, size, root);
_match(out, size, root);
_zombie(out, size, root);
_conduct(out, size, root);
_anticheat(out, size, root);
Expand Down
17 changes: 17 additions & 0 deletions server/Source/Server/ConfigKeys.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ static const ck_key_t ck_anticheat_keys[] = {
{"enabled", CK_ALL}, {"kick_on_protocol_violation", CK_ALL}, {"log_interval_seconds", CK_ALL}, CK_END,
};

/* Gamemodes/Gamemode.c gamemode_match_seconds: the time limit of the
point-scored modes, in the mode's own section (the 0.75 profile has ctf and babel) */
static const ck_key_t ck_match_seconds_keys[] = {
{"match_seconds", CK_ALL},
CK_END,
};
static const ck_key_t ck_match_seconds_keys_10[] = {
{"match_seconds", CK_10},
CK_END,
};

/* Gamemodes/Arena.c: rounds, whose timing the map's [arena] and its .txt
narrow down (the arena is a 1.0 mode: the 0.75 profile has ctf and babel) */
static const ck_key_t ck_arena_keys[] = {
Expand Down Expand Up @@ -315,6 +326,12 @@ static const ck_table_t ck_top_subs[] = {
{.name = "classes", .prof = CK_10, .any = &ck_class_shape, .sub_known = ck_class_name},
{.name = "net", .keys = ck_net_keys},
{.name = "zombie", .prof = CK_10, .keys = ck_zombie_keys},
{.name = "ctf", .keys = ck_match_seconds_keys},
{.name = "babel", .keys = ck_match_seconds_keys},
{.name = "ngctf", .prof = CK_10, .keys = ck_match_seconds_keys_10},
{.name = "tc", .prof = CK_10, .keys = ck_match_seconds_keys_10},
{.name = "tdm", .prof = CK_10, .keys = ck_match_seconds_keys_10},
{.name = "koth", .prof = CK_10, .keys = ck_match_seconds_keys_10},
{.name = "arena", .prof = CK_10, .keys = ck_arena_keys},
{.name = "ptb", .prof = CK_10, .keys = ck_ptb_keys},
{.name = "conduct", .keys = ck_conduct_keys},
Expand Down
47 changes: 47 additions & 0 deletions server/Source/Server/Gamemodes/Ctf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <Server/Structs/ServerStruct.h>
#include <Util/Enums.h>
#include <Util/Log.h>

/* the match's time limit, below (_ctf_time_check): set when a capture wins */
static uint8_t ctf_ended;
#include <Util/Nanos.h>
#include <Util/Types.h>
#include <Util/Weapon.h>
Expand Down Expand Up @@ -597,6 +600,7 @@ void handleTentAndIntel(server_t* server, player_t* player)
server->protocol.gamemode.intel[team] = set_intel_tent_spawn_point(server, team, MAP_META_FLAG);
}
if (winning) {
ctf_ended = 1;
gamemode_match_won(server);
}
}
Expand All @@ -613,9 +617,46 @@ static void _ctf_base_snapshot(server_t* server);
static void _ctf_posts_reset(void);
static void _ctf_posts_tick(server_t* server);

/* the match's time limit: when it runs out the team with more captures wins,
equal captures are a draw. CTF used to end only at the capture limit and
could go on for ever (SP_MATCH_SECONDS shortens it for tests) */
#define CTF_SECONDS 1200
static uint64_t ctf_deadline;

int _ctf_time_left(server_t* server)
{
(void) server;
return ctf_ended ? 0 : gamemode_seconds_until(ctf_deadline);
}

int _ctf_extend(server_t* server, int seconds)
{
ctf_deadline += (uint64_t) seconds * NANO_IN_SECOND;
server->match_extra_seconds += (uint32_t) seconds;
evt_log(NULL, "ctf", "action=extend seconds=%d", seconds);
return 1;
}

static void _ctf_time_check(server_t* server)
{
if (ctf_ended || get_nanos() < ctf_deadline) {
return;
}
ctf_ended = 1;
evt_log(NULL, "ctf", "action=end why=time score=%u-%u", (unsigned) server->protocol.gamemode.score[0],
(unsigned) server->protocol.gamemode.score[1]);
gamemode_match_won(server);
}

void _ctf_init(server_t* server)
{
gamemode_vars_t* gm = &server->protocol.gamemode;
uint8_t mode = server->protocol.current_gamemode;
ctf_deadline = get_nanos() + (uint64_t) gamemode_match_seconds(mode == GAME_MODE_NGCTF ? "ngctf"
: mode == GAME_MODE_BABEL ? "babel"
: "ctf",
CTF_SECONDS) * NANO_IN_SECOND;
ctf_ended = 0;
memset(ctf_spots, 0, sizeof(ctf_spots)); /* a new map: a script sets them again */
gm->intel_flags = 0;
gm->intel[0] = set_intel_tent_spawn_point(server, 0, MAP_META_FLAG);
Expand Down Expand Up @@ -1423,6 +1464,7 @@ static void _ctf_lane_fort(server_t* server, int t, vector3f_t w)
leader (a new one only when it left), and how far along its lane it got */
void _ctf_tick(server_t* server)
{
_ctf_time_check(server);
_ctf_seats_tick(server);
squads_census(server);
_ctf_forts(server);
Expand Down Expand Up @@ -4078,6 +4120,8 @@ const gamemode_ops_t ctf_ops = {
.wire_name = "ctf",
.init = _ctf_init,
.tick = _ctf_tick,
.extend = _ctf_extend,
.time_left = _ctf_time_left,
.player_step = handleTentAndIntel,
.player_out = _ctf_player_out,
.terrain_changed = _ctf_terrain_changed,
Expand Down Expand Up @@ -4130,6 +4174,7 @@ static void _babel_slab_audit(server_t* server)

static void _babel_tick(server_t* server)
{
_ctf_time_check(server);
static uint64_t logged_at;
uint64_t now = get_nanos();
_babel_slab_audit(server);
Expand Down Expand Up @@ -4203,6 +4248,8 @@ const gamemode_ops_t babel_ops = {
.wire_name = "ctf",
.init = _babel_init,
.tick = _babel_tick,
.extend = _ctf_extend,
.time_left = _ctf_time_left,
.player_step = handleTentAndIntel,
.player_out = _ctf_player_out,
.terrain_changed = _ctf_terrain_changed,
Expand Down
2 changes: 2 additions & 0 deletions server/Source/Server/Gamemodes/CtfInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
void handleTentAndIntel(server_t* server, player_t* player);
void _ctf_init(server_t* server);
void _ctf_tick(server_t* server);
int _ctf_time_left(server_t* server);
int _ctf_extend(server_t* server, int seconds);
void _ctf_player_out(server_t* server, player_t* player);
void _ctf_terrain_changed(server_t* server, int built);
void _ctf_state_keys(server_t* server, gm_keys_t* out);
Expand Down
37 changes: 37 additions & 0 deletions server/Source/Server/Gamemodes/Gamemode.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,43 @@ static void _match_summary_send(server_t* server, int wait_seconds, int voting)
winner, gm->score[0], gm->score[1], length, players, parts[6], parts[7], wait_seconds);
}

int gamemode_match_seconds(const char* section, int normal)
{
const char* env = getenv("SP_MATCH_SECONDS");
int n = env != NULL ? atoi(env) : 0;
if (n >= 1 && n <= 86400) {
return n;
}
FILE* fp = fopen(server_config_path(), "r");
if (fp == NULL) {
return normal;
}
char err[200];
toml_table_t* conf = toml_parse_file(fp, err, sizeof err);
fclose(fp);
if (conf == NULL) {
return normal;
}
int seconds = normal;
toml_table_t* table = toml_table_in(conf, section);
if (table != NULL) {
toml_datum_t d = toml_int_in(table, "match_seconds");
if (d.ok && d.u.i >= 30 && d.u.i <= 86400) {
seconds = (int) d.u.i;
} else if (d.ok) {
LOG_WARNING("config.toml [%s] match_seconds = %lld is outside 30..86400: %d s applies", section, (long long) d.u.i, normal);
}
}
toml_free(conf);
return seconds;
}

int gamemode_seconds_until(uint64_t deadline)
{
uint64_t now = get_nanos();
return now >= deadline ? 0 : (int) ((deadline - now + NANO_IN_SECOND - 1) / NANO_IN_SECOND);
}

void gamemode_match_won(server_t* server)
{
if (match_reset_at != 0) {
Expand Down
11 changes: 11 additions & 0 deletions server/Source/Server/Gamemodes/Gamemode.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ typedef struct gamemode_ops
void (*tick)(server_t* server);
/* /extend: add seconds to a timed match; 1 when the mode did */
int (*extend)(server_t* server, int seconds);
/* seconds left of the match's time limit (0 once it has run out or the
match is over); -1 when the mode has none. Sent to the clients as
GameModeState's match-time */
int (*time_left)(server_t* server);
/* every server tick for each READY player (intel pickup, capture, tent: a
player running over the intel is on it for a fraction of a second) */
void (*player_step)(server_t* server, player_t* player);
Expand Down Expand Up @@ -231,6 +235,13 @@ void gamemode_tick(server_t* server);
/* 1 when the mode added the seconds to its clock; 0 when its match has no
time limit (the command says so and changes nothing) */
int gamemode_extend(server_t* server, int seconds);
/* the time limit of a point-scored mode, in seconds: config.toml's
match_seconds in the mode's own section ([ctf], [ngctf], [babel], [tc],
[tdm], [koth]: 30..86400) or normal, and $SP_MATCH_SECONDS over both when
set (tests: a match that ends in a few seconds). A match never runs for ever */
int gamemode_match_seconds(const char* section, int normal);
/* whole seconds, rounded up, from now to a deadline (get_nanos clock); 0 when past */
int gamemode_seconds_until(uint64_t deadline);
/* a team won the match: everyone reloads, the next map starts */
void gamemode_match_won(server_t* server);

Expand Down
11 changes: 9 additions & 2 deletions server/Source/Server/Gamemodes/Koth.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static void _koth_init(server_t* server)
server->protocol.gamemode.score[0] = 0;
server->protocol.gamemode.score[1] = 0;
uint64_t now = get_nanos();
koth.deadline = now + (uint64_t) KOTH_SECONDS * NANO_IN_SECOND;
koth.deadline = now + (uint64_t) gamemode_match_seconds("koth", KOTH_SECONDS) * NANO_IN_SECOND;
koth.next_score = now;
koth.next_fort = now;
koth.ended = 0;
Expand Down Expand Up @@ -261,7 +261,7 @@ static void _koth_init(server_t* server)
server->features_on |= GM_FEAT_CLASSES | GM_FEAT_CLASS_PERKS;
}
LOG_INFO("King of the Hill: hill at %d,%d,%d, %d s held a round, %d rounds win, %d s at most", koth.hx,
koth.hy, koth.hz, KOTH_ROUND_POINTS, KOTH_ROUNDS, KOTH_SECONDS);
koth.hy, koth.hz, KOTH_ROUND_POINTS, KOTH_ROUNDS, (int) ((koth.deadline - now) / NANO_IN_SECOND));
evt_log(NULL, "koth", "action=start at=%d,%d,%d round_points=%d rounds=%d classes=%d", koth.hx, koth.hy,
koth.hz, KOTH_ROUND_POINTS, KOTH_ROUNDS, classes);
}
Expand Down Expand Up @@ -469,6 +469,12 @@ static void _koth_state_keys(server_t* server, gm_keys_t* out)
}
}

static int _koth_time_left(server_t* server)
{
(void) server;
return koth.ended ? 0 : gamemode_seconds_until(koth.deadline);
}

static int _koth_extend(server_t* server, int seconds)
{
koth.deadline += (uint64_t) seconds * NANO_IN_SECOND;
Expand Down Expand Up @@ -734,6 +740,7 @@ const gamemode_ops_t koth_ops = {
.init = _koth_init,
.tick = _koth_tick,
.extend = _koth_extend,
.time_left = _koth_time_left,
.state_keys = _koth_state_keys,
.summary_stat = "hill",
.player_stat = _koth_player_hill,
Expand Down
2 changes: 2 additions & 0 deletions server/Source/Server/Gamemodes/NgCtf.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const gamemode_ops_t ngctf_ops = {
.hit_damage = classes_hit_damage,
.init = _ctf_init,
.tick = _ctf_tick,
.extend = _ctf_extend,
.time_left = _ctf_time_left,
.player_step = handleTentAndIntel,
.player_out = _ctf_player_out,
.terrain_changed = _ctf_terrain_changed,
Expand Down
13 changes: 10 additions & 3 deletions server/Source/Server/Gamemodes/Tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#define TC_SPAWN_THREAT 96.0f /* an enemy this near a territory: spawn one back */
#define TC_REFILL_DISTANCE 3.0f
#define TC_REFILL_SECONDS 20
#define TC_SECONDS 1200
#define TC_SECONDS 1200 /* gamemode_match_seconds */
/* a squad walks to its territory behind its leader until one of them is
this near it, then each bot takes its own place in it */
#define TC_SQUAD_SPLIT (TC_CAPTURE_DISTANCE * 2.5f)
Expand Down Expand Up @@ -229,7 +229,7 @@ static void _tc_init(server_t* server)
server->protocol.gamemode.score_limit = (uint8_t) tc.count;
_tc_score(server);
uint64_t now = get_nanos();
tc.deadline = now + (uint64_t) TC_SECONDS * NANO_IN_SECOND;
tc.deadline = now + (uint64_t) gamemode_match_seconds("tc", TC_SECONDS) * NANO_IN_SECOND;
tc.last_step = now;
/* the classes are the host's choice, off unless asked: the command line
(--classes 0|1) first, then the console (/classes) */
Expand All @@ -241,7 +241,7 @@ static void _tc_init(server_t* server)
server->features_on |= GM_FEAT_CLASSES | GM_FEAT_CLASS_PERKS;
}
LOG_INFO("Territory control: %d territories, %u-%u held, %d s at most, classes %s", tc.count,
server->protocol.gamemode.score[0], server->protocol.gamemode.score[1], TC_SECONDS, classes ? "on" : "off");
server->protocol.gamemode.score[0], server->protocol.gamemode.score[1], (int) ((tc.deadline - now) / NANO_IN_SECOND), classes ? "on" : "off");
evt_log(NULL, "tc", "action=start territories=%d held=%u-%u axis=%c classes=%d", tc.count,
server->protocol.gamemode.score[0], server->protocol.gamemode.score[1], tc.axis ? 'y' : 'x', classes);
}
Expand Down Expand Up @@ -475,6 +475,12 @@ static void _tc_state_keys(server_t* server, gm_keys_t* out)
}
}

static int _tc_time_left(server_t* server)
{
(void) server;
return tc.ended ? 0 : gamemode_seconds_until(tc.deadline);
}

static int _tc_extend(server_t* server, int seconds)
{
tc.deadline += (uint64_t) seconds * NANO_IN_SECOND;
Expand Down Expand Up @@ -772,6 +778,7 @@ const gamemode_ops_t tc_ops = {
.init = _tc_init,
.tick = _tc_tick,
.extend = _tc_extend,
.time_left = _tc_time_left,
.state_keys = _tc_state_keys,
.summary_stat = "captures",
.player_stat = _tc_player_captures,
Expand Down
Loading
Loading