-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdb.c
executable file
·6821 lines (5980 loc) · 201 KB
/
db.c
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
/**************************************************************************
* File: db.c Part of LuminariMUD *
* Usage: Loading/saving chars, booting/resetting world, internal funcs. *
* *
* All rights reserved. See license for complete information. *
* *
* Copyright (C) 1993, 94 by the Trustees of the Johns Hopkins University *
* CircleMUD is based on DikuMUD, Copyright (C) 1990, 1991. *
**************************************************************************/
#define __DB_C__
#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "db.h"
#include "comm.h"
#include "handler.h"
#include "spells.h"
#include "mail.h"
#include "interpreter.h"
#include "house.h"
#include "constants.h"
#include "oasis.h"
#include "dg_scripts.h"
#include "dg_event.h"
#include "act.h"
#include "ban.h"
#include "treasure.h"
#include "spec_procs.h"
#include "genzon.h"
#include "genolc.h"
#include "genobj.h" /* for free_object_strings */
#include "config.h" /* for the default config values. */
#include "fight.h"
#include "modify.h"
#include "shop.h"
#include "quest.h"
#include "ibt.h"
#include "mud_event.h"
#include "class.h"
#include "clan.h"
#include "msgedit.h"
#include "craft.h"
#include "hlquest.h"
#include "mudlim.h"
#include "spec_abilities.h"
#include "perlin.h"
#include "wilderness.h"
#include "mysql.h"
#include "feats.h"
#include "actionqueues.h"
#include "domains_schools.h"
#include "grapple.h"
#include "race.h"
#include "spell_prep.h"
#include "crafts.h" /* NewCraft */
#include <sys/stat.h>
#include "trails.h"
#include "premadebuilds.h"
#include "encounters.h"
#include "hunts.h"
#include "evolutions.h"
#include "treasure.h"
#include "assign_wpn_armor.h"
#include "backgrounds.h"
/* declarations of most of the 'global' variables */
struct config_data config_info; /* Game configuration list. */
struct room_data *world = NULL; /* array of rooms */
room_rnum top_of_world = 0; /* ref to top element of world */
struct raff_node *raff_list = NULL; // list of room affections
struct char_data *character_list = NULL; /* global linked list of chars */
struct index_data *mob_index = NULL; /* index table for mobile file */
struct char_data *mob_proto = NULL; /* prototypes for mobs */
mob_rnum top_of_mobt = 0; /* top of mobile index table */
struct obj_data *object_list = NULL; /* global linked list of objs */
struct index_data *obj_index = NULL; /* index table for object file */
struct obj_data *obj_proto = NULL; /* prototypes for objs */
obj_rnum top_of_objt = 0; /* top of object index table */
struct zone_data *zone_table = NULL; /* zone table */
zone_rnum top_of_zone_table = 0; /* top element of zone tab */
struct region_data *region_table = NULL; /* Region table */
region_rnum top_of_region_table = 0; /* top element of region tab */
struct path_data *path_table = NULL; /* Path table */
path_rnum top_of_path_table = 0; /* top element of path tab */
/* begin previously located in players.c */
struct player_index_element *player_table = NULL; /* index to plr file */
int top_of_p_table = 0; /* ref to top of table */
int top_of_p_file = 0; /* ref of size of p file */
long top_idnum = 0; /* highest idnum in use */
/* end previously located in players.c */
struct message_list fight_messages[MAX_MESSAGES]; /* fighting messages */
struct index_data **trig_index = NULL; /* index table for triggers */
struct trig_data *trigger_list = NULL; /* all attached triggers */
int top_of_trigt = 0; /* top of trigger index table */
long max_mob_id = MOB_ID_BASE; /* for unique mob id's */
long max_obj_id = OBJ_ID_BASE; /* for unique obj id's */
int dg_owner_purged = 0; /* For control of scripts */
struct aq_data *aquest_table = NULL; /* Autoquests table */
qst_rnum total_quests = 0; /* top of autoquest table */
struct shop_data *shop_index = NULL; /* index table for shops */
int top_shop = -1; /* top of shop table */
int no_mail = 0; /* mail disabled? */
int mini_mud = 0; /* mini-mud mode? */
int no_rent_check = 0; /* skip rent check on boot? */
time_t boot_time = 0; /* time of mud boot */
int circle_restrict = 0; /* level of game restriction */
room_rnum r_mortal_start_room = 0; /* rnum of mortal start room */
room_rnum r_immort_start_room = 0; /* rnum of immort start room */
room_rnum r_frozen_start_room = 0; /* rnum of frozen start room */
char *credits = NULL; /* game credits */
char *news = NULL; /* mud news */
char *motd = NULL; /* message of the day - mortals */
char *imotd = NULL; /* message of the day - immorts */
char *GREETINGS = NULL; /* opening credits screen */
char *help = NULL; /* help screen */
char *ihelp = NULL; /* help screen (immortals) */
char *info = NULL; /* info page */
char *wizlist = NULL; /* list of higher gods */
char *immlist = NULL; /* list of peon gods */
char *background = NULL; /* background story */
char *handbook = NULL; /* handbook for new immortals */
char *policies = NULL; /* policies page */
char *bugs = NULL; /* bugs file */
char *typos = NULL; /* typos file */
char *ideas = NULL; /* ideas file */
int top_of_helpt = 0;
struct help_index_element *help_table = NULL;
struct social_messg *soc_mess_list = NULL; /* list of socials */
int top_of_socialt = -1; /* number of socials */
time_t newsmod = 0; /* Time news file was last modified. */
time_t motdmod = 0; /* Time motd file was last modified. */
struct time_info_data time_info; /* the infomation about the time */
struct weather_data weather_info; /* the infomation about the weather */
struct player_special_data dummy_mob; /* dummy spec area for mobs */
struct reset_q_type reset_q; /* queue of zones to be reset */
struct staffevent_struct staffevent_data = {-1, 0, 3}; /* first value is event index which starts with 0, -1 means no event */
struct happyhour happy_data = {0, 0, 0, 0, 0};
/* declaration of local (file scope) variables */
static int converting = FALSE;
/* Local (file scope) utility functions */
static int check_bitvector_names(bitvector_t bits, size_t namecount, const char *whatami, const char *whatbits);
static int check_object_spell_number(struct obj_data *obj, int val);
static int check_object_level(struct obj_data *obj, int val);
static int check_object(struct obj_data *);
static void load_zones(FILE *fl, char *zonename);
static int file_to_string(const char *name, char *buf);
static int file_to_string_alloc(const char *name, char **buf);
static int count_alias_records(FILE *fl);
static void parse_simple_mob(FILE *mob_f, int i, int nr);
static void interpret_espec(const char *keyword, const char *value, int i, int nr);
static void parse_espec(char *buf, int i, int nr);
static void parse_enhanced_mob(FILE *mob_f, int i, int nr);
static void get_one_line(FILE *fl, char *buf);
static void check_start_rooms(void);
static void renum_zone_table(void);
static void log_zone_error(zone_rnum zone, int cmd_no, const char *message);
static void reset_time(void);
static char fread_letter(FILE *fp);
static void free_followers(struct follow_type *k);
static void load_default_config(void);
static void free_extra_descriptions(struct extra_descr_data *edesc);
static bitvector_t asciiflag_conv_aff(char *flag);
static int help_sort(const void *a, const void *b);
void assign_deities(void);
void set_armor_object(struct obj_data *obj, int type);
SPECIAL_DECL(moving_rooms);
/* Ils: Global result_q needed for init_result_q, push_result & test_result */
struct
{
int tail, size;
bool q[RQ_MAXSIZE];
} result_q;
/* init_result_q
* note: just prepares the result_q for usage */
void init_result_q(void)
{
result_q.size = 0;
result_q.tail = 0;
}
/* push_result
* Note: will push result into the result_q at head of queue.
* Queue will be treated as a fixed sized circular list, of 127 entries,
* new entries will overwrite the oldest entries after 127 results have
* been enqueued.
* note: result_q.tail is kept 1 ahead of valid results so that
* result_q.tail - 1 = previous result */
void push_result(byte result)
{
result_q.q[result_q.tail] = result;
result_q.size++;
if (result_q.size > RQ_MAXSIZE)
result_q.size = RQ_MAXSIZE;
result_q.tail = (result_q.tail + 1) % RQ_MAXSIZE;
}
/* test_result
* returns - if offset is positive
* TRUE if result stored at tail - abs(offset) is TRUE
* FALSE if result stored at tail - abs(offset) is FALSE
* - if offset is negative
* FALSE if result stored at tail - abs(offset) is TRUE
* TRUE if result stored at tail - abs(offset) is FALSE
* - if offset is zero return TRUE
* note: a zero offset indicates the command does not depend on previous results
* so it always returns TRUE.
* note: does not remove the value from the queue
* using a fixed sized queue as a way to make a circular list
* usage: TRUE should mean execute the command
* FALSE should mean don't execute the command
* NOTE: Uses the ZONE_ERROR macro defined for reset_zone */
sbyte test_result(sbyte offset)
{
if (abs(offset) > result_q.size)
{
log("ERR: out of bounds if-value in zone reset [offset:%d > result_size:%d]", abs(offset), result_q.size);
return FALSE;
}
if (offset == 0)
return TRUE;
else if (offset > 0)
return (result_q.q[((RQ_MAXSIZE - (abs(offset) - result_q.tail)) % RQ_MAXSIZE)]);
else
return !(result_q.q[((RQ_MAXSIZE - (abs(offset) - result_q.tail)) % RQ_MAXSIZE)]);
}
/* routines for booting the system */
char *fread_action(FILE *fl, int nr)
{
char buf[MAX_STRING_LENGTH] = {'\0'};
char *buf1 = NULL;
int i = 0;
buf1 = fgets(buf, MAX_STRING_LENGTH, fl);
if (feof(fl))
{
log("SYSERR: fread_action: unexpected EOF near action #%d", nr);
/* SYSERR_DESC: fread_action() will fail if it discovers an end of file
* marker before it is able to read in the expected string. This can be
* caused by a truncated socials file. */
exit(1);
}
if (*buf == '#')
return (NULL);
parse_at(buf);
/* Some clients interpret '\r' the same as { '\r' '\n' }, so the original way of just
replacing '\n' with '\0' would appear as 2 new lines following the action */
for (i = 0; buf[i] != '\0'; i++)
if (buf[i] == '\r' || buf[i] == '\n')
{
buf[i] = '\0';
break;
}
return (strdup(buf));
}
void boot_social_messages(void)
{
FILE *fl;
int nr = 0, hide, min_char_pos, min_pos, min_lvl, curr_soc = -1, i;
char next_soc[MAX_STRING_LENGTH] = {'\0'}, sorted[MAX_INPUT_LENGTH] = {'\0'}, *buf;
if (CONFIG_NEW_SOCIALS == TRUE)
{
/* open social file */
if (!(fl = fopen(SOCMESS_FILE_NEW, "r")))
{
log("SYSERR: can't open socials file '%s': %s", SOCMESS_FILE_NEW, strerror(errno));
/* SYSERR_DESC: This error, from boot_social_messages(), occurs when the
* server fails to open the file containing the social messages. The
* error at the end will indicate the reason why. */
exit(1);
}
/* count socials */
*next_soc = '\0';
while (!feof(fl))
{
buf = fgets(next_soc, MAX_STRING_LENGTH, fl);
if (*next_soc == '~')
top_of_socialt++;
}
}
else
{ /* old style */
/* open social file */
if (!(fl = fopen(SOCMESS_FILE, "r")))
{
log("SYSERR: can't open socials file '%s': %s", SOCMESS_FILE, strerror(errno));
/* SYSERR_DESC: This error, from boot_social_messages(), occurs when the
* server fails to open the file containing the social messages. The
* error at the end will indicate the reason why. */
exit(1);
}
/* count socials */
while (!feof(fl))
{
buf = fgets(next_soc, MAX_STRING_LENGTH, fl);
if (*next_soc == '\n' || *next_soc == '\r')
top_of_socialt++; /* all socials are followed by a blank line */
}
}
log("Social table contains %d socials.", top_of_socialt);
rewind(fl);
CREATE(soc_mess_list, struct social_messg, top_of_socialt + 1);
/* now read 'em */
for (;;)
{
i = fscanf(fl, " %s ", next_soc);
if (*next_soc == '$')
break;
if (CONFIG_NEW_SOCIALS == TRUE)
{
if (fscanf(fl, " %s %d %d %d %d \n",
sorted, &hide, &min_char_pos, &min_pos, &min_lvl) != 5)
{
log("SYSERR: format error in social file near social '%s'", next_soc);
/* SYSERR_DESC: From boot_social_messages(), this error is output when
* the server is expecting to find the remainder of the first line of the
* social ('hide' and 'minimum position'). These must follow the name of
* the social with a single space such as: 'accuse 0 5\n'. This error
* often occurs when one of the numbers is missing or the social name has
* a space in it (i.e., 'bend over'). */
exit(1);
}
curr_soc++;
soc_mess_list[curr_soc].command = strdup(next_soc + 1);
soc_mess_list[curr_soc].sort_as = strdup(sorted);
soc_mess_list[curr_soc].hide = hide;
soc_mess_list[curr_soc].min_char_position = min_char_pos;
soc_mess_list[curr_soc].min_victim_position = min_pos;
soc_mess_list[curr_soc].min_level_char = min_lvl;
}
else
{ /* old style */
if (fscanf(fl, " %d %d \n", &hide, &min_pos) != 2)
{
log("SYSERR: format error in social file near social '%s'", next_soc);
/* SYSERR_DESC: From boot_social_messages(), this error is output when the
* server is expecting to find the remainder of the first line of the
* social ('hide' and 'minimum position'). These must follow the name of
* the social with a single space such as: 'accuse 0 5\n'. This error
* often occurs when one of the numbers is missing or the social name has
* a space in it (i.e., 'bend over'). */
exit(1);
}
curr_soc++;
soc_mess_list[curr_soc].command = strdup(next_soc);
soc_mess_list[curr_soc].sort_as = strdup(next_soc);
soc_mess_list[curr_soc].hide = hide;
soc_mess_list[curr_soc].min_char_position = POS_RESTING;
soc_mess_list[curr_soc].min_victim_position = min_pos;
soc_mess_list[curr_soc].min_level_char = 0;
}
#ifdef CIRCLE_ACORN
if (fgetc(fl) != '\n')
log("SYSERR: Acorn bug workaround failed.");
/* SYSERR_DESC: The only time that this error should ever arise is if you
* are running your MUD on the Acorn platform. The error arises when the
* server cannot properly read a '\n' out of the file at the end of the
* first line of the social (that with 'hide' and 'min position'). This
* is in boot_social_messages(). */
#endif
soc_mess_list[curr_soc].char_no_arg = fread_action(fl, nr);
soc_mess_list[curr_soc].others_no_arg = fread_action(fl, nr);
soc_mess_list[curr_soc].char_found = fread_action(fl, nr);
/* if no char_found, the rest is to be ignored */
if (CONFIG_NEW_SOCIALS == FALSE && !soc_mess_list[curr_soc].char_found)
continue;
soc_mess_list[curr_soc].others_found = fread_action(fl, nr);
soc_mess_list[curr_soc].vict_found = fread_action(fl, nr);
soc_mess_list[curr_soc].not_found = fread_action(fl, nr);
soc_mess_list[curr_soc].char_auto = fread_action(fl, nr);
soc_mess_list[curr_soc].others_auto = fread_action(fl, nr);
if (CONFIG_NEW_SOCIALS == FALSE)
continue;
soc_mess_list[curr_soc].char_body_found = fread_action(fl, nr);
soc_mess_list[curr_soc].others_body_found = fread_action(fl, nr);
soc_mess_list[curr_soc].vict_body_found = fread_action(fl, nr);
soc_mess_list[curr_soc].char_obj_found = fread_action(fl, nr);
soc_mess_list[curr_soc].others_obj_found = fread_action(fl, nr);
}
/* close file & set top */
fclose(fl);
assert(curr_soc <= top_of_socialt);
top_of_socialt = curr_soc;
}
/* this is necessary for the autowiz system */
void reboot_wizlists(void)
{
file_to_string_alloc(WIZLIST_FILE, &wizlist);
file_to_string_alloc(IMMLIST_FILE, &immlist);
}
/* Wipe out all the loaded text files, for shutting down. */
void free_text_files(void)
{
char **textfiles[] = {
&wizlist, &immlist, &news, &credits, &motd, &imotd, &help, &ihelp, &info,
&policies, &handbook, &background, &GREETINGS, &bugs, &typos, &ideas, NULL};
int rf;
for (rf = 0; textfiles[rf]; rf++)
if (*textfiles[rf])
{
free(*textfiles[rf]);
*textfiles[rf] = NULL;
}
}
/* Too bad it doesn't check the return values to let the user know about -1
* values. This will result in an 'Okay.' to a 'reload' command even when the
* string was not replaced. To fix later. */
ACMD(do_reboot)
{
char arg[MAX_INPUT_LENGTH] = {'\0'};
one_argument(argument, arg, sizeof(arg));
if (!str_cmp(arg, "all") || *arg == '*')
{
if (file_to_string_alloc(GREETINGS_FILE, &GREETINGS) == 0)
prune_crlf(GREETINGS);
if (file_to_string_alloc(WIZLIST_FILE, &wizlist) < 0)
send_to_char(ch, "Cannot read wizlist\r\n");
if (file_to_string_alloc(IMMLIST_FILE, &immlist) < 0)
send_to_char(ch, "Cannot read immlist\r\n");
if (file_to_string_alloc(NEWS_FILE, &news) < 0)
send_to_char(ch, "Cannot read news\r\n");
if (file_to_string_alloc(CREDITS_FILE, &credits) < 0)
send_to_char(ch, "Cannot read credits\r\n");
if (file_to_string_alloc(MOTD_FILE, &motd) < 0)
send_to_char(ch, "Cannot read motd\r\n");
if (file_to_string_alloc(IMOTD_FILE, &imotd) < 0)
send_to_char(ch, "Cannot read imotd\r\n");
if (file_to_string_alloc(HELP_PAGE_FILE, &help) < 0)
send_to_char(ch, "Cannot read help front page\r\n");
if (file_to_string_alloc(IHELP_PAGE_FILE, &ihelp) < 0)
send_to_char(ch, "Cannot read help front page\r\n");
if (file_to_string_alloc(INFO_FILE, &info) < 0)
send_to_char(ch, "Cannot read info file\r\n");
if (file_to_string_alloc(POLICIES_FILE, &policies) < 0)
send_to_char(ch, "Cannot read policies\r\n");
if (file_to_string_alloc(HANDBOOK_FILE, &handbook) < 0)
send_to_char(ch, "Cannot read handbook\r\n");
if (file_to_string_alloc(BACKGROUND_FILE, &background) < 0)
send_to_char(ch, "Cannot read background\r\n");
if (help_table)
{
free_help_table();
index_boot(DB_BOOT_HLP);
}
}
else if (!str_cmp(arg, "wizlist"))
{
if (file_to_string_alloc(WIZLIST_FILE, &wizlist) < 0)
send_to_char(ch, "Cannot read wizlist\r\n");
}
else if (!str_cmp(arg, "immlist"))
{
if (file_to_string_alloc(IMMLIST_FILE, &immlist) < 0)
send_to_char(ch, "Cannot read immlist\r\n");
}
else if (!str_cmp(arg, "news"))
{
if (file_to_string_alloc(NEWS_FILE, &news) < 0)
send_to_char(ch, "Cannot read news\r\n");
}
else if (!str_cmp(arg, "credits"))
{
if (file_to_string_alloc(CREDITS_FILE, &credits) < 0)
send_to_char(ch, "Cannot read credits\r\n");
}
else if (!str_cmp(arg, "motd"))
{
if (file_to_string_alloc(MOTD_FILE, &motd) < 0)
send_to_char(ch, "Cannot read motd\r\n");
}
else if (!str_cmp(arg, "imotd"))
{
if (file_to_string_alloc(IMOTD_FILE, &imotd) < 0)
send_to_char(ch, "Cannot read imotd\r\n");
}
else if (!str_cmp(arg, "help"))
{
if (file_to_string_alloc(HELP_PAGE_FILE, &help) < 0)
send_to_char(ch, "Cannot read help front page\r\n");
}
else if (!str_cmp(arg, "ihelp"))
{
if (file_to_string_alloc(IHELP_PAGE_FILE, &ihelp) < 0)
send_to_char(ch, "Cannot read help front page\r\n");
}
else if (!str_cmp(arg, "info"))
{
if (file_to_string_alloc(INFO_FILE, &info) < 0)
send_to_char(ch, "Cannot read info\r\n");
}
else if (!str_cmp(arg, "policy"))
{
if (file_to_string_alloc(POLICIES_FILE, &policies) < 0)
send_to_char(ch, "Cannot read policy\r\n");
}
else if (!str_cmp(arg, "handbook"))
{
if (file_to_string_alloc(HANDBOOK_FILE, &handbook) < 0)
send_to_char(ch, "Cannot read handbook\r\n");
}
else if (!str_cmp(arg, "background"))
{
if (file_to_string_alloc(BACKGROUND_FILE, &background) < 0)
send_to_char(ch, "Cannot read background\r\n");
}
else if (!str_cmp(arg, "greetings"))
{
if (file_to_string_alloc(GREETINGS_FILE, &GREETINGS) == 0)
prune_crlf(GREETINGS);
else
send_to_char(ch, "Cannot read greetings.\r\n");
}
else if (!str_cmp(arg, "xhelp"))
{
if (help_table)
{
free_help_table();
index_boot(DB_BOOT_HLP);
}
}
else if (!str_cmp(arg, "regions"))
{
/* Reload wilderness regions */
load_regions();
}
else if (!str_cmp(arg, "paths"))
{
/* Reload wilderness regions */
load_paths();
}
else
{
send_to_char(ch, "Unknown reload option.\r\n");
return;
}
send_to_char(ch, "%s", CONFIG_OK);
}
/* loads up: zone table, triggers, wilderness, regions, region-paths, renum_world(), start rooms,
mobs, objects, renumbers zone table, auto quests, hlquests, class list, assign/sort feats,
extended races, armor/weapon lists, domains and deities */
void boot_world(void)
{
int x = 0;
/* Initialize the db connection. */
connect_to_mysql();
log("Loading zone table.");
index_boot(DB_BOOT_ZON);
log("Loading triggers and generating index.");
index_boot(DB_BOOT_TRG);
log("Loading rooms.");
index_boot(DB_BOOT_WLD);
log("Loading regions. (MySQL)");
load_regions();
log("Loading paths. (MySQL)");
load_paths();
log("Renumbering rooms.");
renum_world();
log("Checking start rooms.");
check_start_rooms();
log("Loading mobs and generating index.");
index_boot(DB_BOOT_MOB);
log("Loading objs and generating index.");
index_boot(DB_BOOT_OBJ);
log("Renumbering zone table.");
renum_zone_table();
if (converting)
{
log("Saving 128bit world files to disk.");
save_all();
}
if (!no_specials)
{
log("Loading shops.");
index_boot(DB_BOOT_SHP);
log("Placing Harvesting Nodes");
for (x = 0; x < NUM_HARVEST_NODE_RESETS; x++)
reset_harvesting_rooms();
}
log("Loading quests.");
index_boot(DB_BOOT_QST);
log("Loading Homeland quests.");
index_boot(DB_BOOT_HLQST);
log("Loading Deities");
assign_deities();
log("Loading Domains.");
assign_domains();
log("Loading Weapons.");
load_weapons();
log("Loading Armor.");
load_armor();
log("Loading Extended Races");
assign_races();
/* this use to be partially dependent on classo() we had
to modify it so there is no dependence due to inability to
load two things at the same time :p */
log("Loading feats.");
assign_feats();
sort_feats();
/* this HAS to come after loading feats, we need feat info
in order to handle the class list (prereqs) */
log("Loading Class List");
load_class_list();
log("Loading evolutions.");
assign_evolutions();
// we'll sort races alphabetically
sort_races();
// assign backgrounds
assign_backgrounds();
sort_backgrounds();
log("Initializing perlin noise generator.");
init_perlin(NOISE_MATERIAL_PLANE_ELEV, NOISE_MATERIAL_PLANE_ELEV_SEED);
init_perlin(NOISE_MATERIAL_PLANE_MOISTURE, NOISE_MATERIAL_PLANE_MOISTURE_SEED);
init_perlin(NOISE_MATERIAL_PLANE_ELEV_DIST, NOISE_MATERIAL_PLANE_ELEV_DIST_SEED);
init_perlin(NOISE_WEATHER, NOISE_WEATHER_SEED);
#if !defined(CAMPAIGN_FR) && !defined(CAMPAIGN_DL)
log("Indexing wilderness rooms.");
initialize_wilderness_lists();
log("Writing wilderness map image.");
// save_map_to_file("luminari_wilderness.png", WILD_X_SIZE, WILD_Y_SIZE);
// save_noise_to_file(NOISE_MATERIAL_PLANE_ELEV, "luminari_wild_noise_elev_zoom.png", WILD_X_SIZE, WILD_Y_SIZE, 0);
// save_noise_to_file(NOISE_MATERIAL_PLANE_ELEV, "luminari_wild_noise_elev_zoom.png", WILD_X_SIZE, WILD_Y_SIZE, 1);
#endif
}
static void free_extra_descriptions(struct extra_descr_data *edesc)
{
struct extra_descr_data *enext;
for (; edesc; edesc = enext)
{
enext = edesc->next;
free(edesc->keyword);
free(edesc->description);
free(edesc);
}
}
/* Free the world, in a memory allocation sense. */
void destroy_db(void)
{
ssize_t cnt = 0, itr = 0;
struct char_data *chtmp = NULL;
struct obj_data *objtmp = NULL;
/* Active Mobiles & Players */
while (character_list)
{
chtmp = character_list;
character_list = character_list->next;
if (chtmp->master)
stop_follower(chtmp);
free_char(chtmp);
}
/* Active Objects */
while (object_list)
{
objtmp = object_list;
object_list = object_list->next;
free_obj(objtmp);
}
/* Rooms */
for (cnt = 0; cnt <= top_of_world; cnt++)
{
if (world[cnt].name)
free(world[cnt].name);
if (world[cnt].description)
free(world[cnt].description);
free_extra_descriptions(world[cnt].ex_description);
/* freeing room events */
if (world[cnt].events != NULL)
{
if (world[cnt].events->iSize > 0)
{
struct event *pEvent;
while ((pEvent = simple_list(world[cnt].events)) != NULL)
event_cancel(pEvent);
}
free_list(world[cnt].events);
world[cnt].events = NULL;
}
/* free any assigned scripts */
if (SCRIPT(&world[cnt]))
extract_script(&world[cnt], WLD_TRIGGER);
/* free script proto list */
free_proto_script(&world[cnt], WLD_TRIGGER);
for (itr = 0; itr < NUM_OF_DIRS; itr++)
{ /* NUM_OF_DIRS here, not DIR_COUNT */
if (!world[cnt].dir_option[itr])
continue;
if (world[cnt].dir_option[itr]->general_description)
free(world[cnt].dir_option[itr]->general_description);
if (world[cnt].dir_option[itr]->keyword)
free(world[cnt].dir_option[itr]->keyword);
free(world[cnt].dir_option[itr]);
}
}
free(world);
top_of_world = 0;
/* Objects */
for (cnt = 0; cnt <= top_of_objt; cnt++)
{
if (obj_proto[cnt].name)
free(obj_proto[cnt].name);
if (obj_proto[cnt].description)
free(obj_proto[cnt].description);
if (obj_proto[cnt].short_description)
free(obj_proto[cnt].short_description);
if (obj_proto[cnt].action_description)
free(obj_proto[cnt].action_description);
free_extra_descriptions(obj_proto[cnt].ex_description);
/* free script proto list */
free_proto_script(&obj_proto[cnt], OBJ_TRIGGER);
}
free(obj_proto);
free(obj_index);
/* Mobiles */
for (cnt = 0; cnt <= top_of_mobt; cnt++)
{
if (mob_proto[cnt].player.name)
free(mob_proto[cnt].player.name);
if (mob_proto[cnt].player.title)
free(mob_proto[cnt].player.title);
if (mob_proto[cnt].player.short_descr)
free(mob_proto[cnt].player.short_descr);
if (mob_proto[cnt].player.long_descr)
free(mob_proto[cnt].player.long_descr);
if (mob_proto[cnt].player.description)
free(mob_proto[cnt].player.description);
if (mob_proto[cnt].player.walkin)
free(mob_proto[cnt].player.walkin);
if (mob_proto[cnt].player.walkout)
free(mob_proto[cnt].player.walkout);
/* free script proto list */
free_proto_script(&mob_proto[cnt], MOB_TRIGGER);
while (mob_proto[cnt].affected)
affect_remove(&mob_proto[cnt], mob_proto[cnt].affected);
}
free(mob_proto);
free(mob_index);
/* Shops */
destroy_shops();
/* Quests */
destroy_quests();
/* Zones */
#define THIS_CMD zone_table[cnt].cmd[itr]
for (cnt = 0; cnt <= top_of_zone_table; cnt++)
{
if (zone_table[cnt].name)
free(zone_table[cnt].name);
if (zone_table[cnt].builders)
free(zone_table[cnt].builders);
if (zone_table[cnt].cmd)
{
/* first see if any vars were defined in this zone */
for (itr = 0; THIS_CMD.command != 'S'; itr++)
if (THIS_CMD.command == 'V')
{
if (THIS_CMD.sarg1)
free(THIS_CMD.sarg1);
if (THIS_CMD.sarg2)
free(THIS_CMD.sarg2);
}
/* then free the command list */
free(zone_table[cnt].cmd);
}
}
free(zone_table);
#undef THIS_CMD
/* zone table reset queue */
if (reset_q.head)
{
struct reset_q_element *ftemp = reset_q.head, *temp;
while (ftemp)
{
temp = ftemp->next;
free(ftemp);
ftemp = temp;
}
}
/* Triggers */
for (cnt = 0; cnt < top_of_trigt; cnt++)
{
if (trig_index[cnt]->proto)
{
/* make sure to nuke the command list (memory leak) */
/* free_trigger() doesn't free the command list */
if (trig_index[cnt]->proto->cmdlist)
{
struct cmdlist_element *i, *j;
i = trig_index[cnt]->proto->cmdlist;
while (i)
{
j = i->next;
if (i->cmd)
free(i->cmd);
free(i);
i = j;
}
}
free_trigger(trig_index[cnt]->proto);
}
free(trig_index[cnt]);
}
free(trig_index);
/* Craft Cleanup */
if (global_craft_list->iSize > 0)
{
struct craft_data *craft;
while ((craft = (struct craft_data *)simple_list(global_craft_list)) != NULL)
{
remove_from_list(craft, global_craft_list);
free_craft(craft);
}
}
free_list(global_craft_list);
/* Events */
event_free_all();
}
/* body of the booting system */
void boot_db(void)
{
zone_rnum i = 0;
char buf1[MAX_INPUT_LENGTH] = {'\0'}; /* strip color off zone names */
log("Boot db -- BEGIN.");
log("Resetting the game time:");
reset_time();
log("Initialize Global / Group Lists");
global_lists = create_list();
group_list = create_list();
global_craft_list = create_list(); /* NewCraft */
log("Initializing Events");
init_events();
log("Reading news, credits, help, ihelp, bground, info & motds.");
file_to_string_alloc(NEWS_FILE, &news);
file_to_string_alloc(CREDITS_FILE, &credits);
file_to_string_alloc(MOTD_FILE, &motd);
file_to_string_alloc(IMOTD_FILE, &imotd);
file_to_string_alloc(HELP_PAGE_FILE, &help);
file_to_string_alloc(IHELP_PAGE_FILE, &ihelp);
file_to_string_alloc(INFO_FILE, &info);
file_to_string_alloc(WIZLIST_FILE, &wizlist);
file_to_string_alloc(IMMLIST_FILE, &immlist);
file_to_string_alloc(POLICIES_FILE, &policies);
file_to_string_alloc(HANDBOOK_FILE, &handbook);
file_to_string_alloc(BACKGROUND_FILE, &background);
if (file_to_string_alloc(GREETINGS_FILE, &GREETINGS) == 0)
prune_crlf(GREETINGS);
log("Loading spell definitions.");
mag_assign_spells();
log("Loading weapon and armor special ability definitions.");
initialize_special_abilities();
boot_world();
log("Loading help entries.");
index_boot(DB_BOOT_HLP);
log("Generating player index.");
build_player_index();
if (auto_pwipe)
{
log("Cleaning out inactive pfiles.");
clean_pfiles();
}
log("Loading fight messages.");
load_messages();
log("Loading social messages.");
boot_social_messages();
log("Building command list.");
create_command_list(); /* aedit patch -- M. Scott */
log("Assigning function pointers:");
if (!no_specials)
{
log(" Mobiles.");
assign_mobiles();
log(" Shopkeepers.");
assign_the_shopkeepers();
log(" Objects.");
assign_objects();
log(" Rooms.");
assign_rooms();