-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathp_db.c
4185 lines (3466 loc) · 106 KB
/
p_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 p_db.c
*
* Implementation of DB related primitives for MUF.
*
* This file is part of Fuzzball MUCK. Please see LICENSE.md for details.
*/
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#include "config.h"
#include "array.h"
#include "boolexp.h"
#include "compile.h"
#include "db.h"
#ifdef DISKBASE
#include "diskprop.h"
#endif
#include "edit.h"
#include "fbstrings.h"
#include "fbtime.h"
#include "game.h"
#include "inst.h"
#include "interface.h"
#include "interp.h"
#include "log.h"
#include "look.h"
#include "match.h"
#include "move.h"
#include "player.h"
#include "predicates.h"
#include "props.h"
#include "timequeue.h"
#include "tune.h"
#include "events.h"
/**
* @private
* @var used to store the parameters passed into the primitives
* This seems to be used for conveinance, but makes this probably
* not threadsafe. Currently used in the abort_interp macro.
*/
static struct inst *oper1, *oper2, *oper3, *oper4;
/**
* Implementation of MUF ADDPENNIES
*
* Consumes a dbref and an integer, and adds that value to the player or
* thing dbref. Requires MUCKER level tp_addpennies_muf_mlev for players
* and 4 for things.
*
* Needs MUCKER level 4 to have a player's penny total exceed tp_max_pennies.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_addpennies(PRIM_PROTOTYPE)
{
int result;
dbref ref;
CHECKOP(2);
oper1 = POP();
oper2 = POP();
if (mlev < tp_addpennies_muf_mlev) {
abort_interp("Permission Denied (mlev < tp_addpennies_muf_mlev)");
}
if (!valid_object(oper2) || (Typeof(oper2->data.objref) != TYPE_PLAYER && Typeof(oper2->data.objref) != TYPE_THING)) {
abort_interp("Invalid player or thing argument.");
}
if (oper1->type != PROG_INTEGER) {
abort_interp("Non-integer argument (2)");
}
ref = oper2->data.objref;
if (mlev < 4 && Typeof(ref) == TYPE_THING) {
abort_interp("Permission denied.");
}
result = GETVALUE(ref);
if (mlev < 4) {
if (oper1->data.number > 0) {
if (result > (result + oper1->data.number)) {
abort_interp("Would roll over player's score.");
}
if ((result + oper1->data.number) > tp_max_pennies) {
abort_interp("Would exceed MAX_PENNIES.");
}
} else {
if (result < (result + oper1->data.number)) {
abort_interp("Would roll over player's score.");
}
if ((result + oper1->data.number) < 0) {
abort_interp("Result would be negative.");
}
}
}
SETVALUE(ref, (GETVALUE(ref) + oper1->data.number));
DBDIRTY(ref);
CLEAR(oper1);
CLEAR(oper2);
}
/**
* Implementation of MUF MOVETO
*
* Consumes two dbrefs, and moves the first object to the non-exit second.
*
* Needs MUCKER level 3 to bypass basic ownership and JUMP_OK checks, and
* also to move an exit.
*
* This code should be further reviewed, and restructured to be easier to
* understand and maintain - and match other movement logic when applicable.
* It *seems* like we may find some unexpected consequences of using
* fallthrough logic in the main switch.
*
* Here we go --
*
* Moving a player will fail if the destination is not a room or basic vehicle.
*
* Moving a player/thing will fail if it would create a parent loop.
*
* Moving a player/thing with less than MUCKER level 3 will fail if:
* - source location or destination is not JUMP_OK
* - source location or destination does not pass basic ownership checks
* - destinaton is a basic vehicle and source is not in the same room
* - source is a guest and the destination room does not accept guests
*
* Moving a player/thing/program will fail if the destination is not a player,
* thing, or room.
*
* Moving a player/thing/program with less than MUCKER level three will fail if
* the source location or destination is not JUMP_OK or does not pass basic
* ownership checks.
*
* Moving an exit will fail if the destination is not a player, thing, or
* room (as above!) - but also if the destination is HOME.
*
* Moving an exit with less that MUCKER level 3 will fail if neither source
* nor destination pass basic ownership checks.
*
* Moving a room will fail if:
* - the desintation is also not a room and tp_secure_thing_movement is off
* - the desitnation is the GLOBAL_ENVIRONMENT
*
* Moving a room with less than MUCKER level 3 will fail if the destination
* is HOME and the source and source location do not pass basic ownership
* checks. Otherwise, the source must pass basic ownership and teleport
* checks and the movement must not create a parent loop.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_moveto(PRIM_PROTOTYPE)
{
struct inst *oper1 = NULL; /* prevents re-entrancy issues! */
struct inst *oper2 = NULL; /* prevents re-entrancy issues! */
/**
* @TODO Combine with other movement logic as possible.
*/
CHECKOP(2);
oper1 = POP();
oper2 = POP();
if (fr->level > tp_max_interp_recursion) {
abort_interp("Interp call loops not allowed.");
}
/* Needs to be an object, and object needs to be valid */
if (!valid_object(oper2)) {
abort_interp("Non-object argument. (2)");
}
/* Needs to be an object, and object needs to be valid or HOME */
if (!valid_object(oper1) && !is_home(oper1)) {
abort_interp("Non-object argument. (1)");
}
dbref victim, dest;
victim = oper2->data.objref;
dest = oper1->data.objref;
if (Typeof(dest) == TYPE_EXIT) {
abort_interp("Destination argument is an exit.");
}
if (Typeof(victim) == TYPE_EXIT && (mlev < 3)) {
abort_interp("Permission denied.");
}
if (!(FLAGS(victim) & JUMP_OK) && !permissions(ProgUID, victim) && (mlev < 3)) {
abort_interp("Object can't be moved.");
}
switch (Typeof(victim)) {
case TYPE_PLAYER:
if (Typeof(dest) != TYPE_ROOM
&& !(Typeof(dest) == TYPE_THING && (FLAGS(dest) & VEHICLE))) {
abort_interp("Bad destination.");
}
/* fall through */
case TYPE_THING:
if (parent_loop_check(victim, dest)) {
abort_interp("Things can't contain themselves.");
}
if ((mlev < 3)) {
if (!(FLAGS(LOCATION(victim)) & JUMP_OK) && !permissions(ProgUID, LOCATION(victim))) {
abort_interp("Source not JUMP_OK.");
}
if (!is_home(oper1) && !(FLAGS(dest) & JUMP_OK) && !permissions(ProgUID, dest)) {
abort_interp("Destination not JUMP_OK.");
}
if (Typeof(dest) == TYPE_THING && LOCATION(victim) != LOCATION(dest)) {
abort_interp("Not in same location as vehicle.");
}
if (ISGUEST(victim) && (FLAGS(dest) & GUEST) && Typeof(dest) == TYPE_ROOM) {
abort_interp("Destination doesn't accept guests.");
}
}
if (Typeof(victim) == TYPE_PLAYER) {
enter_room(fr->descr, victim, dest, program);
break;
}
if (mlev < 3 && (FLAGS(victim) & VEHICLE) &&
(FLAGS(dest) & VEHICLE) && Typeof(dest) != TYPE_THING) {
abort_interp("Destination doesn't accept vehicles.");
}
if (mlev < 3 && (FLAGS(victim) & ZOMBIE) &&
(FLAGS(dest) & ZOMBIE) && Typeof(dest) != TYPE_THING) {
abort_interp("Destination doesn't accept zombies.");
}
ts_lastuseobject(victim);
/* fall through */
case TYPE_PROGRAM: {
dbref matchroom = NOTHING;
if (Typeof(dest) != TYPE_ROOM && Typeof(dest) != TYPE_PLAYER && Typeof(dest) != TYPE_THING) {
abort_interp("Bad destination.");
}
if ((mlev < 3)) {
if (permissions(ProgUID, dest)) {
matchroom = dest;
}
if (permissions(ProgUID, LOCATION(victim))) {
matchroom = LOCATION(victim);
}
if (matchroom != NOTHING && !(FLAGS(matchroom) & JUMP_OK)
&& !permissions(ProgUID, victim)) {
abort_interp("Permission denied.");
}
}
if (Typeof(victim) == TYPE_THING
&& (tp_secure_thing_movement
|| (FLAGS(victim) & ZOMBIE))) {
enter_room(fr->descr, victim, dest, program);
} else {
moveto(victim, dest);
}
break;
}
case TYPE_EXIT:
if ((mlev < 3) && (!permissions(ProgUID, victim) || !permissions(ProgUID, dest))) {
abort_interp("Permission denied.");
}
if ((Typeof(dest) != TYPE_ROOM && Typeof(dest) != TYPE_THING
&& Typeof(dest) != TYPE_PLAYER) || dest == HOME) {
abort_interp("Bad destination object.");
}
unset_source(victim);
set_source(victim, dest);
SetMLevel(victim, 0);
break;
case TYPE_ROOM:
if (!tp_secure_thing_movement && Typeof(dest) != TYPE_ROOM) {
abort_interp("Bad destination.");
}
if (victim == GLOBAL_ENVIRONMENT) {
abort_interp("Permission denied.");
}
if (dest == HOME) {
/* Allow the owner of the room or the owner of
the room's location to reparent the room to
#0 */
if ((mlev < 3) && (!permissions(ProgUID, victim)
&& !permissions(ProgUID, LOCATION(victim)))) {
abort_interp("Permission denied.");
}
dest = GLOBAL_ENVIRONMENT;
} else {
if ((mlev < 3) && (!permissions(ProgUID, victim)
|| !can_teleport_to(ProgUID, dest))) {
abort_interp("Permission denied.");
}
if (parent_loop_check(victim, dest)) {
abort_interp("Parent room would create a loop.");
}
}
ts_lastuseobject(victim);
moveto(victim, dest);
break;
}
CLEAR(oper1);
CLEAR(oper2);
}
/**
* Implementation of MUF PENNIES
*
* Consumes a player or thing dbref and returns its value. Requires
* MUCKER level tp_pennies_muf_mlev and remote-read permissions when
* applicable.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_pennies(PRIM_PROTOTYPE)
{
int result;
CHECKOP(1);
oper1 = POP();
if (mlev < tp_pennies_muf_mlev) {
abort_interp("Permission Denied (mlev < tp_pennies_muf_mlev)");
}
if (!valid_object(oper1) || (Typeof(oper1->data.objref) != TYPE_PLAYER && Typeof(oper1->data.objref) != TYPE_THING)) {
abort_interp("Invalid player or thing argument.");
}
CHECKREMOTE(oper1->data.objref);
result = GETVALUE(oper1->data.objref);
CLEAR(oper1);
PushInt(result);
}
/**
* Implementation of MUF DBREF
*
* Consumes an integer, and returns it as a dbref - which is not guaranteed
* to be valid.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_dbref(PRIM_PROTOTYPE)
{
dbref ref;
CHECKOP(1);
oper1 = POP();
if (oper1->type != PROG_INTEGER) {
abort_interp("Non-integer argument.");
}
ref = (dbref) oper1->data.number;
CLEAR(oper1);
PushObject(ref);
}
/**
* Implementation of MUF CONTENTS
*
* Consumes a dbref, and returns the first dbref in its contents chain -
* which for MUCKER level 1 only returns controlled non-DARK objects.
* Requires remote-read permissions when applicable.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_contents(PRIM_PROTOTYPE)
{
dbref ref;
CHECKOP(1);
oper1 = POP();
if (!valid_object(oper1)) {
abort_interp("Invalid argument type.");
}
CHECKREMOTE(oper1->data.objref);
ref = CONTENTS(oper1->data.objref);
while (mlev < 2 && ref != NOTHING && (FLAGS(ref) & DARK) && !controls(ProgUID, ref)) {
ref = NEXTOBJ(ref);
}
CLEAR(oper1);
PushObject(ref);
}
/**
* Implementation of MUF EXITS
*
* Consumes a dbref, and returns the first dbref in its exits chain.
* Requires remote-read privileges when applicable.
*
* Needs MUCKER level 3 to bypass basic ownership checks.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_exits(PRIM_PROTOTYPE)
{
dbref ref;
CHECKOP(1);
oper1 = POP();
if (!valid_object(oper1) || Typeof(oper1->data.objref) == TYPE_PROGRAM || Typeof(oper1->data.objref) == TYPE_EXIT) {
abort_interp("Invalid player, thing, or room object.");
}
ref = oper1->data.objref;
CHECKREMOTE(ref);
if ((mlev < 3) && !permissions(ProgUID, ref)) {
abort_interp("Permission denied.");
}
ref = EXITS(ref);
CLEAR(oper1);
PushObject(ref);
}
/**
* Implementation of MUF NEXT
*
* Consumes a dbref, and returns the next dbref in its contents/exits
* chain - which for MUCKER level 1 only traverses controlled non-DARK exits.
* Requires remote-read permissions when applicable.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_next(PRIM_PROTOTYPE)
{
dbref ref;
CHECKOP(1);
oper1 = POP();
if (!valid_object(oper1)) {
abort_interp("Invalid object.");
}
CHECKREMOTE(oper1->data.objref);
ref = NEXTOBJ(oper1->data.objref);
while (mlev < 2 && ref != NOTHING && Typeof(ref) != TYPE_EXIT
&& ((FLAGS(ref) & DARK) || Typeof(ref) == TYPE_ROOM)
&& !controls(ProgUID, ref)) {
ref = NEXTOBJ(ref);
}
CLEAR(oper1);
PushObject(ref);
}
/**
* Implementation of MUF NEXTOWNED
*
* Consumes a dbref, and returns the next dbref in the database that is
* owned by the same player. If a player dbref is consumed, the entire
* database is searched. Requires MUCKER level 2.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_nextowned(PRIM_PROTOTYPE)
{
dbref ref, ownr;
CHECKOP(1);
oper1 = POP();
if (!valid_object(oper1)) {
abort_interp("Invalid object.");
}
if (mlev < 2) {
abort_interp("Permission denied.");
}
ref = oper1->data.objref;
CHECKREMOTE(ref);
ownr = OWNER(ref);
if (Typeof(ref) == TYPE_PLAYER) {
ref = 0;
} else {
ref++;
}
while (ref < db_top && (OWNER(ref) != ownr || ref == ownr)) {
ref++;
}
if (ref >= db_top) {
ref = NOTHING;
}
CLEAR(oper1);
PushObject(ref);
}
/**
* Implementation of MUF NAME
*
* Consumes a dbref, and returns the associated name. Requires remote-read
* privileges when applicable.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_name(PRIM_PROTOTYPE)
{
dbref ref;
char buf[BUFFER_LEN];
CHECKOP(1);
oper1 = POP();
if (!valid_object(oper1)) {
abort_interp("Invalid argument type.");
}
ref = oper1->data.objref;
if (Typeof(ref) == TYPE_GARBAGE) {
strcpyn(buf, sizeof(buf), "<garbage>");
} else {
CHECKREMOTE(ref);
if (NAME(ref)) {
strcpyn(buf, sizeof(buf), NAME(ref));
} else {
buf[0] = '\0';
}
}
CLEAR(oper1);
PushString(buf);
}
/**
* Implementation of MUF SETNAME
*
* Consumes a dbref and a string, and sets the name associated with the
* object. Setting a player name requires MUCKER level 4 and the player's
* password inside the given string (delimited by a space). Also required
* to change the name of objects that don't pass basic ownership checks.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_setname(PRIM_PROTOTYPE)
{
dbref ref;
char buf[BUFFER_LEN];
char *password;
/**
* @TODO Combine with logic in do_name as possible.
*/
CHECKOP(2);
oper1 = POP();
oper2 = POP();
if (!valid_object(oper2)) {
abort_interp("Invalid argument type (1)");
}
if (oper1->type != PROG_STRING) {
abort_interp("Non-string argument (2)");
}
ref = oper2->data.objref;
if ((mlev < 4) && !permissions(ProgUID, ref)) {
abort_interp("Permission denied.");
}
const char *b = DoNullInd(oper1->data.string);
if (Typeof(ref) == TYPE_PLAYER) {
strcpyn(buf, sizeof(buf), b);
b = buf;
if (mlev < 4) {
abort_interp("Permission denied.");
}
/* split off password */
for (password = buf; *password && !isspace(*password); password++) {}
if (*password) {
*password++ = '\0'; /* terminate name */
skip_whitespace_var(&password);
}
/* check for null password */
if (!*password) {
abort_interp("Player namechange requires password.");
} else if (!check_password(ref, password)) {
abort_interp("Incorrect password.");
} else if (strcasecmp(b, NAME(ref)) && !ok_object_name(b, TYPE_PLAYER)) {
abort_interp("You can't give a player that name.");
}
/* everything ok, notify */
log_status("NAME CHANGE (MUF): %s(#%d) to %s", NAME(ref), ref, b);
delete_player(ref);
change_player_name(ref, b);
add_player(ref);
} else {
if (!ok_object_name(b, Typeof(ref))) {
abort_interp("Invalid name.");
}
free((void *) NAME(ref));
NAME(ref) = alloc_string(b);
ts_modifyobject(ref);
}
CLEAR(oper1);
CLEAR(oper2);
}
/**
* Implementation of MUF PMATCH
*
* Consumes a string, and returns the player dbref with a name that matches
* the ANSI-stripped string, or NOTHING if no match. Recognizes 'me'.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_pmatch(PRIM_PROTOTYPE)
{
dbref ref;
char buf[BUFFER_LEN];
CHECKOP(1);
oper1 = POP();
if (oper1->type != PROG_STRING) {
abort_interp("Non-string argument.");
}
strip_ansi(buf, DoNullInd(oper1->data.string));
if (!strcasecmp(buf, "me")) {
ref = player;
} else {
ref = lookup_player(buf);
}
CLEAR(oper1);
PushObject(ref);
}
/**
* Implementation of MUF MATCH
*
* Consumes a string, and returns the dbref that matches the ANSI-stripped
* string. Recognizes registered objects, local matches, 'me', 'here',
* 'home', and 'nil'. Wizard programs and users can also match dbref
* strings and player lookups.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_match(PRIM_PROTOTYPE)
{
struct inst *oper1 = NULL; /* prevents re-entrancy issues! */
dbref ref;
CHECKOP(1);
oper1 = POP();
if (oper1->type != PROG_STRING) {
abort_interp("Non-string argument.");
}
char buf[BUFFER_LEN], buf2[BUFFER_LEN], tmppp[BUFFER_LEN];
struct match_data md;
(void) strcpyn(buf, sizeof(buf), match_args);
(void) strcpyn(tmppp, sizeof(tmppp), match_cmdname);
strip_ansi(buf2, DoNullInd(oper1->data.string));
init_match(fr->descr, player, buf2, NOTYPE, &md);
if (buf2[0] == REGISTERED_TOKEN) {
match_registered(&md);
} else {
match_all_exits(&md);
match_neighbor(&md);
match_possession(&md);
match_me(&md);
match_here(&md);
match_home(&md);
match_nil(&md);
}
if (Wizard(ProgUID) || (mlev >= 4)) {
match_absolute(&md);
match_player(&md);
}
ref = match_result(&md);
(void) strcpyn(match_args, sizeof(match_args), buf);
(void) strcpyn(match_cmdname, sizeof(match_cmdname), tmppp);
CLEAR(oper1);
PushObject(ref);
}
/**
* Implementation of MUF RMATCH
*
* Consumes a dbref and a string, and returns the dbref that matches one of
* the object's contents or exits. Requires remote-read privileges when
* applicable. Aborts when given an exit or program dbref.
*
* Does not ANSI-strip the string before matching.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_rmatch(PRIM_PROTOTYPE)
{
struct inst *oper1 = NULL; /* prevents re-entrancy issues! */
struct inst *oper2 = NULL; /* prevents re-entrancy issues! */
dbref ref;
CHECKOP(2);
oper1 = POP();
oper2 = POP();
if (oper1->type != PROG_STRING) {
abort_interp("Invalid argument (2)");
}
if (!valid_object(oper2) || Typeof(oper2->data.objref) == TYPE_PROGRAM || Typeof(oper2->data.objref) == TYPE_EXIT) {
abort_interp("Invalid argument (1)");
}
CHECKREMOTE(oper2->data.objref);
char buf[BUFFER_LEN], buf2[BUFFER_LEN], tmppp[BUFFER_LEN];
struct match_data md;
(void) strcpyn(buf, sizeof(buf), match_args);
(void) strcpyn(tmppp, sizeof(tmppp), match_cmdname);
strip_ansi(buf2, DoNullInd(oper1->data.string));
init_match(fr->descr, player, buf2, TYPE_THING, &md);
match_rmatch(oper2->data.objref, &md);
ref = match_result(&md);
(void) strcpyn(match_args, sizeof(match_args), buf);
(void) strcpyn(match_cmdname, sizeof(match_cmdname), tmppp);
CLEAR(oper1);
CLEAR(oper2);
PushObject(ref);
}
/**
* Implementation of MUF COPYOBJ
*
* Consumes a thing dbref, copies the object's name and properties, and
* returns the new dbref. Requires remote-read privilges when applicable.
*
* Programs below MUCKER level 3 are restricted to creating one object per
* frame. That object must pass basic ownership checks and its copy has
* its value reset to 0.
*
* Currently calls copyobj. @see copyobj
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void
prim_copyobj(PRIM_PROTOTYPE)
{
dbref ref;
char error[SMALL_BUFFER_LEN] = "";
CHECKOP(1);
oper1 = POP();
if (!valid_object(oper1)) {
abort_interp("Invalid object.");
}
CHECKREMOTE(oper1->data.objref);
if ((mlev < 3) && (fr->already_created)) {
abort_interp("An object was already created this program run.");
}
ref = oper1->data.objref;
if (Typeof(ref) != TYPE_THING) {
abort_interp("Invalid object type.");
}
if ((mlev < 3) && !permissions(ProgUID, ref)) {
abort_interp("Permission denied.");
}
fr->already_created++;
dbref newobj = clone_thing(ref, player, mlev == 4, error);
if (newobj == NOTHING) {
abort_interp(error);
}
CLEAR(oper1);
PushObject(newobj);
}
/**
* Implementation of MUF SET
*
* Consumes a dbref and a string, and sets or resets the flag on the object
* accoringly. Reognizes flag aliases and Requires remote-read privileges
* when applicable.
*
* Programs below MUCKER level 4 cannot act on:
* - objects that don't pass basic ownership checks
* - ABODE flags on programs
* - BUIDLER flags
* - DARK flags on exits with exit_darking sysparm = no
* - DARK flags on players
* - DARK flags on things with thing_darking sysparm = no
* - GUEST flags
* - INTERACTIVE, MUCKER, or SMUCKER ("nucker") internal flags
* - OVERT flags
* - QUELL flags
* - WIZARD flags
* - XFORCIBLE flags
* - YIELD flags
* - ZOMBIE flags on players
* - ZOMBIE flags on things if effective user is maked ZOMBIE.
*
* No program is able to:
* - reset the VEHICLE flag of a basic vehicle with players in it
* - interact with the OVERT flag on objects that aren't a thing or room
* - interact with the YIELD flag on objects that aren't a thing or room
*
* "truewizard" is merely an alias for the WIZARD flag here.
*
* @param player the player running the MUF program
* @param program the program being run
* @param mlev the effective MUCKER level
* @param pc the program counter pointer
* @param arg the argument stack
* @param top the top-most item of the stack
* @param fr the program frame
*/
void