diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-04-02 22:01:55 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-04-02 22:01:55 +0200 |
commit | 2c9a9c1a33953eb654b0ef5eb4e4b57601209e86 (patch) | |
tree | 358496a4ee35f07279c62f762ad4186d369cee36 | |
parent | ab6ade6754ad1957c6c77e2adcee13f9d1be6786 (diff) |
Reformatted UpdateRank()
-rw-r--r-- | FICS/ratings.c | 107 |
1 files changed, 59 insertions, 48 deletions
diff --git a/FICS/ratings.c b/FICS/ratings.c index 32ba932..d4b4bc8 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -985,59 +985,70 @@ PRIVATE int GetRankFileName(char *out, int type) } } -/* loon: Turning this off 28 Oct 1995 (temporary:)) since we're lagged - into outer space */ -PUBLIC void UpdateRank(int type, char *addName, - statistics *sNew, char *delName) -{} +PUBLIC void +UpdateRank(int type, char *addName, statistics *sNew, char *delName) +{ + /* TODO: Reenable */; +} #if 0 -PUBLIC void UpdateRank(int type, char *addName, - statistics *sNew, char *delName) +PUBLIC void +UpdateRank(int type, char *addName, statistics *sNew, char *delName) { - char RankFile[MAX_FILENAME_SIZE]; - char TmpRankFile[MAX_FILENAME_SIZE]; - char line[MAX_RANK_LINE]; - char login[MAX_LOGIN_NAME]; - char command[MAX_STRING_LENGTH]; - int comp; - statistics sCur; - FILE *fp; - FILE *fptemp; + FILE *fp; + FILE *fptemp; + char RankFile[MAX_FILENAME_SIZE]; + char TmpRankFile[MAX_FILENAME_SIZE]; + char command[MAX_STRING_LENGTH]; + char line[MAX_RANK_LINE] = { '\0' }; + char login[MAX_LOGIN_NAME] = { '\0' }; + int comp; + statistics sCur; + + if (GetRankFileName(RankFile, type) < 0) + return; - if (GetRankFileName(RankFile, type) < 0) - return; - fp = fopen(RankFile, "r"); - if (fp == NULL) { - fprintf(stderr, "Can't open rank file to update.\n"); - return; - } - sprintf(TmpRankFile, "%s/tmpRank", sdir); - fptemp = fopen(TmpRankFile, "w"); - if (fptemp == NULL) { - fprintf (stderr, "Unable to open rank file for updating.\n"); - return; - } - while (fgets(line, MAX_RANK_LINE - 1, fp)) { - sscanf(line, "%s %d %d %d", login, &sCur.rating, - &sCur.num, &comp); - if (delName != NULL && !strcasecmp(delName, login)) { /* Kill name. */ - delName = NULL; - continue; - } - if (addName != NULL && CompareStats(addName, sNew, login, &sCur) > 0) { - int computer = in_list(-1, L_COMPUTER, addName); - fprintf(fptemp, "%s %d %d %d\n", addName, sNew->rating, - sNew->num, computer); - addName = NULL; - } - fprintf(fptemp, "%s %d %d %d\n", login, sCur.rating, sCur.num, comp); - } - fclose(fptemp); - fclose(fp); + if ((fp = fopen(RankFile, "r")) == NULL) { + fprintf(stderr, "Can't open rank file to update.\n"); + return; + } + + sprintf(TmpRankFile, "%s/tmpRank", sdir); + + if ((fptemp = fopen(TmpRankFile, "w")) == NULL) { + fprintf (stderr, "Unable to open rank file for updating.\n"); + return; + } + + while (fgets(line, MAX_RANK_LINE - 1, fp)) { + sscanf(line, "%s %d %d %d", login, &sCur.rating, &sCur.num, + &comp); + + if (delName != NULL && + !strcasecmp(delName, login)) { // Kill name. + delName = NULL; + continue; + } + + if (addName != NULL && + CompareStats(addName, sNew, login, &sCur) > 0) { + int computer = in_list(-1, L_COMPUTER, addName); + + fprintf(fptemp, "%s %d %d %d\n", addName, sNew->rating, + sNew->num, computer); + addName = NULL; + } + + fprintf(fptemp, "%s %d %d %d\n", login, sCur.rating, sCur.num, + comp); + } + + fclose(fptemp); + fclose(fp); - sprintf(command, "mv %s %s", TmpRankFile, RankFile); - system(command); + // XXX + sprintf(command, "mv %s %s", TmpRankFile, RankFile); + system(command); } #endif |