]> git.pond.sub.org Git - empserver/blob - src/lib/commands/togg.c
Update copyright notice
[empserver] / src / lib / commands / togg.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2021, 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  *  togg.c: Set player flags
28  *
29  *  Known contributors to this file:
30  *     Ken Stevens, 1995
31  *     Steve McClure, 1996
32  */
33
34 #include <config.h>
35
36 #include "commands.h"
37
38 int
39 togg(void)
40 {
41     int flag = 0;
42     int pos;
43     char *name;
44     struct natstr *np;
45
46     np = getnatp(player->cnum);
47     if (player->argp[1]) {
48         switch (*player->argp[1]) {
49         case 'i':
50             name = "inform";
51             flag = NF_INFORM;
52             break;
53         case 'f':
54             name = "flash";
55             flag = NF_FLASH;
56             break;
57         case 'b':
58             name = "beep";
59             flag = NF_BEEP;
60             break;
61         case 'c':
62             name = "coastwatch";
63             flag = NF_COASTWATCH;
64             break;
65         case 's':
66             name = "sonar";
67             flag = NF_SONAR;
68             break;
69         case 't':
70             name = "techlists";
71             flag = NF_TECHLISTS;
72             break;
73         default:
74             return RET_SYN;
75         }
76         if (player->argp[2])
77             if (!strcmp(player->argp[2], "on"))
78                 pos = 1;
79             else if (!strcmp(player->argp[2], "off"))
80                 pos = 0;
81             else
82                 return RET_SYN;
83         else
84             pos = !(np->nat_flags & flag);
85         if (pos)
86             np->nat_flags |= flag;
87         else
88             np->nat_flags &= ~flag;
89         putnat(np);
90         pr("%s flag %s\n", name, pos ? "on" : "off");
91     } else {
92         if (np->nat_flags & NF_INFORM)
93             pr("inform flag on\n");
94         else
95             pr("inform flag off\n");
96         if (np->nat_flags & NF_FLASH)
97             pr("flash flag on\n");
98         else
99             pr("flash flag off\n");
100         if (np->nat_flags & NF_BEEP)
101             pr("beep flag on\n");
102         else
103             pr("beep flag off\n");
104         if (np->nat_flags & NF_COASTWATCH)
105             pr("coastwatch flag on\n");
106         else
107             pr("coastwatch flag off\n");
108         if (np->nat_flags & NF_SONAR)
109             pr("sonar flag on\n");
110         else
111             pr("sonar flag off\n");
112         if (np->nat_flags & NF_TECHLISTS)
113             pr("techlists flag on\n");
114         else
115             pr("techlists flag off\n");
116     }
117
118     return RET_OK;
119 }