diff options
Diffstat (limited to 'FICS/adminproc.c')
-rw-r--r-- | FICS/adminproc.c | 194 |
1 files changed, 109 insertions, 85 deletions
diff --git a/FICS/adminproc.c b/FICS/adminproc.c index bbb0c24..e670d44 100644 --- a/FICS/adminproc.c +++ b/FICS/adminproc.c @@ -1,17 +1,17 @@ /* - * fics - An internet chess server - * Copyright (c) 1993 Richard V. Nash - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - */ + fics - An internet chess server. + Copyright (C) 1993 Richard V. Nash + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. +*/ #include "stdinclude.h" #include "common.h" @@ -19,6 +19,8 @@ #include <sys/param.h> #include <err.h> +#include <inttypes.h> +#include <stdint.h> #include "adminproc.h" #include "command.h" @@ -183,9 +185,10 @@ create_news_file(int p, param_list param, int admin) msnprintf(filename, sizeof filename, "%s/adminnews.%d", news_dir, param[0].val.integer); - fp = fopen(filename, "w"); - fprintf(fp, "%s\n", param[1].val.string); - fclose(fp); + if ((fp = fopen(filename, "w")) != NULL) { + fprintf(fp, "%s\n", param[1].val.string); + fclose(fp); + } } } else { if (param[0].val.integer > num_news) { @@ -195,9 +198,10 @@ create_news_file(int p, param_list param, int admin) msnprintf(filename, sizeof filename, "%s/news.%d", news_dir, param[0].val.integer); - fp = fopen(filename, "w"); - fprintf(fp, "%s\n", param[1].val.string); - fclose(fp); + if ((fp = fopen(filename, "w")) != NULL) { + fprintf(fp, "%s\n", param[1].val.string); + fclose(fp); + } } } @@ -228,13 +232,14 @@ add_item(char *new_item, char *filename) } end: - fclose(new_fp); + (void) fclose(new_fp); + if (old_fp) { - fclose(old_fp); - remove(filename); + (void) fclose(old_fp); + (void) remove(filename); } - rename(tmp_file, filename); + (void) rename(tmp_file, filename); return 1; } @@ -364,12 +369,12 @@ PUBLIC int com_anews(int p, param_list param) { FILE *fp = NULL; - char *junkp = NULL; char count[10] = { '\0' }; char filename[MAX_FILENAME_SIZE] = { '\0' }; char junk[MAX_LINE_SIZE] = { '\0' }; + char *junkp = NULL; int found = 0; - long int lval = 0; + int64_t lval = 0; time_t crtime = 0; msnprintf(filename, sizeof filename, "%s/newadminnews.index", news_dir); @@ -379,7 +384,7 @@ com_anews(int p, param_list param) return COM_OK; } -#define SCAN_JUNK "%ld %9s" +#define SCAN_JUNK ("%" SCNd64 " " "%9s") _Static_assert(9 < ARRAY_SIZE(count), "Array too small"); if (param[0].type == 0) { @@ -499,9 +504,15 @@ com_anews(int p, param_list param) PUBLIC int strcmpwild(char *mainstr, char *searchstr) { - if (strlen(mainstr) < strlen(searchstr)) + size_t len[2]; + + len[0] = strlen(mainstr); + len[1] = strlen(searchstr); + + if (len[0] < len[1]) return 1; - for (size_t i = 0; i < strlen(mainstr); i++) { + + for (size_t i = 0; i < len[0]; i++) { if (searchstr[i] == '*') return 0; if (mainstr[i] != searchstr[i]) @@ -589,7 +600,7 @@ com_checkSOCKET(int p, param_list param) PUBLIC int com_checkPLAYER(int p, param_list param) { - char *player = param[0].val.word; + char *v_player = param[0].val.word; int p1; ASSERT(parray[p].adminLevel >= ADMIN_ADMIN); @@ -601,48 +612,60 @@ com_checkPLAYER(int p, param_list param) if (p1 < 0) { p1 = (-p1) - 1; - pprintf(p, "%s is not logged in.\n", player); - stolower(player); - - pprintf(p, "name = %s\n", parray[p1].name); - pprintf(p, "login = %s\n", parray[p1].login); - pprintf(p, "fullName = %s\n", (parray[p1].fullName ? - parray[p1].fullName : "(none)")); - pprintf(p, "emailAddress = %s\n", (parray[p1].emailAddress ? - parray[p1].emailAddress : "(none)")); - pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); + pprintf(p, "%s is not logged in.\n", v_player); + stolower(v_player); + + pprintf(p, "name = %s\n", parray[p1].name); + pprintf(p, "login = %s\n", parray[p1].login); + pprintf(p, "fullName = %s\n", + (parray[p1].fullName + ? parray[p1].fullName + : "(none)")); + pprintf(p, "emailAddress = %s\n", + (parray[p1].emailAddress + ? parray[p1].emailAddress + : "(none)")); + pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); #if 0 pprintf(p, "network_player = %d\n", parray[p1].network_player); #endif - pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); - pprintf(p, "num_comments = %d\n", parray[p1].num_comments); + pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); + pprintf(p, "num_comments = %d\n", parray[p1].num_comments); player_remove(p1); return COM_OK; } else { + char tbuf[30] = { '\0' }; + p1 = p1 - 1; - pprintf(p, "%s is number %d in parray of size %d\n", player, p1, + pprintf(p, "%s is number %d in parray of size %d\n", v_player, p1, (p_num + 1)); - pprintf(p, "name = %s\n", parray[p1].name); - pprintf(p, "login = %s\n", parray[p1].login); - pprintf(p, "fullName = %s\n", (parray[p1].fullName ? - parray[p1].fullName : "(none)")); - pprintf(p, "emailAddress = %s\n", (parray[p1].emailAddress ? - parray[p1].emailAddress : "(none)")); - pprintf(p, "socket = %d\n", parray[p1].socket); - pprintf(p, "registered = %d\n", parray[p1].registered); - pprintf(p, "last_tell = %d\n", parray[p1].last_tell); - pprintf(p, "last_channel = %d\n", parray[p1].last_channel); - pprintf(p, "logon_time = %s", - ctime((time_t *) &parray[p1].logon_time)); - pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); + pprintf(p, "name = %s\n", parray[p1].name); + pprintf(p, "login = %s\n", parray[p1].login); + pprintf(p, "fullName = %s\n", + (parray[p1].fullName + ? parray[p1].fullName + : "(none)")); + pprintf(p, "emailAddress = %s\n", + (parray[p1].emailAddress + ? parray[p1].emailAddress + : "(none)")); + pprintf(p, "socket = %d\n", parray[p1].socket); + pprintf(p, "registered = %d\n", parray[p1].registered); + pprintf(p, "last_tell = %d\n", parray[p1].last_tell); + pprintf(p, "last_channel = %d\n", parray[p1].last_channel); + pprintf(p, "logon_time = %s", + (ctime_r(&parray[p1].logon_time, tbuf) != NULL + ? &tbuf[0] + : "n/a")); + pprintf(p, "adminLevel = %d\n", parray[p1].adminLevel); #if 0 pprintf(p, "network_player = %d\n", parray[p1].network_player); #endif - pprintf(p, "thisHost = %s\n", dotQuad(parray[p1].thisHost)); - pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); - pprintf(p, "num_comments = %d\n", parray[p1].num_comments); + pprintf(p, "thisHost = %s\n", dotQuad(parray[p1].thisHost)); + pprintf(p, "lastHost = %s\n", dotQuad(parray[p1].lastHost)); + pprintf(p, "num_comments = %d\n", parray[p1].num_comments); } return COM_OK; @@ -713,7 +736,8 @@ com_checkGAME(int p, param_list param) // than that for (g = 0; g < g_num; g++) { - multicol_store(m, tmp); + memset(tmp, 0, sizeof tmp); // XXX + multicol_store(m, tmp); // is this call right? if (!strcasecmp(garray[g].white_name, param[0].val.word)) { @@ -877,13 +901,13 @@ com_checkGAME(int p, param_list param) PUBLIC int com_remplayer(int p, param_list param) { - char *player = param[0].val.word; + char *v_player = param[0].val.word; char playerlower[MAX_LOGIN_NAME] = { '\0' }; int p1, lookup; ASSERT(parray[p].adminLevel >= ADMIN_ADMIN); - mstrlcpy(playerlower, player, sizeof(playerlower)); + mstrlcpy(playerlower, v_player, sizeof(playerlower)); stolower(playerlower); p1 = player_new(); lookup = player_read(p1, playerlower); @@ -901,7 +925,7 @@ com_remplayer(int p, param_list param) player_remove(p1); if (lookup) { - pprintf(p, "No player by the name %s is registered.\n", player); + pprintf(p, "No player by the name %s is registered.\n", v_player); return COM_OK; } @@ -911,10 +935,10 @@ com_remplayer(int p, param_list param) } if (!player_kill(playerlower)) { - pprintf(p, "Player %s removed.\n", player); - UpdateRank(TYPE_BLITZ, NULL, NULL, player); - UpdateRank(TYPE_STAND, NULL, NULL, player); - UpdateRank(TYPE_WILD, NULL, NULL, player); + pprintf(p, "Player %s removed.\n", v_player); + UpdateRank(TYPE_BLITZ, NULL, NULL, v_player); + UpdateRank(TYPE_STAND, NULL, NULL, v_player); + UpdateRank(TYPE_WILD, NULL, NULL, v_player); } else { pprintf(p, "Remplayer failed.\n"); } @@ -939,14 +963,14 @@ com_remplayer(int p, param_list param) PUBLIC int com_raisedead(int p, param_list param) { - char *player = param[0].val.word; + char *v_player = param[0].val.word; char newplayerlower[MAX_LOGIN_NAME] = { '\0' }; char playerlower[MAX_LOGIN_NAME] = { '\0' }; int p1, p2, lookup; ASSERT(parray[p].adminLevel >= ADMIN_ADMIN); - mstrlcpy(playerlower, player, sizeof playerlower); + mstrlcpy(playerlower, v_player, sizeof playerlower); stolower(playerlower); if (player_find_bylogin(playerlower) >= 0) { @@ -961,7 +985,7 @@ com_raisedead(int p, param_list param) if (!lookup) { pprintf(p, "A player by the name %s is already registered.\n", - player); + v_player); pprintf(p, "Obtain a new handle for the dead person.\n"); pprintf(p, "Then use raisedead [oldname] [newname].\n"); return COM_OK; @@ -969,22 +993,22 @@ com_raisedead(int p, param_list param) if (param[1].type == TYPE_NULL) { if (!player_raise(playerlower)) { - pprintf(p, "Player %s raised from dead.\n", player); + pprintf(p, "Player %s raised from dead.\n", v_player); p1 = player_new(); if (!player_read(p1, playerlower)) { if (parray[p1].s_stats.rating > 0) { - UpdateRank(TYPE_STAND, player, - &parray[p1].s_stats, player); + UpdateRank(TYPE_STAND, v_player, + &parray[p1].s_stats, v_player); } if (parray[p1].b_stats.rating > 0) { - UpdateRank(TYPE_BLITZ, player, - &parray[p1].b_stats, player); + UpdateRank(TYPE_BLITZ, v_player, + &parray[p1].b_stats, v_player); } if (parray[p1].w_stats.rating > 0) { - UpdateRank(TYPE_WILD, player, - &parray[p1].w_stats, player); + UpdateRank(TYPE_WILD, v_player, + &parray[p1].w_stats, v_player); } } @@ -1013,14 +1037,14 @@ com_raisedead(int p, param_list param) if (!lookup) { pprintf(p, "A player by the name %s is already " - "registered.\n", player); + "registered.\n", v_player); pprintf(p, "Obtain another new handle for the dead " "person.\n"); return COM_OK; } if (!player_reincarn(playerlower, newplayerlower)) { - pprintf(p, "Player %s reincarnated to %s.\n", player, + pprintf(p, "Player %s reincarnated to %s.\n", v_player, newplayer); p2 = player_new(); @@ -1543,14 +1567,14 @@ PUBLIC int com_asethandle(int p, param_list param) { char *newplayer = param[1].val.word; - char *player = param[0].val.word; + char *v_player = param[0].val.word; char newplayerlower[MAX_LOGIN_NAME] = { '\0' }; char playerlower[MAX_LOGIN_NAME] = { '\0' }; int p1; ASSERT(parray[p].adminLevel >= ADMIN_ADMIN); - mstrlcpy(playerlower, player, sizeof playerlower); + mstrlcpy(playerlower, v_player, sizeof playerlower); stolower(playerlower); mstrlcpy(newplayerlower, newplayer, sizeof newplayerlower); @@ -1569,7 +1593,7 @@ com_asethandle(int p, param_list param) p1 = player_new(); if (player_read(p1, playerlower)) { - pprintf(p, "No player by the name %s is registered.\n", player); + pprintf(p, "No player by the name %s is registered.\n", v_player); player_remove(p1); return COM_OK; } else { @@ -1596,22 +1620,22 @@ com_asethandle(int p, param_list param) if ((!player_rename(playerlower, newplayerlower)) && (!player_read(p1, newplayerlower))) { - pprintf(p, "Player %s renamed to %s.\n", player, newplayer); + pprintf(p, "Player %s renamed to %s.\n", v_player, newplayer); strfree(parray[p1].name); parray[p1].name = xstrdup(newplayer); player_save(p1); if (parray[p1].s_stats.rating > 0) { UpdateRank(TYPE_STAND, newplayer, &parray[p1].s_stats, - player); + v_player); } if (parray[p1].b_stats.rating > 0) { UpdateRank(TYPE_BLITZ, newplayer, &parray[p1].b_stats, - player); + v_player); } if (parray[p1].w_stats.rating > 0) { UpdateRank(TYPE_WILD, newplayer, &parray[p1].w_stats, - player); + v_player); } } else { pprintf(p, "Asethandle failed.\n"); |