| 1045 GameState gamestate; |
1045 GameState gamestate; |
| 1046 gamestate_init(&gamestate); |
1046 gamestate_init(&gamestate); |
| 1047 settings_apply(&gamestate); |
1047 settings_apply(&gamestate); |
| 1048 if (settings.continuepgn) { |
1048 if (settings.continuepgn) { |
| 1049 /* preload PGN data before handshake */ |
1049 /* preload PGN data before handshake */ |
| |
1050 bool cancel = false; |
| 1050 FILE *pgnfile = fopen(settings.continuepgn, "r"); |
1051 FILE *pgnfile = fopen(settings.continuepgn, "r"); |
| 1051 if (pgnfile) { |
1052 if (pgnfile) { |
| 1052 int result = read_pgn(pgnfile, &gamestate); |
1053 int result = read_pgn(pgnfile, &gamestate); |
| 1053 long position = ftell(pgnfile); |
1054 long position = ftell(pgnfile); |
| 1054 fclose(pgnfile); |
1055 fclose(pgnfile); |
| 1055 if (result) { |
1056 if (result) { |
| 1056 printw("Invalid PGN file content at position %ld:\n%s\n", |
1057 printw("Invalid PGN file content at position %ld:\n%s\n", |
| 1057 position, pgn_error_str(result)); |
1058 position, pgn_error_str(result)); |
| 1058 return 1; |
1059 cancel = true; |
| 1059 } |
1060 } else if (!is_game_running(&gamestate)) { |
| 1060 if (!is_game_running(&gamestate)) { |
|
| 1061 addstr("Game has ended. Use -s to analyze it locally.\n"); |
1061 addstr("Game has ended. Use -s to analyze it locally.\n"); |
| 1062 return 1; |
1062 cancel = true; |
| 1063 } |
1063 } |
| 1064 } else { |
1064 } else { |
| 1065 printw("Can't read PGN file (%s)\n", strerror(errno)); |
1065 printw("Can't read PGN file (%s)\n", strerror(errno)); |
| |
1066 cancel = true; |
| |
1067 } |
| |
1068 if (cancel) { |
| |
1069 gamestate_cleanup(&gamestate); |
| 1066 return 1; |
1070 return 1; |
| 1067 } |
1071 } |
| 1068 } |
1072 } |
| 1069 dump_gameinfo(&gamestate); |
1073 dump_gameinfo(&gamestate); |
| 1070 |
1074 |
| 1071 if (server_open(&server)) { |
1075 if (server_open(&server)) { |
| 1072 net_destroy(&server); |
1076 net_destroy(&server); |
| |
1077 gamestate_cleanup(&gamestate); |
| 1073 return 1; |
1078 return 1; |
| 1074 } |
1079 } |
| 1075 |
1080 |
| 1076 if (server_handshake(server.client)) { |
1081 if (server_handshake(server.client)) { |
| 1077 net_destroy(&server); |
1082 net_destroy(&server); |
| |
1083 gamestate_cleanup(&gamestate); |
| 1078 return 1; |
1084 return 1; |
| 1079 } |
1085 } |
| 1080 |
1086 |
| 1081 int fd = server.client->fd; |
1087 int fd = server.client->fd; |
| 1082 if (settings.continuepgn) { |
1088 if (settings.continuepgn) { |