diff -r 189c7c77aaab -r 3fc6b1d6cbe9 src/main.c --- a/src/main.c Thu May 28 12:15:26 2026 +0200 +++ b/src/main.c Thu May 28 13:58:24 2026 +0200 @@ -44,7 +44,6 @@ #include typedef struct { - GameInfo gameinfo; /** * Server host address. * TCP: server address or \c NULL when we are the server @@ -52,7 +51,12 @@ */ char* serverhost; char* continuepgn; + unsigned short time; + unsigned short addtime; + unsigned short delay; short port; + uint8_t servercolor; + bool timecontrol; bool ishost; bool usedomainsocket; bool singlemachine; @@ -60,29 +64,53 @@ bool unicode; } Settings; -int get_settings(int argc, char **argv, Settings *settings) { +static Settings settings; + +static void init_settings(void) { + memset(&settings, 0, sizeof(settings)); + settings.servercolor = WHITE; + settings.port = 27015; + settings.unicode = !!setlocale(LC_CTYPE, "C.UTF-8"); +} + +static void cleanup() { + endwin(); + if (settings.usedomainsocket && settings.ishost) { + remove(settings.serverhost); + } +} + +static void settings_apply(GameState *gamestate) { + gamestate->info.servercolor = settings.servercolor; + gamestate->info.timecontrol = settings.timecontrol; + gamestate->info.time = settings.time; + gamestate->info.addtime = settings.addtime; + gamestate->info.delay = settings.delay; +} + +static int get_settings(int argc, char **argv) { char *valid; unsigned long int time, port; uint8_t timeunit = 60; size_t len; bool port_set = false; - for (int opt ; (opt = getopt(argc, argv, "a:bc:Fhp:rsS:t:uUv")) != -1 ;) { + for (int opt ; (opt = getopt(argc, argv, "a:bc:d:Fhp:rsS:t:uUv")) != -1 ;) { switch (opt) { case 'c': - settings->continuepgn = optarg; + settings.continuepgn = optarg; break; case 'b': - settings->gameinfo.servercolor = BLACK; + settings.servercolor = BLACK; break; case 'r': - settings->gameinfo.servercolor = rand() & 1 ? WHITE : BLACK; + settings.servercolor = rand() & 1 ? WHITE : BLACK; break; case 's': - settings->singlemachine = true; + settings.singlemachine = true; break; case 'F': - settings->disableflip = true; + settings.disableflip = true; break; case 'u': if (port_set) { @@ -90,13 +118,14 @@ "when a TCP port was specified.\n"); return 1; } - settings->usedomainsocket = true; + settings.usedomainsocket = true; break; case 'U': - settings->unicode = false; + settings.unicode = false; break; case 't': case 'a': + case 'd': len = strlen(optarg); if (optarg[len-1] == 's') { optarg[len-1] = '\0'; @@ -109,11 +138,13 @@ "- Maximum: 65535 seconds (1092 minutes)\n", optarg); return 1; } else { - settings->gameinfo.timecontrol = 1; + settings.timecontrol = 1; if (opt=='t') { - settings->gameinfo.time = timeunit * time; + settings.time = timeunit * time; + } else if (opt=='a') { + settings.addtime = time; } else { - settings->gameinfo.addtime = time; + settings.delay = time; } } break; @@ -122,7 +153,7 @@ fprintf(stderr, "Cannot use -p twice.\n"); return 1; } - if (settings->usedomainsocket) { + if (settings.usedomainsocket) { fprintf(stderr, "Cannot specify TCP port " "when using Unix domain sockets.\n"); return 1; @@ -135,7 +166,7 @@ optarg); return 1; } else { - settings->port = (short) port; + settings.port = (short) port; port_set = true; } break; @@ -155,18 +186,17 @@ " -u Use Unix domain socket instead of TCP\n" " -U Disables unicode pieces\n" " -v Print version information and exits\n" +"\nTime control (default: disabled)\n" +" -t