diff options
Diffstat (limited to 'web/web_match.c')
-rw-r--r-- | web/web_match.c | 18 |
1 files changed, 17 insertions, 1 deletions
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 <stdbool.h> #include <stddef.h> #include <stdlib.h> +#include <string.h> 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; |