/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
*
* ---
*
- * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- * related information and legal notices. It is expected that any future
- * projects/authors will amend these files as needed.
+ * See files README, COPYING and CREDITS in the root of the source
+ * tree for related information and legal notices. It is expected
+ * that future projects/authors will amend these files as needed.
*
* ---
*
* Steve McClure, 1998-2000
*/
+#include <config.h>
+
#include "misc.h"
#include "player.h"
#include "nat.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];
+ char buf[1024];
+ char msgbuf[4096]; /* UTF-8 */
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));
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) {
- if ((n = natarg(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], NULL)) < 0)
return RET_SYN;
num = n;
+ may_delete = 0;
}
mbox = mailbox(mbox_buf, num);
clear_telegram_is_new(player->cnum);
return RET_FAIL;
}
teles = 0;
- fseek(telfp, 0L, 0);
+ fseek(telfp, 0L, SEEK_SET);
size = fsize(fileno(telfp));
more:
lastdate = 0;
lastcnum = -1;
lasttype = -1;
- while (fread((s_char *)&tgm, sizeof(tgm), 1, telfp) == 1) {
+ while (fread(&tgm, sizeof(tgm), 1, telfp) == 1) {
readit = 1;
if (tgm.tel_length < 0) {
logerror("bad telegram file header in %s", mbox);
skip:
while (tgm.tel_length > 0) {
nbytes = tgm.tel_length;
- if (nbytes > sizeof(buf) - 1)
- nbytes = sizeof(buf) - 1;
- (void)fread(buf, sizeof(s_char), nbytes, telfp);
- buf[nbytes] = 0;
+ if (nbytes > sizeof(msgbuf) - 1)
+ nbytes = sizeof(msgbuf) - 1;
+ (void)fread(msgbuf, sizeof(s_char), nbytes, telfp);
+ msgbuf[nbytes] = 0;
if (readit)
- prnf(buf);
+ uprnf(msgbuf);
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);