]> git.pond.sub.org Git - empserver/blob - src/lib/commands/chan.c
7555044ec61e98253f5d334982f35e9879822596
[empserver] / src / lib / commands / chan.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
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.
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, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
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.
25  *
26  *  ---
27  *
28  *  chan.c: Change country/representative name
29  * 
30  *  Known contributors to this file:
31  *     Steve McClure, 2000
32  *     
33  */
34
35 #include <config.h>
36
37 #include <ctype.h>
38 #include "misc.h"
39 #include "player.h"
40 #include "nat.h"
41 #include "file.h"
42 #include "news.h"
43 #include "optlist.h"
44 #include "commands.h"
45
46 int
47 chan(void)
48 {
49     s_char *temp;
50     struct natstr *natp;
51     register s_char *p;
52     natid cn;
53     int charge;
54     int nonb;
55     int btucost;
56     s_char buf[1024];
57     struct natstr *us;
58
59     if ((p =
60          getstarg(player->argp[1], "country name or representative? ",
61                   buf)) == 0)
62         return RET_SYN;
63     us = getnatp(player->cnum);
64     if (us->nat_stat == STAT_VIS) {
65         pr("Visitor countries can't change their country name or representative.\n");
66         return RET_FAIL;
67     }
68     switch (*p) {
69     case 'n':
70     case 'c':
71         charge = 0;
72         btucost = 0;
73         if (us->nat_stat == STAT_ACTIVE) {
74             if (opt_BLITZ == 0) {
75                 if (us->nat_btu < 254) {
76                     pr("You need 254 btus to change your country name!\n");
77                     return RET_FAIL;
78                 }
79                 pr("This command costs 254 BTU's and 10%% of your money.\n");
80                 if (!confirm("Are you sure you want to do this? "))
81                     return RET_FAIL;
82                 btucost = 254;
83                 if (us->nat_money <= 0)
84                     charge = 0;
85                 else
86                     charge = us->nat_money / 10;
87             }
88         }
89         if ((p =
90              getstarg(player->argp[2], "New country name -- ", buf)) == 0)
91             return RET_SYN;
92         p[sizeof(us->nat_cnam) - 1] = 0;
93         for (cn = 0; NULL != (natp = getnatp(cn)); cn++) {
94             if (!strcmp(p, natp->nat_cnam)) {
95                 pr("Country #%d is already called `%s'!\n", cn, p);
96                 return RET_FAIL;
97             }
98         }
99         nonb = 0;
100         for (temp = p; *temp != '\0'; temp++) {
101             if (iscntrl(*temp)) {
102                 pr("No control characters allowed in country names!\n");
103                 return RET_FAIL;
104             } else if (*temp != ' ')
105                 nonb = 1;
106         }
107         if (!nonb) {
108             pr("Must have a non-blank name!\n");
109             return RET_FAIL;
110         }
111         player->dolcost += charge;
112         player->btused += btucost;
113         strcpy(us->nat_cnam, p);
114         putnat(us);
115         nreport(player->cnum, N_NAME_CHNG, 0, 1);
116         break;
117     case 'p':
118     case 'r':
119         pr("(note: these are stored in plain text.)\n");
120         if ((p = getstarg(player->argp[2],
121                           "New representative name -- ", buf)) == 0)
122             return RET_SYN;
123         p[sizeof(us->nat_pnam) - 1] = 0;
124         strcpy(us->nat_pnam, p);
125         putnat(us);
126         break;
127     default:
128         pr("Only \"country\" or \"representative\" can change.\n");
129         return RET_SYN;
130     }
131     return RET_OK;
132 }