/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* Steve McClure, 1998-2000
*/
-
-#ifdef aix
-#define L_SET 0
-#endif /* aix */
-
#include "misc.h"
#include "player.h"
#include "nat.h"
#include "file.h"
#include "tel.h"
#include "commands.h"
+#include "optlist.h"
+#include "match.h"
#include <stdio.h>
#include <fcntl.h>
int teles;
int size;
unsigned int nbytes;
- s_char buf[4096];
+ s_char buf[4096]; /* buf is message text */
int lasttype;
int lastcnum;
time_t lastdate;
time_t delta;
int first = 1;
int readit;
+ int may_delete = 1; /* may messages be deleted? */
memset(kind, 0, sizeof(kind));
- (void)time(&now);
+ now = time(NULL);
if (*player->argp[0] == 'w') {
- sprintf(kind, "announcement");
+ strcpy(kind, "announcement");
if (player->argp[1] && isdigit(*player->argp[1])) {
delta = days(atoi(player->argp[1]));
then = now - delta;
+ may_delete = 0;
} else
then = np->nat_annotim;
mbox = annfil;
} else {
- sprintf(kind, "telegram");
- if (player->god && player->argp[1] != 0) {
+ strcpy(kind, "telegram");
+ if (player->god && player->argp[1] &&
+ (mineq(player->argp[1], "yes") == ME_MISMATCH) &&
+ (mineq(player->argp[1], "no") == ME_MISMATCH)) {
if ((n = natarg(player->argp[1], "")) < 0)
return RET_SYN;
num = n;
+ may_delete = 0;
}
mbox = mailbox(mbox_buf, num);
clear_telegram_is_new(player->cnum);
}
-#if !defined(_WIN32)
- if ((telfp = fopen(mbox, "r+")) == 0) {
-#else
- if ((telfp = fopen(mbox, "r+b")) == 0) {
-#endif
+ if ((telfp = fopen(mbox, "rb+")) == 0) {
logerror("telegram file %s", mbox);
return RET_FAIL;
}
lasttype = tgm.tel_type;
pr("%s ", telnames[(int)tgm.tel_type]);
if ((tgm.tel_type == TEL_NORM) ||
- (tgm.tel_type == TEL_ANNOUNCE)) {
- pr("from %s, (#%d)", cname(tgm.tel_from), tgm.tel_from);
- }
- if (tgm.tel_type == TEL_BULLETIN) {
+ (tgm.tel_type == TEL_ANNOUNCE) ||
+ (tgm.tel_type == TEL_BULLETIN))
pr("from %s, (#%d)", cname(tgm.tel_from), tgm.tel_from);
- }
pr(" dated %s", ctime(&tgm.tel_date));
lastdate = tgm.tel_date;
}
(void)fread(buf, sizeof(s_char), nbytes, telfp);
buf[nbytes] = 0;
if (readit)
- prnf(buf);
+ uprnf(buf);
tgm.tel_length -= nbytes;
}
}
p = NULL;
- if (teles > 0 && player->cnum == num) { /* } */
+ if (teles > 0 && player->cnum == num && may_delete) {
pr("\n");
if (teles == 1) {
if (chance(0.25))
else
p = "Can I throw away these old love letters? ";
}
- if (player->god && *kind == 't')
- p = getstarg(player->argp[2], p, buf);
- else
- p = getstarg(player->argp[1], p, buf);
+ p = getstarg(player->argp[1], p, buf);
if (p && *p == 'y') {
if ((filelen = fsize(fileno(telfp))) > size) {
pr("Wait a sec! A new %s has arrived...\n", kind);
/* force stdio to re-read tel file */
(void)fflush(telfp);
-#if !defined(_WIN32)
- (void)fseek(telfp, (long)size, L_SET);
-#else
(void)fseek(telfp, (long)size, SEEK_SET);
-#endif
size = filelen;
- (void)time(&now);
+ now = time(NULL);
goto more;
}
if (*kind == 'a') {
/* Here, we just re-open the file for "w" only,
and that will wipe the file clean automatically */
(void)fclose(telfp);
-#if !defined(_WIN32)
- telfp = fopen((char *)mbox, "w");
-#else
telfp = fopen((char *)mbox, "wb");
-#endif
}
}
}