src/misc.h File Reference

#include "copyright.h"
#include "db.h"
#include "flags.h"
#include "powers.h"

Include dependency graph for misc.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  search_type
struct  stats_type

Typedefs

typedef search_type SEARCH
typedef stats_type STATS

Functions

int search_setup (dbref, char *, SEARCH *)
void search_perform (dbref, dbref, SEARCH *)
int get_stats (dbref, dbref, STATS *)


Typedef Documentation

typedef struct search_type SEARCH

Definition at line 17 of file misc.h.

typedef struct stats_type STATS

Definition at line 35 of file misc.h.


Function Documentation

int get_stats ( dbref  player,
dbref  who,
STATS info 
)

Get counts of items in the db.

Definition at line 111 of file walkdb.c.

References Controls, DO_WHOLE_DB, Going, Good_obj, confdata::many_coins, mudconf, NOTHING, notify, notify_printf(), Owner, payfor(), stats_type::s_exits, stats_type::s_garbage, stats_type::s_players, stats_type::s_rooms, stats_type::s_things, stats_type::s_total, confdata::searchcost, Stat_Any, TYPE_EXIT, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, and Typeof.

Referenced by do_stats(), and fun_stats().

00112 {
00113         dbref i;
00114 
00115         info->s_total = 0;
00116         info->s_rooms = 0;
00117         info->s_exits = 0;
00118         info->s_things = 0;
00119         info->s_players = 0;
00120         info->s_garbage = 0;
00121 
00122         /*
00123          * Do we have permission? 
00124          */
00125 
00126         if(Good_obj(who) && !Controls(player, who) && !Stat_Any(player)) {
00127                 notify(player, "Permission denied.");
00128                 return 0;
00129         }
00130         /*
00131          * Can we afford it? 
00132          */
00133 
00134         if(!payfor(player, mudconf.searchcost)) {
00135                 notify_printf(player, "You don't have enough %s.",
00136                                           mudconf.many_coins);
00137                 return 0;
00138         }
00139         DO_WHOLE_DB(i) {
00140                 if((who == NOTHING) || (who == Owner(i))) {
00141                         info->s_total++;
00142                         if(Going(i) && (Typeof(i) != TYPE_ROOM)) {
00143                                 info->s_garbage++;
00144                                 continue;
00145                         }
00146                         switch (Typeof(i)) {
00147                         case TYPE_ROOM:
00148                                 info->s_rooms++;
00149                                 break;
00150                         case TYPE_EXIT:
00151                                 info->s_exits++;
00152                                 break;
00153                         case TYPE_THING:
00154                                 info->s_things++;
00155                                 break;
00156                         case TYPE_PLAYER:
00157                                 info->s_players++;
00158                                 break;
00159                         default:
00160                                 info->s_garbage++;
00161                         }
00162                 }
00163         }
00164         return 1;
00165 }

void search_perform ( dbref  ,
dbref  ,
SEARCH  
)

Definition at line 575 of file walkdb.c.

References alloc_lbuf, alloc_sbuf, ANY_OWNER, BOUND_VAR, EV_EVAL, EV_FCHECK, EV_NOTRACE, exec(), Flags, Flags2, Flags3, free_lbuf, free_sbuf, statedata::func_invk_ctr, search_type::low_bound, mudstate, NOTHING, NOTYPE, olist_add(), Owner, Parent, Powers, Powers2, PureName(), replace_string(), search_type::s_fset, search_type::s_parent, search_type::s_pset, search_type::s_rst_eval, search_type::s_rst_name, search_type::s_rst_owner, search_type::s_rst_type, search_type::s_zone, string_prefix(), TYPE_GARBAGE, Typeof, flagset::word1, powerset::word1, flagset::word2, powerset::word2, flagset::word3, xlate(), and Zone.

Referenced by do_search(), and fun_search().

00576 {
00577         FLAG thing1flags, thing2flags, thing3flags;
00578         POWER thing1powers, thing2powers;
00579         dbref thing;
00580         char *buff, *buff2, *result, *bp, *str;
00581         int save_invk_ctr;
00582 
00583         buff = alloc_sbuf("search_perform.num");
00584         save_invk_ctr = mudstate.func_invk_ctr;
00585 
00586         for(thing = parm->low_bound; thing <= parm->high_bound; thing++) {
00587                 mudstate.func_invk_ctr = save_invk_ctr;
00588 
00589                 /*
00590                  * Check for matching type 
00591                  */
00592 
00593                 if((parm->s_rst_type != NOTYPE) &&
00594                    (parm->s_rst_type != Typeof(thing)))
00595                         continue;
00596 
00597                 /*
00598                  * Check for matching owner 
00599                  */
00600 
00601                 if((parm->s_rst_owner != ANY_OWNER) &&
00602                    (parm->s_rst_owner != Owner(thing)))
00603                         continue;
00604 
00605                 /*
00606                  * Check for matching parent 
00607                  */
00608 
00609                 if((parm->s_parent != NOTHING) && (parm->s_parent != Parent(thing)))
00610                         continue;
00611 
00612                 /*
00613                  * Check for matching zone 
00614                  */
00615 
00616                 if((parm->s_zone != NOTHING) && (parm->s_zone != Zone(thing)))
00617                         continue;
00618 
00619                 /*
00620                  * Check for matching flags 
00621                  */
00622 
00623                 thing3flags = Flags3(thing);
00624                 thing2flags = Flags2(thing);
00625                 thing1flags = Flags(thing);
00626                 if((thing1flags & parm->s_fset.word1) != parm->s_fset.word1)
00627                         continue;
00628                 if((thing2flags & parm->s_fset.word2) != parm->s_fset.word2)
00629                         continue;
00630                 if((thing3flags & parm->s_fset.word3) != parm->s_fset.word3)
00631                         continue;
00632 
00633                 /*
00634                  * Check for matching power 
00635                  */
00636 
00637                 thing1powers = Powers(thing);
00638                 thing2powers = Powers2(thing);
00639                 if((thing1powers & parm->s_pset.word1) != parm->s_pset.word1)
00640                         continue;
00641                 if((thing2powers & parm->s_pset.word2) != parm->s_pset.word2)
00642                         continue;
00643 
00644                 /*
00645                  * Check for matching name 
00646                  */
00647 
00648                 if(parm->s_rst_name != NULL) {
00649                         if(!string_prefix((char *) PureName(thing), parm->s_rst_name))
00650                                 continue;
00651                 }
00652                 /*
00653                  * Check for successful evaluation 
00654                  */
00655 
00656                 if(parm->s_rst_eval != NULL) {
00657                         if(Typeof(thing) == TYPE_GARBAGE)
00658                                 continue;
00659                         sprintf(buff, "#%d", thing);
00660                         buff2 = replace_string(BOUND_VAR, buff, parm->s_rst_eval);
00661                         result = bp = alloc_lbuf("search_perform");
00662                         str = buff2;
00663                         exec(result, &bp, 0, player, cause,
00664                                  EV_FCHECK | EV_EVAL | EV_NOTRACE, &str, (char **) NULL, 0);
00665                         *bp = '\0';
00666                         free_lbuf(buff2);
00667                         if(!*result || !xlate(result)) {
00668                                 free_lbuf(result);
00669                                 continue;
00670                         }
00671                         free_lbuf(result);
00672                 }
00673                 /*
00674                  * It passed everything.  Amazing. 
00675                  */
00676 
00677                 olist_add(thing);
00678         }
00679         free_sbuf(buff);
00680         mudstate.func_invk_ctr = save_invk_ctr;
00681 }

int search_setup ( dbref  player,
char *  searchfor,
SEARCH parm 
)

Walk the db reporting various things (or setting/clearing mark bits)

Definition at line 327 of file walkdb.c.

References ANY_OWNER, convert_flags(), decode_power(), EV_STRIP_TS, Good_obj, search_type::high_bound, lookup_player(), search_type::low_bound, confdata::many_coins, match_controlled(), mudconf, NOTHING, notify, notify_printf(), NOTYPE, Owner, parse_range(), parse_to(), payfor(), search_type::s_fset, search_type::s_owner, search_type::s_parent, search_type::s_pset, search_type::s_rst_eval, search_type::s_rst_name, search_type::s_rst_owner, search_type::s_rst_type, search_type::s_wizard, search_type::s_zone, Search, confdata::searchcost, string_prefix(), TYPE_EXIT, TYPE_GARBAGE, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, Typeof, flagset::word1, powerset::word1, flagset::word2, powerset::word2, and flagset::word3.

Referenced by do_search(), and fun_search().

00328 {
00329         char *pname, *searchtype, *t;
00330         int err;
00331 
00332         /*
00333          * Crack arg into <pname> <type>=<targ>,<low>,<high> 
00334          */
00335 
00336         pname = parse_to(&searchfor, '=', EV_STRIP_TS);
00337         if(!pname || !*pname) {
00338                 pname = (char *) "me";
00339         } else
00340                 for(t = pname; *t; t++) {
00341                         if(isupper(*t))
00342                                 *t = tolower(*t);
00343                 }
00344 
00345         if(searchfor && *searchfor) {
00346                 searchtype = (char *) rindex(pname, ' ');
00347                 if(searchtype) {
00348                         *searchtype++ = '\0';
00349                 } else {
00350                         searchtype = pname;
00351                         pname = (char *) "";
00352                 }
00353         } else {
00354                 searchtype = (char *) "";
00355         }
00356 
00357         /*
00358          * If the player name is quoted, strip the quotes 
00359          */
00360 
00361         if(*pname == '\"') {
00362                 err = strlen(pname) - 1;
00363                 if(pname[err] == '"') {
00364                         pname[err] = '\0';
00365                         pname++;
00366                 }
00367         }
00368         /*
00369          * Strip any range arguments 
00370          */
00371 
00372         parse_range(&searchfor, &parm->low_bound, &parm->high_bound);
00373 
00374         /*
00375          * set limits on who we search 
00376          */
00377 
00378         parm->s_owner = Owner(player);
00379         parm->s_wizard = Search(player);
00380         parm->s_rst_owner = NOTHING;
00381         if(!*pname) {
00382                 parm->s_rst_owner = parm->s_wizard ? ANY_OWNER : player;
00383         } else if(pname[0] == '#') {
00384                 parm->s_rst_owner = atoi(&pname[1]);
00385                 if(!Good_obj(parm->s_rst_owner))
00386                         parm->s_rst_owner = NOTHING;
00387                 else if(Typeof(parm->s_rst_owner) != TYPE_PLAYER)
00388                         parm->s_rst_owner = NOTHING;
00389 
00390         } else if(strcmp(pname, "me") == 0) {
00391                 parm->s_rst_owner = player;
00392         } else {
00393                 parm->s_rst_owner = lookup_player(player, pname, 1);
00394         }
00395 
00396         if(parm->s_rst_owner == NOTHING) {
00397                 notify_printf(player, "%s: No such player", pname);
00398                 return 0;
00399         }
00400         /*
00401          * set limits on what we search for 
00402          */
00403 
00404         err = 0;
00405         parm->s_rst_name = NULL;
00406         parm->s_rst_eval = NULL;
00407         parm->s_rst_type = NOTYPE;
00408         parm->s_parent = NOTHING;
00409         parm->s_zone = NOTHING;
00410         parm->s_fset.word1 = 0;
00411         parm->s_fset.word2 = 0;
00412         parm->s_fset.word3 = 0;
00413         parm->s_pset.word1 = 0;
00414         parm->s_pset.word2 = 0;
00415 
00416         switch (searchtype[0]) {
00417         case '\0':                                      /*
00418                                                                  * the no class requested class  :)  
00419                                                                  */
00420                 break;
00421         case 'e':
00422                 if(string_prefix("exits", searchtype)) {
00423                         parm->s_rst_name = searchfor;
00424                         parm->s_rst_type = TYPE_EXIT;
00425                 } else if(string_prefix("evaluate", searchtype)) {
00426                         parm->s_rst_eval = searchfor;
00427                 } else if(string_prefix("eplayer", searchtype)) {
00428                         parm->s_rst_type = TYPE_PLAYER;
00429                         parm->s_rst_eval = searchfor;
00430                 } else if(string_prefix("eroom", searchtype)) {
00431                         parm->s_rst_type = TYPE_ROOM;
00432                         parm->s_rst_eval = searchfor;
00433                 } else if(string_prefix("eobject", searchtype)) {
00434                         parm->s_rst_type = TYPE_THING;
00435                         parm->s_rst_eval = searchfor;
00436                 } else if(string_prefix("ething", searchtype)) {
00437                         parm->s_rst_type = TYPE_THING;
00438                         parm->s_rst_eval = searchfor;
00439                 } else if(string_prefix("eexit", searchtype)) {
00440                         parm->s_rst_type = TYPE_EXIT;
00441                         parm->s_rst_eval = searchfor;
00442                 } else {
00443                         err = 1;
00444                 }
00445                 break;
00446         case 'f':
00447                 if(string_prefix("flags", searchtype)) {
00448 
00449                         /*
00450                          * convert_flags ignores previous values of flag_mask
00451                          * * * * * and s_rst_type while setting them 
00452                          */
00453 
00454                         if(!convert_flags(player, searchfor, &parm->s_fset,
00455                                                           &parm->s_rst_type))
00456                                 return 0;
00457                 } else {
00458                         err = 1;
00459                 }
00460                 break;
00461         case 'n':
00462                 if(string_prefix("name", searchtype)) {
00463                         parm->s_rst_name = searchfor;
00464                 } else {
00465                         err = 1;
00466                 }
00467                 break;
00468         case 'o':
00469                 if(string_prefix("objects", searchtype)) {
00470                         parm->s_rst_name = searchfor;
00471                         parm->s_rst_type = TYPE_THING;
00472                 } else {
00473                         err = 1;
00474                 }
00475                 break;
00476         case 'p':
00477                 if(string_prefix("players", searchtype)) {
00478                         parm->s_rst_name = searchfor;
00479                         parm->s_rst_type = TYPE_PLAYER;
00480                         if(!*pname)
00481                                 parm->s_rst_owner = ANY_OWNER;
00482                 } else if(string_prefix("parent", searchtype)) {
00483                         parm->s_parent = match_controlled(player, searchfor);
00484                         if(!Good_obj(parm->s_parent))
00485                                 return 0;
00486                         if(!*pname)
00487                                 parm->s_rst_owner = ANY_OWNER;
00488                 } else if(string_prefix("power", searchtype)) {
00489                         if(!decode_power(player, searchfor, &parm->s_pset))
00490                                 return 0;
00491                 } else {
00492                         err = 1;
00493 
00494                 }
00495                 break;
00496         case 'r':
00497                 if(string_prefix("rooms", searchtype)) {
00498                         parm->s_rst_name = searchfor;
00499                         parm->s_rst_type = TYPE_ROOM;
00500                 } else {
00501                         err = 1;
00502                 }
00503                 break;
00504         case 't':
00505                 if(string_prefix("type", searchtype)) {
00506                         if(searchfor[0] == '\0')
00507                                 break;
00508                         if(string_prefix("rooms", searchfor))
00509                                 parm->s_rst_type = TYPE_ROOM;
00510                         else if(string_prefix("exits", searchfor))
00511                                 parm->s_rst_type = TYPE_EXIT;
00512                         else if(string_prefix("objects", searchfor))
00513                                 parm->s_rst_type = TYPE_THING;
00514                         else if(string_prefix("things", searchfor))
00515                                 parm->s_rst_type = TYPE_THING;
00516                         else if(string_prefix("garbage", searchfor))
00517                                 parm->s_rst_type = TYPE_GARBAGE;
00518                         else if(string_prefix("players", searchfor)) {
00519                                 parm->s_rst_type = TYPE_PLAYER;
00520                                 if(!*pname)
00521                                         parm->s_rst_owner = ANY_OWNER;
00522                         } else {
00523                                 notify_printf(player, "%s: unknown type", searchfor);
00524                                 return 0;
00525                         }
00526                 } else if(string_prefix("things", searchtype)) {
00527                         parm->s_rst_name = searchfor;
00528                         parm->s_rst_type = TYPE_THING;
00529                 } else {
00530                         err = 1;
00531                 }
00532                 break;
00533         case 'z':
00534                 if(string_prefix("zone", searchtype)) {
00535                         parm->s_zone = match_controlled(player, searchfor);
00536                         if(!Good_obj(parm->s_zone))
00537                                 return 0;
00538                         if(!*pname)
00539                                 parm->s_rst_owner = ANY_OWNER;
00540                 } else {
00541                         err = 1;
00542 
00543                 }
00544                 break;
00545         default:
00546                 err = 1;
00547         }
00548 
00549         if(err) {
00550                 notify_printf(player, "%s: unknown class", searchtype);
00551                 return 0;
00552         }
00553         /*
00554          * Make sure player is authorized to do the search 
00555          */
00556 
00557         if(!parm->s_wizard && (parm->s_rst_type != TYPE_PLAYER) &&
00558            (parm->s_rst_owner != player) && (parm->s_rst_owner != ANY_OWNER)) {
00559                 notify(player, "You need a search warrant to do that!");
00560                 return 0;
00561         }
00562         /*
00563          * make sure player has money to do the search 
00564          */
00565 
00566         if(!payfor(player, mudconf.searchcost)) {
00567                 notify_printf(player,
00568                                           "You don't have enough %s to search. (You need %d)",
00569                                           mudconf.many_coins, mudconf.searchcost);
00570                 return 0;
00571         }
00572         return 1;
00573 }


Generated on Mon May 28 04:25:46 2007 for BattletechMUX by  doxygen 1.4.7