Get rid of RET_SYS, just use RET_FAIL
RET_SYS was used for commands failing due to internal or environmental errors, but not really systematically. The difference to RET_FAIL is how dispatch() treats them: RET_SYS got logged, and cost no BTUs. More specific logging is possible at the point of failure than in dispatch(). Make sure that's done for all failures that used to return RET_SYS. The change in BTU charging affects commands consider, offer, repay, trade failing due to internal errors. It also affects deity commands reload and turn (irrelevant because deities get unlimited BTUs), and commands apropos, info and motd (irrelevant because they cost no BTUs).
This commit is contained in:
parent
e803950463
commit
29aefc356f
10 changed files with 42 additions and 36 deletions
|
@ -91,7 +91,6 @@ void exit_nomem(void) ATTRIBUTE((noreturn));
|
|||
#define RET_OK 0 /* command completed sucessfully */
|
||||
#define RET_FAIL 1 /* command completed unsucessfully [?] */
|
||||
#define RET_SYN 2 /* syntax error in command */
|
||||
#define RET_SYS 3 /* system error (missing file, etc) */
|
||||
|
||||
extern char *getstarg(char *input, char *prompt, char buf[]);
|
||||
extern char *getstring(char *prompt, char buf[]);
|
||||
|
|
|
@ -196,8 +196,9 @@ loan_accept(struct ltcomstr *ltcp)
|
|||
return RET_OK;
|
||||
}
|
||||
if (!getloan(ltcp->num, lp)) {
|
||||
pr("loan_accept: can't read loan; get help!\n");
|
||||
return RET_SYS;
|
||||
logerror("loan_accept: can't read loan");
|
||||
pr("can't read loan; get help!\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
if (lp->l_status == LS_FREE) { /* other guy retratcted already */
|
||||
late(ltcp);
|
||||
|
@ -250,8 +251,9 @@ loan_decline(struct ltcomstr *ltcp)
|
|||
|
||||
lp = <cp->u.l;
|
||||
if (!getloan(ltcp->num, lp)) {
|
||||
pr("Decline: can't read loan; get help!\n");
|
||||
return RET_SYS;
|
||||
logerror("loan_decline: can't read loan");
|
||||
pr("can't read loan; get help!\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
/* loan got accepted somehow between now and last time we checked */
|
||||
if (lp->l_status == LS_SIGNED) {
|
||||
|
@ -260,8 +262,9 @@ loan_decline(struct ltcomstr *ltcp)
|
|||
}
|
||||
lp->l_status = LS_FREE;
|
||||
if (!putloan(ltcp->num, lp)) {
|
||||
pr("loan_decline: can't write loan; get help!\n");
|
||||
return RET_SYS;
|
||||
logerror("loan_decline: can't write loan");
|
||||
pr("can't write loan; get help!\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
decline(ltcp);
|
||||
return RET_OK;
|
||||
|
@ -281,8 +284,9 @@ treaty_accept(struct ltcomstr *ltcp)
|
|||
return RET_OK;
|
||||
}
|
||||
if (!gettre(ltcp->num, tp)) {
|
||||
pr("Accept: can't read treaty; get help!\n");
|
||||
return RET_SYS;
|
||||
pr("treaty_accept: can't read treaty");
|
||||
pr("can't read treaty; get help!\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
if (tp->trt_status == TS_FREE) { /* treaty offer withdrawn */
|
||||
late(ltcp);
|
||||
|
@ -294,8 +298,9 @@ treaty_accept(struct ltcomstr *ltcp)
|
|||
}
|
||||
tp->trt_status = TS_SIGNED;
|
||||
if (!puttre(ltcp->num, tp)) {
|
||||
pr("treaty_accept: can't write treaty");
|
||||
pr("Problem saving treaty; get help!\n");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
accpt(ltcp);
|
||||
pr("Treaty in effect until %s", ctime(&tp->trt_exp));
|
||||
|
@ -312,8 +317,9 @@ treaty_decline(struct ltcomstr *ltcp)
|
|||
|
||||
tp = <cp->u.t;
|
||||
if (!gettre(ltcp->num, tp)) {
|
||||
pr("Decline: can't read treaty; get help!\n");
|
||||
return RET_SYS;
|
||||
logerror("treaty_decline: can't read treaty");
|
||||
pr("can't read treaty; get help!\n");
|
||||
return RET_FAIL;
|
||||
}
|
||||
/* treaty got signed somehow between now and last time we read it */
|
||||
if (tp->trt_status == TS_SIGNED) {
|
||||
|
@ -322,8 +328,9 @@ treaty_decline(struct ltcomstr *ltcp)
|
|||
}
|
||||
tp->trt_status = TS_FREE;
|
||||
if (!puttre(ltcp->num, tp)) {
|
||||
logerror("treaty_decline: can't write treaty");
|
||||
pr("Problem saving treaty; get help!\n");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
decline(ltcp);
|
||||
return RET_OK;
|
||||
|
|
|
@ -99,7 +99,7 @@ info(void)
|
|||
if (info_dp == 0) {
|
||||
pr("Can't open info dir\n");
|
||||
logerror("Can't open info dir \"%s\"\n", infodir);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
while ((dp = readdir(info_dp)) != 0) {
|
||||
|
@ -146,13 +146,13 @@ info(void)
|
|||
logerror("Cannot fstat for \"%s\" info file (%s)",
|
||||
filename, strerror(errno));
|
||||
fclose(fp);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
if ((statb.st_mode & S_IFREG) == 0) {
|
||||
pr("Error reading info file for %s\n", name);
|
||||
logerror("The info file \"%s\" is not regular file\n", filename);
|
||||
fclose(fp);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
pr("Information on: %s Last modification date: %s",
|
||||
name, ctime(&statb.st_mtime));
|
||||
|
@ -193,7 +193,7 @@ apro(void)
|
|||
if (info_dp == NULL) {
|
||||
pr("Can't open info dir \n");
|
||||
logerror("Can't open info dir \"%s\"", infodir);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
fbuf = malloc(256);
|
||||
|
@ -315,7 +315,6 @@ info(void)
|
|||
switch (GetLastError()) {
|
||||
case ERROR_FILE_NOT_FOUND:
|
||||
pr("Sorry, there is no info on %s\n", name);
|
||||
return RET_FAIL;
|
||||
break;
|
||||
case ERROR_PATH_NOT_FOUND:
|
||||
pr("Can't open info dir\n");
|
||||
|
@ -326,7 +325,7 @@ info(void)
|
|||
logerror("Error (%lu) reading info dir(%s)\\file(%s)",
|
||||
GetLastError(), infodir, filename);
|
||||
}
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
do {
|
||||
if ((fData.dwFileAttributes != (DWORD)-1) &&
|
||||
|
@ -381,7 +380,7 @@ info(void)
|
|||
logerror("The info file \"%s\" is not regular file\n",
|
||||
filename);
|
||||
fclose(fp);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -429,7 +428,7 @@ apro(void)
|
|||
logerror("Error (%lu) reading info dir(%s)\\file(%s)",
|
||||
GetLastError(), infodir, filename);
|
||||
}
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
fbuf = malloc(256);
|
||||
|
|
|
@ -142,8 +142,9 @@ do_treaty(void)
|
|||
trty.trt_cnb = recipient;
|
||||
trty.trt_exp = j * SECS_PER_DAY + now;
|
||||
if (!puttre(nstr.cur, &trty)) {
|
||||
logerror("do_treaty: can't write treaty");
|
||||
pr("Couldn't save treaty; get help.\n");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
wu(0, recipient, "Treaty #%d proposed to you by %s\n",
|
||||
nstr.cur, cname(player->cnum));
|
||||
|
@ -230,8 +231,9 @@ do_loan(void)
|
|||
(void)time(&loan.l_lastpay);
|
||||
loan.l_duedate = loan.l_ldur * SECS_PER_DAY + loan.l_lastpay;
|
||||
if (!putloan(nstr.cur, &loan)) {
|
||||
logerror("do_loan: can't save loan");
|
||||
pr("Couldn't save loan; get help!\n");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
pr("You have offered loan %d\n", nstr.cur);
|
||||
wu(0, recipient, "Country #%d has offered you a loan (#%d)\n",
|
||||
|
|
|
@ -47,7 +47,7 @@ relo(void)
|
|||
|
||||
if (journal_reopen() < 0) {
|
||||
pr("Can't reopen journal");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
pr("Journal reopened.\n");
|
||||
|
||||
|
@ -56,7 +56,7 @@ relo(void)
|
|||
|
||||
if (logreopen() < 0) {
|
||||
pr("Can't reopen log");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
pr("Log reopened.\n");
|
||||
|
||||
|
|
|
@ -105,8 +105,9 @@ repa(void)
|
|||
loan.l_amtpaid += payment;
|
||||
}
|
||||
if (!putloan(loan_num, &loan)) {
|
||||
logerror("repa: can't write loan");
|
||||
pr("Can't save loan; get help!\n");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
|
|
@ -134,8 +134,9 @@ trad(void)
|
|||
pr("Can't find trade #%d!\n", trade.trd_unitid);
|
||||
trade.trd_unitid = -1;
|
||||
if (!puttrade(lotno, &trade)) {
|
||||
logerror("trad: can't write trade");
|
||||
pr("Couldn't save after getitem failed; get help!\n");
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
return RET_OK;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ turn(void)
|
|||
if ((unlink(downfil) == -1) && (errno != ENOENT)) {
|
||||
pr("Could not remove no-login file, logins still disabled.\n");
|
||||
logerror("Could not remove no-login file (%s).\n", downfil);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
return RET_OK;
|
||||
} else {
|
||||
|
@ -89,7 +89,7 @@ turn(void)
|
|||
pr("Could not remove motd.\n");
|
||||
logerror("Could not remove motd file (%s).\n",
|
||||
msgfilepath);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
return RET_OK;
|
||||
} else
|
||||
|
@ -100,7 +100,7 @@ turn(void)
|
|||
if (fptr == NULL) {
|
||||
pr("Something went wrong opening the message file.\n");
|
||||
logerror("Could not open message file (%s).\n", msgfilepath);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
if (msgfilepath == downfil)
|
||||
|
@ -112,13 +112,13 @@ turn(void)
|
|||
pr("Something went wrong writing the message file.\n");
|
||||
logerror("Could not properly write message file (%s).\n",
|
||||
msgfilepath);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
if (fclose(fptr)) {
|
||||
pr("Something went wrong closing the message.\n");
|
||||
logerror("Could not properly close message file (%s).\n",
|
||||
msgfilepath);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
pr("\n");
|
||||
|
|
|
@ -113,9 +113,6 @@ dispatch(char *buf, char *redir)
|
|||
case RET_SYN:
|
||||
pr("Usage: %s\n", command->c_form);
|
||||
break;
|
||||
case RET_SYS:
|
||||
logerror("System error, command failed: %s", command->c_form);
|
||||
break;
|
||||
default:
|
||||
CANT_REACH();
|
||||
break;
|
||||
|
|
|
@ -295,7 +295,7 @@ show_motd(void)
|
|||
else {
|
||||
pr ("Could not open motd.\n");
|
||||
logerror("Could not open motd (%s).\n", motdfil);
|
||||
return RET_SYS;
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue