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 *, struct natstr *, char *);
42 static int sendmessage(struct natstr *, 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 && getrel(to, player->cnum) < FRIENDLY) {
67 pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
72 return chat(us, to, player->comtail[2]);
78 return chat(getnatp(player->cnum), NULL, player->comtail[1]);
82 * Send flash message(s) from US 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 *us, struct natstr *to, char *message)
90 char buf[1024]; /* UTF-8 */
95 strcpy(buf+2, message);
96 sendmessage(us, to, buf, 1);
98 sendmessage(us, to, "...", 1);
99 while (ugetstring("> ", buf)) {
102 sendmessage(us, to, buf, 0);
104 sendmessage(us, to, "<EOT>", 0);
110 * Send flash message MESSAGE from US to TO.
112 * Null TO broadcasts to all.
113 * A header identifying US is prepended to the message. It is more
114 * verbose if VERBOSE.
117 sendmessage(struct natstr *us, 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)
134 if (other->cnum != to->nat_cnum)
139 wto = getnatp(other->cnum);
140 if (CANT_HAPPEN(!wto))
142 if (!player->god && getrel(wto, player->cnum) != ALLIED)
145 if (!player->god && !(wto->nat_flags & NF_FLASH)) {
152 pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n",
153 us->nat_cnam, us->nat_cnum, tm->tm_hour,
154 tm->tm_min, message);
156 pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n",
157 us->nat_cnam, us->nat_cnum, tm->tm_hour,
158 tm->tm_min, message);
161 pr_flash(other, "%s (#%d): %s\n",
162 us->nat_cnam, us->nat_cnum, message);
168 if (player->god || getrel(to, player->cnum) == ALLIED) {
169 /* Can see TO logged in anyway, so it's okay to tell */
171 pr("%s is not accepting flashes\n", to->nat_cnam);
173 pr("%s is not logged on\n", to->nat_cnam);
180 pr("Broadcast sent to %d players\n", sent);
182 pr("No-one is logged in\n");