From c4c7913d5c48958732f645c8a3edb57c9004dd30 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Sat, 21 May 2022 16:36:36 -0700 Subject: web: add support for custom matches --- web/web_match.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'web/web_match.c') diff --git a/web/web_match.c b/web/web_match.c index cd87c5a..58b0aca 100644 --- a/web/web_match.c +++ b/web/web_match.c @@ -5,6 +5,7 @@ #include #include #include +#include struct match_state *state; struct match_opts *match_opts; @@ -83,7 +84,20 @@ void match_opts_add_player(enum player_type type, char *name) match_opts->throws_first = pn; match_opts->players[pn - 1].type = type; - match_opts->players[pn - 1].name = name; + match_opts->players[pn - 1].name = strdup(name); +} + +void match_opts_remove_player(int pn) +{ + if (match_opts->throws_first == pn) + match_opts->throws_first = match_opts->num_players > 1 ? 1 : 0; + else if (match_opts->throws_first > pn) + --match_opts->throws_first; + + free(match_opts->players[pn - 1].name); + for (int i = pn; i < match_opts->num_players; ++i) + match_opts->players[i - 1] = match_opts->players[i]; + --match_opts->num_players; } void match_opts_free() @@ -91,6 +105,8 @@ void match_opts_free() if (!match_opts) return; + for (int i = 0; i < match_opts->num_players; ++i) + free(match_opts->players[i].name); free(match_opts->players); free(match_opts); match_opts = NULL; -- cgit v1.2.3-70-g09d2