]> git.pond.sub.org Git - empserver/blob - src/lib/subs/natsub.c
nat_reset() is no longer used with STAT_SANCT, simplify
[empserver] / src / lib / subs / natsub.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2011, 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  *  nat.c: Nation subroutines
28  *
29  *  Known contributors to this file:
30  *     Markus Armbruster, 2009-2011
31  *     Ron Koenderink, 2008-2009
32  */
33
34 #include <config.h>
35
36 #include <string.h>
37 #include <ctype.h>
38 #include <fcntl.h>
39 #include <sys/stat.h>
40 #include <unistd.h>
41 #include "file.h"
42 #include "nat.h"
43 #include "optlist.h"
44 #include "prototypes.h"
45 #include "tel.h"
46
47 /*
48  * Initialize NATP for country #CNUM in status STAT.
49  * STAT must be STAT_UNUSED, STAT_NEW, STAT_VIS or STAT_GOD.
50  * Also wipe realms and telegrams.
51  */
52 struct natstr *
53 nat_reset(struct natstr *natp, natid cnum, enum nat_status stat)
54 {
55     struct realmstr newrealm;
56     char buf[1024];
57     int i;
58
59     ef_blank(EF_NATION, cnum, natp);
60     natp->nat_stat = stat;
61     for (i = 0; i < MAXNOR; i++) {
62         ef_blank(EF_REALM, i + cnum * MAXNOR, &newrealm);
63         putrealm(&newrealm);
64     }
65     close(creat(mailbox(buf, cnum),
66                 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP));
67     /* FIXME natp->nat_ann = #annos */
68     natp->nat_level[NAT_HLEV] = start_happiness;
69     natp->nat_level[NAT_RLEV] = start_research;
70     natp->nat_level[NAT_TLEV] = start_technology;
71     natp->nat_level[NAT_ELEV] = start_education;
72     for (i = 0; i < MAXNOC; i++)
73         natp->nat_relate[i] = NEUTRAL;
74     natp->nat_flags =
75         NF_FLASH | NF_BEEP | NF_COASTWATCH | NF_SONAR | NF_TECHLISTS;
76     return natp;
77 }
78
79 int
80 check_nat_name(char *cname, natid cnum)
81 {
82     struct natstr *natp;
83     natid cn;
84     int allblank;
85     char *p;
86
87     if (strlen(cname) >= sizeof(natp->nat_cnam)) {
88         pr("Country name too long\n");
89         return 0;
90     }
91
92     allblank = 1;
93     for (p = cname; *p != '\0'; p++) {
94         if (iscntrl(*p)) {
95             pr("No control characters allowed in country names!\n");
96             return 0;
97         } else if (!isspace(*p))
98             allblank = 0;
99     }
100     if (allblank) {
101         pr("Country name can't be all blank\n");
102         return 0;
103     }
104
105     for (cn = 0; NULL != (natp = getnatp(cn)); cn++) {
106         if (cn != cnum && !strcmp(cname, natp->nat_cnam)) {
107             pr("Country #%d is already called `%s'\n", cn, cname);
108             return 0;
109         }
110     }
111     return 1;
112 }