-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.cpp
5048 lines (4359 loc) · 137 KB
/
db.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************************************************************/
// db.cpp - reads in areas, logging code etc
/***************************************************************************
* The Dawn of Time v1.69r (c)1997-2004 Michael Garratt *
* >> A number of people have contributed to the Dawn codebase, with the *
* majority of code written by Michael Garratt - www.dawnoftime.org *
* >> To use this source code, you must fully comply with all the licenses *
* in licenses.txt... In particular, you may not remove this copyright *
* notice. *
***************************************************************************
* >> Original Diku Mud copyright (c)1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, & Katja Nyboe. *
* >> Merc Diku Mud improvements copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* >> ROM 2.4 is copyright 1993-1995 Russ Taylor and has been brought to *
* you by the ROM consortium: Russ Taylor([email protected]), *
* Gabrielle Taylor([email protected]) & Brian Moore([email protected]) *
* >> Oblivion 1.2 is copyright 1996 Wes Wagner *
**************************************************************************/
#ifdef WIN32
#ifndef OLD_RAND
#define OLD_RAND
#endif
#include <direct.h>
#endif
#include "include.h" // dawn standard includes
#include "areas.h"
#include "db.h"
#include "clan.h"
#include "olc.h"
#include "interp.h"
#include "colour.h"
#include "support.h"
#include "track.h"
#include "ictime.h"
#include "help.h"
#include "lockers.h"
#include "shop.h"
#ifdef WIN32
#include "process.h"
#endif
#ifndef OLD_RAND
int getpid();
time_t time(time_t *tloc);
#endif
/* externals for counting purposes */
extern OBJ_DATA *obj_free;
extern char_data *char_free;
extern PC_DATA *pcdata_free;
extern AFFECT_DATA *affect_free;
/*
* Globals.
*/
SHOP_DATA * shop_first;
cInnData* pFirstInn; // Inns for recalling to.
MPROG_CODE * mprog_list;
char bug_buf [2*MIL];
char_data * char_list;
char log_buf [2*MIL];
KILL_DATA kill_table [MAX_LEVEL];
OBJ_DATA * object_list;
TIME_INFO_DATA time_info;
WEATHER_DATA weather_info [SECT_MAX];
void log_area_import_format_notice();
void do_read_skillgroups(char_data *ch, char *);
// prototype from in global.cpp
void init_static_characters();
GAMBLE_FUN *gamble_lookup( const char *name );
DECLARE_DO_FUN( do_read_commandtable);
/*
* Locals.
*/
MOB_INDEX_DATA * mob_index_hash [MAX_KEY_HASH];
OBJ_INDEX_DATA * obj_index_hash [MAX_KEY_HASH];
ROOM_INDEX_DATA * room_index_hash [MAX_KEY_HASH];
char * string_hash [MAX_KEY_HASH];
void sort_arealists();
void check_tables();
char * string_space=NULL;
char * top_string;
char str_empty [1];
int top_affect;
int top_area;
int top_deity;
int top_ed;
int top_exit;
int top_help;
int top_mob_index;
int top_obj_index;
int top_reset;
int top_room;
int top_shop;
int top_inn; // Like top_shop, but for inns.
int top_vnum_room;
int top_vnum_mob;
int top_vnum_obj;
int top_mprog_index;
int mobile_count = 0;
int dbVersion;
#define MAX_PERM_BLOCK 131072
int nAllocString;
int sAllocString;
int nAllocPerm;
int sAllocPerm;
/*
* Semi-locals.
*/
bool fBootDb;
FILE *fpArea;
char strArea[MIL];
long last_vnum;
/*
* Local booting procedures.
*/
void init_mm args( ( void ) );
void load_area ( FILE *fp, bool dawnareadata );
void load_arearom ( FILE *fp );
void load_helps args( ( FILE *fp ) );
void load_old_mob args( ( FILE *fp ) );
void load_mobiles ( FILE *fp, int version );
void load_old_obj args( ( FILE *fp ) );
void load_objects ( FILE *fp, int version );
void load_resets args( ( FILE *fp, int resets_version, int area_version ) );
void load_rooms ( FILE *fp, int version );
void load_shops args( ( FILE *fp ) );
void oldload_socials args( ( FILE *fp ) );
void load_specials args( ( FILE *fp ) );
void load_gamble args( ( FILE *fp ) );
void load_attunes args( ( FILE *fp ) );
void load_notes args( ( void ) );
void load_bans args( ( void ) );
void load_mobprogs args( ( FILE *fp ) );
void laston_load args( ( void ) );
void fix_exits args( ( void ) );
void fix_mobprogs args( ( void ) );
void fix_resets args( ( void ) );
void reset_area args( ( AREA_DATA * pArea ) );
void room_update( AREA_DATA *pArea );
void load_quest_db args( ( void ) );
void load_mix_db args( ( void ) );
void load_script_db args( ( void ) );
void load_deity_db args( ( void ) );
void load_herb_db args( ( void ) );
void load_offmoot_db args( ( void ) );
void import_helps( FILE *fp );
/**************************************************************************/
void save_clsses();
void load_clsses();
void do_read_classes(char_data *ch, char *argument);
/**************************************************************************/
void init_string_space()
{
if ( ( string_space = (char *) calloc( 1, MAX_STRING ) ) == NULL )
{
bugf( "Boot_db: can't alloc %d string space.", MAX_STRING );
exit_error( 1 , "init_string_space", "failed to allocate memory");
}
top_string = string_space;
if(MAX_STRING>90000){
logf("Allocated %d bytes for string storage. (MAX_STRING setting)",
MAX_STRING);
}
}
/**************************************************************************/
void load_races();
void load_socials();
void load_autostat_files();
void load_intro_database();
void init_limbo_mob_index_data();
void do_load_corpses(char_data *ch, char *);
void race_convert_skills();
void colour_convert_area( AREA_DATA *area);
void load_continents();
void save_continents();
/**************************************************************************/
// Big mama top level function.
void boot_db()
{
char buf[MSL];
char strfname[MSL];
bool socialnew = true;
fBootDb = true;
load_intro_database();
load_autostat_files();
set_ictime();
set_weather();
// read in the languages
languages_load_and_initialise(); update_currenttime();
// read in the core system tables
load_clan_db( ); update_currenttime();
do_read_classes(NULL,""); update_currenttime();
load_races();
do_loadskilltable(NULL,""); update_currenttime();
race_convert_skills(); update_currenttime();
do_read_commandtable(NULL,""); update_currenttime();
init_track_table();
// read in the skillgroups, if no skillgroups file exists
// then convert 'spell names' to skills gsn's in group_table[]
// and write a skill groups file
do_read_skillgroups(NULL, "");
load_continents(); update_currenttime();
language_init_gsn_and_unique_id();
// check all hard coded tables
check_tables(); update_currenttime();
/*
* Read in all the area files.
*/
/**************************/
/* read in the AREA files */
update_currenttime();
{
FILE *fpList;
area_first = NULL;
fulltime_log_string("Opening area list file " AREA_LIST );
if ( ( fpList = fopen( AREA_LIST, "r" ) ) == NULL )
{
bugf("boot_db(): fopen '%s' failed for read - error %d (%s)",
AREA_LIST, errno, strerror( errno));
log_note("File " AREA_LIST " not found... this file contains the list "
"of all the area files to be read in and the mud can not complete its "
"bootup process if this file is missing.`1"
"`1"
"It is possible to create an empty version of this file so the mud can "
"boot by typing 'echo $>" AREA_LIST "' (without the quotes) - Because dawn "
"automatically generates a 'limbo' room at bootup if one doesn't exist, "
"it is possible to boot the mud with no area files and successfully login.`1"
"`1"
"If you are importing a complete set of area files from another mud "
"(such as rom), it is some times possible to copy the area list "
"used by that mud to the filename listed above.");
exit_error( 1 , "boot_db", "fopen for read of arealist failed");
}
#ifdef WIN32 // turn off read in buffering so ftell() reports the correct position
if(setvbuf( fpList, NULL, _IONBF, 0 )){
bugf("boot_db(): error setting setvbuf( fpList, NULL, _IONBF, 0 ) on '%s' - error %d (%s).",
AREA_LIST, errno, strerror( errno));
}
#endif
for ( ; ; )
{
// any line in arealist.txt starting with a $ indicates
// the end of the arealist
char letter=fread_letter(fpList);
if ( letter == '$' ){
break;
}else{
ungetc( letter, fpList );
}
strcpy( strfname, fread_word( fpList ) );
// prefix the filename with the default area directory
sprintf(strArea, "%s%s", AREA_DIR, strfname);
if (!fBootTestOnly)
{
sprintf(buf," Reading in area %s",strArea);
log_string( buf );
}
if ( strArea[0] == '-' )
{
fpArea = stdin;
}
else
{
if ( ( fpArea = fopen( strArea, "r" ) ) == NULL )
{
bugf("boot_db(): fopen '%s' failed for read - error %d (%s)",
strArea, errno, strerror( errno));
exit_error( 1 , "boot_db", "fopen for read of areafile failed");
}
#ifdef WIN32 // turn off read in buffering so ftell() reports the correct position
if(setvbuf( fpArea, NULL, _IONBF, 0 )){
bugf("boot_db(): error setting setvbuf( fpArea, NULL, _IONBF, 0 ) for '%s' - error %d (%s).",
strArea, errno, strerror( errno));
}
#endif
}
for ( ; ; )
{
char *word;
if(fread_letter(fpArea)!='#')
{
bug("Boot_db: # sign not found.");
exit_error( 1 , "boot_db", "# not found");
}
word = fread_word( fpArea );
if ( word[0] == '$' ) break;
else if ( !str_cmp( word, "DAWNAREADATA" ) ) load_area(fpArea, true);
else if ( !str_cmp( word, "AREADATA" ) ) load_area(fpArea, false);
else if ( !str_cmp( word, "AREA" ) ) load_arearom(fpArea); // rom format
else if ( !str_cmp( word, "MOBILES" ) )
{
if (dbVersion < 11 ){
load_mobiles(fpArea, dbVersion);
}else{
load_mobiles_NAFF(fpArea, dbVersion);
}
}
else if ( !str_cmp( word, "MOBPROGS" ) ) {
if (dbVersion < 11 ){
load_mobprogs(fpArea);
}else{
load_mobprogs_NAFF(fpArea);
}
}
else if ( !str_cmp( word, "OBJECTS" ) )
{
if(dbVersion < 11 ){
load_objects(fpArea, dbVersion);
}else{
load_objects_NAFF(fpArea, dbVersion);
}
}
else if ( !str_cmp( word, "RESETS" ) ) load_resets(fpArea, 1, dbVersion);
else if ( !str_cmp( word, "RESETS2" ) ) load_resets(fpArea, 2, dbVersion);
else if ( !str_cmp( word, "ROOMS" ) )
{
if (dbVersion < 11 ){
load_rooms(fpArea, dbVersion);
}else{
load_rooms_NAFF(fpArea, dbVersion);
}
}
else if ( !str_cmp( word, "SHOPS" ) )
{
if (dbVersion < 11 ){
load_shops(fpArea);
}else{
load_shops_NAFF(fpArea);
}
}
else if ( !str_cmp( word, "SPECIALS" ) ) load_specials(fpArea);
else if ( !str_cmp( word, "GAMBLE" ) ) load_gamble( fpArea);
else if ( !str_cmp( word, "ATTUNE" ) ) load_attunes( fpArea);
else
{
bool exiting=true;
bugf( "Boot_db: bad section name for an area file '#%s'.", word );
if(!str_cmp(word, "HELPS")){
char helpfilename[MIL];
sprintf(helpfilename, "%s%s0.txt", BACKUP_HELP_DIR, strfname);
if(AREA_IMPORT_FLAG(AREAIMPORTFLAG_IGNORE_HELPS_IN_AREAFILES)){
for(int hi=0; file_exists(helpfilename); hi++){
sprintf(helpfilename, "%s%s%d.txt", BACKUP_HELP_DIR, strfname, hi);
}
logf("#HELPS sections encounted... ignoring entire section\r\n"
"(saving ignored text to '%s'):", helpfilename);
append_string_to_file(helpfilename, "#HELPS", true);
while(true){
char *dumptext=fread_string(fpArea);
if(strcmp("-1 $", dumptext)){
append_string_to_file(helpfilename, fix_string(dumptext), true);
append_string_to_file(helpfilename,"~", true);
}else{
append_string_to_file(helpfilename, "-1 $~", true);
logf("Found end of help marker (-1 $~)... leaving ignore help mode.");
break;
}
}
exiting=false;
}else{
log_notef(
"This mud does not store help entries within areafiles, "
"instead they are stored in one or more dedicated helpfiles."
"`1"
"`1"
"A #HELPS section has been encounted within %s."
"`1- There are three options available to handle this:"
"`11. Manually edit the listed area file and remove the entire #HELPS section."
"`12. Don't load the area at all (manually remove the area filename from "
"the arealist file '%s')."
"`13. Add the 'ignore_helps_in_areafiles' flag directly after the "
"area_import_flags keyword in the game settings file (gameset.txt)."
"`1`1If you add the flag described in option 3, all helps within all "
"area files will be ignored. The help contents will be "
"written to a file with a name in the format '%s' "
"(based on area filename, and the number may vary).`1",
strArea, AREA_LIST, helpfilename);
}
}
if(!str_cmp(word, "SOCIALS")){
bugf("\r\n"
"#SOCIALS sections can't be loaded in from files listed in arealist.txt\r\n"
"Normally socials are stored in their own socials file... you can however\r\n"
"import socials by listing the file containing a series of socials in\r\n"
"helplist.txt then use the social_import command.\r\n"
"The prefered way of creating/editing socials is using socedit (olc cmd).\r\n" );
}
if(exiting){
exit_error( 1 , "boot_db", "exiting due to previous error");
}
}
}
if ( fpArea != stdin ){
fclose( fpArea );
}
fpArea = NULL;
// end of a single area, read in room invite list if one exists for this area
if(area_last){
load_area_roominvitelist(area_last);
}
// transpose the area min and max vnums
// also convert the colour code if appropriate
if(area_last){
area_last->min_vnum+=area_last->vnum_offset;
area_last->max_vnum+=area_last->vnum_offset;
area_last->vnum_offset=0;
colour_convert_area(area_last);
}
}
fclose( fpList );
update_currenttime();
/* end of reading in the AREA files */
/************************************/
/*************************************/
/* read in the HELP and SOCIAL files */
update_currenttime();
load_socials();
update_currenttime();
fulltime_log_string("Opening help list file " HELP_LIST );
if ( ( fpList = fopen( HELP_LIST, "r" ) ) == NULL )
{
bugf("boot_db(): fopen '%s' failed for read - error %d (%s)",
HELP_LIST, errno, strerror( errno));
exit_error( 1 , "boot_db", "fopen for read of helplist failed");
}
#ifdef WIN32 // turn off read in buffering so ftell() reports the correct position
if(setvbuf( fpList, NULL, _IONBF, 0 )){
bugf("boot_db(): error setting setvbuf( fpList, NULL, _IONBF, 0 ) for '%s' - error %d (%s)",
HELP_LIST, errno, strerror( errno));
}
#endif
for ( ; ; )
{
// any line in arealist.txt starting with a $ indicates
// the end of the arealist
char letter=fread_letter(fpList);
if ( letter == '$' ){
break;
}else{
ungetc( letter, fpList );
}
strcpy( strfname, fread_word( fpList ) );
// prefix the filename with the default help directory
strcpy (strArea, HELP_DIR);
strcat (strArea, strfname);
if (!fBootTestOnly)
{
sprintf(buf," Reading in help file %s",strArea);
log_string( buf );
}
if ( strArea[0] == '-' )
{
fpArea = stdin;
}
else
{
if ( ( fpArea = fopen( strArea, "r" ) ) == NULL )
{
bugf("boot_db(): fopen '%s' failed for read - error %d (%s)",
strArea, errno, strerror( errno));
exit_error( 1 , "boot_db", "fopen for read of areafile failed");
}
#ifdef WIN32 // turn off read in buffering so ftell() reports the correct position
if(setvbuf( fpArea, NULL, _IONBF, 0 )){
bugf("boot_db(): error setting "
"setvbuf( fpArea, NULL, _IONBF, 0 ) for '%s' - error %d (%s).",
strArea, errno, strerror( errno));
}
#endif
}
for ( ; ; )
{
char *word;
if(fread_letter(fpArea)!='#')
{
bug("Boot_db : # sign not found.");
exit_error( 1 , "boot_db", "# sign not found");
}
word = fread_word( fpArea );
if ( word[0] == '$' )
break;
else if ( !str_cmp( word, "HELPS" )) import_helps(fpArea);
else if ( !str_cmp( word, "HELPFILEDATA")) load_helpfile_NAFF(fpArea);
else if ( !str_cmp( word, "SOCIALS" )) {
socialnew = false;
oldload_socials(fpArea); // old SOCIALS file
}
else
{
bugf("Boot_db: bad section name '%s'.", word);
exit_error( 1 , "boot_db", "bad section name");
}
}
if ( fpArea != stdin )
fclose( fpArea );
fpArea = NULL;
}
fclose( fpList );
}
update_currenttime();
help_init_quicklookup_table();
/* end of reading in the HELP and SOCIAL files */
/***********************************************/
// read in the lockers database
lockers->lockers_load_db();
// read in saved objects for all rooms with corpses
do_load_corpses(NULL, "");
/*
* Fix up exits.
* Declare db booting over.
* Convert all old_format objects to new_format, ROM OLC
* Reset all areas once.
* Load up the songs, notes and ban files.
*/
{
// ensure there is a limbo room, if not exit
if(!get_room_index( ROOM_VNUM_LIMBO )){
bugf("boot_db(): limbo room could not be found (room vnum %d)!", ROOM_VNUM_LIMBO);
log_note("You MUST have the limbo room, along with a number of other "
"rooms and objects. If you are wanting to start a mud with 100% "
"original areas, it is STRONGLY recommended that you retain "
"dawn.are. This is a special system area file which contains "
"a lot of library objects (e.g. the corpse object, piles of "
"gold etc).`1`1"
"WITHOUT THE OBJECTS AND ROOMS IN DAWN.ARE THE MUD WILL BE UNSTABLE!"
"`1`1It is safe to remove any of the other area files... "
"however we recommended that you retain the ooc.are or "
"at least recreate and configure a main ooc room... "
"this room is used by the goooc command, and dawn also uses "
"this room as a backup when some other rooms are missing "
"(instead of crashing)."
"`1`1Please note, dawn.are occupies vnum ranges 1 "
"to 500 - the range which is specifically reserved for Dawn's "
"internal use, you should NOT build anything in this range.");
exit_error( 1 , "boot_db", "missing limbo");
}
fulltime_log_string( "All area files read in, sorting area lists." );
sort_arealists(); update_currenttime();
fulltime_log_string( "All area files sorted, linking rooms together." );
fix_exits( ); update_currenttime();
fulltime_log_string( "Exit testing completed." );
attach_resets(); update_currenttime();
fix_resets( ); update_currenttime();
fix_mobprogs( ); update_currenttime();
fulltime_log_string( "Mobprog testing completed." );
fBootDb = false;
area_update( ); update_currenttime();
load_notes( ); update_currenttime();
load_disabled(); update_currenttime();
load_bans(); update_currenttime();
laston_load(); update_currenttime();
resort_top_roleplayers(); update_currenttime();
}
// setup the web character and colour convertion systems
init_static_characters();
init_limbo_mob_index_data();
// loadup letgain database
load_letgain_db(); update_currenttime();
// loadup quest database
load_quest_db();
// loadup mix database
load_mix_db(); update_currenttime();
// loadup scripts database
load_script_db();
// loadup deity database
load_deity_db(); update_currenttime();
// loadup herb database
load_herb_db(); update_currenttime();
// loadup offmoot database
load_offmoot_db();
// load the name generator profiles
do_read_nameprofiles(NULL,""); update_currenttime();
// go thru all rooms setting all tracks to empty
init_room_tracks(); update_currenttime();
/* if(resave_npcraces){
do_saveraces(NULL,"");
autonote(NOTE_SNOTE, "boot_db()",
"races were dynamically created", "admin",
"Some npc races were dynamically created to read in the area files. "
"It is recommended that you check the properties on all new npc races.", true);
}
*/
return;
}
/**************************************************************************/
void hotreboot_check_tables();
/**************************************************************************/
// check all hard coded tables - like that race and pcrace tables match
void check_tables(){
fulltime_log_string("Checking cross reference tables match...");
hotreboot_check_tables();
fulltime_log_string("Check complete");
};
/**************************************************************************/
// insert the area into the vnum sorted area list
static void newarea_insert_vnum_sort(AREA_DATA *pArea)
{
if ( !area_vnumsort_first ){
area_vnumsort_first = pArea;
}else{ // sort areas by vnum
AREA_DATA *vsort;
AREA_DATA *vsort_prev = NULL;
bool inserted = false;
for ( vsort = area_vnumsort_first;
vsort && !inserted; vsort= vsort->vnumsort_next)
{
if (pArea->min_vnum < vsort->min_vnum )
{
if (vsort_prev)
{ // insert in the list
pArea->vnumsort_next = vsort;
vsort_prev->vnumsort_next = pArea;
}
else // we are at the head
{
// insert at the head
pArea->vnumsort_next = area_vnumsort_first;
area_vnumsort_first = pArea;
}
inserted = true;
}
vsort_prev = vsort;
}
if (!inserted)
{
vsort_prev->vnumsort_next = pArea;
}
}
}
/**************************************************************************/
// insert the area into the level sorted area list
static void newarea_insert_level_sort(AREA_DATA *a)
{
if ( !area_levelsort_first ){
area_levelsort_first = a;
return;
}
// sort areas by level
AREA_DATA *lsort=area_levelsort_first;
AREA_DATA *lsort_prev = NULL;
for ( ; lsort; lsort_prev = lsort, lsort= lsort->levelsort_next)
{
if(IS_NULLSTR(a->lcomment)){
if(IS_NULLSTR(lsort->lcomment)){
if(lsort->low_level>0){
if(a->low_level<=0 || a->low_level>lsort->low_level){
continue;
}
if(a->low_level==lsort->low_level && a->high_level>lsort->high_level){
continue;
}
}else{
if(a->low_level<lsort->low_level){
continue;
}
}
}
}else{
if(IS_NULLSTR(lsort->lcomment)){
continue;
}
int i=strcmp(a->lcomment,lsort->lcomment);
if(i>0){
continue;
}
if(i==0 && strcmp( FORMATF("%s%s", a->colour, a->name),
FORMATF("%s%s", lsort->colour, lsort->name))>0
)
{
continue;
}
}
// add area to this point in the list
if (lsort_prev)
{ // insert in the list
a->levelsort_next = lsort;
lsort_prev->levelsort_next = a;
}
else // we are at the head
{
// insert at the head
a->levelsort_next = area_levelsort_first;
area_levelsort_first = a;
}
return;
}
lsort_prev->levelsort_next = a;
}
/**************************************************************************/
// insert the area into the alphabetically sorted arealist
static void newarea_insert_arealist_sort(AREA_DATA *pArea)
{
if( !area_arealist_first ){
area_arealist_first = pArea;
}else{ // sort areas by name
AREA_DATA *asort;
AREA_DATA *asort_prev = NULL;
bool inserted = false;
char aname[MSL], buf[MSL];
char *p;
sprintf(aname, "%s", pArea->name);
for( p = aname; p < aname+ str_len( aname); p++ )
{
*p = LOWER(*p);
}
for ( asort = area_arealist_first;
asort && !inserted; asort= asort->arealist_sort_next)
{
// get lowercase - inefficient but rarely called
sprintf(buf, "%s", asort->name);
for( p = buf; p < buf+ str_len( buf); p++ )
{
*p = LOWER(*p);
}
if (strcmp(aname, buf)<0)
{
if (asort_prev)
{ /* insert in the list */
pArea->arealist_sort_next= asort;
asort_prev->arealist_sort_next= pArea;
}
else /* we are at the head */
{
/* insert at the head */
pArea->arealist_sort_next= area_arealist_first;
area_arealist_first= pArea;
}
inserted = true;
}
asort_prev = asort;
}
// tail end of the list
if (!inserted)
{
asort_prev->arealist_sort_next= pArea;
}
}
}
/**************************************************************************/
// sort the arealist, levellist and vlist
// this isn't the most efficient way but is very simple.
// It is only called on startup and when an area is added, level range changed
// so being efficient doesn't matter here much
void sort_arealists()
{
AREA_DATA *pArea;
// no areas
if (!area_first)
return;
fulltime_log_string("Sorting arealists");
// first clear existing sorts
for ( pArea = area_first; pArea; pArea= pArea->next)
{
pArea->vnumsort_next= NULL;
pArea->levelsort_next= NULL;
pArea->arealist_sort_next= NULL;
}
area_vnumsort_first = NULL;
area_levelsort_first = NULL;
area_arealist_first = NULL;
// next insert into the sorted lists
for ( pArea = area_first; pArea; pArea= pArea->next)
{
newarea_insert_vnum_sort(pArea);
newarea_insert_level_sort(pArea);
newarea_insert_arealist_sort(pArea);
}
}
/**************************************************************************/
// import help section from old format - oblivion code.
void import_helps( FILE *fp )
{
char c;
help_data *pHelp;
helpfile_data *pHelpfile;
// setup the helpfile entry
pHelpfile =helpfile_allocate_new_entry();
pHelpfile->file_name = str_dup((char *) &strArea[str_len(HELP_DIR)]);
pHelpfile->title=str_dup("");
pHelpfile->editors=str_dup("");
pHelpfile->security=7;
pHelpfile->vnum=top_helpfile;
pHelpfile->flags = HELPFILE_NONE;
// add at the bottom of the list
if (helpfile_first)
{
helpfile_last->next=pHelpfile;
helpfile_last=pHelpfile;
}
else
{
helpfile_first=pHelpfile;
helpfile_last=pHelpfile;
}
// check if we have a # for HELPDATA section
c = getc( fp );
if (c!='#'){ // old format
pHelpfile->version=0;
ungetc( c, fp );
}
for ( ; ; ){
char * pTrim;
pHelp = help_allocate_new_entry();
pHelp->helpfile = pHelpfile;
pHelp->level = fread_number( fp );
pHelp->keyword = fread_string( fp );
// -2 versioning system
if ( pHelp->level == -2 )
{
if ( is_number( pHelp->keyword ))
{
pHelp->level = fread_number( fp );
pHelp->keyword = fread_string( fp );
pHelp->flags = fread_wordflag( help_flags, fp );
}
else
{
break;
}
}
// change level -1 to level 0 and set the HELP_HIDE_KEYWORDS flag
if(pHelp->level==-1){
pHelp->level=0;
SET_BIT(pHelp->flags, HELP_HIDE_KEYWORDS);
}
if ( pHelp->keyword[0] == '$' )
break;
pHelp->text = fread_string( fp );
// system to trim off the . at the start of a text, resaved if necessary
if (pHelp->text[0]=='.')
{
pTrim = str_dup((char *)&(pHelp->text[1]));
free_string(pHelp->text);
pHelp->text = pTrim;
}
// swaps ¡ (ascii 173) for the tilde ~ (pre `- days)
show_tilde(pHelp->text);
// link it into the list
if ( !help_first){
help_first = pHelp;
help_first->prev=NULL;
}
if ( help_last){
help_last->next = pHelp;
pHelp->prev = help_last;
}
pHelp->undo_edittext=str_dup("");
pHelp->undo_wraptext=str_dup("");
help_last = pHelp;
pHelp->next = NULL;
pHelp->helpfile->entries++;
top_help++;
}
top_helpfile++;
return;
}
/**************************************************************************/
void load_arearom( FILE *fp )
{
logf("Loading area from rom format...");
AREA_DATA *pArea;
pArea = (AREA_DATA *)alloc_perm( sizeof(*pArea) );
pArea->age = 15;
pArea->nplayer = 0;
pArea->file_name = str_dup((char *) &strArea[str_len(AREA_DIR)]);
char short_name[MIL];
strcpy(short_name,pArea->file_name);
for (char *p=short_name; !IS_NULLSTR(p); p++){
if(*p=='.'){
*p='\0';
break;
}