]> git.pond.sub.org Git - empserver/blob - src/lib/commands/rang.c
(lrange, shoo, execute): Buffer passed to getstarg() was too small.
[empserver] / src / lib / commands / rang.c
1 /*
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
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  *  rang.c: Edit range of plane/land unit
29  * 
30  *  Known contributors to this file:
31  *     Jeff Bailey
32  */
33
34 #include "misc.h"
35 #include "player.h"
36 #include "plane.h"
37 #include "land.h"
38 #include "nsc.h"
39 #include "file.h"
40 #include "commands.h"
41
42 int
43 range(void)
44 {
45     struct nstr_item np;
46     struct plnstr plane;
47     int i;
48     s_char *p;
49     s_char buf[1024];
50
51     if (!snxtitem(&np, EF_PLANE, player->argp[1]))
52         return RET_SYN;
53     while (nxtitem(&np, &plane)) {
54         if (!player->owner || plane.pln_own == 0)
55             continue;
56         p = getstarg(player->argp[2], "New range? ", buf);
57         if (!check_plane_ok(&plane))
58             return RET_SYN;
59         if (!p || (i = atoi(p)) < 0)
60             continue;
61         plane.pln_range = (plane.pln_range_max < i) ?
62             plane.pln_range_max : i;
63         pr("Plane %d range changed to %d\n", plane.pln_uid,
64            plane.pln_range);
65
66         putplane(plane.pln_uid, &plane);
67     }
68
69     return RET_OK;
70 }
71
72 int
73 lrange(void)
74 {
75     struct nstr_item np;
76     struct lndstr land;
77     struct lchrstr *lcp;
78     int i;
79     char *p;
80     char prompt[128];
81     char buf[1024];
82
83     if (!snxtitem(&np, EF_LAND, player->argp[1]))
84         return RET_SYN;
85     while (nxtitem(&np, &land)) {
86         if (!player->owner || land.lnd_own == 0)
87             continue;
88         lcp = &lchr[(int)land.lnd_type];
89         sprintf(prompt, "New range for %s? ", prland(&land));
90         if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
91             return RET_SYN;
92         if (!check_land_ok(&land))
93             return RET_SYN;
94         if ((i = atoi(p)) < 0)
95             continue;
96         land.lnd_rad_max = (i < land.lnd_rad) ? i : land.lnd_rad;
97         pr("%s reaction radius changed to %d\n", prland(&land),
98            land.lnd_rad_max);
99         putland(land.lnd_uid, &land);
100     }
101
102     return RET_OK;
103 }