Don't log out deity when gamedown() can't read downfil
Broken in commit c7e2442d
. Fix by factoring show_first_tel() out of
gamedown() and show_motd().
This commit is contained in:
parent
1dba1fccee
commit
d2cd46ce20
3 changed files with 30 additions and 45 deletions
|
@ -382,6 +382,7 @@ extern int natbyname(char *, natid *);
|
||||||
extern int natpass(int, char *);
|
extern int natpass(int, char *);
|
||||||
/* player.c */
|
/* player.c */
|
||||||
extern struct player *player; /* current player's context */
|
extern struct player *player; /* current player's context */
|
||||||
|
extern int show_first_tel(char *);
|
||||||
extern char *praddr(struct player *);
|
extern char *praddr(struct player *);
|
||||||
extern void player_main(struct player *);
|
extern void player_main(struct player *);
|
||||||
/* more under Commands */
|
/* more under Commands */
|
||||||
|
|
|
@ -48,7 +48,6 @@
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "tel.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define KEEP_COMMANDS 50
|
#define KEEP_COMMANDS 50
|
||||||
|
@ -184,40 +183,14 @@ disable_coms(void)
|
||||||
static int
|
static int
|
||||||
gamedown(int suppress_deity_message)
|
gamedown(int suppress_deity_message)
|
||||||
{
|
{
|
||||||
FILE *down_fp;
|
|
||||||
struct telstr tgm;
|
|
||||||
char buf[MAXTELSIZE + 1]; /* UTF-8 */
|
|
||||||
|
|
||||||
if (!game_play_disabled())
|
if (!game_play_disabled())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if ((down_fp = fopen(downfil, "rb")) == NULL) {
|
|
||||||
logerror("Could not open downfil.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (fread(&tgm, sizeof(tgm), 1, down_fp) != 1) {
|
|
||||||
logerror("bad header on login message (downfil)");
|
|
||||||
fclose(down_fp);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (tgm.tel_length >= (long)sizeof(buf)) {
|
|
||||||
logerror("text length (%ld) is too long for login message (downfil)", tgm.tel_length);
|
|
||||||
fclose(down_fp);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (fread(buf, tgm.tel_length, 1, down_fp) != 1) {
|
|
||||||
logerror("bad length %ld on login message", tgm.tel_length);
|
|
||||||
fclose(down_fp);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
buf[tgm.tel_length] = 0;
|
|
||||||
fclose(down_fp);
|
|
||||||
if (player->god) {
|
if (player->god) {
|
||||||
if (!suppress_deity_message)
|
if (!suppress_deity_message)
|
||||||
pr("The game is down\n");
|
pr("The game is down\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
uprnf(buf);
|
show_first_tel(downfil);
|
||||||
pr("\nThe game is down\n");
|
pr("\nThe game is down\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,37 +257,48 @@ execute(void)
|
||||||
int
|
int
|
||||||
show_motd(void)
|
show_motd(void)
|
||||||
{
|
{
|
||||||
FILE *motd_fp;
|
show_first_tel(motdfil);
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print first telegram in file FNAME.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
show_first_tel(char *fname)
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
struct telstr tgm;
|
struct telstr tgm;
|
||||||
char buf[MAXTELSIZE + 1]; /* UTF-8 */
|
char buf[MAXTELSIZE + 1]; /* UTF-8 */
|
||||||
|
|
||||||
if ((motd_fp = fopen(motdfil, "rb")) == NULL) {
|
if ((fp = fopen(fname, "rb")) == NULL) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return RET_OK;
|
return 0;
|
||||||
else {
|
else {
|
||||||
logerror("Could not open motd (%s).\n", motdfil);
|
logerror("Could not open %s.\n", fname);
|
||||||
return RET_OK;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fread(&tgm, sizeof(tgm), 1, motd_fp) != 1) {
|
if (fread(&tgm, sizeof(tgm), 1, fp) != 1) {
|
||||||
logerror("bad header on login message (motdfil)");
|
logerror("bad header on login message (%s)", fname);
|
||||||
fclose(motd_fp);
|
fclose(fp);
|
||||||
return RET_OK;
|
return -1;
|
||||||
}
|
}
|
||||||
if (tgm.tel_length >= (long)sizeof(buf)) {
|
if (tgm.tel_length >= (long)sizeof(buf)) {
|
||||||
logerror("text length (%ld) is too long for login message (motdfil)", tgm.tel_length);
|
logerror("text length (%ld) is too long for login message (%s)",
|
||||||
fclose(motd_fp);
|
tgm.tel_length, fname);
|
||||||
return RET_OK;
|
fclose(fp);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (fread(buf, tgm.tel_length, 1, motd_fp) != 1) {
|
if (fread(buf, tgm.tel_length, 1, fp) != 1) {
|
||||||
logerror("bad length %ld on login message", tgm.tel_length);
|
logerror("bad length %ld on login message", tgm.tel_length);
|
||||||
fclose(motd_fp);
|
fclose(fp);
|
||||||
return RET_OK;
|
return -1;
|
||||||
}
|
}
|
||||||
buf[tgm.tel_length] = 0;
|
buf[tgm.tel_length] = 0;
|
||||||
uprnf(buf);
|
uprnf(buf);
|
||||||
fclose(motd_fp);
|
fclose(fp);
|
||||||
return RET_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue