2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * flash.c: Flash a message to another player
29 * Known contributors to this file:
32 * Ron Koenderink, 2005
33 * Markus Armbruster, 2004-2013
40 static int chat(struct natstr *, char *);
41 static int sendmessage(struct natstr *, char *, int);
50 us = getnatp(player->cnum);
51 if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
55 if (us->nat_stat == STAT_GOD) {
56 /* We are gods, we can flash anyone */
57 } else if (us->nat_stat == STAT_VIS) {
58 /* We are a visitor. We can only flash the gods. :) */
59 if (to->nat_stat != STAT_GOD) {
60 pr("Visitors can only flash the gods.\n");
64 /* Ok, we are a normal country, can we flash them? */
65 if (to->nat_stat != STAT_GOD
66 && relations_with(tocn, player->cnum) < FRIENDLY) {
67 pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
72 return chat(to, player->comtail[2]);
78 return chat(NULL, player->comtail[1]);
82 * Send flash message(s) to @to.
83 * Null @to broadcasts to all.
84 * @message is UTF-8. If it is null, prompt for messages interactively.
88 chat(struct natstr *to, char *message)
90 char buf[1024]; /* UTF-8 */
95 strcpy(buf+2, message);
96 sendmessage(to, buf, 1);
98 sendmessage(to, "...", 1);
99 while (ugetstring("> ", buf)) {
102 sendmessage(to, buf, 0);
104 sendmessage(to, "<EOT>", 0);
110 * Send flash message @message to @to.
112 * Null @to broadcasts to all.
113 * A header identifying the player is prepended to the message. It is
114 * more verbose if @verbose.
117 sendmessage(struct natstr *to, char *message, int verbose)
119 struct player *other;
122 int sent = 0, rejected = 0;
126 tm = localtime(&now);
127 for (other = player_next(NULL); other; other = player_next(other)) {
128 if (other->state != PS_PLAYING)
132 if (other->cnum != to->nat_cnum)
139 wto = getnatp(other->cnum);
140 if (CANT_HAPPEN(!wto))
143 && relations_with(other->cnum, player->cnum) != ALLIED)
146 if (!player->god && !(wto->nat_flags & NF_FLASH)) {
153 pr_flash(other, "FLASH from %s @ %02d:%02d%s\n",
154 prnatid(player->cnum),
155 tm->tm_hour, tm->tm_min, message);
157 pr_flash(other, "BROADCAST from %s @ %02d:%02d%s\n",
158 prnatid(player->cnum),
159 tm->tm_hour, tm->tm_min, message);
162 pr_flash(other, "%s: %s\n",
163 prnatid(player->cnum), message);
170 || relations_with(to->nat_cnum, player->cnum) == ALLIED) {
171 /* Can see TO logged in anyway, so it's okay to tell */
173 pr("%s is not accepting flashes\n", to->nat_cnam);
175 pr("%s is not logged on\n", to->nat_cnam);
182 pr("Broadcast sent to %d players\n", sent);
184 pr("No-one is logged in\n");