2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * flash.c: Flash a message to another player
30 * Known contributors to this file:
47 char buf[1024]; /* UTF-8 */
49 char *sp; /* points into player->combuf[], UTF-8 */
51 us = getnatp(player->cnum);
52 if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
54 if (!(to = getnatp((natid)tocn))) {
55 pr("Bad country number\n");
59 if (us->nat_stat & STAT_GOD) {
60 /* We are gods, we can flash anyone */
61 } else if (us->nat_stat == VIS) {
62 /* We are a visitor. We can only flash the gods. :) */
63 if (!(to->nat_stat & STAT_GOD)) {
64 pr("Visitors can only flash the gods.\n");
68 /* Ok, we are a normal country, can we flash them? */
69 if ((!(to->nat_stat & STAT_GOD)) &&
70 (getrel(to, player->cnum) < FRIENDLY)) {
71 pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
76 if (player->argp[2]) {
77 for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ;
78 for (++sp; *sp && *sp != ' '; ++sp) ;
80 if (player->flags & PF_UTF8)
83 copy_utf8_to_ascii_no_funny(buf+1, sp);
84 sendmessage(us, to, buf, 1);
86 sendmessage(us, to, "...", 1);
87 while (ugetstring("> ", buf)) {
90 sendmessage(us, to, buf, 0);
92 sendmessage(us, to, "<EOT>", 0);
101 char buf[1024]; /* UTF-8 */
102 char *sp; /* points into player->combuf[], UTF-8 */
104 us = getnatp(player->cnum);
105 if (player->argp[1]) {
106 for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ;
108 if (player->flags & PF_UTF8)
111 copy_utf8_to_ascii_no_funny(buf+1, sp);
112 sendmessage(us, 0, buf, 1);
114 sendmessage(us, 0, "...", 1);
115 while (ugetstring("> ", buf)) {
118 sendmessage(us, 0, buf, 0);
120 sendmessage(us, 0, "<EOT>", 0);
126 sendmessage(struct natstr *us, struct natstr *to, char *message
127 /* message is message text */, int oneshot)
129 struct player *other;
134 char c; /* c is message text */
137 pos = ufindpfx(message, 60);
143 tm = localtime(&now);
144 for (other = player_next(0); other != 0; other = player_next(other)) {
145 if (other->state != PS_PLAYING)
147 if (to && other->cnum != to->nat_cnum)
149 if (!(wto = getnatp(other->cnum)))
151 if (!to && !player->god && getrel(wto, player->cnum) != ALLIED)
153 if (!player->god && !(wto->nat_flags & NF_FLASH))
159 pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n",
160 us->nat_cnam, us->nat_cnum, tm->tm_hour,
161 tm->tm_min, message);
163 pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n",
164 us->nat_cnam, us->nat_cnum, tm->tm_hour,
165 tm->tm_min, message);
168 pr_flash(other, "%s (#%d): %s\n",
169 us->nat_cnam, us->nat_cnum, message);
170 player_wakeup(other);
176 pr("Flash sent to %s\n", to->nat_cnam);
178 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");
184 if (to && !player->god) {
185 /* If they are allied with us, we would normally see that
186 * they are logged in anyway, so just tell us */
187 if ((getrel(to, player->cnum) == ALLIED) && !sent) {
188 if (to->nat_flags & NF_FLASH)
189 pr("%s is not logged on\n", to->nat_cnam);
191 pr("%s is not accepting flashes\n", to->nat_cnam);
196 sendmessage(us, to, &message[pos], 0);