39 char *valid; |
39 char *valid; |
40 unsigned long int time, port; |
40 unsigned long int time, port; |
41 uint8_t timeunit = 60; |
41 uint8_t timeunit = 60; |
42 size_t len; |
42 size_t len; |
43 |
43 |
44 for (int opt ; (opt = getopt(argc, argv, "a:bc:hp:rst:")) != -1 ;) { |
44 for (int opt ; (opt = getopt(argc, argv, "a:bc:hp:rsS:t:")) != -1 ;) { |
45 switch (opt) { |
45 switch (opt) { |
46 case 'c': |
46 case 'c': |
47 settings->continuepgn = optarg; |
47 settings->continuepgn = optarg; |
48 break; |
48 break; |
49 case 'b': |
49 case 'b': |
101 } else if (optind < argc - 1) { |
104 } else if (optind < argc - 1) { |
102 fprintf(stderr, "Too many arguments\n"); |
105 fprintf(stderr, "Too many arguments\n"); |
103 return 1; |
106 return 1; |
104 } |
107 } |
105 |
108 |
|
109 |
|
110 if (settings->continuepgn) { |
|
111 if (settings->serverhost) { |
|
112 fprintf(stderr, "Can't continue a game when joining a server.\n"); |
|
113 return 1; |
|
114 } |
|
115 if (settings->analyzepgn) { |
|
116 fprintf(stderr, "The options -c and -S are mutually exclusive\n"); |
|
117 return 1; |
|
118 } |
|
119 // TODO: implement |
|
120 if (!settings->singlemachine) { |
|
121 fprintf(stderr, "Game continuation currently not supported for " |
|
122 "network games.\n"); |
|
123 return 1; |
|
124 } |
|
125 } |
|
126 |
106 return 0; |
127 return 0; |
107 } |
128 } |
108 |
129 |
109 Settings default_settings() { |
130 Settings default_settings() { |
110 Settings settings; |
131 Settings settings; |
111 memset(&settings, 0, sizeof(Settings)); |
132 memset(&settings, 0, sizeof(Settings)); |
112 settings.gameinfo.servercolor = WHITE; |
133 settings.gameinfo.servercolor = WHITE; |
113 settings.port = "27015"; |
134 settings.port = "27015"; |
114 settings.continuepgn = NULL; |
|
115 return settings; |
135 return settings; |
116 } |
136 } |
117 |
137 |
118 void dump_gameinfo(GameInfo *gameinfo) { |
138 void dump_gameinfo(GameInfo *gameinfo) { |
119 int serverwhite = gameinfo->servercolor == WHITE; |
139 int serverwhite = gameinfo->servercolor == WHITE; |
152 if (settings.printhelp) { |
172 if (settings.printhelp) { |
153 printf( |
173 printf( |
154 "Usage: terminal-chess [OPTION]... [HOST]\n" |
174 "Usage: terminal-chess [OPTION]... [HOST]\n" |
155 "Starts/joins a network chess game\n" |
175 "Starts/joins a network chess game\n" |
156 "\nGeneral options\n" |
176 "\nGeneral options\n" |
|
177 " -c <PGN file> Continue the specified game\n" |
157 " -h This help page\n" |
178 " -h This help page\n" |
158 " -p TCP port to use (default: 27015)\n" |
179 " -p TCP port to use (default: 27015)\n" |
|
180 // TODO: implement and activate feature |
|
181 //" -S <PGN file> Compute and print statistics for the specified game\n" |
159 "\nServer options\n" |
182 "\nServer options\n" |
160 " -a <time> Specifies the time to add after each move\n" |
183 " -a <time> Specifies the time to add after each move\n" |
161 " -b Server plays black pieces (default: white)\n" |
184 " -b Server plays black pieces (default: white)\n" |
162 // TODO: implement and activate feature |
|
163 //" -c <PGN file> Continue the specified game\n" |
|
164 " -r Distribute color randomly\n" |
185 " -r Distribute color randomly\n" |
165 " -s Single machine mode\n" |
186 " -s Single machine mode\n" |
166 // TODO: implement and activate feature |
|
167 //" -S <PGN file> Compute and print statistics for the specified game\n" |
|
168 " -t <time> Specifies time limit (default: no limit)\n" |
187 " -t <time> Specifies time limit (default: no limit)\n" |
169 "\nNotes\n" |
188 "\nNotes\n" |
170 "The time unit for -a is seconds and for -t minutes by default. To " |
189 "The time unit for -a is seconds and for -t minutes by default. To " |
171 "specify\nseconds for the -t option, use the s suffix.\n" |
190 "specify\nseconds for the -t option, use the s suffix.\n" |
172 "Example: -t 150s\n\n" |
191 "Example: -t 150s\n\n" |
190 |
209 |
191 int exitcode; |
210 int exitcode; |
192 if (settings.singlemachine) { |
211 if (settings.singlemachine) { |
193 game_start_singlemachine(&settings); |
212 game_start_singlemachine(&settings); |
194 exitcode = EXIT_SUCCESS; |
213 exitcode = EXIT_SUCCESS; |
|
214 } else if (settings.analyzepgn) { |
|
215 printw("Not implemented yet.\n"); |
|
216 exitcode = EXIT_SUCCESS; |
195 } else { |
217 } else { |
196 exitcode = is_server(&settings) ? |
218 exitcode = is_server(&settings) ? |
197 server_run(&settings) : client_run(&settings); |
219 server_run(&settings) : client_run(&settings); |
198 } |
220 } |
199 |
221 |
200 mvaddstr(getmaxy(stdscr)-1, 0, |
222 mvaddstr(getmaxy(stdscr)-1, 0, |
201 "Game has ended. Press any key to leave..."); |
223 "Game has ended. Press any key to leave..."); |
|
224 clrtoeol(); |
202 refresh(); |
225 refresh(); |
203 cbreak(); |
226 cbreak(); |
204 flushinp(); |
227 flushinp(); |
205 getch(); |
228 getch(); |
206 |
229 |