/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire 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
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
*
* Known contributors to this file:
* Steve McClure, 2000
+ * Markus Armbruster, 2005-2011
*/
#include <config.h>
clear_telegram_is_new(natid to)
{
last_tel[to].tel_type = 0;
- last_tel[to].tel_from = 0;
+ last_tel[to].tel_from = NATID_BAD;
last_tel[to].tel_date = 0;
}
is_new |= tel->tel_type != last_tel[to].tel_type;
is_new |= tel->tel_from != last_tel[to].tel_from;
- is_new |= !update_running && /* updates can take a long time */
+ is_new |= tel->tel_type != TEL_UPDATE &&
abs(tel->tel_date - last_tel[to].tel_date) > TEL_SECONDS;
last_tel[to].tel_type = tel->tel_type;
struct iovec iov[2];
int fd;
char box[1024];
- int write_ok = 0;
- int new_tele = 0;
struct player *other;
if (type == TEL_ANNOUNCE)
#else
if ((fd = open(box, O_WRONLY | O_APPEND | O_BINARY, 0)) < 0) {
#endif
- logerror("telegram 'open' of %s (#%d) failed", box, to);
+ logerror("telegram 'open' of %s failed", box);
return -1;
}
+
memset(&tel, 0, sizeof(tel));
tel.tel_from = from;
(void)time(&tel.tel_date);
len = strlen(message);
tel.tel_length = len;
tel.tel_type = type;
+ tel.tel_cont = !telegram_is_new(to, &tel);
iov[0].iov_base = &tel;
iov[0].iov_len = sizeof(tel);
iov[1].iov_base = message;
iov[1].iov_len = len;
if (writev(fd, iov, 2) < (int)(iov[0].iov_len + iov[1].iov_len)) {
- logerror("telegram 'write' to #%d failed", to);
- } else
- write_ok = 1;
+ logerror("telegram 'write' to %s failed", box);
+ close(fd);
+ return -1;
+ }
+ if (close(fd) < 0) {
+ logerror("telegram 'write' to %s failed to close.", box);
+ return -1;
+ }
- if (close(fd) == -1) {
- logerror("telegram 'write' to #%d failed to close.", to);
- } else if (write_ok && type == TEL_ANNOUNCE) {
+ if (type == TEL_ANNOUNCE) {
for (to = 0; NULL != (np = getnatp(to)); to++) {
if (np->nat_stat < STAT_SANCT)
continue;
if (!player->god && (getrejects(from, np) & REJ_ANNO))
continue;
- np->nat_ann++;
- putnat(np);
+ if (!np->nat_ann || !tel.tel_cont) {
+ np->nat_ann++;
+ putnat(np);
+ }
}
- } else if (write_ok) {
- new_tele = telegram_is_new(to, &tel);
- np->nat_tgms += new_tele || np->nat_tgms == 0;
- putnat(np);
-
- if (new_tele && np->nat_flags & NF_INFORM) {
- if (NULL != (other = getplayer(to))) {
- if (np->nat_tgms == 1)
- pr_inform(other, "[new tele]\n");
- else
- pr_inform(other, "[%d new teles]\n", np->nat_tgms);
+ } else {
+ if (!np->nat_tgms || !tel.tel_cont) {
+ np->nat_tgms++;
+ putnat(np);
+ if (np->nat_flags & NF_INFORM) {
+ other = getplayer(to);
+ if (other) {
+ if (np->nat_tgms == 1)
+ pr_inform(other, "[new tele]\n");
+ else
+ pr_inform(other, "[%d new teles]\n", np->nat_tgms);
+ }
}
}
}