diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-04-17 03:44:44 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-04-17 03:44:44 +0200 |
commit | 016b0bc138027d79be0bca23357a3b585d57839c (patch) | |
tree | b9f86da0a87566f22eac0f975f64e4300d5a3ab4 | |
parent | 1c2005e0647830a71ebd413a5964820be07af575 (diff) |
Revised jsave_journalentry()
-rw-r--r-- | FICS/obsproc.c | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/FICS/obsproc.c b/FICS/obsproc.c index 9720467..3abe6af 100644 --- a/FICS/obsproc.c +++ b/FICS/obsproc.c @@ -1408,58 +1408,63 @@ if (!parray[p1].registered) { return COM_OK; } -PRIVATE void jsave_journalentry(int p,char save_spot,int p1,char from_spot,char* to_file) - +PRIVATE void +jsave_journalentry(int p, char save_spot, int p1, char from_spot, char *to_file) { - FILE *Game; + FILE *Game; + char *name_from = parray[p1].login; + char *name_to = parray[p].login; + char BlackName[MAX_LOGIN_NAME + 1]; + char WhiteName[MAX_LOGIN_NAME + 1]; + char command[MAX_FILENAME_SIZE * 2 + 3]; + char eco[100]; + char ending[100]; + char fname[MAX_FILENAME_SIZE]; + char fname2[MAX_FILENAME_SIZE]; + char result[100]; + char type[100]; + int BlackRating; + int WhiteRating; + int i, t; + + msnprintf(fname, sizeof fname, "%s/%c/%s.%c", journal_dir, name_from[0], + name_from, from_spot); + + if ((Game = fopen(fname, "r")) == NULL) { + pprintf(p, "Journal entry %c not available for %s.\n", + toupper(from_spot), + parray[p1].name); + return; + } - char fname[MAX_FILENAME_SIZE], fname2[MAX_FILENAME_SIZE]; - char command[MAX_FILENAME_SIZE*2+3]; - char* name_from = parray[p1].login; - char* name_to = parray[p].login; - char WhiteName[MAX_LOGIN_NAME + 1]; - char BlackName[MAX_LOGIN_NAME + 1]; - int WhiteRating; - int BlackRating; - int i,t; - char type[100]; - char eco[100]; - char ending[100]; - char result[100]; - - sprintf(fname, "%s/%c/%s.%c", journal_dir, name_from[0],name_from,from_spot); - Game = fopen(fname, "r"); - if (Game == NULL) { - pprintf(p, "Journal entry %c not available for %s.\n", toupper(from_spot), parray[p1].name); - return; - } - fclose (Game); - - sprintf(fname2, "%s/%c/%s.%c", journal_dir, name_to[0],name_to,save_spot); - unlink (fname2); /* necessarity if cp is hard aliased to cp -i */ - sprintf(command, "cp %s %s",fname,fname2); - - if (system(command)) { /* A little messy, but works */ - pprintf (p,"System command in jsave_journalentry failed!\n"); - pprintf (p,"Please report this to an admin.\n"); - fprintf (stderr, "FICS: System command failed in jsave_journalentry\n"); - return; - } - - sprintf(fname, "%s/player_data/%c/%s.%s", stats_dir, name_to[0], - name_to, STATS_JOURNAL); - - if (!journal_get_info(p,from_spot,WhiteName,&WhiteRating, - BlackName,&BlackRating,type,&t,&i,eco, - ending,result,fname)) { - return; - } - - addjournalitem(p, toupper(save_spot), WhiteName, WhiteRating, - BlackName,BlackRating,type,t,i,eco, - ending,result, to_file); - - pprintf(p,"Journal entry %s %c saved in slot %c in journal.\n",parray[p1].name, toupper(from_spot), toupper(save_spot)); + fclose(Game); + + msnprintf(fname2, sizeof fname2, "%s/%c/%s.%c", journal_dir, name_to[0], + name_to, save_spot); + unlink(fname2); + + msnprintf(command, sizeof command, "cp %s %s", fname, fname2); + if (system(command)) { // XXX + pprintf(p, "System command in jsave_journalentry failed!\n"); + pprintf(p, "Please report this to an admin.\n"); + fprintf(stderr, "FICS: System command failed in " + "jsave_journalentry\n"); + return; + } + + msnprintf(fname, sizeof fname, "%s/player_data/%c/%s.%s", stats_dir, + name_to[0], name_to, STATS_JOURNAL); + + if (!journal_get_info(p, from_spot, WhiteName, &WhiteRating, + BlackName, &BlackRating, type, &t, &i, eco, ending, result, fname)) + return; + + addjournalitem(p, toupper(save_spot), + WhiteName, WhiteRating, + BlackName, BlackRating, + type, t, i, eco, ending, result, to_file); + pprintf(p, "Journal entry %s %c saved in slot %c in journal.\n", + parray[p1].name, toupper(from_spot), toupper(save_spot)); } PUBLIC void |