#include "copyright.h"
#include "config.h"
#include "db.h"
#include "mudconf.h"
#include "externs.h"
#include "match.h"
#include "attrs.h"
#include "powers.h"
Include dependency graph for match.c:
Go to the source code of this file.
Defines | |
#define | CON_LOCAL 0x01 |
#define | CON_TYPE 0x02 |
#define | CON_LOCK 0x04 |
#define | CON_COMPLETE 0x08 |
#define | CON_TOKEN 0x10 |
#define | CON_DBREF 0x20 |
Functions | |
static void | promote_match (dbref what, int confidence) |
static char * | munge_space_for_match (char *name) |
void | match_player (void) |
static dbref | absolute_name (int need_pound) |
void | match_absolute (void) |
void | match_numeric (void) |
void | match_me (void) |
void | match_home (void) |
void | match_here (void) |
static void | match_list (dbref first, int local) |
void | match_possession (void) |
void | match_neighbor (void) |
static int | match_exit_internal (dbref loc, dbref baseloc, int local) |
void | match_exit (void) |
void | match_exit_with_parents (void) |
void | match_carried_exit (void) |
void | match_carried_exit_with_parents (void) |
void | match_master_exit (void) |
void | match_zone_exit (void) |
void | match_everything (int key) |
dbref | match_result (void) |
dbref | last_match_result (void) |
dbref | match_status (dbref player, dbref match) |
dbref | noisy_match_result (void) |
dbref | dispatched_match_result (dbref player) |
int | matched_locally (void) |
void | save_match_state (MSTATE *mstate) |
void | restore_match_state (MSTATE *mstate) |
void | init_match (dbref player, char *name, int type) |
void | init_match_check_keys (dbref player, char *name, int type) |
Variables | |
static MSTATE | md |
#define CON_COMPLETE 0x08 |
Definition at line 25 of file match.c.
Referenced by match_exit_internal(), match_here(), and match_list().
#define CON_DBREF 0x20 |
Definition at line 31 of file match.c.
Referenced by match_absolute(), match_carried_exit(), match_carried_exit_with_parents(), match_exit(), match_exit_internal(), match_exit_with_parents(), match_here(), match_home(), match_list(), match_master_exit(), match_me(), match_neighbor(), match_numeric(), match_player(), match_possession(), and match_zone_exit().
#define CON_LOCAL 0x01 |
Definition at line 16 of file match.c.
Referenced by match_carried_exit(), match_carried_exit_with_parents(), match_exit(), match_exit_with_parents(), match_here(), match_me(), match_neighbor(), match_possession(), and matched_locally().
#define CON_LOCK 0x04 |
#define CON_TOKEN 0x10 |
Definition at line 28 of file match.c.
Referenced by match_everything(), match_here(), match_home(), match_me(), and match_player().
#define CON_TYPE 0x02 |
static dbref absolute_name | ( | int | need_pound | ) | [static] |
Definition at line 150 of file match.c.
References Good_obj, md, NOTHING, NUMBER_TOKEN, parse_dbref(), and match_state::string.
Referenced by init_match(), and match_numeric().
00151 { 00152 dbref match; 00153 char *mname; 00154 00155 mname = md.string; 00156 if(need_pound) { 00157 if(*md.string != NUMBER_TOKEN) { 00158 return NOTHING; 00159 } else { 00160 mname++; 00161 } 00162 } 00163 match = parse_dbref(mname); 00164 if(Good_obj(match)) { 00165 return match; 00166 } 00167 return NOTHING; 00168 }
Definition at line 456 of file match.c.
References match_result(), and match_status().
00458 { 00459 return match_status(player, match_result()); 00460 }
void init_match | ( | dbref | player, | |
char * | name, | |||
int | type | |||
) |
Definition at line 495 of file match.c.
References match_state::absolute_form, absolute_name(), match_state::check_keys, match_state::confidence, match_state::count, match_state::match, md, munge_space_for_match(), NOTHING, match_state::player, match_state::pref_type, and match_state::string.
00496 { 00497 md.confidence = -1; 00498 md.count = md.check_keys = 0; 00499 md.pref_type = type; 00500 md.match = NOTHING; 00501 md.player = player; 00502 md.string = munge_space_for_match((char *) name); 00503 md.absolute_form = absolute_name(1); 00504 }
void init_match_check_keys | ( | dbref | player, | |
char * | name, | |||
int | type | |||
) |
Definition at line 506 of file match.c.
References match_state::check_keys, init_match(), and md.
Referenced by do_get(), do_move(), fun_locate(), and process_command().
00507 { 00508 init_match(player, name, type); 00509 md.check_keys = 1; 00510 }
dbref last_match_result | ( | void | ) |
Definition at line 426 of file match.c.
References match_state::match, and md.
Referenced by do_destroy(), fun_locate(), and process_command().
void match_absolute | ( | void | ) |
Definition at line 170 of file match.c.
References match_state::absolute_form, CON_DBREF, match_state::confidence, Good_obj, md, and promote_match().
00171 { 00172 if(md.confidence >= CON_DBREF) 00173 return; 00174 if(Good_obj(md.absolute_form)) 00175 promote_match(md.absolute_form, CON_DBREF); 00176 }
void match_carried_exit | ( | void | ) |
Definition at line 338 of file match.c.
References CON_DBREF, CON_LOCAL, match_state::confidence, Good_obj, Has_exits, match_exit_internal(), md, and match_state::player.
Referenced by do_drop(), and match_everything().
00339 { 00340 if(md.confidence >= CON_DBREF) 00341 return; 00342 if(Good_obj(md.player) && Has_exits(md.player)) 00343 (void) match_exit_internal(md.player, md.player, CON_LOCAL); 00344 }
void match_carried_exit_with_parents | ( | void | ) |
Definition at line 346 of file match.c.
References CON_DBREF, CON_LOCAL, match_state::confidence, Good_obj, Has_exits, isRoom, ITER_PARENTS, match_exit_internal(), md, and match_state::player.
Referenced by fun_locate(), and match_everything().
00347 { 00348 dbref parent; 00349 int lev; 00350 00351 if(md.confidence >= CON_DBREF) 00352 return; 00353 if(Good_obj(md.player) && (Has_exits(md.player) || isRoom(md.player))) { 00354 ITER_PARENTS(md.player, parent, lev) { 00355 if(match_exit_internal(parent, md.player, CON_LOCAL)) 00356 break; 00357 } 00358 } 00359 }
void match_everything | ( | int | key | ) |
Definition at line 378 of file match.c.
References CON_TOKEN, match_state::confidence, MAT_EXIT_PARENTS, MAT_HOME, MAT_NO_EXITS, MAT_NUMERIC, match_absolute(), match_carried_exit(), match_carried_exit_with_parents(), match_exit(), match_exit_with_parents(), match_here(), match_home(), match_me(), match_neighbor(), match_numeric(), match_player(), match_possession(), and md.
Referenced by do_chanobj(), do_chzone(), do_clone(), do_entrances(), do_examine(), do_fixdb(), do_link(), do_lock(), do_notify(), do_parent(), do_pemit(), do_pemit_list(), do_setattr(), do_teleport(), do_unlink(), do_verb(), do_wait(), fun_locate(), fun_setlock(), match_affected(), match_controlled(), match_controlled_quiet(), match_examinable(), match_thing(), parse_attrib_wild(), parse_boolexp_L(), parse_linkable_room(), and parse_thing_slash().
00379 { 00380 /* 00381 * Try matching me, then here, then absolute, then player FIRST, since 00382 * this will hit most cases. STOP if we get something, since those are 00383 * exact matches. 00384 */ 00385 00386 match_me(); 00387 match_here(); 00388 match_absolute(); 00389 if(key & MAT_NUMERIC) 00390 match_numeric(); 00391 if(key & MAT_HOME) 00392 match_home(); 00393 match_player(); 00394 if(md.confidence >= CON_TOKEN) 00395 return; 00396 00397 if(!(key & MAT_NO_EXITS)) { 00398 if(key & MAT_EXIT_PARENTS) { 00399 match_carried_exit_with_parents(); 00400 match_exit_with_parents(); 00401 } else { 00402 match_carried_exit(); 00403 match_exit(); 00404 } 00405 } 00406 match_neighbor(); 00407 match_possession(); 00408 }
void match_exit | ( | void | ) |
Definition at line 311 of file match.c.
References CON_DBREF, CON_LOCAL, match_state::confidence, Good_obj, Has_location, loc, Location, match_exit_internal(), md, and match_state::player.
Referenced by do_chown(), do_destroy(), do_get(), do_move(), and match_everything().
00312 { 00313 dbref loc; 00314 00315 if(md.confidence >= CON_DBREF) 00316 return; 00317 loc = Location(md.player); 00318 if(Good_obj(md.player) && Has_location(md.player)) 00319 (void) match_exit_internal(loc, loc, CON_LOCAL); 00320 }
Definition at line 280 of file match.c.
References match_state::absolute_form, CON_COMPLETE, CON_DBREF, Dark, DOLIST, Examinable, exit_visible(), Exits, Good_obj, Has_exits, matches_exit_from_list(), md, match_state::player, promote_match(), PureName(), match_state::string, VE_BASE_DARK, VE_LOC_DARK, and VE_LOC_XAM.
Referenced by match_carried_exit(), match_carried_exit_with_parents(), match_exit(), match_exit_with_parents(), match_master_exit(), and match_zone_exit().
00281 { 00282 dbref exit; 00283 int result, key; 00284 00285 if(!Good_obj(loc) || !Has_exits(loc)) 00286 return 1; 00287 00288 result = 0; 00289 DOLIST(exit, Exits(loc)) { 00290 if(exit == md.absolute_form) { 00291 key = 0; 00292 if(Examinable(md.player, loc)) 00293 key |= VE_LOC_XAM; 00294 if(Dark(loc)) 00295 key |= VE_LOC_DARK; 00296 if(Dark(baseloc)) 00297 key |= VE_BASE_DARK; 00298 if(exit_visible(exit, md.player, key)) { 00299 promote_match(exit, CON_DBREF | local); 00300 return 1; 00301 } 00302 } 00303 if(matches_exit_from_list(md.string, (char *) PureName(exit))) { 00304 promote_match(exit, CON_COMPLETE | local); 00305 result = 1; 00306 } 00307 } 00308 return result; 00309 }
void match_exit_with_parents | ( | void | ) |
Definition at line 322 of file match.c.
References CON_DBREF, CON_LOCAL, match_state::confidence, Good_obj, Has_location, ITER_PARENTS, loc, Location, match_exit_internal(), md, and match_state::player.
Referenced by do_look(), fun_locate(), match_everything(), and process_command().
00323 { 00324 dbref loc, parent; 00325 int lev; 00326 00327 if(md.confidence >= CON_DBREF) 00328 return; 00329 if(Good_obj(md.player) && Has_location(md.player)) { 00330 loc = Location(md.player); 00331 ITER_PARENTS(loc, parent, lev) { 00332 if(match_exit_internal(parent, loc, CON_LOCAL)) 00333 break; 00334 } 00335 } 00336 }
void match_here | ( | void | ) |
Definition at line 211 of file match.c.
References match_state::absolute_form, CON_COMPLETE, CON_DBREF, CON_LOCAL, CON_TOKEN, match_state::confidence, Good_obj, Has_location, loc, Location, md, match_state::player, promote_match(), PureName(), match_state::string, and string_compare().
Referenced by do_chown(), do_kill(), do_look(), do_use(), fun_locate(), and match_everything().
00212 { 00213 dbref loc; 00214 00215 if(md.confidence >= CON_DBREF) 00216 return; 00217 if(Good_obj(md.player) && Has_location(md.player)) { 00218 loc = Location(md.player); 00219 if(Good_obj(loc)) { 00220 if(loc == md.absolute_form) { 00221 promote_match(loc, CON_DBREF | CON_LOCAL); 00222 } else if(!string_compare(md.string, "here")) { 00223 promote_match(loc, CON_TOKEN | CON_LOCAL); 00224 } else if(!string_compare(md.string, (char *) PureName(loc))) { 00225 promote_match(loc, CON_COMPLETE | CON_LOCAL); 00226 } 00227 } 00228 } 00229 }
void match_home | ( | void | ) |
Definition at line 202 of file match.c.
References CON_DBREF, CON_TOKEN, match_state::confidence, HOME, md, promote_match(), match_state::string, and string_compare().
Referenced by match_everything().
00203 { 00204 if(md.confidence >= CON_DBREF) 00205 return; 00206 if(!string_compare(md.string, "home")) 00207 promote_match(HOME, CON_TOKEN); 00208 return; 00209 }
static void match_list | ( | dbref | first, | |
int | local | |||
) | [static] |
Definition at line 231 of file match.c.
References match_state::absolute_form, CON_COMPLETE, CON_DBREF, match_state::confidence, DOLIST, md, promote_match(), PureName(), match_state::string, string_compare(), and string_match().
Referenced by match_neighbor(), and match_possession().
00232 { 00233 char *namebuf; 00234 00235 if(md.confidence >= CON_DBREF) 00236 return; 00237 DOLIST(first, first) { 00238 if(first == md.absolute_form) { 00239 promote_match(first, CON_DBREF | local); 00240 return; 00241 } 00242 /* 00243 * Warning: make sure there are no other calls to Name() in 00244 * promote_match or its called subroutines; they 00245 * would overwrite Name()'s static buffer which is 00246 * needed by string_match(). 00247 */ 00248 namebuf = (char *) PureName(first); 00249 00250 if(!string_compare(namebuf, md.string)) { 00251 promote_match(first, CON_COMPLETE | local); 00252 } else if(string_match(namebuf, md.string)) { 00253 promote_match(first, local); 00254 } 00255 } 00256 }
void match_master_exit | ( | void | ) |
Definition at line 361 of file match.c.
References CON_DBREF, match_state::confidence, Good_obj, Has_exits, confdata::master_room, match_exit_internal(), md, mudconf, and match_state::player.
Referenced by do_look(), and process_command().
00362 { 00363 if(md.confidence >= CON_DBREF) 00364 return; 00365 if(Good_obj(md.player) && Has_exits(md.player)) 00366 (void) match_exit_internal(mudconf.master_room, 00367 mudconf.master_room, 0); 00368 }
void match_me | ( | void | ) |
Definition at line 189 of file match.c.
References match_state::absolute_form, CON_DBREF, CON_LOCAL, CON_TOKEN, match_state::confidence, Good_obj, md, match_state::player, promote_match(), match_state::string, and string_compare().
Referenced by do_chown(), do_give(), do_kill(), do_look(), do_use(), fun_locate(), give_thing(), and match_everything().
00190 { 00191 if(md.confidence >= CON_DBREF) 00192 return; 00193 if(Good_obj(md.absolute_form) && (md.absolute_form == md.player)) { 00194 promote_match(md.player, CON_DBREF | CON_LOCAL); 00195 return; 00196 } 00197 if(!string_compare(md.string, "me")) 00198 promote_match(md.player, CON_TOKEN | CON_LOCAL); 00199 return; 00200 }
void match_neighbor | ( | void | ) |
Definition at line 266 of file match.c.
References CON_DBREF, CON_LOCAL, match_state::confidence, Contents, Good_obj, Has_location, loc, Location, match_list(), md, and match_state::player.
Referenced by do_boot(), do_chownall(), do_enter(), do_get(), do_give(), do_kill(), do_look(), do_toad(), do_use(), fun_locate(), match_everything(), and match_possessed().
00267 { 00268 dbref loc; 00269 00270 if(md.confidence >= CON_DBREF) 00271 return; 00272 if(Good_obj(md.player) && Has_location(md.player)) { 00273 loc = Location(md.player); 00274 if(Good_obj(loc)) { 00275 match_list(Contents(loc), CON_LOCAL); 00276 } 00277 } 00278 }
void match_numeric | ( | void | ) |
Definition at line 178 of file match.c.
References absolute_name(), CON_DBREF, match_state::confidence, Good_obj, md, and promote_match().
Referenced by match_everything().
00179 { 00180 dbref match; 00181 00182 if(md.confidence >= CON_DBREF) 00183 return; 00184 match = absolute_name(0); 00185 if(Good_obj(match)) 00186 promote_match(match, CON_DBREF); 00187 }
void match_player | ( | void | ) |
Definition at line 125 of file match.c.
References match_state::absolute_form, CON_DBREF, CON_TOKEN, match_state::confidence, Good_obj, isPlayer, lookup_player(), LOOKUP_TOKEN, md, NOTHING, promote_match(), and match_state::string.
Referenced by do_boot(), do_chown(), do_chownall(), do_give(), do_kill(), do_look(), do_toad(), do_use(), fun_locate(), and match_everything().
00126 { 00127 dbref match; 00128 char *p; 00129 00130 if(md.confidence >= CON_DBREF) { 00131 return; 00132 } 00133 if(Good_obj(md.absolute_form) && isPlayer(md.absolute_form)) { 00134 promote_match(md.absolute_form, CON_DBREF); 00135 return; 00136 } 00137 if(*md.string == LOOKUP_TOKEN) { 00138 for(p = md.string + 1; isspace(*p); p++); 00139 match = lookup_player(NOTHING, p, 1); 00140 if(Good_obj(match)) { 00141 promote_match(match, CON_TOKEN); 00142 } 00143 } 00144 }
void match_possession | ( | void | ) |
Definition at line 258 of file match.c.
References CON_DBREF, CON_LOCAL, match_state::confidence, Contents, Good_obj, Has_contents, match_list(), md, and match_state::player.
Referenced by do_chown(), do_destroy(), do_drop(), do_give(), do_look(), do_use(), fun_locate(), give_thing(), match_everything(), and match_possessed().
00259 { 00260 if(md.confidence >= CON_DBREF) 00261 return; 00262 if(Good_obj(md.player) && Has_contents(md.player)) 00263 match_list(Contents(md.player), CON_LOCAL); 00264 }
dbref match_result | ( | void | ) |
Definition at line 431 of file match.c.
References AMBIGUOUS, AMBIGUOUS_MESSAGE, Builder, Dark, Good_obj, match_status(), NOMATCH_MESSAGE, NOPERM, NOPERM_MESSAGE, NOTHING, notify, Owner, and WizRoy.
Referenced by dispatched_match_result(), do_destroy(), do_get(), do_look(), fun_locate(), match_status(), and noisy_match_result().
00433 { 00434 switch (match) { 00435 case NOTHING: 00436 notify(player, NOMATCH_MESSAGE); 00437 return NOTHING; 00438 case AMBIGUOUS: 00439 notify(player, AMBIGUOUS_MESSAGE); 00440 return NOTHING; 00441 case NOPERM: 00442 notify(player, NOPERM_MESSAGE); 00443 return NOTHING; 00444 } 00445 if(Good_obj(match) && Dark(match) && Good_obj(player) && 00446 !WizRoy(Owner(player)) && !Builder(Owner(player))) 00447 return match_status(player, NOTHING); 00448 return match; 00449 }
void match_zone_exit | ( | void | ) |
Definition at line 370 of file match.c.
References CON_DBREF, match_state::confidence, Good_obj, Has_exits, match_exit_internal(), md, match_state::player, and Zone.
Referenced by process_command().
00371 { 00372 if(md.confidence >= CON_DBREF) 00373 return; 00374 if(Good_obj(md.player) && Has_exits(md.player)) 00375 (void) match_exit_internal(Zone(md.player), Zone(md.player), 0); 00376 }
int matched_locally | ( | void | ) |
Definition at line 462 of file match.c.
References CON_LOCAL, match_state::confidence, and md.
00463 { 00464 return (md.confidence & CON_LOCAL); 00465 }
static char* munge_space_for_match | ( | char * | name | ) | [static] |
Definition at line 99 of file match.c.
References LBUF_SIZE.
Referenced by init_match().
00100 { 00101 static char buffer[LBUF_SIZE]; 00102 char *p, *q; 00103 00104 p = name; 00105 q = buffer; 00106 while (isspace(*p)) 00107 p++; /* 00108 * remove inital spaces 00109 */ 00110 while (*p) { 00111 while (*p && !isspace(*p)) 00112 *q++ = *p++; 00113 while (*p && isspace(*++p)); 00114 if(*p) 00115 *q++ = ' '; 00116 } 00117 *q = '\0'; /* 00118 * remove terminal spaces and terminate * * * 00119 * 00120 * * string 00121 */ 00122 return (buffer); 00123 }
dbref noisy_match_result | ( | void | ) |
Definition at line 451 of file match.c.
References match_result(), match_status(), md, and match_state::player.
Referenced by do_boot(), do_chownall(), do_chzone(), do_clone(), do_enter(), do_entrances(), do_examine(), do_fixdb(), do_link(), do_notify(), do_parent(), do_setattr(), do_teleport(), do_toad(), do_use(), do_verb(), do_wait(), match_affected(), match_controlled(), match_examinable(), and match_thing().
00452 { 00453 return match_status(md.player, match_result()); 00454 }
static void promote_match | ( | dbref | what, | |
int | confidence | |||
) | [static] |
Definition at line 37 of file match.c.
References A_LOCK, match_state::check_keys, CON_LOCK, CON_TYPE, match_state::confidence, could_doit(), match_state::count, Good_obj, match_state::match, md, NOTYPE, match_state::player, match_state::pref_type, random, restore_match_state(), save_match_state(), and Typeof.
Referenced by match_absolute(), match_exit_internal(), match_here(), match_home(), match_list(), match_me(), match_numeric(), and match_player().
00038 { 00039 /* 00040 * Check for type and locks, if requested 00041 */ 00042 00043 if(md.pref_type != NOTYPE) { 00044 if(Good_obj(what) && (Typeof(what) == md.pref_type)) 00045 confidence |= CON_TYPE; 00046 } 00047 if(md.check_keys) { 00048 MSTATE save_md; 00049 00050 save_match_state(&save_md); 00051 if(Good_obj(what) && could_doit(md.player, what, A_LOCK)); 00052 confidence |= CON_LOCK; 00053 restore_match_state(&save_md); 00054 } 00055 /* 00056 * If nothing matched, take it 00057 */ 00058 00059 if(md.count == 0) { 00060 md.match = what; 00061 md.confidence = confidence; 00062 md.count = 1; 00063 return; 00064 } 00065 /* 00066 * If confidence is lower, ignore 00067 */ 00068 00069 if(confidence < md.confidence) { 00070 return; 00071 } 00072 /* 00073 * If confidence is higher, replace 00074 */ 00075 00076 if(confidence > md.confidence) { 00077 md.match = what; 00078 md.confidence = confidence; 00079 md.count = 1; 00080 return; 00081 } 00082 /* 00083 * Equal confidence, pick randomly 00084 */ 00085 00086 if(random() % 2) { 00087 md.match = what; 00088 } 00089 md.count++; 00090 return; 00091 }
void restore_match_state | ( | MSTATE * | mstate | ) |
Definition at line 481 of file match.c.
References match_state::absolute_form, match_state::check_keys, match_state::confidence, match_state::count, free_lbuf, match_state::match, md, match_state::player, match_state::pref_type, match_state::string, and StringCopy.
Referenced by parse_boolexp_L(), and promote_match().
00483 { 00484 md.confidence = mstate->confidence; 00485 md.count = mstate->count; 00486 md.pref_type = mstate->pref_type; 00487 md.check_keys = mstate->check_keys; 00488 md.absolute_form = mstate->absolute_form; 00489 md.match = mstate->match; 00490 md.player = mstate->player; 00491 StringCopy(md.string, mstate->string); 00492 free_lbuf(mstate->string); 00493 }
void save_match_state | ( | MSTATE * | mstate | ) |
Definition at line 467 of file match.c.
References match_state::absolute_form, alloc_lbuf, match_state::check_keys, match_state::confidence, match_state::count, match_state::match, md, match_state::player, match_state::pref_type, match_state::string, and StringCopy.
Referenced by parse_boolexp_L(), and promote_match().
00469 { 00470 mstate->confidence = md.confidence; 00471 mstate->count = md.count; 00472 mstate->pref_type = md.pref_type; 00473 mstate->check_keys = md.check_keys; 00474 mstate->absolute_form = md.absolute_form; 00475 mstate->match = md.match; 00476 mstate->player = md.player; 00477 mstate->string = alloc_lbuf("save_match_state"); 00478 StringCopy(mstate->string, md.string); 00479 }
Definition at line 35 of file match.c.
Referenced by absolute_name(), init_match(), init_match_check_keys(), last_match_result(), match_absolute(), match_carried_exit(), match_carried_exit_with_parents(), match_everything(), match_exit(), match_exit_internal(), match_exit_with_parents(), match_here(), match_home(), match_list(), match_master_exit(), match_me(), match_neighbor(), match_numeric(), match_player(), match_possession(), match_result(), match_zone_exit(), matched_locally(), noisy_match_result(), promote_match(), restore_match_state(), and save_match_state().