/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
*
* Known contributors to this file:
* Steve McClure, 2000
+ * Markus Armbruster, 2005-2016
*/
#include <config.h>
#include <stdarg.h>
#include <sys/uio.h>
#include <unistd.h>
-#include "file.h"
#include "misc.h"
#include "nat.h"
#include "optlist.h"
-#include "player.h"
#include "prototypes.h"
-#include "server.h"
#include "tel.h"
+#include "update.h"
static struct telstr last_tel[MAXNOC];
void
clear_telegram_is_new(natid to)
{
- last_tel[to].tel_type = 0;
last_tel[to].tel_from = NATID_BAD;
- last_tel[to].tel_date = 0;
}
-/*
- * telegram_is_new counts new telegrams the same as read_telegrams in
- * lib/commands/mail.c and lib/commands/rea.c
- */
-
static int
telegram_is_new(natid to, struct telstr *tel)
{
- int is_new = 0;
-
- is_new |= tel->tel_type != last_tel[to].tel_type;
- is_new |= tel->tel_from != last_tel[to].tel_from;
- 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;
- last_tel[to].tel_from = tel->tel_from;
- last_tel[to].tel_date = tel->tel_date;
-
- return is_new;
+ if (tel->tel_from != last_tel[to].tel_from
+ || tel->tel_type != last_tel[to].tel_type
+ || (tel->tel_type != TEL_UPDATE
+ && tel->tel_date - last_tel[to].tel_date > TEL_SECONDS)) {
+ last_tel[to] = *tel;
+ return 1;
+ }
+ return 0;
}
/*
- * Send a telegram from FROM to TO.
- * Format text to send using printf-style FORMAT and optional
+ * Send a telegram from @from to @to.
+ * Format text to send using printf-style @format and optional
* arguments. It is plain ASCII.
* If running from the update, telegram type is TEL_UPDATE.
- * Else if FROM is a deity, type is TEL_BULLETIN.
+ * Else if @from is a deity, type is TEL_BULLETIN.
* Else it is TEL_NORM.
* Return 0 on success, -1 on error.
*/
}
/*
- * Send a telegram from FROM to TO.
- * MESSAGE is the text to send, in UTF-8.
- * TYPE is the telegram type.
+ * Send a telegram from @from to @to.
+ * @message is the text to send, in UTF-8.
+ * @type is the telegram type.
* Return 0 on success, -1 on error.
*/
int
struct iovec iov[2];
int fd;
char box[1024];
- int new_tele = 0;
struct player *other;
if (type == TEL_ANNOUNCE)
tel.tel_from = from;
(void)time(&tel.tel_date);
len = strlen(message);
+ CANT_HAPPEN(len && message[len - 1] != '\n');
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;
for (to = 0; NULL != (np = getnatp(to)); to++) {
if (np->nat_stat < STAT_SANCT)
continue;
- if (!player->god && (getrejects(from, np) & REJ_ANNO))
+ if (!nat_accepts(to, from, REJ_ANNO))
continue;
- np->nat_ann++;
- putnat(np);
+ if (!np->nat_ann || !tel.tel_cont) {
+ np->nat_ann++;
+ putnat(np);
+ }
}
} else {
- 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);
+ 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);
+ }
}
}
}