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