src/main.c

Mon, 31 Mar 2014 14:08:00 +0200

author
Mike Becker <universe@uap-core.de>
date
Mon, 31 Mar 2014 14:08:00 +0200
changeset 22
41bbfd4d17a3
parent 16
a298c6637c30
child 23
824c9522ce66
permissions
-rw-r--r--

improved network performance

0
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2014 Mike Becker. All rights reserved.
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 *
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 */
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
30 #include "terminal-chess.h"
7
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
31 #include "game.h"
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
32 #include "input.h"
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
33 #include <string.h>
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
34 #include <time.h>
7
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
35 #include <getopt.h>
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
36
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
37 int get_settings(int argc, char **argv, Settings *settings) {
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
38 char *valid;
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
39 unsigned long int time, port;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
40 uint8_t timeunit = 60;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
41 size_t len;
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
42
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
43 for (char opt ; (opt = getopt(argc, argv, "a:bhp:rt:")) != -1 ;) {
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
44 switch (opt) {
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
45 case 'b':
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
46 settings->gameinfo.servercolor = BLACK;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
47 break;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
48 case 'r':
7
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
49 settings->gameinfo.servercolor = rand() & 1 ? WHITE : BLACK;
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
50 break;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
51 case 't':
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
52 case 'a':
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
53 len = strlen(optarg);
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
54 if (optarg[len-1] == 's') {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
55 optarg[len-1] = '\0';
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
56 timeunit = 1;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
57 }
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
58
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
59 if ((time = strtoul(optarg, &valid, 10)) > TIME_MAX
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
60 || *valid != '\0') {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
61 fprintf(stderr, "Specified time is invalid (%s)\n", optarg);
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
62 return 1;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
63 } else {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
64 if (opt=='t') {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
65 settings->gameinfo.time = timeunit * time;
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
66 } else {
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
67 settings->gameinfo.addtime = time;
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
68 }
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
69 }
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
70 break;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
71 case 'p':
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
72 port = strtol(optarg, &valid, 10);
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
73 if (port < 1025 || port > 65535 || *valid != '\0') {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
74 fprintf(stderr,
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
75 "Invalid port number (%s) - choose a number between "
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
76 "1025 and 65535\n",
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
77 optarg);
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
78 return 1;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
79 } else {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
80 settings->port = optarg;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
81 }
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
82 break;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
83 case 'h':
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
84 case '?':
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
85 settings->printhelp = 1;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
86 break;
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
87 }
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
88 }
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
89
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
90 if (optind == argc - 1) {
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
91 settings->serverhost = argv[optind];
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
92 } else if (optind < argc - 1) {
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
93 fprintf(stderr, "Too many arguments\n");
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
94 return 1;
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
95 }
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
96
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
97 return 0;
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
98 }
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
99
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
100 Settings default_settings() {
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
101 Settings settings;
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
102 memset(&settings, 0, sizeof(Settings));
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
103 settings.gameinfo.servercolor = WHITE;
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
104 settings.port = "27015";
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
105 return settings;
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
106 }
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
107
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
108 void dump_gameinfo(Gameinfo *gameinfo) {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
109 int serverwhite = gameinfo->servercolor == WHITE;
3
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
110 attron(A_UNDERLINE);
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
111 printw("Game details\n");
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
112 attroff(A_UNDERLINE);
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
113 printw(" Server: %s\n Client: %s\n",
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
114 serverwhite?"white":"black", serverwhite?"black":"White"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
115 );
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
116 if (gameinfo->time > 0) {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
117 if (gameinfo->time % 60) {
3
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
118 printw(" Time limit: %ds + %ds\n",
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
119 gameinfo->time, gameinfo->addtime);
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
120 } else {
3
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
121 printw(" Time limit: %dm + %ds\n",
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
122 gameinfo->time/60, gameinfo->addtime);
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
123 }
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
124 } else {
3
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
125 printw(" No time limit\n");
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
126 }
3
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
127 refresh();
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
128 }
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
129
4
560e07f7a6a1 exit hook
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
130 void leavescr() {
560e07f7a6a1 exit hook
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
131 endwin();
560e07f7a6a1 exit hook
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
132 }
560e07f7a6a1 exit hook
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
133
0
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 int main(int argc, char **argv) {
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
135 srand(time(NULL));
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
136
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
137 Settings settings = default_settings();
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
138 if (get_settings(argc, argv, &settings)) {
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
139 return 1;
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
140 }
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
141
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
142 if (settings.printhelp) {
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
143 printf(
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
144 "Usage: terminal-chess [OPTION]... [HOST]\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
145 "Starts/joins a network chess game\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
146 "\nGeneral options\n"
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
147 " -h This help page\n"
2
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
148 " -p TCP port to use (default: 27015)\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
149 "\nServer options\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
150 " -a <time> Specifies the time to add after each move\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
151 " -b Server plays black pieces (default: white)\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
152 " -r Distribute color randomly\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
153 " -t <time> Specifies time limit (default: no limit)\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
154 "\nNotes\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
155 "White pieces are displayed as uppercase and black pieces as "
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
156 "lowercase letters.\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
157 "The time unit for -a is seconds and for -t minutes by default. To "
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
158 "specify\nseconds for the -t option, use the s suffix.\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
159 "Example: -t 150s\n"
0a08f79c320d fixed network code + added game info and transmission of game info
Mike Becker <universe@uap-core.de>
parents: 1
diff changeset
160 );
1
e5fbb8f9edbe added (single) client / server architecture
Mike Becker <universe@uap-core.de>
parents: 0
diff changeset
161 return EXIT_SUCCESS;
16
a298c6637c30 introduced status codes for get_location to produce detailed error messages + added knight rules
Mike Becker <universe@uap-core.de>
parents: 7
diff changeset
162 }
7
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
163 tchess_window = initscr();
3
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
164 cbreak();
7
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
165 if (has_colors()) {
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
166 start_color();
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
167 init_colorpairs();
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
168 bkgd(COLOR_PAIR(COL_YB));
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
169 } else {
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
170 fprintf(stderr, "Non-colored terminals are not supported yet.");
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
171 endwin();
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
172 return EXIT_FAILURE;
41468077b5bb implemented chess board and remis/surrender messages
Mike Becker <universe@uap-core.de>
parents: 5
diff changeset
173 }
4
560e07f7a6a1 exit hook
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
174 atexit(leavescr);
3
3693fd2eb0e9 changed UI to ncurses session + added network handshake
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
175
5
f7dfef88947d separated server and client module
Mike Becker <universe@uap-core.de>
parents: 4
diff changeset
176 return is_server(&settings) ? server_run(&settings) : client_run(&settings);
0
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 }
98034084033f init project
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178

mercurial