2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2007, 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-2007
41 static int sendmessage(struct natstr *, struct natstr *, char *, int);
48 char buf[1024]; /* UTF-8 */
50 char *sp; /* points into player->combuf[], UTF-8 */
52 us = getnatp(player->cnum);
53 if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
57 if (us->nat_stat == STAT_GOD) {
58 /* We are gods, we can flash anyone */
59 } else if (us->nat_stat == STAT_VIS) {
60 /* We are a visitor. We can only flash the gods. :) */
61 if (to->nat_stat != STAT_GOD) {
62 pr("Visitors can only flash the gods.\n");
66 /* Ok, we are a normal country, can we flash them? */
67 if (to->nat_stat != STAT_GOD && getrel(to, player->cnum) < FRIENDLY) {
68 pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
73 if (player->argp[2]) {
74 for (sp = player->combuf; *sp && *sp != ' '; ++sp) ;
75 for (++sp; *sp && *sp != ' '; ++sp) ;
77 if (player->flags & PF_UTF8)
80 copy_utf8_to_ascii_no_funny(buf+1, sp);
81 sendmessage(us, to, buf, 1);
83 sendmessage(us, to, "...", 1);
84 while (ugetstring("> ", buf)) {
87 sendmessage(us, to, buf, 0);
89 sendmessage(us, to, "<EOT>", 0);
98 char buf[1024]; /* UTF-8 */
99 char *sp; /* points into player->combuf[], UTF-8 */
101 us = getnatp(player->cnum);
102 if (player->argp[1]) {
103 for (sp = player->combuf; *sp && *sp != ' '; ++sp) ;
105 if (player->flags & PF_UTF8)
108 copy_utf8_to_ascii_no_funny(buf+1, sp);
109 sendmessage(us, 0, buf, 1);
111 sendmessage(us, 0, "...", 1);
112 while (ugetstring("> ", buf)) {
115 sendmessage(us, 0, buf, 0);
117 sendmessage(us, 0, "<EOT>", 0);
123 * Send flash message MESSAGE from US to TO.
125 * Null TO broadcasts to all.
126 * A header identifying US is prepended to the message. It is more
127 * verbose if VERBOSE.
130 sendmessage(struct natstr *us, struct natstr *to, char *message, int verbose)
132 struct player *other;
139 tm = localtime(&now);
140 for (other = player_next(0); other != 0; other = player_next(other)) {
141 if (other->state != PS_PLAYING)
143 if (to && other->cnum != to->nat_cnum)
145 if (!(wto = getnatp(other->cnum)))
147 if (!to && !player->god && getrel(wto, player->cnum) != ALLIED)
149 if (!player->god && !(wto->nat_flags & NF_FLASH))
155 pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n",
156 us->nat_cnam, us->nat_cnum, tm->tm_hour,
157 tm->tm_min, message);
159 pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n",
160 us->nat_cnam, us->nat_cnum, tm->tm_hour,
161 tm->tm_min, message);
164 pr_flash(other, "%s (#%d): %s\n",
165 us->nat_cnam, us->nat_cnum, message);
171 pr("Flash sent to %s\n", to->nat_cnam);
173 pr("%s is not logged on\n", to->nat_cnam);
175 pr("Broadcast sent to %d players\n", sent);
177 pr("No-one is logged in\n");
179 if (to && !player->god) {
180 /* If they are allied with us, we would normally see that
181 * they are logged in anyway, so just tell us */
182 if ((getrel(to, player->cnum) == ALLIED) && !sent) {
183 if (to->nat_flags & NF_FLASH)
184 pr("%s is not logged on\n", to->nat_cnam);
186 pr("%s is not accepting flashes\n", to->nat_cnam);