-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimulate.c
More file actions
2886 lines (2687 loc) · 71.6 KB
/
simulate.c
File metadata and controls
2886 lines (2687 loc) · 71.6 KB
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
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include <fcntl.h>
#include <setjmp.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <memory.h>
#if defined(sun)
#include <alloca.h>
#endif
#ifdef M_UNIX
#include <dirent.h>
#endif
#include "lint.h"
#include "config.h"
#include "stdio.h"
#include "lang.h"
#include "interpret.h"
#include "object.h"
#include "sent.h"
#include "wiz_list.h"
#include "exec.h"
#include "comm.h"
extern int errno;
extern int comp_flag;
char *inherit_file;
extern int readlink PROT((char *, char *, int));
extern int symlink PROT((char *, char *));
#ifndef MSDOS
extern int lstat PROT((char *, struct stat *));
#else
#define lstat stat
#endif
extern int fchmod PROT((int, int));
char *last_verb;
extern int special_parse PROT((char *)),
set_call PROT((struct object *, struct sentence *, int)),
legal_path PROT((char *));
void pre_compile PROT((char *)),
remove_interactive PROT((struct object *)),
add_light PROT((struct object *, int)),
add_action PROT((char *, char *, int)),
add_verb PROT((char *, int)),
print_local_commands(), ipc_remove(),
show_info_about PROT((char *, char *, struct interactive *)),
set_snoop PROT((struct object *, struct object *)),
print_lnode_status PROT((int)),
remove_all_players(), start_new_file PROT((FILE *)), end_new_file(),
move_or_destruct PROT((struct object *, struct object *)),
load_ob_from_swap PROT((struct object *)), dump_malloc_data(),
print_svalue PROT((struct svalue *)),
debug_message_value(),
destruct2();
extern int d_flag;
struct object *obj_list, *obj_list_destruct, *master_ob;
extern struct wiz_list *back_bone_uid;
struct object *current_object; /* The object interpreting a function. */
struct object *command_giver; /* Where the current command came from. */
struct object *current_interactive; /* The user who caused this execution */
int num_parse_error; /* Number of errors in the parser. */
void shutdowngame();
extern void flush_all_player_mess();
struct variable *find_status(str, must_find)
char *str;
int must_find;
{
int i;
for (i=0; i < current_object->prog->num_variables; i++) {
if (strcmp(current_object->prog->variable_names[i].name, str) == 0)
return ¤t_object->prog->variable_names[i];
}
if (!must_find)
return 0;
error("--Status %s not found in prog for %s\n", str,
current_object->name);
return 0;
}
/*
* Give the correct uid and euid to a created object.
*/
int give_uid_to_object(ob)
struct object *ob;
{
struct object *tmp_ob;
#ifdef COMPAT_MODE
char wiz_name[100];
#else
struct svalue *ret;
char *creator_name;
#endif
if (master_ob == 0)
tmp_ob = ob;
else {
assert_master_ob_loaded();
tmp_ob = master_ob;
}
#ifdef COMPAT_MODE
/* Is this object wizard defined ? */
if (sscanf(ob->name, "players/%s", wiz_name) == 1) {
char *np;
np = strchr(wiz_name, '/');
if (np)
*np = '\0';
ob->user = add_name(wiz_name);
} else {
ob->user = 0;
}
ob->eff_user = ob->user; /* Initial state */
return 1;
#else
if (!current_object || !current_object->user) {
/*
* Only for the master and void object. Note that
* back_bone_uid is not defined when master.c is being loaded.
*/
ob->user = add_name("NONAME");
ob->eff_user = 0;
return 1;
}
/*
* Ask master.c who the creator of this object is.
*/
push_string(ob->name, STRING_CONSTANT);
ret = apply("creator_file", tmp_ob, 1);
if (!ret)
error("No function 'creator_file' in master.c!\n");
if (ret->type != T_STRING) {
struct svalue arg;
/* This can be the case for objects in /ftp and /open. */
arg.type = T_OBJECT;
arg.u.ob = ob;
destruct_object(&arg);
error("Illegal object to load.\n");
}
creator_name = ret->u.string;
/*
* Now we are sure that we have a creator name.
* Do not call apply() again, because creator_name will be lost !
*/
if (strcmp(current_object->user->name, creator_name) == 0) {
/*
* The loaded object has the same uid as the loader.
*/
ob->user = current_object->eff_user;
ob->eff_user = current_object->eff_user;
return 1;
}
if (strcmp(back_bone_uid->name, creator_name) == 0) {
/*
* The object is loaded from backbone. This is trusted, so we
* let it inherit the value of eff_user.
*/
ob->user = current_object->eff_user;
ob->eff_user = current_object->eff_user;
return 1;
}
/*
* The object is not loaded from backbone, nor from
* from the loading objects path. That should be an object
* defined by another wizard. It can't be trusted, so we give it the
* same uid as the creator. Also give it eff_user 0, which means that
* player 'a' can't use objects from player 'b' to load new objects nor
* modify files owned by player 'b'.
*
* If this effect is wanted, player 'b' must let his object do
* 'seteuid()' to himself. That is the case for most rooms.
*/
ob->user = add_name(creator_name);
ob->eff_user = (struct wiz_list *)0;
return 1;
#endif /* COMPAT_MODE */
}
/*
* Load an object definition from file. If the object wants to inherit
* from an object that is not loaded, discard all, load the inherited object,
* and reload again.
*
* In mudlib3.0 when loading inherited objects, their reset() is not called.
*
* Save the command_giver, because reset() in the new object might change
* it.
*
*
*/
struct object *load_object(lname, dont_reset)
char *lname;
int dont_reset;
{
FILE *f;
extern int total_lines;
extern int approved_object;
struct object *ob, *save_command_giver = command_giver;
extern struct program *prog;
extern char *current_file;
struct stat c_st;
int name_length;
char real_name[200], name[200];
#ifndef COMPAT_MODE
if (current_object && current_object->eff_user == 0)
error("Can't load objects when no effective user.\n");
#endif
/* Truncate possible .c in the object name. */
/* Remove leading '/' if any. */
while(lname[0] == '/')
lname++;
strncpy(name, lname, sizeof(name) - 1);
name[sizeof name - 1] = '\0';
name_length = strlen(name);
if (name_length > sizeof name - 4)
name_length = sizeof name - 4;
name[name_length] = '\0';
if (name[name_length-2] == '.' && name[name_length-1] == 'c') {
name[name_length-2] = '\0';
name_length -= 2;
}
/*
* First check that the c-file exists.
*/
(void)strcpy(real_name, name);
(void)strcat(real_name, ".c");
if (stat(real_name, &c_st) == -1) {
fprintf(stderr, "Could not load descr for %s\n", real_name);
error("Failed to load file.\n");
return 0;
}
/*
* Check if it's a legal name.
*/
if (!legal_path(real_name)) {
fprintf(stderr, "Illegal pathname: %s\n", real_name);
error("Illegal path name.\n");
return 0;
}
if (comp_flag)
fprintf(stderr, " compiling %s ...", real_name);
f = fopen(real_name, "r");
if (f == 0) {
perror(real_name);
error("Could not read the file.\n");
}
start_new_file(f);
current_file = string_copy(real_name); /* This one is freed below */
compile_file();
end_new_file();
if (comp_flag)
fprintf(stderr, " done\n");
update_compile_av(total_lines);
total_lines = 0;
(void)fclose(f);
free(current_file);
current_file = 0;
/* Sorry, can't handle objects without programs yet. */
if (inherit_file == 0 && (num_parse_error > 0 || prog == 0)) {
if (prog)
free_prog(prog, 1);
if (num_parse_error == 0 && prog == 0)
error("No program in object !\n");
error("Error in loading object\n");
}
/*
* This is an iterative process. If this object wants to inherit an
* unloaded object, then discard current object, load the object to be
* inherited and reload the current object again. The global variable
* "inherit_file" will be set by lang.y to point to a file name.
*/
if (inherit_file) {
char *tmp = inherit_file;
if (prog) {
free_prog(prog, 1);
prog = 0;
}
if (strcmp(inherit_file, name) == 0) {
free(inherit_file);
inherit_file = 0;
error("Illegal to inherit self.\n");
}
inherit_file = 0;
#if 1 /* MUDLIB3_NEED, It's very awkard to have to have a debug3 /JnA */
#ifdef COMPAT_MODE
load_object(tmp, 0);
#else
load_object(tmp, 1);
#endif
#else
load_object(tmp, 0); /* Remove this feature for now */
#endif
free(tmp);
ob = load_object(name, dont_reset);
return ob;
}
ob = get_empty_object(prog->num_variables);
/*
* Can we approve of this object ?
*/
if (approved_object || strcmp(prog->name, "std/object.c") == 0)
ob->flags |= O_APPROVED;
ob->name = string_copy(name); /* Shared string is no good here */
ob->prog = prog;
ob->next_all = obj_list;
obj_list = ob;
enter_object_hash(ob); /* add name to fast object lookup table */
if (give_uid_to_object(ob) && !dont_reset)
reset_object(ob, 0);
if (!(ob->flags & O_DESTRUCTED) && function_exists("clean_up",ob)) {
ob->flags |= O_WILL_CLEAN_UP;
}
command_giver = save_command_giver;
if (d_flag > 1 && ob)
debug_message("--%s loaded\n", ob->name);
return ob;
}
char *make_new_name(str)
char *str;
{
static int i;
char *p = xalloc(strlen(str) + 10);
(void)sprintf(p, "%s#%d", str, i);
i++;
return p;
}
/*
* Save the command_giver, because reset() in the new object might change
* it.
*/
struct object *clone_object(str1)
char *str1;
{
struct object *ob, *new_ob;
struct object *save_command_giver = command_giver;
#ifndef COMPAT_MODE
if (current_object && current_object->eff_user == 0)
error("Illegal to call clone_object() with effective user 0\n");
#endif
ob = find_object(str1);
/*
* If the object self-destructed...
*/
if (ob == 0)
return 0;
if (ob->super || (ob->flags & O_CLONE))
error("Cloning a bad object !\n");
/* We do not want the heart beat to be running for unused copied objects */
if (ob->flags & O_HEART_BEAT)
(void)set_heart_beat(ob, 0);
new_ob = get_empty_object(ob->prog->num_variables);
new_ob->name = make_new_name(ob->name);
new_ob->flags |= O_CLONE | ob->flags & ( O_APPROVED | O_WILL_CLEAN_UP ) ;
#if 0
if (ob->flags & O_APPROVED)
new_ob->flags |= O_APPROVED;
#endif
new_ob->prog = ob->prog;
reference_prog (ob->prog, "clone_object");
#ifdef COMPAT_MODE
if (current_object && current_object->user && !ob->user)
new_ob->user = current_object->user;
else
new_ob->user = ob->user; /* Possibly a null pointer */
new_ob->eff_user = new_ob->user; /* Init state */
#else
if (!current_object)
fatal("clone_object() from no current_object !\n");
give_uid_to_object(new_ob);
#endif
new_ob->next_all = obj_list;
obj_list = new_ob;
enter_object_hash(new_ob); /* Add name to fast object lookup table */
reset_object(new_ob, 0);
command_giver = save_command_giver;
/* Never know what can happen ! :-( */
if (new_ob->flags & O_DESTRUCTED)
return 0;
return new_ob;
}
struct object *environment(arg)
struct svalue *arg;
{
struct object *ob = current_object;
if (arg && arg->type == T_OBJECT)
ob = arg->u.ob;
else if (arg && arg->type == T_STRING)
ob = find_object2(arg->u.string);
if (ob == 0 || ob->super == 0 || (ob->flags & O_DESTRUCTED))
return 0;
if (ob->flags & O_DESTRUCTED)
error("environment() off destructed object.\n");
return ob->super;
}
/*
* Execute a command for an object. Copy the command into a
* new buffer, because 'parse_command()' can modify the command.
* If the object is not current object, static functions will not
* be executed. This will prevent forcing players to do illegal things.
*
* Return cost of the command executed if success (> 0).
* When failure, return 0.
*/
int command_for_object(str, ob)
char *str;
struct object *ob;
{
char buff[1000];
extern int eval_cost;
int save_eval_cost = eval_cost - 1000;
if (strlen(str) > sizeof(buff) - 1)
error("Too long command.\n");
if (ob == 0)
ob = current_object;
else if (ob->flags & O_DESTRUCTED)
return 0;
strncpy(buff, str, sizeof buff);
buff[sizeof buff - 1] = '\0';
if (parse_command(buff, ob))
return eval_cost - save_eval_cost;
else
return 0;
}
/*
* To find if an object is present, we have to look in two inventory
* lists. The first list is the inventory of the current object.
* The second list is all things that have the same ->super as
* current_object.
* Also test the environment.
* If the second argument 'ob' is non zero, only search in the
* inventory of 'ob'. The argument 'ob' will be mandatory, later.
*/
static struct object *object_present2 PROT((char *, struct object *));
struct object *object_present(v, ob)
struct svalue *v;
struct object *ob;
{
struct svalue *ret;
struct object *ret_ob;
int specific = 0;
if (ob == 0)
ob = current_object;
else
specific = 1;
if (ob->flags & O_DESTRUCTED)
return 0;
if (v->type == T_OBJECT) {
if (specific) {
if (v->u.ob->super == ob)
return v->u.ob;
else
return 0;
}
if (v->u.ob->super == ob ||
(v->u.ob->super == ob->super && ob->super != 0))
return v->u.ob->super;
return 0;
}
ret_ob = object_present2(v->u.string, ob->contains);
if (ret_ob)
return ret_ob;
if (specific)
return 0;
if (ob->super) {
push_string(v->u.string, STRING_CONSTANT);
ret = apply("id", ob->super, 1);
if (ob->super->flags & O_DESTRUCTED)
return 0;
if (ret && !(ret->type == T_NUMBER && ret->u.number == 0))
return ob->super;
return object_present2(v->u.string, ob->super->contains);
}
return 0;
}
static struct object *object_present2(str, ob)
char *str;
struct object *ob;
{
struct svalue *ret;
char *p;
int count = 0, length;
char *item;
item = string_copy(str);
length = strlen(item);
p = item + length - 1;
if (*p >= '0' && *p <= '9') {
while(p > item && *p >= '0' && *p <= '9')
p--;
if (p > item && *p == ' ') {
count = atoi(p+1) - 1;
*p = '\0';
length = p - item; /* This is never used again ! */
}
}
for (; ob; ob = ob->next_inv) {
push_string(item, STRING_CONSTANT);
ret = apply("id", ob, 1);
if (ob->flags & O_DESTRUCTED) {
free(item);
return 0;
}
if (ret == 0 || (ret->type == T_NUMBER && ret->u.number == 0))
continue;
if (count-- > 0)
continue;
free(item);
return ob;
}
free(item);
return 0;
}
/*
* Remove an object. It is first moved into the destruct list, and
* not really destructed until later. (see destruct2()).
*/
void destruct_object(v)
struct svalue *v;
{
struct object *ob, *super;
struct object **pp;
int removed;
if (v->type == T_OBJECT)
ob = v->u.ob;
else {
ob = find_object2(v->u.string);
if (ob == 0)
error("destruct_object: Could not find %s\n", v->u.string);
}
if (ob->flags & O_DESTRUCTED)
return;
if (ob->flags & O_SWAPPED)
load_ob_from_swap(ob);
remove_object_from_stack(ob);
/*
* If this is the first object being shadowed by another object, then
* destruct the whole list of shadows.
*/
if (ob->shadowed && !ob->shadowing) {
struct svalue svp;
struct object *ob2;
svp.type = T_OBJECT;
for (ob2 = ob->shadowed; ob2; ) {
svp.u.ob = ob2;
ob2 = ob2->shadowed;
svp.u.ob->shadowed = 0;
svp.u.ob->shadowing = 0;
destruct_object(&svp);
}
}
/*
* The chain of shadows is a double linked list. Take care to update
* it correctly.
*/
if (ob->shadowing)
ob->shadowing->shadowed = ob->shadowed;
if (ob->shadowed)
ob->shadowed->shadowing = ob->shadowing;
ob->shadowing = 0;
ob->shadowed = 0;
if (d_flag > 1)
debug_message("Destruct object %s (ref %d)\n", ob->name, ob->ref);
super = ob->super;
if (super) {
#ifdef COMPAT_MODE
struct svalue *weight;
/* Call exit in current room, if player or npc not in mudlib 3.0 */
if((ob->flags & O_ENABLE_COMMANDS)) {
push_object(ob);
(void)apply("exit",super,1);
}
weight = apply("query_weight", ob, 0);
if (weight && weight->type == T_NUMBER) {
push_number(-weight->u.number);
(void)apply("add_weight", super, 1);
}
#endif
}
if (super == 0) {
/*
* There is nowhere to move the objects.
*/
struct svalue svp;
svp.type = T_OBJECT;
while(ob->contains) {
svp.u.ob = ob->contains;
push_object(ob->contains);
/* An error here will not leave destruct() in an inconsistent
* stage.
*/
apply_master_ob("destruct_environment_of",1);
if (svp.u.ob == ob->contains)
destruct_object(&svp);
}
} else {
while(ob->contains)
move_or_destruct(ob->contains, super);
}
if ( ob->interactive ) {
struct object *save=command_giver;
command_giver=ob;
if (ob->interactive->ed_buffer) {
extern void save_ed_buffer();
save_ed_buffer();
}
flush_all_player_mess();
command_giver=save;
}
set_heart_beat(ob, 0);
/*
* Remove us out of this current room (if any).
* Remove all sentences defined by this object from all objects here.
*/
if (ob->super) {
if (ob->super->flags & O_ENABLE_COMMANDS)
remove_sent(ob, ob->super);
add_light(ob->super, - ob->total_light);
for (pp = &ob->super->contains; *pp;) {
if ((*pp)->flags & O_ENABLE_COMMANDS)
remove_sent(ob, *pp);
if (*pp != ob)
pp = &(*pp)->next_inv;
else
*pp = (*pp)->next_inv;
}
}
/*
* Now remove us out of the list of all objects.
* This must be done last, because an error in the above code would
* halt execution.
*/
removed = 0;
for (pp = &obj_list; *pp; pp = &(*pp)->next_all) {
if (*pp != ob)
continue;
*pp = (*pp)->next_all;
removed = 1;
remove_object_hash(ob);
break;
}
if (!removed)
fatal("Failed to delete object.\n");
if (ob->living_name)
remove_living_name(ob);
ob->super = 0;
ob->next_inv = 0;
ob->contains = 0;
ob->flags &= ~O_ENABLE_COMMANDS;
ob->next_all = obj_list_destruct;
obj_list_destruct = ob;
ob->flags |= O_DESTRUCTED;
}
/*
* This one is called when no program is executing from the main loop.
*/
void destruct2(ob)
struct object *ob;
{
if (d_flag > 1) {
debug_message("Destruct-2 object %s (ref %d)\n", ob->name, ob->ref);
}
if (ob->interactive)
remove_interactive(ob);
/*
* We must deallocate variables here, not in 'free_object()'.
* That is because one of the local variables may point to this object,
* and deallocation of this pointer will also decrease the reference
* count of this object. Otherwise, an object with a variable pointing
* to itself, would never be freed.
* Just in case the program in this object would continue to
* execute, change string and object variables into the number 0.
*/
if (ob->prog->num_variables > 0) {
/*
* Deallocate variables in this object.
* The space of the variables are not deallocated until
* the object structure is freed in free_object().
*/
int i;
for (i=0; i<ob->prog->num_variables; i++) {
free_svalue(&ob->variables[i]);
ob->variables[i].type = T_NUMBER;
ob->variables[i].u.number = 0;
}
}
free_object(ob, "destruct_object");
}
#ifdef F_CREATE_WIZARD
/*
* This is the efun create_wizard(). Create a home dir for a wizard,
* and other files he may want.
*
* The real job is done by the master.c object, so the call could as well
* have been done to it directly. But, this function remains for
* compatibility.
*
* It should be replaced by a function in simul_efun.c !
*/
char *create_wizard(owner, domain)
char *owner;
char *domain;
{
struct svalue *ret;
#if 0
struct stat st;
FILE *f;
char cmd[200], lbuf[128];
static char name[200], name2[200]; /* Ugly fix /Lars (static) */
struct object *owner_obj;
#endif
/*
* Let the master object do the job.
*/
push_constant_string(owner);
push_constant_string(domain);
push_object(current_object);
ret = apply_master_ob("master_create_wizard", 3);
if (ret && ret->type == T_STRING)
return ret->u.string;
return 0;
#if 0
/*
* Verify that it is a valid call of create_wizard(). This is done
* by a function in master.c. It will take the calling object as
* argument, and must return a non-zero value.
*/
push_object(current_object);
ret = apply_master_ob("verify_create_wizard", 1);
if (ret == 0)
error("No wizards allowed ! (because no verify_create_wizard() in master.c)\n");
if (ret->type == T_NUMBER && ret->u.number == 0)
error("Illegal use of create_wizard() !\n");
/*
* Even if the object that called create_wizard() is trusted, we won't
* allow it to use funny names for the owner.
*/
if (!legal_path(owner))
error("Bad name to create_wizard: %s\n", owner);
owner_obj = find_living_object(owner, 1);
if (owner_obj == 0) {
fprintf(stderr,
"create_wizard: Could not find living object %s.\n", owner);
return 0;
}
/*
* Create the path to wizards home directory.
*/
(void)sprintf(name, "%s/%s", PLAYER_DIR, owner);
/*
* If we are using domains, make a path to the domain.
*/
if(domain) {
(void)sprintf(name2, "%s/%s/%s", DOMAIN_DIR, domain, owner);
fprintf(stderr, "name = %s, name2 = %s\n", name, name2);
/*
* If the directory already exists, we move it to the domain.
*/
if (stat(name, &st) == 0) {
if((st.st_mode & S_IFMT) == S_IFDIR) {
rename(name, name2);
}
} else {
if (mkdir(name2, 0777) == -1) {
perror(name2);
error("Could not mkdir %s\n", name2);
}
}
} else {
if (stat(name, &st) == 0)
error("Player %s already has a castle!\n", owner);
else
if (mkdir(name, 0777) == -1) {
perror(name);
error("Could not mkdir %s\n", name);
}
}
/* add castle */
if(domain) {
(void)sprintf(name, "%s/%s/common/domain.c", DOMAIN_DIR, domain);
} else {
(void)sprintf(name, "%s/%s/%s", PLAYER_DIR, owner, "castle.c");
}
if(stat(name, &st) == 0) {
fprintf(stderr, "castle file %s already exists.\n", name);
} else {
f = fopen(name, "w");
if (f == NULL)
error("Could not create a castle file %s!\n", name);
(void)fprintf(f, "#define NAME \"%s\"\n", domain ? domain : owner);
#ifdef CASTLE_ROOM
(void)fprintf(f, "#define DEST \"%s\"\n", CASTLE_ROOM);
#else
(void)fprintf(f, "#define DEST \"%s\"\n",
current_object->super->name);
#endif
(void)fclose(f);
(void)sprintf(cmd, "cat %s >> %s", DEFAULT_CASTLE, name);
(void)system(cmd);
}
/*
* Add this castle name to the list of files to be loaded.
*/
f = fopen(INIT_FILE, "a");
if (f == NULL)
error("Could not add the new castle to the %s\n", INIT_FILE);
(void)fprintf(f, "%s\n", name);
(void)fclose(f);
return name;
#endif
}
#endif /* F_CREATE_WIZARD */
/*
* A message from an object will reach
* all objects in the inventory,
* all objects in the same environment and
* the surrounding object.
* Non interactive objects gets no messages.
*
* There are two cases to take care of. If this routine is called from
* a player (indirectly), then the message goes to all in his
* environment. Otherwise, the message goes to all in the current_object's
* environment (as the case when called from a heart_beat()).
*
* If there is a second argument 'avoid_ob', then do not send the message
* to that object.
*/
void say(v, avoid)
struct svalue *v;
struct vector *avoid;
{
extern struct vector *order_alist PROT((struct vector *));
struct vector *vtmpp;
static struct vector vtmp = { 1, 1,
#ifdef DEBUG
1,
#endif
(struct wiz_list *)NULL,
{ { T_POINTER } }
};
extern int assoc PROT((struct svalue *key, struct vector *));
struct object *ob, *save_command_giver = command_giver;
struct object *origin;
char buff[256];
#define INITIAL_MAX_RECIPIENTS 50
int max_recipients = INITIAL_MAX_RECIPIENTS;
struct object *first_recipients[INITIAL_MAX_RECIPIENTS];
struct object **recipients = first_recipients;
struct object **curr_recipient = first_recipients;
struct object **last_recipients =
&first_recipients[INITIAL_MAX_RECIPIENTS-1];
struct object *save_again;
static struct svalue stmp = { T_OBJECT };
if (current_object->flags & O_ENABLE_COMMANDS)
command_giver = current_object;
else if (current_object->shadowing)
command_giver = current_object->shadowing;
if (command_giver) {
origin = command_giver;
if (avoid->item[0].type == T_NUMBER) {
avoid->item[0].type = T_OBJECT;
avoid->item[0].u.ob = command_giver;
add_ref(command_giver, "ass to var");
}
} else
origin = current_object;
vtmp.item[0].u.vec = avoid;
vtmpp = order_alist(&vtmp);
avoid = vtmpp->item[0].u.vec;
if (ob = origin->super) {
if (ob->flags & O_ENABLE_COMMANDS || ob->interactive) {
*curr_recipient++ = ob;
}
for (ob = origin->super->contains; ob; ob = ob->next_inv) {
if (ob->flags & O_ENABLE_COMMANDS || ob->interactive) {
if (curr_recipient >= last_recipients) {
max_recipients <<= 1;
curr_recipient = (struct object **)
alloca(max_recipients * sizeof(struct object *));
memcpy((char*)curr_recipient, (char*)recipients,
max_recipients * sizeof(struct object *)>>1);
recipients = curr_recipient;
last_recipients = &recipients[max_recipients-1];
curr_recipient += (max_recipients>>1) - 1;
}
*curr_recipient++ = ob;
}
}
}
for (ob = origin->contains; ob; ob = ob->next_inv) {
if (ob->flags & O_ENABLE_COMMANDS || ob->interactive) {
if (curr_recipient >= last_recipients) {
max_recipients <<= 1;
curr_recipient = (struct object **)alloca(max_recipients);
memcpy((char*)curr_recipient, (char*)recipients,
max_recipients * sizeof(struct object *)>>1);
recipients = curr_recipient;
last_recipients = &recipients[max_recipients-1];
curr_recipient += (max_recipients>>1) - 1;
}
*curr_recipient++ = ob;
}
}
*curr_recipient = (struct object *)0;
switch(v->type) {
case T_STRING:
strncpy(buff, v->u.string, sizeof buff);
buff[sizeof buff - 1] = '\0';
break;
case T_OBJECT:
strncpy(buff, v->u.ob->name, sizeof buff);
buff[sizeof buff - 1] = '\0';
break;
case T_NUMBER:
sprintf(buff, "%d", v->u.number);
break;
case T_POINTER:
for (curr_recipient = recipients; ob = *curr_recipient++; ) {
extern void push_vector PROT((struct vector *));
if (ob->flags & O_DESTRUCTED) continue;
stmp.u.ob = ob;
if (assoc(&stmp, avoid) >= 0) continue;
push_vector(v->u.vec);
push_object(command_giver);
apply("catch_msg", ob, 2);
}
break;
default:
error("Invalid argument %d to say()\n", v->type);
}
save_again = command_giver;
for (curr_recipient = recipients; ob = *curr_recipient++; ) {
if (ob->flags & O_DESTRUCTED) continue;
stmp.u.ob = ob;
if (assoc(&stmp, avoid) >= 0) continue;
if (ob->interactive == 0) {
tell_npc(ob, buff);
continue;