Debian Codegraph @

Descent3/multi_save_setting.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/multi_save_setting.cpp $
21 * $Revision: 12 $
22 * $Date: 5/05/00 9:04a $
23 * $Author: Matt $
24 *
25 * Multiplayer settings save/load
26 *
27 * $Log: /DescentIII/main/multi_save_setting.cpp $
28 *
29 * 12 5/05/00 9:04a Matt
30 * Allow ship names for the SHIPBAN command to have spaces, so the black
31 * pyro will work.
32 *
33 * 11 5/09/99 1:34p Kevin
34 * Added diffuculty level system to multiplayer
35 *
36 * 10 4/14/99 2:51a Jeff
37 * fixed some case mismatched #includes
38 *
39 * 9 3/25/99 3:29p Jason
40 * added option to randomize powerup respawn points
41 *
42 * 8 2/05/99 1:17p Jason
43 * added some options
44 *
45 * 7 12/07/98 12:54p Kevin
46 * Added Accurate weapon collisions flag
47 *
48 * 6 12/01/98 12:47p Jason
49 * got rid of NF_DROPMISORDERED and added NF_USE_SMOOTHING
50 *
51 * 5 10/17/98 2:32p Kevin
52 * FIxed problem with banned users getting stuck on the ban message
53 * screen.
54 *
55 * 4 10/02/98 10:11a Kevin
56 * dealt with spaces in the name of values
57 *
58 * 3 9/23/98 6:33p Kevin
59 * Fixed load settings
60 *
61 * 2 9/23/98 2:54p Kevin
62 * Saved multi config and changed UI to conform
63 *
64 * 1 9/23/98 10:15a Kevin
65 * Initial Version
66 *
67 * $NoKeywords: $
68 */
69
70 #include <stdio.h>
71 #include "cfile.h"
72 #include "multi.h"
73 #include "objinfo.h"
74 #include "ship.h"
75 #include "multi_save_settings.h"
76
77 int MultiSaveSettings(const char *filename) {
78 CFILE *cf;
79 char szoutput[MAX_MPS_LINE_LEN];
80 int i;
81 cf = cfopen(filename, "wt");
82 if (!cf)
83 return 0;
84 snprintf(szoutput, sizeof(szoutput), "NAME\t%s", Netgame.name);
85 cf_WriteString(cf, szoutput);
86 snprintf(szoutput, sizeof(szoutput), "MISSION\t%s", Netgame.mission);
87 cf_WriteString(cf, szoutput);
88 snprintf(szoutput, sizeof(szoutput), "SCRIPT\t%s", Netgame.scriptname);
89 cf_WriteString(cf, szoutput);
90 snprintf(szoutput, sizeof(szoutput), "PPS\t%d", Netgame.packets_per_second);
91 cf_WriteString(cf, szoutput);
92 snprintf(szoutput, sizeof(szoutput), "PEERPEER\t%s", (Netgame.flags & NF_PEER_PEER) ? "TRUE" : "FALSE");
93 cf_WriteString(cf, szoutput);
94 snprintf(szoutput, sizeof(szoutput), "PERMISSABLE\t%s", (Netgame.flags & NF_PERMISSABLE) ? "TRUE" : "FALSE");
95 cf_WriteString(cf, szoutput);
96 snprintf(szoutput, sizeof(szoutput), "RANDOMIZERESPAWN\t%s",
97 (Netgame.flags & NF_RANDOMIZE_RESPAWN) ? "TRUE" : "FALSE");
98 cf_WriteString(cf, szoutput);
99 snprintf(szoutput, sizeof(szoutput), "ROTVEL\t%s", (Netgame.flags & NF_SENDROTVEL) ? "TRUE" : "FALSE");
100 cf_WriteString(cf, szoutput);
101 snprintf(szoutput, sizeof(szoutput), "USESMOOTHING\t%s", (Netgame.flags & NF_USE_SMOOTHING) ? "TRUE" : "FALSE");
102 cf_WriteString(cf, szoutput);
103 snprintf(szoutput, sizeof(szoutput), "BRIGHTPLAYERS\t%s", (Netgame.flags & NF_BRIGHT_PLAYERS) ? "TRUE" : "FALSE");
104 cf_WriteString(cf, szoutput);
105 snprintf(szoutput, sizeof(szoutput), "MAXPLAYERS\t%d", Netgame.max_players);
106 cf_WriteString(cf, szoutput);
107 snprintf(szoutput, sizeof(szoutput), "RESPAWNTIME\t%d", Netgame.respawn_time);
108 cf_WriteString(cf, szoutput);
109 snprintf(szoutput, sizeof(szoutput), "KILLGOAL\t%d", Netgame.killgoal);
110 cf_WriteString(cf, szoutput);
111 snprintf(szoutput, sizeof(szoutput), "TIMELIMIT\t%d", Netgame.timelimit);
112 cf_WriteString(cf, szoutput);
113 snprintf(szoutput, sizeof(szoutput), "ACCWEAP\t%s", (Netgame.flags & NF_USE_ACC_WEAP) ? "TRUE" : "FALSE");
114 cf_WriteString(cf, szoutput);
115 snprintf(szoutput, sizeof(szoutput), "MLOOK\t%s", (Netgame.flags & NF_ALLOW_MLOOK) ? "TRUE" : "FALSE");
116 cf_WriteString(cf, szoutput);
117 snprintf(szoutput, sizeof(szoutput), "DIFFICULTY\t%d", Netgame.difficulty);
118 cf_WriteString(cf, szoutput);
119
120 for (i = 0; i < MAX_OBJECT_IDS; i++) {
121 if (Object_info[i].type == OBJ_POWERUP) {
122 if (!Object_info[i].multi_allowed) {
123 snprintf(szoutput, sizeof(szoutput), "OBJBAN\t%s", Object_info[i].name);
124 cf_WriteString(cf, szoutput);
125 }
126 }
127 }
128 for (i = 0; i < MAX_SHIPS; i++) {
129 if (Ships[i].used) {
130 if (!PlayerIsShipAllowed(0, i)) {
131 snprintf(szoutput, sizeof(szoutput), "SHIPBAN\t%s", Ships[i].name);
132 cf_WriteString(cf, szoutput);
133 }
134 }
135 }
136 cfclose(cf);
137 return 1;
138 }
139
140 int MultiLoadSettings(const char *filename) {
141 CFILE *cf;
142 char szinput[MAX_MPS_LINE_LEN];
143 char *toklabel, *tokval;
144 char seps[] = "\t ";
145 int objid;
146 cf = cfopen(filename, "rt");
147 if (!cf)
148 return 0;
149
150 while (cf_ReadString(szinput, MAX_MPS_LINE_LEN - 1, cf)) {
151
152 toklabel = strtok(szinput, seps);
153 tokval = strtok(NULL, seps);
154 if (!tokval) {
155 continue;
156 }
157 if (stricmp(toklabel, "NAME") == 0) {
158 strcpy(Netgame.name, tokval);
159 // Do this so the name can still have spaces
160 tokval = strtok(NULL, seps);
161 while (tokval) {
162 strcat(Netgame.name, " ");
163 strcat(Netgame.name, tokval);
164 tokval = strtok(NULL, seps);
165 }
166 } else if (stricmp(toklabel, "MISSION") == 0) {
167 strcpy(Netgame.mission, tokval);
168 // Do this so the mission can still have spaces
169 tokval = strtok(NULL, seps);
170 while (tokval) {
171 strcat(Netgame.mission, " ");
172 strcat(Netgame.mission, tokval);
173 tokval = strtok(NULL, seps);
174 }
175 } else if (stricmp(toklabel, "SCRIPT") == 0) {
176 strcpy(Netgame.scriptname, tokval);
177 // Do this so the script can still have spaces
178 tokval = strtok(NULL, seps);
179 while (tokval) {
180 strcat(Netgame.scriptname, " ");
181 strcat(Netgame.scriptname, tokval);
182 tokval = strtok(NULL, seps);
183 }
184 } else if (stricmp(toklabel, "PPS") == 0) {
185 Netgame.packets_per_second = atoi(tokval);
186 } else if (stricmp(toklabel, "PEERPEER") == 0) {
187 if (stricmp(tokval, "true") == 0)
188 Netgame.flags |= NF_PEER_PEER;
189 else
190 Netgame.flags &= ~NF_PEER_PEER;
191 } else if (stricmp(toklabel, "PERMISSABLE") == 0) {
192 if (stricmp(tokval, "true") == 0)
193 Netgame.flags |= NF_PERMISSABLE;
194 else
195 Netgame.flags &= ~NF_PERMISSABLE;
196 } else if (stricmp(toklabel, "RANDOMIZERESPAWN") == 0) {
197 if (stricmp(tokval, "true") == 0)
198 Netgame.flags |= NF_RANDOMIZE_RESPAWN;
199 else
200 Netgame.flags &= ~NF_RANDOMIZE_RESPAWN;
201 } else if (stricmp(toklabel, "ACCWEAP") == 0) {
202 if (stricmp(tokval, "true") == 0)
203 Netgame.flags |= NF_USE_ACC_WEAP;
204 else
205 Netgame.flags &= ~NF_USE_ACC_WEAP;
206 } else if (stricmp(toklabel, "ROTVEL") == 0) {
207 if (stricmp(tokval, "true") == 0)
208 Netgame.flags |= NF_SENDROTVEL;
209 else
210 Netgame.flags &= ~NF_SENDROTVEL;
211 } else if (stricmp(toklabel, "USESMOOTHING") == 0) {
212 if (stricmp(tokval, "true") == 0)
213 Netgame.flags |= NF_USE_SMOOTHING;
214 else
215 Netgame.flags &= ~NF_USE_SMOOTHING;
216 } else if (stricmp(toklabel, "BRIGHTPLAYERS") == 0) {
217 if (stricmp(tokval, "true") == 0)
218 Netgame.flags |= NF_BRIGHT_PLAYERS;
219 else
220 Netgame.flags &= ~NF_BRIGHT_PLAYERS;
221 } else if (stricmp(toklabel, "MAXPLAYERS") == 0) {
222 Netgame.max_players = atoi(tokval);
223 } else if (stricmp(toklabel, "RESPAWNTIME") == 0) {
224 Netgame.respawn_time = atoi(tokval);
225 } else if (stricmp(toklabel, "KILLGOAL") == 0) {
226 Netgame.killgoal = atoi(tokval);
227 if (Netgame.killgoal)
228 Netgame.flags |= NF_KILLGOAL;
229 else
230 Netgame.flags &= ~NF_KILLGOAL;
231
232 } else if (stricmp(toklabel, "TIMELIMIT") == 0) {
233 Netgame.timelimit = atoi(tokval);
234 if (Netgame.timelimit)
235 Netgame.flags |= NF_TIMER;
236 else
237 Netgame.flags &= ~NF_TIMER;
238 } else if (stricmp(toklabel, "OBJBAN") == 0) {
239 objid = FindObjectIDName(tokval);
240 if (objid != -1) {
241 Object_info[objid].multi_allowed = 0;
242 }
243 } else if (stricmp(toklabel, "SHIPBAN") == 0) {
244 // Do this so the name can have spaces
245 char buf[100];
246 strcpy(buf, tokval);
247 tokval = strtok(NULL, seps);
248 while (tokval) {
249 strcat(buf, " ");
250 strcat(buf, tokval);
251 tokval = strtok(NULL, seps);
252 }
253 PlayerSetShipPermission(-1, buf, 0);
254 } else if (stricmp(toklabel, "MLOOK") == 0) {
255 if (stricmp(tokval, "true") == 0)
256 Netgame.flags |= NF_ALLOW_MLOOK;
257 else
258 Netgame.flags &= ~NF_ALLOW_MLOOK;
259 } else if (stricmp(toklabel, "DIFFICULTY") == 0) {
260 Netgame.difficulty = atoi(tokval);
261 if ((Netgame.difficulty > 4) || (Netgame.difficulty < 0))
262 Netgame.difficulty = 0;
263 } else {
264 mprintf(0, "Unknown line in multiplayer config file %s\t%s\n", toklabel, tokval);
265 }
266 };
267 return 1;
268 }