]> git.pond.sub.org Git - empserver/blob - src/lib/commands/tele.c
Update copyright notice
[empserver] / src / lib / commands / tele.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                Ken Stevens, Steve McClure, Markus Armbruster
5  *
6  *  Empire 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 3 of the License, or
9  *  (at your option) any later version.
10  *
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.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  *  ---
20  *
21  *  See files README, COPYING and CREDITS in the root of the source
22  *  tree for related information and legal notices.  It is expected
23  *  that future projects/authors will amend these files as needed.
24  *
25  *  ---
26  *
27  *  tele.c: Send a telegram
28  *
29  *  Known contributors to this file:
30  *     Steve McClure, 2000
31  */
32
33 #include <config.h>
34
35 #include "commands.h"
36 #include "news.h"
37 #include "optlist.h"
38 #include "tel.h"
39
40 int
41 tele(void)
42 {
43     natid to;
44     struct natstr *natp;
45     char buf[MAXTELSIZE + 1];   /* UTF-8 */
46     int n;
47
48     if (*player->argp[0] == 'a') {
49         if (getele("everybody", buf) <= 0) {
50             pr("Announcement aborted\n");
51             return RET_FAIL;
52         }
53         pr("\n");
54         to = 0;
55         if (typed_wu(player->cnum, to, buf, TEL_ANNOUNCE) < 0)
56             logerror("tele: typed_wu failed to #%d", to);
57     } else if (*player->argp[0] == 'p') {
58         if (getele("your Gracious Deity", buf) <= 0) {
59             pr("Prayer aborted\n");
60             return RET_FAIL;
61         }
62         pr("\n");
63         if (typed_wu(player->cnum, 0, buf, TEL_NORM) < 0)
64             logerror("tele: typed_wu failed to #0");
65     } else {
66         int kk;
67
68         kk = 1;
69         do {
70             if ((n = natarg(player->argp[kk], "for which country? ")) < 0)
71                 return RET_SYN;
72             to = n;
73
74             if (kk == 1) {
75                 if (player->argp[2]) {
76                     if (getele("multiple recipients", buf) < 0) {
77                         pr("Telegram aborted\n");
78                         return RET_FAIL;
79                     }
80                 } else {
81                     if (getele(cname(to), buf) < 0) {
82                         pr("Telegram aborted\n");
83                         return RET_FAIL;
84                     }
85                 }
86                 pr("\n");
87             }
88
89             natp = getnatp(to);
90             if (natp->nat_stat < STAT_SANCT) {
91                 pr("%s has no \"telegram privileges\".\n", cname(to));
92                 kk++;
93                 continue;
94             }
95             if (!player->god
96                 && (getrejects(player->cnum, natp) & REJ_TELE)) {
97                 pr("%s is rejecting your telegrams.\n", cname(to));
98                 return RET_SYN;
99             }
100             if (typed_wu(player->cnum, to, buf, TEL_NORM) < 0) {
101                 logerror("tele: typed_wu failed to #%d", n);
102                 return RET_FAIL;
103             }
104
105             if (!player->god && natp->nat_stat != STAT_GOD
106                 && player->cnum != to)
107                 nreport(player->cnum, N_SENT_TEL, to, 1);
108             if (opt_HIDDEN) {
109                 setcont(to, player->cnum, FOUND_TELE);
110             }
111             kk++;
112         } while (player->argp[kk] != NULL);
113     }
114     return RET_OK;
115 }