Tue, 28 Aug 2018 15:56:33 +0200
fixes move validation working on old king's position, when the king moves
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
55
54ea19938d57
updated copyright and version info
Mike Becker <universe@uap-core.de>
parents:
51
diff
changeset
|
4 | * Copyright 2016 Mike Becker. All rights reserved. |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
f7dfef88947d
separated server and client module
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 |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | * |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | */ |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | #include "terminal-chess.h" |
6 | 31 | #include "game.h" |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | #include <ncurses.h> |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
33 | #include <errno.h> |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
34 | #include <string.h> |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | |
6 | 36 | static int server_open(Server *server, char *port) { |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
37 | printw("\nListening for client...\n"); |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
38 | refresh(); |
6 | 39 | if (net_create(server, port)) { |
34
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
40 | addstr("Server creation failed"); |
6 | 41 | return 1; |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
42 | } |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
43 | |
6 | 44 | if (net_listen(server)) { |
34
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
45 | addstr("Listening for client failed"); |
6 | 46 | return 1; |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | } |
6 | 48 | |
49 | return 0; | |
50 | } | |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | |
6 | 52 | static int server_handshake(Client *client) { |
53 | net_send_code(client->fd, NETCODE_VERSION); | |
54 | if (net_recieve_code(client->fd) != NETCODE_VERSION) { | |
34
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
55 | addstr("Client uses an incompatible software version."); |
6 | 56 | return 1; |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | } |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | |
46
4dcfb4c58b6d
netcode is now aware of connection losses
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
59 | addstr("Client connected - transmitting gameinfo..."); |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | refresh(); |
6 | 61 | |
62 | return 0; | |
63 | } | |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | |
6 | 65 | int server_run(Settings *settings) { |
66 | Server server; | |
67 | ||
68 | dump_gameinfo(&(settings->gameinfo)); | |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
69 | GameState continuegame; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
70 | gamestate_init(&continuegame); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
71 | if (settings->continuepgn) { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
72 | // preload PGN data before handshake |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
73 | FILE *pgnfile = fopen(settings->continuepgn, "r"); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
74 | if (pgnfile) { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
75 | int result = read_pgn(pgnfile, &continuegame, |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
76 | &(settings->gameinfo)); |
60
0c50aac49e55
adds error messages to PGN reader
Mike Becker <universe@uap-core.de>
parents:
59
diff
changeset
|
77 | long position = ftell(pgnfile); |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
78 | fclose(pgnfile); |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
79 | if (result) { |
60
0c50aac49e55
adds error messages to PGN reader
Mike Becker <universe@uap-core.de>
parents:
59
diff
changeset
|
80 | printw("Invalid PGN file content at position %ld:\n%s\n", |
0c50aac49e55
adds error messages to PGN reader
Mike Becker <universe@uap-core.de>
parents:
59
diff
changeset
|
81 | position, pgn_error_str(result)); |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
82 | return 1; |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
83 | } |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
84 | if (!is_game_running(&continuegame)) { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
85 | addstr("Game has ended. Use -S to analyze it.\n"); |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
86 | return 1; |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
87 | } |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
88 | addch('\n'); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
89 | dump_moveinfo(&continuegame); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
90 | addch('\n'); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
91 | } else { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
92 | printw("Can't read PGN file (%s)\n", strerror(errno)); |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
93 | return 1; |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
94 | } |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
95 | } |
6 | 96 | |
97 | if (server_open(&server, settings->port)) { | |
98 | net_destroy(&server); | |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
99 | return 1; |
6 | 100 | } |
101 | ||
102 | if (server_handshake(server.client)) { | |
103 | net_destroy(&server); | |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
104 | return 1; |
6 | 105 | } |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | |
6 | 107 | int fd = server.client->fd; |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
108 | if (settings->continuepgn) { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
109 | // Continue game, send PGN data |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
110 | uint16_t mc = 0; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
111 | MoveList *movelist = continuegame.movelist; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
112 | while (movelist) { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
113 | mc++; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
114 | movelist = movelist->next; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
115 | } |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
116 | |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
117 | Move* moves = calloc(mc, sizeof(Move)); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
118 | |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
119 | movelist = continuegame.movelist; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
120 | mc = 0; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
121 | while (movelist) { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
122 | moves[mc] = movelist->move; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
123 | mc++; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
124 | movelist = movelist->next; |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
125 | } |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
126 | |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
127 | size_t pgndata_size = sizeof(GameInfo)+sizeof(mc)+mc*sizeof(Move); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
128 | char *pgndata = malloc(pgndata_size); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
129 | memcpy(pgndata, &(settings->gameinfo), sizeof(GameInfo)); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
130 | memcpy(pgndata+sizeof(GameInfo), &mc, sizeof(mc)); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
131 | memcpy(pgndata+sizeof(GameInfo)+sizeof(mc), moves, mc*sizeof(Move)); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
132 | free(moves); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
133 | net_send_data(fd, NETCODE_PGNDATA, pgndata, pgndata_size); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
134 | free(pgndata); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
135 | } else { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
136 | // Start new game |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
137 | net_send_data(fd, NETCODE_GAMEINFO, |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
138 | &(settings->gameinfo), sizeof(GameInfo)); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
139 | } |
46
4dcfb4c58b6d
netcode is now aware of connection losses
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
140 | addstr("\rClient connected - awaiting challenge acceptance..."); |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | refresh(); |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | int code = net_recieve_code(fd); |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | if (code == NETCODE_ACCEPT) { |
46
4dcfb4c58b6d
netcode is now aware of connection losses
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
144 | addstr("\rClient connected - challenge accepted."); |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | clrtoeol(); |
51
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
146 | if (settings->continuepgn) { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
147 | game_continue(settings, fd, &continuegame); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
148 | } else { |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
149 | game_start(settings, fd); |
84f2e380a434
added support for game continuation over network + fixed major bug in checkmate anticipation when the king is attacked diagonally
Mike Becker <universe@uap-core.de>
parents:
46
diff
changeset
|
150 | } |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | } else if (code == NETCODE_DECLINE) { |
46
4dcfb4c58b6d
netcode is now aware of connection losses
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
152 | addstr("\rClient connected - challenge declined."); |
4dcfb4c58b6d
netcode is now aware of connection losses
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
153 | clrtoeol(); |
4dcfb4c58b6d
netcode is now aware of connection losses
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
154 | } else if (code == NETCODE_CONNLOST) { |
4dcfb4c58b6d
netcode is now aware of connection losses
Mike Becker <universe@uap-core.de>
parents:
34
diff
changeset
|
155 | addstr("\rClient connected - but gave no response."); |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | clrtoeol(); |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | } else { |
34
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
158 | addstr("\rInvalid client response"); |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
159 | clrtoeol(); |
c4d4b8a8f902
added nonblocking read for network games + minor build system fixes
Mike Becker <universe@uap-core.de>
parents:
30
diff
changeset
|
160 | |
6 | 161 | net_destroy(&server); |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
162 | return 1; |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | } |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | |
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | net_destroy(&server); |
59
3fa1de896666
fixes inappropriate use of EXIT_ macros + adds a sample PGN file
Mike Becker <universe@uap-core.de>
parents:
55
diff
changeset
|
166 | return 0; |
5
f7dfef88947d
separated server and client module
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | } |