From a2ede58964cee647c092d59d1e075242f83d69d0 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 4 May 2024 11:54:56 +0200 Subject: Revised game_read() --- FICS/gamedb.c | 112 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 63 insertions(+), 49 deletions(-) diff --git a/FICS/gamedb.c b/FICS/gamedb.c index 765f361..fc19758 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -1104,57 +1104,71 @@ PUBLIC int ReadGameAttrs(FILE * fp, char *fname, int g) return 0; } -PUBLIC int game_read(int g, int wp, int bp) +PUBLIC int +game_read(int g, int wp, int bp) { - FILE *fp; - char fname[MAX_FILENAME_SIZE]; + FILE *fp; + char fname[MAX_FILENAME_SIZE] = { '\0' }; - garray[g].white = wp; - garray[g].black = bp; -/* garray[g].old_white = -1; - garray[g].old_black = -1; -*/ - garray[g].moveListSize = 0; - garray[g].game_state.gameNum = g; - strcpy(garray[g].white_name, parray[wp].name); - strcpy(garray[g].black_name, parray[bp].name); - if (garray[g].type == TYPE_BLITZ) { - garray[g].white_rating = parray[wp].b_stats.rating; - garray[g].black_rating = parray[bp].b_stats.rating; - } else if (garray[g].type == TYPE_WILD) { - garray[g].white_rating = parray[wp].w_stats.rating; - garray[g].black_rating = parray[bp].w_stats.rating; - } else if (garray[g].type == TYPE_LIGHT) { - garray[g].white_rating = parray[wp].l_stats.rating; - garray[g].black_rating = parray[bp].l_stats.rating; - } else if (garray[g].type == TYPE_BUGHOUSE) { - garray[g].white_rating = parray[wp].bug_stats.rating; - garray[g].black_rating = parray[bp].bug_stats.rating; - } else { - garray[g].white_rating = parray[wp].s_stats.rating; - garray[g].black_rating = parray[bp].s_stats.rating; - } - sprintf(fname, "%s/%c/%s-%s", adj_dir, parray[wp].login[0], - parray[wp].login, parray[bp].login); - fp = fopen(fname, "r"); - if (!fp) { - return -1; - } - if (ReadGameAttrs(fp, fname, g) < 0) { - fclose(fp); - return -1; - } - fclose(fp); - - if (garray[g].result == END_ADJOURN - || garray[g].result == END_COURTESYADJOURN) - garray[g].result = END_NOTENDED; - garray[g].status = GAME_ACTIVE; - garray[g].startTime = tenth_secs(); - garray[g].lastMoveTime = garray[g].startTime; - garray[g].lastDecTime = garray[g].startTime; - /* Need to do notification and pending cleanup */ - return 0; + garray[g].white = wp; + garray[g].black = bp; + +#if 0 + garray[g].old_white = -1; + garray[g].old_black = -1; +#endif + + garray[g].moveListSize = 0; + garray[g].game_state.gameNum = g; + + mstrlcpy(garray[g].white_name, parray[wp].name, + sizeof(garray[g].white_name)); + mstrlcpy(garray[g].black_name, parray[bp].name, + sizeof(garray[g].black_name)); + + if (garray[g].type == TYPE_BLITZ) { + garray[g].white_rating = parray[wp].b_stats.rating; + garray[g].black_rating = parray[bp].b_stats.rating; + } else if (garray[g].type == TYPE_WILD) { + garray[g].white_rating = parray[wp].w_stats.rating; + garray[g].black_rating = parray[bp].w_stats.rating; + } else if (garray[g].type == TYPE_LIGHT) { + garray[g].white_rating = parray[wp].l_stats.rating; + garray[g].black_rating = parray[bp].l_stats.rating; + } else if (garray[g].type == TYPE_BUGHOUSE) { + garray[g].white_rating = parray[wp].bug_stats.rating; + garray[g].black_rating = parray[bp].bug_stats.rating; + } else { + garray[g].white_rating = parray[wp].s_stats.rating; + garray[g].black_rating = parray[bp].s_stats.rating; + } + + msnprintf(fname, sizeof fname, "%s/%c/%s-%s", adj_dir, + parray[wp].login[0], parray[wp].login, parray[bp].login); + fp = fopen(fname, "r"); + + if (!fp) { + return -1; + } + + if (ReadGameAttrs(fp, fname, g) < 0) { + fclose(fp); + return -1; + } + + fclose(fp); + + if (garray[g].result == END_ADJOURN || garray[g].result == + END_COURTESYADJOURN) + garray[g].result = END_NOTENDED; + + garray[g].status = GAME_ACTIVE; + garray[g].startTime = tenth_secs(); + garray[g].lastMoveTime = garray[g].startTime; + garray[g].lastDecTime = garray[g].startTime; + + // Need to do notification and pending cleanup + return 0; } PUBLIC int -- cgit v1.2.3