]> git.pond.sub.org Git - empserver/blob - src/lib/commands/togg.c
23476e19d62fa4238980c99ef03badea6ef38f7f
[empserver] / src / lib / commands / togg.c
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2007, 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 files README, COPYING and CREDITS in the root of the source
23  *  tree for related information and legal notices.  It is expected
24  *  that future 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 "commands.h"
38
39 int
40 togg(void)
41 {
42     int flag = 0;
43     int pos;
44     char *name;
45     struct natstr *np;
46
47     np = getnatp(player->cnum);
48     if (player->argp[1]) {
49         switch (*player->argp[1]) {
50         case 'i':
51             name = "inform";
52             flag = NF_INFORM;
53             break;
54         case 'f':
55             name = "flash";
56             flag = NF_FLASH;
57             break;
58         case 'b':
59             name = "beep";
60             flag = NF_BEEP;
61             break;
62         case 'c':
63             name = "coastwatch";
64             flag = NF_COASTWATCH;
65             break;
66         case 's':
67             name = "sonar";
68             flag = NF_SONAR;
69             break;
70         case 't':
71             name = "techlists";
72             flag = NF_TECHLISTS;
73             break;
74         default:
75             return RET_SYN;
76         }
77         if (player->argp[2])
78             if (!strcmp(player->argp[2], "on"))
79                 pos = 1;
80             else if (!strcmp(player->argp[2], "off"))
81                 pos = 0;
82             else
83                 return RET_SYN;
84         else
85             pos = !(np->nat_flags & flag);
86         if (pos)
87             np->nat_flags |= flag;
88         else
89             np->nat_flags &= ~flag;
90         putnat(np);
91         pr("%s flag %s\n", name, pos ? "on" : "off");
92     } else {
93         if (np->nat_flags & NF_INFORM)
94             pr("inform flag on\n");
95         else
96             pr("inform flag off\n");
97         if (np->nat_flags & NF_FLASH)
98             pr("flash flag on\n");
99         else
100             pr("flash flag off\n");
101         if (np->nat_flags & NF_BEEP)
102             pr("beep flag on\n");
103         else
104             pr("beep flag off\n");
105         if (np->nat_flags & NF_COASTWATCH)
106             pr("coastwatch flag on\n");
107         else
108             pr("coastwatch flag off\n");
109         if (np->nat_flags & NF_SONAR)
110             pr("sonar flag on\n");
111         else
112             pr("sonar flag off\n");
113         if (np->nat_flags & NF_TECHLISTS)
114             pr("techlists flag on\n");
115         else
116             pr("techlists flag off\n");
117     }
118
119     return RET_OK;
120 }