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:
42 static int ufindbreak(char *message /* message is message text */,
50 char buf[1024]; /* buf is message text */
52 char *sp; /* sp is message text */
54 us = getnatp(player->cnum);
55 if ((tocn = natarg(player->argp[1], "to which country? ")) < 0)
57 if (!(to = getnatp((natid)tocn))) {
58 pr("Bad country number\n");
62 if (us->nat_stat & STAT_GOD) {
63 /* We are gods, we can flash anyone */
64 } else if (us->nat_stat == VIS) {
65 /* We are a visitor. We can only flash the gods. :) */
66 if (!(to->nat_stat & STAT_GOD)) {
67 pr("Visitors can only flash the gods.\n");
71 /* Ok, we are a normal country, can we flash them? */
72 if ((!(to->nat_stat & STAT_GOD)) &&
73 (getrel(to, player->cnum) < FRIENDLY)) {
74 pr("%s is not a deity or friendly with us.\n", to->nat_cnam);
79 if (player->argp[2]) {
80 for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ;
81 for (++sp; *sp && *sp != ' '; ++sp) ;
82 sprintf(buf, ":%s", sp);
83 for(sp = buf; 0 != *sp; ++sp) {
84 if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') ||
87 else if (!(us->nat_flags & NF_UTF8) && (*sp & 0x80))
90 sendmessage(us, to, buf, 1);
92 sendmessage(us, to, "...", 1);
93 while (ugetstring("> ", buf)) {
96 sendmessage(us, to, buf, 0);
98 sendmessage(us, to, "<EOT>", 0);
107 char buf[1024]; /* buf is message text */
108 char *sp; /* sp is message text */
110 us = getnatp(player->cnum);
111 if (player->argp[1]) {
112 for (sp = &player->combuf[0]; *sp && *sp != ' '; ++sp) ;
113 sprintf(buf, ":%s", sp);
114 for(sp = buf; 0 != *sp; ++sp) {
115 if ((*sp >= 0x0 && *sp < 0x20 && *sp != '\t') ||
118 else if (!(us->nat_flags & NF_UTF8) && (*sp & 0x80))
121 sendmessage(us, 0, buf, 1);
123 sendmessage(us, 0, "...", 1);
124 while (ugetstring("> ", buf)) {
127 sendmessage(us, 0, buf, 0);
129 sendmessage(us, 0, "<EOT>", 0);
135 sendmessage(struct natstr *us, struct natstr *to, char *message
136 /* message is message text */, int oneshot)
138 struct player *other;
143 char c; /* c is message text */
146 pos = ufindbreak(message, 60);
152 tm = localtime(&now);
153 for (other = player_next(0); other != 0; other = player_next(other)) {
154 if (to && other->cnum != to->nat_cnum)
156 if (!(wto = getnatp(other->cnum)))
158 if (!to && !player->god && getrel(wto, player->cnum) != ALLIED)
160 if (!player->god && !(wto->nat_flags & NF_FLASH))
166 pr_flash(other, "FLASH from %s (#%d) @ %02d:%02d%s\n",
167 us->nat_cnam, us->nat_cnum, tm->tm_hour,
168 tm->tm_min, message);
170 pr_flash(other, "BROADCAST from %s (#%d) @ %02d:%02d%s\n",
171 us->nat_cnam, us->nat_cnum, tm->tm_hour,
172 tm->tm_min, message);
175 pr_flash(other, "%s (#%d): %s\n",
176 us->nat_cnam, us->nat_cnum, message);
177 player_wakeup(other);
183 pr("Flash sent to %s\n", to->nat_cnam);
185 pr("%s is not logged on\n", to->nat_cnam);
187 pr("Broadcast sent to %d players\n", sent);
189 pr("No-one is logged in\n");
191 if (to && !player->god) {
192 /* If they are allied with us, we would normally see that
193 * they are logged in anyway, so just tell us */
194 if ((getrel(to, player->cnum) == ALLIED) && !sent) {
195 if (to->nat_flags & NF_FLASH)
196 pr("%s is not logged on\n", to->nat_cnam);
198 pr("%s is not accepting flashes\n", to->nat_cnam);
203 sendmessage(us, to, &message[pos], 0);
209 * Return byte-index of the N-th UTF-8 character in UTF-8 string S.
210 * If S doesn't have that many characters, return its length instead.
213 ufindbreak(char *s /* s is message text */, int n)
219 if ((s[i++] & 0xc0) == 0xc0)
220 while ((s[i] & 0xc0) == 0x80)