-
Notifications
You must be signed in to change notification settings - Fork 26
/
match.c
1089 lines (952 loc) · 30.1 KB
/
match.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 match.c
*
* Implementation for the object matching system used by Fuzzball.
*
* This file is part of Fuzzball MUCK. Please see LICENSE.md for details.
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "db.h"
#ifdef DISKBASE
#include "diskprop.h"
#endif
#include "fbstrings.h"
#include "game.h"
#include "interface.h"
#include "match.h"
#include "player.h"
#include "predicates.h"
#include "props.h"
#include "tune.h"
char match_cmdname[BUFFER_LEN]; /* triggering command */
char match_args[BUFFER_LEN]; /* remaining text */
/**
* Initialize a match structure with initial values for doing an object search
*
* @param descr the descriptor of the person doing the search
* @param player the player doing the search
* @param name the name you're looking for
* @param type the object type you are looking for (TYPE_*)
* @param md the match_data structure to initialize
*/
void
init_match(int descr, dbref player, const char *name, int type, struct match_data *md)
{
md->exact_match = md->last_match = NOTHING;
md->match_count = 0;
md->match_who = player;
md->match_from = player;
md->match_descr = descr;
md->match_name = name;
md->check_keys = 0;
md->preferred_type = type;
md->longest_match = 0;
md->match_level = 0;
md->block_equals = 0;
md->partial_exits = (TYPE_EXIT == type);
}
/**
* Initializes a match object, with the check_keys flag set
*
* This means in case of a match where more than one item counts as an
* exact match, we will use if the objects are locked against the player
* as part of the selection process and only pick something that is not
* locked against the player.
*
* This seems pretty edge-case-y, but it is useful in a very narrow
* context -- it is used primarily by movement and exit selection.
*
* @param descr the descriptor of the person doing the search
* @param player the player doing the search
* @param name the name you're looking for
* @param type the object type you are looking for (TYPE_*)
* @param md the match_data structure to initialize
*/
void
init_match_check_keys(int descr, dbref player, const char *name, int type,
struct match_data *md)
{
init_match(descr, player, name, type, md);
md->check_keys = 1;
}
/**
* Initializes a match object, setting match_from to 'what'
*
* This is used in exactly one place for a questionable purpose (in MPI parsing)
* 'match_from' is the location where the match is 'run from' which effects
* the precidence of different objects. This call defaults match_from to
* whatever is in 'what' instead of from 'player' which is the default.
*
* @param descr the descriptor of the person doing the search
* @param player the player doing the search
* @param what the location to search relative to
* @param name the name you're looking for
* @param type the object type you are looking for (TYPE_*)
* @param md the match_data structure to initialize
*/
void
init_match_remote(int descr, dbref player, dbref what, const char *name,
int type, struct match_data *md)
{
init_match(descr, player, name, type, md);
md->match_from = what;
}
/**
* Given two refs, try to choose the more appropriate one based on parameters.
*
* The parameters are defined in the struct match_data. The following
* aspects influence the selection in order:
*
* - If either object is NOTHING, the other object wins.
* - If there is a preferred type (md->preferred_type), if one matches the
* preferred type and the other does not, the one that matches wins.
* - If one of the objects is locked against the player, and md->check_keys
* is set, then the unlocked object wins.
* - If one object has a shorter 'env_distance' than the other, then that
* one wins -- @see env_distance
* - Otherwise, it is coin toss to see which wins.
*
* Whichever one "wins" is the one that is returned.
*
* @private
* @param descr the descriptor of the person matching.
* @param thing1 the first object to consider
* @param thing2 the second object to consider
* @param md the match_data match configuration
* @return the dbref thing1 or thing2 based on above criteria
*/
static dbref
choose_thing(int descr, dbref thing1, dbref thing2, struct match_data *md)
{
int has1;
int has2;
int preferred = md->preferred_type;
/* If one or the other is unset, that makes it easy. */
if (thing1 == NOTHING) {
return thing2;
} else if (thing2 == NOTHING) {
return thing1;
}
/* Check for type preference */
if (preferred != NOTYPE) {
if (Typeof(thing1) == preferred) {
if (Typeof(thing2) != preferred) {
return thing1;
}
} else if (Typeof(thing2) == preferred) {
return thing2;
}
}
/* Do we want to check if the objects are locked against the player? */
if (md->check_keys) {
has1 = could_doit(descr, md->match_who, thing1);
has2 = could_doit(descr, md->match_who, thing2);
if (has1 && !has2) {
return thing1;
} else if (has2 && !has1) {
return thing2;
}
/* else fall through */
}
/* Try environment distance, pick the closer one if applicable. */
int d1 = env_distance(md->match_from, thing1);
int d2 = env_distance(md->match_from, thing2);
if (d1 < d2) return thing1;
else if (d2 < d1) return thing2;
/* All else fails, toss a coin. */
return (RANDOM() % 2 ? thing1 : thing2);
}
/*
* @TODO The way matching happens right now is ridiculous. You set up
* a structure, then you run a series of functions. The order matters
* and could be easily messed up.
*
* There are a lot of different ways we could sort this out.
* I'm thinking we could provide two ways to do it. We could stack
* up the match_data structure like we do now ... and just have what
* forms of searches we want as like a bitvector so there's a single
* call to do the match instead of calling matches in a series.
*
* We can also provide a simple 'standard match' function that covers
* the 99% case and doesn't require setting up match_data.
*/
/**
* Match player based on name.
*
* This also deducts the tp_lookup_cost if applicable.
*
* If the md->match_name does not start with a '*' this does absolutely
* nothing.
*
* Always does an exact match, and if a player is found, it will be
* put in md->exact_match
*
* @param md the match_data struct initialized with match settings
*/
void
match_player(struct match_data *md)
{
dbref match;
const char *p;
if (*(md->match_name) == LOOKUP_TOKEN
&& payfor(OWNER(md->match_from), tp_lookup_cost)) {
p = md->match_name + 1;
if ((match = lookup_player(p)) != NOTHING) {
md->exact_match = match;
}
}
}
/**
* Returns dbref if registered object found for name, else NOTHING
*
* This processes strings that start with $. If the 'name' does not start
* with $, it is ignored. The search is done relative to 'player'.
* Registration props are looked for in REGISTRATION_PROPDIR
*
* Strings, refs, and integer type props are all converted to dbref if
* possible.
*
* @param player the player where our registration search starts
* @param name the name of the registration property to find
* @return dbref that the registration resolves to or NOTHING
*/
dbref
find_registered_obj(dbref player, const char *name)
{
dbref match;
const char *p;
char buf[BUFFER_LEN];
PropPtr ptr;
if (*name != REGISTERED_TOKEN)
return (NOTHING);
p = name + 1;
if (!*p)
return (NOTHING);
snprintf(buf, sizeof(buf), "%s/%s", REGISTRATION_PROPDIR, p);
ptr = envprop(&player, buf, 0);
if (!ptr)
return NOTHING;
#ifdef DISKBASE
propfetch(player, ptr); /* DISKBASE PROPVALS */
#endif
switch (PropType(ptr)) {
case PROP_STRTYP:
p = PropDataStr(ptr);
if (*p == NUMBER_TOKEN)
p++;
if (number(p)) {
match = (dbref) atoi(p);
if (OkObj(match))
return match;
}
break;
case PROP_REFTYP:
match = PropDataRef(ptr);
if (match == HOME || match == NIL || OkObj(match))
return match;
break;
case PROP_INTTYP:
match = (dbref) PropDataVal(ptr);
if (OkObj(match))
return match;
break;
case PROP_LOKTYP:
return (NOTHING);
}
return (NOTHING);
}
/**
* Check md->match_name to see if it is a $registration match
*
* If md->match_name doesn't start with $, this does nothing. If it
* finds something, it stores the result in md->exact_match. Otherwise
* it does nothing. Uses find_registered_obj under the hood.
*
* @see find_registered_obj
*
* @param md the match_data configuration structure
*/
void
match_registered(struct match_data *md)
{
dbref match;
match = find_registered_obj(md->match_from, md->match_name);
if (match != NOTHING)
md->exact_match = match;
}
/**
* Returns a dbref of the match_name is in the format of #12345
*
* Returns NOTHING if the string isn't in the right format, or if ths
* parsed reference doesn't resolve to an actual object.
*
* @private
* @param md the configured match_data struct
* @return either the dbref if the string resolves to a proper #dbref or
* NOTHING
*/
static dbref
absolute_name(struct match_data *md)
{
dbref match;
if (*(md->match_name) == NUMBER_TOKEN && !isspace(*(md->match_name + 1))) {
const char *s = md->match_name + 1;
char *p;
long x = strtol(s, &p, 10);
match = (p == s) ? NOTHING : x;
if (!ObjExists(match)) {
return NOTHING;
}
return match;
}
return NOTHING;
}
/**
* Matches match_names that are dbref strings that start with #
*
* If the dbref fails to parse, or the string doesn't start with #, or
* if the dbref doesn't belong to an object in the DB, this will do nothing.
* On successful match, it populates md->exact_match
*
* @param md the configured match_data struct
*/
void
match_absolute(struct match_data *md)
{
dbref match;
if ((match = absolute_name(md)) != NOTHING) {
md->exact_match = match;
}
}
/**
* Matches the word 'me', case insensitive, and resolves it to match_who
*
* If the match_name is not 'me', then this does nothing. Otherwise, it
* will set md->exact_match
*
* @param md the configured match_data struct
*/
void
match_me(struct match_data *md)
{
if (!strcasecmp(md->match_name, "me")) {
md->exact_match = md->match_who;
}
}
/**
* Matches 'here', case insensitive, and resolves to match_who's location
*
* If the match_name is not 'here', then this does nothing. If match_who's
* location is NOTHING, it will also do nothing. Otherwise, it will set
* md->exact_match
*
* @param md the configured match_data struct
*/
void
match_here(struct match_data *md)
{
if (!strcasecmp(md->match_name, "here")
&& LOCATION(md->match_who) != NOTHING) {
md->exact_match = LOCATION(md->match_who);
}
}
/**
* Matches the word 'home', case insensitive, and resolves it to HOME
*
* If the match_name is not 'home', then this does nothing. Otherwise, it
* will set md->exact_match
*
* @param md the configured match_data struct
*/
void
match_home(struct match_data *md)
{
if (!strcasecmp(md->match_name, "home"))
md->exact_match = HOME;
}
/**
* Matches the word 'nil', case insensitive, and resolves it to NIL
*
* If the match_name is not 'nil', then this does nothing. Otherwise, it
* will set md->exact_match
*
* @param md the configured match_data struct
*/
void
match_nil(struct match_data *md)
{
if (!strcasecmp(md->match_name, "nil"))
md->exact_match = NIL;
}
/**
* Use the contents of 'obj' as a basis for matching what is set up in 'md'
*
* It will only match things in 'obj', even if match_from is a #dbref.
*
* @private
* @param obj the object to scan contents for
* @param md the configured match_data structure.
*/
static void
match_contents(dbref obj, struct match_data *md)
{
dbref absolute, first;
absolute = absolute_name(md);
if (!controls(OWNER(md->match_from), absolute))
absolute = NOTHING;
first = CONTENTS(obj);
DOLIST(first, first) {
if (first == absolute) {
md->exact_match = first;
return;
} else if (!strcasecmp(NAME(first), md->match_name)) {
/*
* If there are multiple exact matches, randomly choose one.
* This works becaus md->exact_match will have been populated
* (potentially) by past iterations of this loop.
*/
md->exact_match = choose_thing(md->match_descr, md->exact_match,
first, md);
} else if (string_match(NAME(first), md->match_name)) {
md->last_match = first; /* Partial match case */
(md->match_count)++;
}
}
}
/**
* Match match_from's contents list
*
* This is an obnoxiously tiny function, but it serves a purpose (for now).
* Uses the static function @match_contents under the hood.
*
* @param md the configured match structure
*/
void
match_possession(struct match_data *md)
{
match_contents(md->match_from, md);
}
/**
* Match match_from's location's content list
*
* If match_from's location is NOTHING, this does nothing.
* Uses the static function @match_contents under the hood.
*
* @param md the configured match structure
*/
void
match_neighbor(struct match_data *md)
{
dbref loc;
if ((loc = LOCATION(md->match_from)) != NOTHING) {
match_contents(loc, md);
}
}
/**
* Match a list of exits, starting with the first entry of EXITS(obj)
*
* It will match exits of players, rooms, or things using the criteria
* loaded in 'md'. It understands how to parse exit aliases and works
* pretty smartly. Only the object 'obj' is searched by this, environmental
* style searches are not done.
*
* @private
* @param obj the object to search for exits on
* @param md the matching criteria
*/
static void
match_exits(dbref obj, struct match_data *md)
{
dbref exit, absolute, first;
const char *exitname, *p;
int exitprog, lev, partial;
first = EXITS(obj);
if (first == NOTHING)
return; /* Easy fail match */
if ((LOCATION(md->match_from)) == NOTHING)
return;
absolute = absolute_name(md); /* parse #nnn entries */
if (!controls(OWNER(md->match_from), absolute))
absolute = NOTHING;
DOLIST(exit, first) {
if (exit == absolute) {
md->exact_match = exit;
continue;
}
exitprog = 0;
if (FLAGS(exit) & HAVEN) {
exitprog = 1;
} else if (DBFETCH(exit)->sp.exit.dest) {
for (int i = 0; i < DBFETCH(exit)->sp.exit.ndest; i++)
if ((DBFETCH(exit)->sp.exit.dest)[i] == NIL
|| Typeof((DBFETCH(exit)->sp.exit.dest)[i]) == TYPE_PROGRAM)
exitprog = 1;
}
if (tp_enable_prefix && exitprog && md->partial_exits &&
(FLAGS(exit) & XFORCIBLE) && FLAGS(OWNER(exit)) & WIZARD) {
partial = 1;
} else {
partial = 0;
}
exitname = NAME(exit);
while (*exitname) { /* for all exit aliases */
int notnull = 0;
for (p = md->match_name; /* check out 1 alias */
*p &&
tolower(*p) == tolower(*exitname) &&
*exitname != EXIT_DELIMITER; p++, exitname++) {
if (!isspace(*p)) {
notnull = 1;
}
}
/* did we get a match on this alias? */
if ((partial && notnull) || ((*p == '\0')
|| (*p == ' ' && exitprog))) {
skip_whitespace(&exitname);
lev = PLevel(exit);
if (tp_compatible_priorities && (lev == 1) &&
(LOCATION(exit) == NOTHING ||
Typeof(LOCATION(exit)) != TYPE_THING ||
controls(OWNER(exit), LOCATION(md->match_from))))
lev = 2;
if (*exitname == '\0' || *exitname == EXIT_DELIMITER) {
/* we got a match on this alias */
if (lev >= md->match_level) {
if (strlen(md->match_name) - strlen(p)
> (size_t) md->longest_match) {
if (lev > md->match_level) {
md->match_level = lev;
md->block_equals = 0;
}
md->exact_match = exit;
md->longest_match =
strlen(md->match_name) - strlen(p);
if ((*p == ' ') || (partial && notnull)) {
strcpyn(match_args, sizeof(match_args),
(partial && notnull) ? p : (p + 1));
{
const char *pp;
int ip;
for (ip = 0, pp = md->match_name;
*pp && (pp != p); pp++)
match_cmdname[ip++] = *pp;
match_cmdname[ip] = '\0';
}
} else {
*match_args = '\0';
strcpyn(match_cmdname, sizeof(match_cmdname),
md->match_name);
}
} else if ((strlen(md->match_name) - strlen(p) ==
(size_t) md->longest_match)
&& !((lev == md->match_level)
&& (md->block_equals))) {
if (lev > md->match_level) {
md->exact_match = exit;
md->match_level = lev;
md->block_equals = 0;
} else {
md->exact_match =
choose_thing(md->match_descr,
md->exact_match, exit,
md);
}
if (md->exact_match == exit) {
if ((*p == ' ') || (partial && notnull)) {
strcpyn(match_args, sizeof(match_args),
(partial && notnull) ? p : (p + 1));
{
const char *pp;
int ip;
for (ip = 0,
pp = md->match_name;
*pp && (pp != p); pp++)
match_cmdname[ip++] = *pp;
match_cmdname[ip] = '\0';
}
} else {
*match_args = '\0';
strcpyn(match_cmdname, sizeof(match_cmdname),
md->match_name);
}
}
}
}
goto next_exit;
}
}
/* we didn't get it, go on to next alias */
while (*exitname && *exitname++ != EXIT_DELIMITER) ;
skip_whitespace(&exitname);
} /* end of while alias string matches */
next_exit:
;
}
}
/**
* Matches actions attached to objects in inventory
*
* Thie object who's inventory is searched is md->match_from
*
* @private
* @param md the configured match object
*/
static void
match_invobj_actions(struct match_data *md)
{
dbref thing;
if (CONTENTS(md->match_from) == NOTHING)
return;
DOLIST(thing, CONTENTS(md->match_from)) {
if (Typeof(thing) == TYPE_THING && EXITS(thing) != NOTHING) {
match_exits(thing, md);
}
}
}
/**
* Matches actions attached to objects in the room.
*
* Thie object who's location is searched is md->match_from
*
* @private
* @param md the configured match object
*/
static void
match_roomobj_actions(struct match_data *md)
{
dbref thing, loc;
if ((loc = LOCATION(md->match_from)) == NOTHING)
return;
if (CONTENTS(loc) == NOTHING)
return;
DOLIST(thing, CONTENTS(loc)) {
if (Typeof(thing) == TYPE_THING && EXITS(thing) != NOTHING) {
match_exits(thing, md);
}
}
}
/**
* Matches actions attached to player or maybe more generally "caller"
*
* The object who's actions are scanned is md->match_from. This only
* does something for TYPE_PLAYER, TYPE_ROOM, and TYPE_THING objects.
* Other types are ignored.
*
* @private
* @param md the configured match object
*/
static void
match_player_actions(struct match_data *md)
{
switch (Typeof(md->match_from)) {
case TYPE_PLAYER:
case TYPE_ROOM:
case TYPE_THING:
match_exits(md->match_from, md);
default:
break;
}
}
/**
* Matches actions attached to the location 'loc'
*
* Only does matching if loc is TYPE_PLAYER, TYPE_ROOM, or TYPE_THING.
* This is a very thin wrapper around match_exits.
*
* @see match_exits
*
* @private
* @param md the configured match object
*/
static void
match_room_exits(dbref loc, struct match_data *md)
{
switch (Typeof(loc)) {
case TYPE_PLAYER:
case TYPE_ROOM:
case TYPE_THING:
match_exits(loc, md);
default:
break;
}
}
/**
* Matches actions on player, objects in room, objects in inventory, and room
*
* This happens in reverse order of priority order. This is the heart-and-soul
* of what powers finding exits on the MUCK.
*
* This will scan the entire environment (up to a hard coded depth of 88
* environment rooms) until it finds a match or stops. This respects
* the YIELD and OVERT flags. If YIELD is set on a room in the
* environment, it is considered "blocking" and other rooms in the
* environment will be ignored unless they are set OVERT.
*
* The matching starts from md->match_from
*
* @param md the configured match_data structure
*/
void
match_all_exits(struct match_data *md)
{
dbref loc;
int limit = 88;
int blocking = 0;
strcpyn(match_args, sizeof(match_args), "\0");
strcpyn(match_cmdname, sizeof(match_cmdname), "\0");
if ((loc = LOCATION(md->match_from)) != NOTHING)
{
if (FLAGS(loc) & YIELD)
blocking = 1;
match_room_exits(loc, md);
}
if (md->exact_match != NOTHING)
md->block_equals = 1;
match_invobj_actions(md);
if (md->exact_match != NOTHING)
md->block_equals = 1;
match_roomobj_actions(md);
if (md->exact_match != NOTHING)
md->block_equals = 1;
match_player_actions(md);
if (loc == NOTHING)
return;
/* if player is in a vehicle, use environment of vehicle's home */
if (Typeof(loc) == TYPE_THING) {
loc = THING_HOME(loc);
if (loc == NOTHING)
return;
if (md->exact_match != NOTHING)
md->block_equals = 1;
match_room_exits(loc, md);
}
/*
* Walk the environment chain to #0, or until depth chain limit
* has been hit, looking for a match.
*/
while ((loc = LOCATION(loc)) != NOTHING) {
/*
* If we're blocking (because of a yield), only match a room if
* and only if it has overt set on it.
*/
if ((blocking && FLAGS(loc) & OVERT) || !blocking) {
if (md->exact_match != NOTHING)
md->block_equals = 1;
match_room_exits(loc, md);
}
if (!limit--)
break;
/* Does this room have env-chain exit blocking enabled? */
if (!blocking && FLAGS(loc) & YIELD) {
blocking = 1;
}
}
}
/**
* Shortcut to run all matches in a logical order.
*
* The order done is:
*
* - match_all_exits
* - match_neighbor
* - match_posession
* - match_me
* - match_here
* - match_registered
* - match_absolute
* - match_player (if owner md->match_from or md->match_who is wizard)
*
* @param md a configured match_data structure.
*/
void
match_everything(struct match_data *md)
{
match_all_exits(md);
match_neighbor(md);
match_possession(md);
match_me(md);
match_here(md);
match_registered(md);
match_absolute(md);
if (Wizard(OWNER(md->match_from)) || Wizard(md->match_who)) {
match_player(md);
}
}
/**
* Extracts the final results from a match_data structure.
*
* md->exact_match wins if set. Otherwise, if there was only one match,
* md->last_match wins. If there were no matches, returns NOTHING, otherwise
* it will return AMBIGUOUS for too many matches.
*
* If you don't care about ambiguous results, @see last_match_result
*
* @param md the configured match_data object to unpack results from.
* @return a matched dbref, NOTHING, or AMBIGUOUS as described above.
*/
dbref
match_result(struct match_data *md)
{
if (md->exact_match != NOTHING) {
return (md->exact_match);
} else {
switch (md->match_count) {
case 0:
return NOTHING;
case 1:
return (md->last_match);
default:
return AMBIGUOUS;
}
}
}
/**
* Extracts the final results from a match_data, ignoring ambiguity.
*
* What this specifically means, is if there is not an exact match,
* then the last match (whatever it was) is picked regardless of if
* multiple potentials matched equally well (which would match as
* AMBIGUOUS if you used match_result).
*
* @see match_result
*
* This may, of course, still return NOTHING if nothing matched.
*
* @param md the configured match_data object to unpack results from
* @return a matched dbref or NOTHING.
*/
dbref
last_match_result(struct match_data * md)
{
if (md->exact_match != NOTHING) {
return (md->exact_match);
} else {
return (md->last_match);
}
}
/**
* Like match_result, except it emits a message on failure to match.
*
* @see match_result
*
* The message is sent to md->match_who with an appropriate message
* for NOTHING or AMBIGUOUS results. This function will either return
* a matched ref or NOTHING.
*
* @param md the configured match_data object to unpack results from
* @return a matched dbref or NOTHING
*/
dbref
noisy_match_result(struct match_data * md)
{
dbref match;
switch (match = match_result(md)) {
case NOTHING:
notify_nolisten(md->match_who,
match_msg_nomatch(md->match_name),
1);
return NOTHING;
case AMBIGUOUS:
notify_nolisten(md->match_who,
match_msg_ambiguous(md->match_name),
1);
return NOTHING;
default:
return match;
}
}
/**
* Match contents and exits of 'arg1'
*
* MUF describes this as checking "all objects and actions associated"
* with object 'arg1'. This is used in a very limited context; mostly
* around fetching things from container objects it looks like.
*
* @param arg1 the object we're basing our search around
* @param md the configured match_data object with search string
*/
void