2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program 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 2 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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * flash.c: Flash a message to another player
30 * Known contributors to this file:
33 * Ron Koenderink, 2005
34 * Markus Armbruster, 2004-2009
41 static int chat(struct natstr *, char *);
42 static int sendmessage(struct natstr *, char *, int);
51 us = getnatp(player->cnum);
52 if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
56 if (us->nat_stat == STAT_GOD) {
57 /* We are gods, we can flash anyone */
58 } else if (us->nat_stat == STAT_VIS) {
59 /* We are a visitor. We can only flash the gods. :) */
60 if (to->nat_stat != STAT_GOD) {
61 pr("Visitors can only flash the gods.\n");
65 /* Ok, we are a normal country, can we flash them? */
66 if (to->nat_stat != STAT_GOD && tocn != player->cnum
67 && getrel(to, player->cnum) < FRIENDLY) {
68 pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
73 return chat(to, player->comtail[2]);
79 return chat(NULL, player->comtail[1]);
83 * Send flash message(s) from US to TO.
84 * Null TO broadcasts to all.
85 * MESSAGE is UTF-8. If it is null, prompt for messages interactively.
89 chat(struct natstr *to, char *message)
91 char buf[1024]; /* UTF-8 */
96 strcpy(buf+2, message);
97 sendmessage(to, buf, 1);
99 sendmessage(to, "...", 1);
100 while (ugetstring("> ", buf)) {
103 sendmessage(to, buf, 0);
105 sendmessage(to, "<EOT>", 0);
111 * Send flash message MESSAGE from US to TO.
113 * Null TO broadcasts to all.
114 * A header identifying US is prepended to the message. It is more
115 * verbose if VERBOSE.
118 sendmessage(struct natstr *to, char *message, int verbose)
120 struct player *other;
123 int sent = 0, rejected = 0;
127 tm = localtime(&now);
128 for (other = player_next(NULL); other; other = player_next(other)) {
129 if (other->state != PS_PLAYING)
133 if (other->cnum != to->nat_cnum)
140 wto = getnatp(other->cnum);
141 if (CANT_HAPPEN(!wto))
143 if (!player->god && getrel(wto, player->cnum) != ALLIED)
146 if (!player->god && !(wto->nat_flags & NF_FLASH)) {
153 pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n",
154 cname(player->cnum), player->cnum, tm->tm_hour,
155 tm->tm_min, message);
157 pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n",
158 cname(player->cnum), player->cnum, tm->tm_hour,
159 tm->tm_min, message);
162 pr_flash(other, "%s (#%d): %s\n",
163 cname(player->cnum), player->cnum, message);
169 if (player->god || to->nat_cnum == player->cnum
170 || getrel(to, 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");