diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-21 16:36:36 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2022-05-21 16:36:36 -0700 |
commit | c4c7913d5c48958732f645c8a3edb57c9004dd30 (patch) | |
tree | 9f1a04efa3fa1e95793bd710bfb583b8469ae2c0 /web/web_match.c | |
parent | e7a2e5e24bf0523fb49a3ce07e3eb96d1fd5aea2 (diff) | |
download | dartboat-multi.tar.gz dartboat-multi.tar.xz |
web: add support for custom matchesmulti
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; |