Debian Codegraph @

manage/pagelock.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
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/manage/pagelock.cpp $
21 * $Revision: 42 $
22 * $Date: 5/17/99 2:09p $
23 * $Author: Jeff $
24 *
25 * Jason should put something here
26 *
27 * $Log: /DescentIII/Main/manage/pagelock.cpp $
28 *
29 * 42 5/17/99 2:09p Jeff
30 * fixed tablefile logging
31 *
32 * 41 5/14/99 12:15p Jason
33 * added page logging
34 *
35 * 40 4/30/99 8:53p Matt
36 * Added a "voice" directory for gamefiles.
37 *
38 * 39 4/22/99 7:08p Matt
39 * Reduced the number of object sounds from 3 to 2, since we were only
40 * using two.
41 *
42 * 38 4/18/99 4:49p Matt
43 * Took out code that hacked in ammo amounts for weapon powerups, and
44 * added code to set the counts on the page and read and write to the
45 * table file.
46 *
47 * 37 4/14/99 10:46a Kevin
48 * Removed OutrageMessageBox from release builds
49 *
50 * 36 4/14/99 1:33a Jeff
51 * fixed case mismatched #includes
52 *
53 * 35 4/12/99 12:49p Jeff
54 * added recoil_force to weapon's page
55 *
56 * 34 4/09/99 12:51p Jason
57 * corrected bug sound resolving code
58 *
59 * 33 4/06/99 6:02p Matt
60 * Added score system
61 *
62 * 32 3/30/99 6:11p Jason
63 * changed pagelock version
64 *
65 * 31 3/29/99 11:20a Matt
66 * Added more flexibility to death delays, and added fade away deaths.
67 *
68 * 30 3/04/99 1:47p Jason
69 * fixed some manage problems
70 *
71 *
72 * 29 3/01/99 12:54a Matt
73 * Incremented table file version
74 *
75 * 28 2/23/99 12:39p Jason
76 * added more options for generic objects
77 *
78 * 27 2/22/99 2:03p Jason
79 * added different damages for players and generics
80 *
81 * 26 2/03/99 1:58a Matt
82 * Added a system to show all pages locked.
83 *
84 * 25 2/02/99 8:44a Chris
85 * I made buildings with AI work correctly (ie really big robots should be
86 * buildings)
87 * anim to and from states are now shorts instead of bytes
88 *
89 * 24 12/30/98 5:17p Jeff
90 * changes made to handle script name override, to override the name of
91 * the script to use in a module.
92 *
93 * 23 12/21/98 5:27p Jeff
94 * added osiris module information to door page. Fixed up dialogs for
95 * objects and doors for script interface (added a browse button)
96 *
97 * 22 12/17/98 7:26p Jeff
98 * new script system data
99 *
100 * 21 12/17/98 12:50p Jason
101 * changed doorpage
102 *
103 * 20 12/01/98 4:31p Chris
104 * Checked in a massive amount of AI work. Improved flocking code. :)
105 * (Still hacked lightly). In addition, I am moving toward using the
106 * composite dir. :)
107 *
108 * 19 11/19/98 8:25p Chris
109 *
110 * 18 11/13/98 12:30p Jason
111 * changes for weapons
112 *
113 * 17 11/06/98 11:24a Jason
114 * fixed length bug
115 *
116 * 16 11/05/98 7:55p Jason
117 * changes for new manage system
118 *
119 * 15 10/19/98 11:57a Chris
120 * Update the sound system to use the import volume
121 *
122 * 14 10/14/98 5:15p Jason
123 * added version checking to the table file
124 *
125 * 13 6/23/98 2:43p Matt
126 * Changed calls to OutrageMessageBox() & Debug_MessageBox() to deal with
127 * int return value (instead of bool).
128 *
129 * 12 6/05/98 12:54p Jason
130 * fixed stupid pagelock bug
131 *
132 * 11 6/03/98 3:46p Jason
133 * made megacell system more robust
134 *
135 * 10 5/04/98 5:13p Jason
136 * better error handling
137 *
138 * 9 3/19/98 1:15p Jason
139 * more error checking
140 *
141 * 8 3/19/98 12:02p Jason
142 * added better error checking to pagelocks
143 *
144 * 7 2/19/98 1:52p Jason
145 * added emergency override to unlock function
146 *
147 * 6 10/06/97 3:30p Samir
148 * FROM JASON: added error message
149 *
150 * 5 9/25/97 2:19p Jason
151 * added test case to EraseLocker
152 *
153 * 4 9/25/97 11:22a Jason
154 * added error checking to EraseLocker
155 *
156 * 3 8/12/97 12:07p Matt
157 * Treat old robot locks as generic locks
158 *
159 * 2 8/08/97 1:48p Matt
160 * Change mng_MakeLocker() bring up dialog if no network, and give the
161 * player a chance to retry if someone else has the database locked.
162 *
163 * 16 3/17/97 6:52p Jason
164 * added mprintf to locker file error
165 *
166 * 15 3/13/97 7:38p Matt
167 * Added include of string.h
168 *
169 * 14 3/13/97 6:42 PM Jeremy
170 * #included <errno.h> and unincluded <windows.h>
171 *
172 * 13 3/03/97 6:21p Matt
173 * Changed cfile functions to use D3 naming convention
174 *
175 * $NoKeywords: $
176 */
177
178 #include <cerrno>
179 #include <cstdio>
180 #include <cstdlib>
181 #include <cstring>
182 #include <filesystem>
183
184 #include "cfile.h"cxx . . $ `<file>/cfile/cfile.h`/
185 #include "manage.h"cxx . . $ `<file>/lib/manage.h`/
186 #include "pstypes.h"cxx . . $ `<file>/lib/pstypes.h`/
187 #include "pserror.h"cxx . . $ `<file>/misc/pserror.h`/
188 #include "mono.h"cxx . . $ `<file>/ddebug/mono.h`/
189 #include "mem.h"cxx . . $ `<file>/mem/mem.h`/
190
191 #ifndef RELEASE
192 #include <ctime>
193 #endif
194
195 #define CURRENT_TABLE_VERSIONcxx . . $ `manage/pagelock.cpp:195:9`! 22
196 extern const char *PageNamescxx . . $ PageNames.[];
197
198 void mng_InitPagelockscxx . . $ mng_InitPagelocks(49f6e7a06ebc5aa8).() {
199 // If there is not a pagelock file, create one with a dummy header.
200
201 CFILEcxx . . $ CFILE# *infile = nullptr, *outfile = nullptr;
202 mngs_Pagelockcxx . . $ mngs_Pagelock# testlock;
203
204 if (!Network_upcxx . . $ Network_up.)
205 return;
206
207 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
208 if (infile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
209 outfile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "wb");
210 if (!outfile) {
211 Errorcxx . . $ Error(326aeb464d16410c).("Error creating table lock file!");
212 return;
213 }
214 testlock.pagetypecxx . . $ mngs_Pagelock#pagetype. = PAGETYPE_UNKNOWNcxx . . $ `lib/manage.h:48:9`!;
215 strcpy(testlock.namecxx . . $ mngs_Pagelock#name., "DUMMY PAGE");
216 strcpy(testlock.holdercxx . . $ mngs_Pagelock#holder., "NOT HELD AT ALL");
217 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &testlock);
218
219 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
220 } else
221 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
222 }
223
224 // Checks to see if the locker file is present.
225 // Returns pointer to locker's name, or NULL if the file is unlocked
226 char *mng_CheckIfLockerPresentcxx . . $ mng_CheckIfLockerPresent(41208ce6ca65dd58).() {
227 CFILEcxx . . $ CFILE# *infile;
228 int i = 0;
229 static char lockname[200];
230
231 ASSERTcxx . . $ `misc/pserror.h:246:9`!(Network_up);
232
233 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(LockerFilecxx . . $ LockerFile., "rb");
234 if (!infile)
235 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
236
237 cf_ReadStringcxx . . $ cf_ReadString(38cd788e4423eff6).(lockname, sizeof(lockname), infile);
238
•239 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "%s has already got exclusive access to the table file.\n", lockname);
240
241 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
242
243 return lockname;
244 }
245
246 // Returns 1 if we have the most up to date code for the manage system, else 0
247 int TableVersionCurrentcxx . . $ TableVersionCurrent(b126dc7c1de90089).() {
248 CFILEcxx . . $ CFILE# *infile;
249
250 if (!cfexistcxx . . $ cfexist(293b0826c8d9cb54).(VersionFilecxx . . $ VersionFile.))
251 return 1; // Doesn't exist, so go ahead
252
253 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(VersionFilecxx . . $ VersionFile., "rb");
254 if (!infile) {
255 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Couldn't open the version file for querying!\n");
256 return 0;
257 }
258
259 int version = cf_ReadIntcxx . . $ cf_ReadInt(d60d6f5e30f0c96a).(infile);
260
261 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
262
263 if (version > CURRENT_TABLE_VERSIONcxx . . $ `manage/pagelock.cpp:195:9`!)
264 return 0;
265
266 return 1;
267 }
268
269 // Call this before any chokepoint functions are executed.
270 // Locks the whole table system for our exclusive use
271 int mng_MakeLockercxx . . $ mng_MakeLocker(b126dc7c1de90089).() {
272 CFILEcxx . . $ CFILE# *outfile = nullptr;
273 int len;
274 char *locker;
275
276 len = strlen(TableUsercxx . . $ TableUser.);
277 #ifndef RELEASE
278 if (!Network_upcxx . . $ Network_up.) {
279 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("Error: You are not connected to the network.");
280 return 0;
281 }
282
283 // See if someone else has the file locked
284 do {
285 locker = mng_CheckIfLockerPresentcxx . . $ mng_CheckIfLockerPresent(41208ce6ca65dd58).();
286 if (locker) {
287 struprcxx . . $ strupr(7a9722d75b371431).(locker);
288 if (OutrageMessageBoxcxx . . $ OutrageMessageBox(811d273381043e7b).(MBOX_YESNOcxx . . $ `misc/pserror.h:165:9`!,
289 "The network database is already locked by %s.\nIt will probably become available if you "
290 "wait a few moments.\n\nWould you like to try again?",
291 locker) != IDYEScxx . . $ `ddebug/debug.h:130:9`!)
292 return 0;
293 }
294 } while (locker);
295
296 // Make sure the version is current
297 if (!TableVersionCurrentcxx . . $ TableVersionCurrent(b126dc7c1de90089).()) {
298 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("You must do a source update and recompile. Your table file code is outdated!");
299 return 0;
300 }
301
302 outfile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(LockerFilecxx . . $ LockerFile., "wb");
303 if (!outfile) {
304 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("Error opening the locker file!");
305 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "couldn't open the locker file!\n");
306 return 0;
307 }
308 #endif
309 for (int i = 0; i < len; i++)
310 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(outfile, TableUsercxx . . $ TableUser.[i]);
311 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
312 return 1;
313 }
314
315 // Simply erases the Lockerfile
316 void mng_EraseLockercxx . . $ mng_EraseLocker(49f6e7a06ebc5aa8).() {
317
318 #ifndef RELEASE
319 int count = 0;
320 int done = 0;
321
322 while (!done) {
323 CFILEcxx . . $ CFILE# *fp = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(LockerFilecxx . . $ LockerFile., "rt");
324 if (!fp)
325 return;
326 else
327 cfclosecxx . . $ cfclose(3639e799710acb68).(fp);
328
329 if (removecxx . . $ std/filesystem/remove(c53a6ef3278968b1).(LockerFilecxx . . $ LockerFile.)) {
330 if (count >= 10) {
331 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("There was a problem deleting the locker file...get Jason immediately!");
332 return;
333 } else
334 count++;
335 } else {
336 done = 1;
337 }
338 }
339
340 // Now update the version info
341 count = 0;
342 while (1) {
343 CFILEcxx . . $ CFILE# *fp = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(VersionFilecxx . . $ VersionFile., "wb");
344 if (!fp) {
345 if (count >= 10) {
346 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("There was a problem opening the version file...get Jason immediately!");
347 return;
348 } else
349 count++;
350 } else {
351 cf_WriteIntcxx . . $ cf_WriteInt(966989f25543eb13).(fp, CURRENT_TABLE_VERSIONcxx . . $ `manage/pagelock.cpp:195:9`!);
352 cfclosecxx . . $ cfclose(3639e799710acb68).(fp);
353 return;
354 }
355 }
356 #endif
357 }
358
359 int mng_CheckIfPageLockedcxx . . $ mng_CheckIfPageLocked(3a5f8d799798b818).(mngs_Pagelockcxx . . $ mngs_Pagelock# *pl) {
360 // Given a page name, checks to see if it is locked.
361 // Returns 1 if locked, 0 if not.
362
363 CFILEcxx . . $ CFILE# *infile;
364 mngs_Pagelockcxx . . $ mngs_Pagelock# testlock;
365 int r = -1, done = 0;
366
367 if (!Network_upcxx . . $ Network_up.)
368 return 1;
369
370 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
371 if (infile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
372 strcpy(ErrorStringcxx . . $ ErrorString., "There was a problem opening the table lock file for reading.");
373 return -1;
374 }
375
376 while (!done) {
377 r = mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &testlock);
378 if (r == 0) {
379 done = 1;
380 r = 2;
381 } else {
382 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(pl->name, testlock.name)) {
383 int test = 0;
384 if (pl->pagetypecxx . . $ mngs_Pagelock#pagetype. == testlock.pagetypecxx . . $ mngs_Pagelock#pagetype.) {
385 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(testlock.holder, "UNLOCKED"))
386 r = 0;
387 else {
388 snprintf(InfoStringcxx . . $ InfoString., sizeof(InfoStringcxx . . $ InfoString.), "User %s already has this page locked.", testlock.holdercxx . . $ mngs_Pagelock#holder.);
389 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(testlock.holder, TableUser))
390 r = 0;
391 else
392 r = 1;
393 }
394 strcpy(pl->holdercxx . . $ mngs_Pagelock#holder., testlock.holdercxx . . $ mngs_Pagelock#holder.);
395 done = 1;
396 }
397 }
398 }
399 }
400
401 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
402 return r;
403 }
404
405 int mng_CheckIfPageOwnedcxx . . $ mng_CheckIfPageOwned(36c4fbc4bece4f16).(mngs_Pagelockcxx . . $ mngs_Pagelock# *pl, char *owner) {
406 // Given a page name, checks to see if it is locked by owner.
407 // Returns 1 if locked by owner, 0 if not.
408
409 CFILEcxx . . $ CFILE# *infile;
410 mngs_Pagelockcxx . . $ mngs_Pagelock# testlock;
411 int r = -1, done = 0;
412
413 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
414 if (infile == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) {
415 strcpy(ErrorStringcxx . . $ ErrorString., "There was a problem opening the table lock file for reading.");
416 Int3cxx . . $ `misc/pserror.h:247:9`!();
417 return -1;
418 }
419
420 while (!done) {
421 r = mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &testlock);
422 if (r == 0) {
423 // We've reached the end of file, must be a new page and nobody owns it
424 done = 1;
425 r = 2;
426 } else {
427 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(pl->name, testlock.name) && pl->pagetypecxx . . $ mngs_Pagelock#pagetype. == testlock.pagetypecxx . . $ mngs_Pagelock#pagetype.) {
428 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(testlock.holder, owner))
429 r = 1;
430 else {
431 snprintf(InfoStringcxx . . $ InfoString., sizeof(InfoStringcxx . . $ InfoString.), "User %s does not have this page locked.", owner);
432 r = 0;
433 }
434 done = 1;
435 }
436 }
437 }
438
439 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
440 return r;
441 }
442
443 int mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(CFILEcxx . . $ CFILE# *fp, mngs_Pagelockcxx . . $ mngs_Pagelock# *pl) {
444 // Reads a pagelock from the fp file. Returns 1 if successfully read, 0 if eof was encountered.
445
446 char c;
447 int i;
448
449 if (cfeofcxx . . $ cfeof(413716a422df0036).(fp))
450 return 0;
451
452 // Read type of page
453 pl->pagetypecxx . . $ mngs_Pagelock#pagetype. = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
454
455 // Convert old robot locks to generic locks
456 if (pl->pagetypecxx . . $ mngs_Pagelock#pagetype. == PAGETYPE_ROBOTcxx . . $ `lib/manage.h:51:9`!)
457 pl->pagetypecxx . . $ mngs_Pagelock#pagetype. = PAGETYPE_GENERICcxx . . $ `lib/manage.h:58:9`!;
458
459 // Read the name of this page
460 for (i = 0; i < PAGELOCK_NAME_LENcxx . . $ `lib/manage.h:42:9`!; i++) {
461 c = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
462 pl->namecxx . . $ mngs_Pagelock#name.[i] = c;
463 }
464
465 // Read the user who has this page locked.
466 for (i = 0; i < PAGELOCK_NAME_LENcxx . . $ `lib/manage.h:42:9`!; i++) {
467 c = cf_ReadBytecxx . . $ cf_ReadByte(dcbbf0b0e13758ec).(fp);
468 pl->holdercxx . . $ mngs_Pagelock#holder.[i] = c;
469 }
470
471 pl->namecxx . . $ mngs_Pagelock#name.[PAGELOCK_NAME_LENcxx . . $ `lib/manage.h:42:9`!] = 0;
472 pl->holdercxx . . $ mngs_Pagelock#holder.[PAGELOCK_NAME_LENcxx . . $ `lib/manage.h:42:9`!] = 0;
473
474 if (pl->pagetypecxx . . $ mngs_Pagelock#pagetype. == PAGETYPE_POWERUPcxx . . $ `lib/manage.h:52:9`!) {
475 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Powerup lock: %d, %s, %s\n", pl->pagetype, pl->name, pl->holder);
476 }
477
478 return 1;
479 }
480
481 int mng_ReplacePagelockcxx . . $ mng_ReplacePagelock(6129c99dc712daa0).(char *name, mngs_Pagelockcxx . . $ mngs_Pagelock# *pl) {
482 // Given a pagelock, replaces the one already inside the lock file, or if not present, adds it to
483 // the lock file. Returns 0 on error, or 1 if successful.
484
485 CFILEcxx . . $ CFILE# *infile, *outfile;
486 int replaced = 0;
487 int done = 0;
488
489 mngs_Pagelockcxx . . $ mngs_Pagelock# temp_pl;
490
491 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
492 if (!infile) {
493 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open Table lock file!");
494 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason
495 return 0;
496 }
497 outfile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TempTableLockFilenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "wb");
498 if (!outfile) {
499 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
500 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open temporary table lock file!");
501 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason
502 return 0;
503 }
504
505 while (!done) {
506 if (mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &temp_pl)) {
507 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(temp_pl.name, name) && pl->pagetypecxx . . $ mngs_Pagelock#pagetype. == temp_pl.pagetypecxx . . $ mngs_Pagelock#pagetype.) {
508 // This is the page we want to replace, so write the new one out.
509 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, pl);
510 replaced = 1;
511 } else {
512 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &temp_pl);
513 }
514 } else {
515
516 if (!replaced) {
517 // This is a new page, so append it to the end of file.
518 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, pl);
519 strcpy(InfoStringcxx . . $ InfoString., "Page was successfully added.");
520 } else
521 strcpy(InfoStringcxx . . $ InfoString., "Page was successfully replaced.");
522 done = 1;
523 }
524 }
525 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
526 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
527
528 if (!SwitcherooFilescxx . . $ SwitcherooFiles(2f051e3560ff300f).(TableLockFilenamecxx . . $ TableLockFilename..u8stringcxx . . $ std/filesystem/__cxx11/path#u8string(219584694fe2b248).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), TempTableLockFilenamecxx . . $ TempTableLockFilename.)) {
529 Int3cxx . . $ `misc/pserror.h:247:9`!();
530 return 0;
531 }
532
533 // Log this change
534 #ifndef RELEASE
535 stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path# pathstr = stdcxx . . $ std/::filesystemcxx . . $ std/filesystem/::pathcxx . . $ std/filesystem/__cxx11/path#(NetD3Dircxx . . $ NetD3Dir.) /cxx . . $ std/filesystem/__cxx11/`operator/`(578e0438ad5f0e7e). "TableLog"cxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d).;
536 FILE *logfile = fopen(pathstr.u8stringcxx . . $ std/filesystem/__cxx11/path#u8string(219584694fe2b248).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), "at");
537 if (logfile) {
538 char str[255 + 32];
539 char date[255];
540 time_t t;
541 t = time(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!);
542 strftime(date, 254, "[%a %m/%d/%y %H:%M:%S]", localtime(&t));
543 snprintf(str, sizeof(str), "%s Page %s (%s) last touched by %s\n", date, name, PageNamescxx . . $ PageNames.[pl->pagetypecxx . . $ mngs_Pagelock#pagetype.], TableUsercxx . . $ TableUser.);
544 fwrite(str, 1, strlen(str), logfile);
545 fflush(logfile);
546 fclose(logfile);
547 }
548 #endif
549
550 return 1; // successful!
551 }
552
553 // Given a name and a pagetype, deletes the one already inside the lock file
554 int mng_DeletePagelockcxx . . $ mng_DeletePagelock(6abd07ddb1a912f0).(char *name, int pagetype) {
555 CFILEcxx . . $ CFILE# *infile, *outfile;
556 int done = 0, deleted = 0;
557 mngs_Pagelockcxx . . $ mngs_Pagelock# temp_pl;
558
559 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Deleting pagelock %s.\n", name);
560
561 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
562 if (!infile) {
563 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open Table lock file!");
564 return 0;
565 }
566 outfile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TempTableLockFilenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "wb");
567 if (!outfile) {
568 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
569 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open temporary table lock file!");
570 return 0;
571 }
572
573 while (!done) {
574 if (mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &temp_pl)) {
575 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(temp_pl.name, name) && pagetype == temp_pl.pagetypecxx . . $ mngs_Pagelock#pagetype.)
576 deleted = 1;
577 else
578 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &temp_pl);
579
580 } else
581 done = 1;
582 }
583 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
584 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
585
586 if (!deleted) {
587 Int3cxx . . $ `misc/pserror.h:247:9`!(); // Get Jason!
588 }
589
590 if (removecxx . . $ std/filesystem/remove(c53a6ef3278968b1).(TableLockFilenamecxx . . $ TableLockFilename.)) {
591 snprintf(ErrorStringcxx . . $ ErrorString., sizeof(ErrorStringcxx . . $ ErrorString.), "There was a problem deleting the temp file - errno %d", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
592 return (0);
593 }
594 if (rename(TempTableLockFilenamecxx . . $ TempTableLockFilename., TableLockFilenamecxx . . $ TableLockFilename..u8stringcxx . . $ std/filesystem/__cxx11/path#u8string(219584694fe2b248).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).())) {
595 snprintf(ErrorStringcxx . . $ ErrorString., sizeof(ErrorStringcxx . . $ ErrorString.), "There was a problem renaming the temp file - errno %d", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
596
597 return (0);
598 }
599 return 1; // successful!
600 }
601
602 // Given a list of names and a pagetype, deletes the ones already inside the lock file
603 int mng_DeletePagelockSeriescxx . . $ mng_DeletePagelockSeries(6f6099c1eba6c17c).(char *names[], int num, int pagetype) {
604 CFILEcxx . . $ CFILE# *infile, *outfile;
605 int done = 0, deleted = 0;
606 mngs_Pagelockcxx . . $ mngs_Pagelock# temp_pl;
607
608 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
609 if (!infile) {
610 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open Table lock file!");
611 return 0;
612 }
613 outfile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TempTableLockFilenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "wb");
614 if (!outfile) {
615 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
616 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open temporary table lock file!");
617 return 0;
618 }
619
620 while (!done) {
621 if (mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &temp_pl)) {
622 if (pagetype == temp_pl.pagetypecxx . . $ mngs_Pagelock#pagetype.) {
623 int found = -1;
624
625 for (int i = 0; i < num && found == -1; i++) {
626 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(names[i], temp_pl.name)) {
627 found = i;
628 }
629 }
630
631 if (found == -1)
632 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &temp_pl);
633 else
634 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Deleting pagelock %s.\n", names[found]);
635 } else
636 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &temp_pl);
637
638 } else
639 done = 1;
640 }
641 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
642 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
643
644 if (removecxx . . $ std/filesystem/remove(c53a6ef3278968b1).(TableLockFilenamecxx . . $ TableLockFilename.)) {
645 snprintf(ErrorStringcxx . . $ ErrorString., sizeof(ErrorStringcxx . . $ ErrorString.), "There was a problem deleting the temp file - errno %d", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
646 return (0);
647 }
648 if (rename(TempTableLockFilenamecxx . . $ TempTableLockFilename., TableLockFilenamecxx . . $ TableLockFilename..u8stringcxx . . $ std/filesystem/__cxx11/path#u8string(219584694fe2b248).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).())) {
649 snprintf(ErrorStringcxx . . $ ErrorString., sizeof(ErrorStringcxx . . $ ErrorString.), "There was a problem renaming the temp file - errno %d", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
650
651 return (0);
652 }
653 return 1; // successful!
654 }
655
656 // Goes through the pagelock table and deletes all duplicate entries
657 int mng_DeleteDuplicatePagelockscxx . . $ mng_DeleteDuplicatePagelocks(b126dc7c1de90089).() {
658 CFILEcxx . . $ CFILE# *infile; //,*outfile;
659 int done = 0, deleted = 0;
660 mngs_Pagelockcxx . . $ mngs_Pagelock# temp_pl;
661 mngs_Pagelockcxx . . $ mngs_Pagelock# *already_read;
662 int num = 0, duplicates = 0, i;
663
664 already_read = (mngs_Pagelockcxx . . $ mngs_Pagelock# *)mem_malloccxx . . $ `mem/mem.h:79:9`!(sizeof(mngs_Pagelock) * 8000);
665 ASSERTcxx . . $ `misc/pserror.h:246:9`!(already_read);
666
667 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
668 if (!infile) {
669 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open Table lock file!");
670 return 0;
671 }
672 /* outfile=(CFILE *)cfopen (TempTableLockFilename,"wb");
673 if (!outfile)
674 {
675 cfclose (infile);
676 strcpy (ErrorString,"Couldn't open temporary table lock file!");
677 return 0;
678 }*/
679
680 while (!done) {
681 if (mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &temp_pl)) {
682 int found = -1;
683 for (i = 0; i < num; i++) {
684 if (temp_pl.pagetypecxx . . $ mngs_Pagelock#pagetype. == already_read[i].pagetypecxx . . $ mngs_Pagelock#pagetype. && !stricmpcxx . . $ `linux/linux_fix.h:43:9`!(temp_pl.name, already_read[i].name)) {
685 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Found duplicated %s\n", temp_pl.name);
686 found = i;
687 duplicates++;
688 }
689 }
690
691 if (found == -1) {
692 // Hurray, a new entry
693 strcpy(already_read[num].namecxx . . $ mngs_Pagelock#name., temp_pl.namecxx . . $ mngs_Pagelock#name.);
694 already_read[num].pagetypecxx . . $ mngs_Pagelock#pagetype. = temp_pl.pagetypecxx . . $ mngs_Pagelock#pagetype.;
695 num++;
696 ASSERTcxx . . $ `misc/pserror.h:246:9`!(num < 8000);
697 }
698
699 } else
700 done = 1;
701 }
702 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
703
704 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Found %d duplicates!\n", duplicates);
705 /* cfclose (outfile);
706
707 if (remove (TableLockFilename))
708 {
709 sprintf (ErrorString,"There was a problem deleting the temp file - errno %d",errno);
710 return (0);
711 }
712 if (rename (TempTableLockFilename,TableLockFilename))
713 {
714 sprintf (ErrorString,"There was a problem renaming the temp file - errno %d",errno);
715
716 return (0);
717 }*/
718 mem_freecxx . . $ `mem/mem.h:80:9`!(already_read);
719 return 1; // successful!
720 }
721
722 // Given a list of names and a pagetype, unlocks the ones already inside the lock file
723 int mng_UnlockPagelockSeriescxx . . $ mng_UnlockPagelockSeries(5362d03810990486).(const char *names[], int *pagetypes, int num) {
724 ASSERTcxx . . $ `misc/pserror.h:246:9`!(num < 500);
725
726 uint8_tcxx . . $ uint8_t# already_done[500];
727 memset(already_done, 0, 500);
728
729 CFILEcxx . . $ CFILE# *infile, *outfile;
730 int done = 0, deleted = 0;
731 mngs_Pagelockcxx . . $ mngs_Pagelock# temp_pl;
732 int total = 0;
733
734 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
735 if (!infile) {
736 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open Table lock file!");
737 return 0;
738 }
739 outfile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TempTableLockFilenamecxx . . $ std/filesystem/__cxx11/path#path(835bc3a16b770d4d)., "wb");
740 if (!outfile) {
741 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
742 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open temporary table lock file!");
743 return 0;
744 }
745
746 while (!done) {
747 if (mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &temp_pl)) {
748 int found = -1;
749 for (int i = 0; i < num && found == -1; i++) {
750 if (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(names[i], temp_pl.name)) {
751 found = i;
752 }
753 }
754
755 if (found == -1)
756 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &temp_pl);
757 else {
758 if (pagetypes[found] == temp_pl.pagetypecxx . . $ mngs_Pagelock#pagetype.) {
759 if (already_done[found]) {
760 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Found duplicate=%s\n", names[found]);
761 } else {
762 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Replacing pagelock %s to UNLOCKED.\n", names[found]);
763 strcpy(temp_pl.holdercxx . . $ mngs_Pagelock#holder., "UNLOCKED");
764 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &temp_pl);
765 total++;
766 already_done[found] = 1;
767 }
768
769 } else
770 mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(outfile, &temp_pl);
771 }
772
773 } else
774 done = 1;
775 }
776 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
777 cfclosecxx . . $ cfclose(3639e799710acb68).(outfile);
778
779 mprintfcxx . . $ `ddebug/mono.h:82:9`!(0, "Unlocked %d pages\n", total);
780
781 if (removecxx . . $ std/filesystem/remove(c53a6ef3278968b1).(TableLockFilenamecxx . . $ TableLockFilename.)) {
782 snprintf(ErrorStringcxx . . $ ErrorString., sizeof(ErrorStringcxx . . $ ErrorString.), "There was a problem deleting the temp file - errno %d", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
783 return (0);
784 }
785 if (rename(TempTableLockFilenamecxx . . $ TempTableLockFilename., TableLockFilenamecxx . . $ TableLockFilename..u8stringcxx . . $ std/filesystem/__cxx11/path#u8string(219584694fe2b248).().c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).())) {
786 snprintf(ErrorStringcxx . . $ ErrorString., sizeof(ErrorStringcxx . . $ ErrorString.), "There was a problem renaming the temp file - errno %d", errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!);
787
788 return (0);
789 }
790 return 1; // successful!
791 }
792
793 // Writes a given pagelock out to the file pointed to by fp
794 void mng_WritePagelockcxx . . $ mng_WritePagelock(ff2922c737f3239c).(CFILEcxx . . $ CFILE# *fp, mngs_Pagelockcxx . . $ mngs_Pagelock# *pl) {
795 int i;
796
797 // Write pagetype
798 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, pl->pagetypecxx . . $ mngs_Pagelock#pagetype.);
799
800 // Write name
801 for (i = 0; i < PAGELOCK_NAME_LENcxx . . $ `lib/manage.h:42:9`!; i++)
802 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, pl->namecxx . . $ mngs_Pagelock#name.[i]);
803
804 // Who owns this page?
805 for (i = 0; i < PAGELOCK_NAME_LENcxx . . $ `lib/manage.h:42:9`!; i++)
806 cf_WriteBytecxx . . $ cf_WriteByte(17377ebd5835367f).(fp, pl->holdercxx . . $ mngs_Pagelock#holder.[i]);
807 }
808
809 int mng_GetListOfLockscxx . . $ mng_GetListOfLocks(1efb1472e1428b14).(mngs_Pagelockcxx . . $ mngs_Pagelock# *pl, int max, char *who) {
810 // Given a list of pagelocks, a max number allowed, and a specified user "who", fills in the
811 // given pagelocks with all the pages that are locked by "who".
812
813 CFILEcxx . . $ CFILE# *infile;
814 mngs_Pagelockcxx . . $ mngs_Pagelock# temp_pl;
815 int done = 0, num = 0;
816
817 infile = (CFILEcxx . . $ CFILE# *)cfopencxx . . $ cfopen(7c7b94e455f1ae56).(TableLockFilenamecxx . . $ TableLockFilename., "rb");
818 if (!infile) {
819 strcpy(ErrorStringcxx . . $ ErrorString., "Couldn't open Table lock file!");
820 return -1;
821 }
822
823 while (!done) {
824 // Read in a page, compare it with the owner we're searching for. If found, make a copy of it.
825
826 if (mng_ReadPagelockcxx . . $ mng_ReadPagelock(3ecdf56edd8e796c).(infile, &temp_pl)) {
827 if (((who == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && stricmpcxx . . $ `linux/linux_fix.h:43:9`!(temp_pl.holder, "UNLOCKED")) ||
828 ((who != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) && (!stricmpcxx . . $ `linux/linux_fix.h:43:9`!(temp_pl.holder, who)))) {
829 pl[num] =cxx . . $ mngs_Pagelock#`operator=`(3642b757dcc0137a). temp_pl;
830 num++;
831 if (num >= max)
832 done = 1;
833 }
834
835 } else
836 done = 1;
837 }
838
839 cfclosecxx . . $ cfclose(3639e799710acb68).(infile);
840 return num;
841 }
842
843 // Takes a pagelock and sets its holder name to UNLOCKED
844 void mng_OverrideToUnlockedcxx . . $ mng_OverrideToUnlocked(25670cb995833605).(mngs_Pagelockcxx . . $ mngs_Pagelock# *temp_pl) {
845 int r;
846 #ifndef RELEASE
847 r = mng_CheckIfPageOwnedcxx . . $ mng_CheckIfPageOwned(36c4fbc4bece4f16).(temp_pl, TableUsercxx . . $ TableUser.);
848
849 if (r == 1) {
850 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("You own this page, so there is no use in you setting it to unlocked!");
851 return;
852 }
853
854 int answer = OutrageMessageBoxcxx . . $ OutrageMessageBox(811d273381043e7b).(
855 MBOX_YESNOcxx . . $ `misc/pserror.h:165:9`!,
856 "Are you sure you wish to override this page to unlocked? (choose 'NO' if you don't know what you're doing!)");
857
858 if (answer == IDNOcxx . . $ `ddebug/debug.h:133:9`!)
859 return;
860
861 answer = OutrageMessageBoxcxx . . $ OutrageMessageBox(811d273381043e7b).(MBOX_YESNOcxx . . $ `misc/pserror.h:165:9`!,
862 "Do you wish to actually erase this pagelock? (Again, answer NO if you are not sure!)");
863
864 if (!mng_MakeLockercxx . . $ mng_MakeLocker(b126dc7c1de90089).())
865 return;
866
867 strcpy(temp_pl->holdercxx . . $ mngs_Pagelock#holder., "UNLOCKED");
868
869 if (answer == IDNOcxx . . $ `ddebug/debug.h:133:9`!) {
870 if (!mng_ReplacePagelockcxx . . $ mng_ReplacePagelock(6129c99dc712daa0).(temp_pl->namecxx . . $ mngs_Pagelock#name., temp_pl))
871 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).(ErrorStringcxx . . $ ErrorString., "Error!");
872 else {
873 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("Page set to unlocked.");
874 }
875 } else {
876 // Given a name and a pagetype, deletes the one already inside the lock file
877 if (!mng_DeletePagelockcxx . . $ mng_DeletePagelock(6abd07ddb1a912f0).(temp_pl->namecxx . . $ mngs_Pagelock#name., temp_pl->pagetypecxx . . $ mngs_Pagelock#pagetype.)) {
878 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).(ErrorStringcxx . . $ ErrorString., "Error!");
879 } else
880 OutrageMessageBoxcxx . . $ OutrageMessageBox(326aeb464d16410c).("Pagelock deleted!");
881 }
882 #endif
883 mng_EraseLockercxx . . $ mng_EraseLocker(49f6e7a06ebc5aa8).();
884 }