mux/src/misc.h File Reference

#include "copyright.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

bool search_setup (dbref, char *, SEARCH *)
void search_perform (dbref executor, dbref caller, dbref enactor, SEARCH *)
bool get_stats (dbref, dbref, STATS *)


Typedef Documentation

typedef struct search_type SEARCH

Definition at line 15 of file misc.h.

typedef struct stats_type STATS

Definition at line 33 of file misc.h.


Function Documentation

bool get_stats ( dbref  ,
dbref  ,
STATS  
)

Definition at line 118 of file walkdb.cpp.

References Controls, DO_WHOLE_DB, Going, Good_obj, info(), confdata::many_coins, mudconf, NOPERM_MESSAGE, NOTHING, notify, Owner, payfor(), confdata::searchcost, Stat_Any, tprintf(), TYPE_EXIT, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, and Typeof.

Referenced by do_stats(), and FUNCTION().

00119 {
00120     // Do we have permission?
00121     //
00122     if (Good_obj(who) && !Controls(player, who) && !Stat_Any(player))
00123     {
00124         notify(player, NOPERM_MESSAGE);
00125         return false;
00126     }
00127 
00128     // Can we afford it?
00129     //
00130     if (!payfor(player, mudconf.searchcost))
00131     {
00132         notify(player, tprintf("You don't have enough %s.", mudconf.many_coins));
00133         return false;
00134     }
00135     info->s_total = 0;
00136     info->s_rooms = 0;
00137     info->s_exits = 0;
00138     info->s_things = 0;
00139     info->s_players = 0;
00140     info->s_garbage = 0;
00141 
00142     dbref i;
00143     DO_WHOLE_DB(i)
00144     {
00145         if ((who == NOTHING) || (who == Owner(i)))
00146         {
00147             info->s_total++;
00148             if (Going(i) && (Typeof(i) != TYPE_ROOM))
00149             {
00150                 info->s_garbage++;
00151                 continue;
00152             }
00153             switch (Typeof(i))
00154             {
00155             case TYPE_ROOM:
00156 
00157                 info->s_rooms++;
00158                 break;
00159 
00160             case TYPE_EXIT:
00161 
00162                 info->s_exits++;
00163                 break;
00164 
00165             case TYPE_THING:
00166 
00167                 info->s_things++;
00168                 break;
00169 
00170             case TYPE_PLAYER:
00171 
00172                 info->s_players++;
00173                 break;
00174 
00175             default:
00176 
00177                 info->s_garbage++;
00178             }
00179         }
00180     }
00181     return true;
00182 }

void search_perform ( dbref  executor,
dbref  caller,
dbref  enactor,
SEARCH  
)

Definition at line 741 of file walkdb.cpp.

References alloc_lbuf, alloc_sbuf, ANY_OWNER, db, EV_EVAL, EV_FCHECK, EV_NOTRACE, FLAG_WORD1, FLAG_WORD3, free_lbuf, statedata::func_invk_ctr, Going, search_type::low_bound, mudstate, mux_exec(), mux_ltoa(), NOTHING, NOTYPE, olist_add(), Owner, Parent, Powers, Powers2, PureName(), replace_tokens(), 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(), Typeof, flagset::word, powerset::word1, powerset::word2, xlate(), and Zone.

Referenced by do_search(), and FUNCTION().

00742 {
00743     POWER thing1powers, thing2powers;
00744     char *result, *bp, *str;
00745 
00746     char *buff = alloc_sbuf("search_perform.num");
00747     int save_invk_ctr = mudstate.func_invk_ctr;
00748 
00749     dbref thing;
00750     for (thing = parm->low_bound; thing <= parm->high_bound; thing++)
00751     {
00752         mudstate.func_invk_ctr = save_invk_ctr;
00753 
00754         // Check for matching type.
00755         //
00756         if (  (parm->s_rst_type != NOTYPE)
00757            && (parm->s_rst_type != Typeof(thing)))
00758         {
00759             continue;
00760         }
00761 
00762         // Check for matching owner.
00763         //
00764         if (  (parm->s_rst_owner != ANY_OWNER)
00765            && (parm->s_rst_owner != Owner(thing)))
00766         {
00767             continue;
00768         }
00769 
00770         // Toss out destroyed things.
00771         //
00772         if (Going(thing))
00773         {
00774             continue;
00775         }
00776 
00777         // Check for matching parent.
00778         //
00779         if (  (parm->s_parent != NOTHING)
00780            && (parm->s_parent != Parent(thing)))
00781         {
00782             continue;
00783         }
00784 
00785         // Check for matching zone.
00786         //
00787         if (  (parm->s_zone != NOTHING)
00788            && (parm->s_zone != Zone(thing)))
00789         {
00790             continue;
00791         }
00792 
00793         // Check for matching flags.
00794         //
00795         bool b = false;
00796         for (int i = FLAG_WORD1; i <= FLAG_WORD3; i++)
00797         {
00798             FLAG f = parm->s_fset.word[i];
00799             if ((db[thing].fs.word[i] & f) != f)
00800             {
00801                 b = true;
00802                 break;
00803             }
00804         }
00805         if (b)
00806         {
00807             continue;
00808         }
00809 
00810         // Check for matching power.
00811         //
00812         thing1powers = Powers(thing);
00813         thing2powers = Powers2(thing);
00814         if ((thing1powers & parm->s_pset.word1) != parm->s_pset.word1)
00815         {
00816             continue;
00817         }
00818         if ((thing2powers & parm->s_pset.word2) != parm->s_pset.word2)
00819         {
00820             continue;
00821         }
00822 
00823         // Check for matching name.
00824         //
00825         if (parm->s_rst_name != NULL)
00826         {
00827             if (!string_prefix(PureName(thing), parm->s_rst_name))
00828                 continue;
00829         }
00830 
00831         // Check for successful evaluation.
00832         //
00833         if (parm->s_rst_eval != NULL)
00834         {
00835             buff[0] = '#';
00836             mux_ltoa(thing, buff+1);
00837             char *buff2 = replace_tokens(parm->s_rst_eval, buff, NULL, NULL);
00838             result = bp = alloc_lbuf("search_perform");
00839             str = buff2;
00840             mux_exec(result, &bp, executor, caller, enactor,
00841                 EV_FCHECK | EV_EVAL | EV_NOTRACE, &str, (char **)NULL, 0);
00842             *bp = '\0';
00843             free_lbuf(buff2);
00844             if (!*result || !xlate(result))
00845             {
00846                 free_lbuf(result);
00847                 continue;
00848             }
00849             free_lbuf(result);
00850         }
00851 
00852         // It passed everything. Amazing.
00853         //
00854         olist_add(thing);
00855     }
00856     free_sbuf(buff);
00857     mudstate.func_invk_ctr = save_invk_ctr;
00858 }

bool search_setup ( dbref  ,
char *  ,
SEARCH  
)

Definition at line 389 of file walkdb.cpp.

References ANY_OWNER, convert_flags(), EV_STRIP_TS, FLAG_WORD1, FLAG_WORD3, Good_obj, search_type::high_bound, lookup_player(), search_type::low_bound, match_controlled, mux_atol(), mux_strlwr(), NOTHING, notify, NOTYPE, Owner, parse_range(), parse_to(), 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, string_prefix(), tprintf(), TYPE_EXIT, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, Typeof, flagset::word, powerset::word1, and powerset::word2.

Referenced by do_search(), and FUNCTION().

00390 {
00391     // Crack arg into <pname> <type>=<targ>,<low>,<high>
00392     //
00393     char *pname = parse_to(&searchfor, '=', EV_STRIP_TS);
00394     if (!pname || !*pname)
00395     {
00396         pname = "me";
00397     }
00398     else
00399     {
00400         mux_strlwr(pname);
00401     }
00402 
00403     char *searchtype;
00404     if (searchfor && *searchfor)
00405     {
00406         searchtype = strrchr(pname, ' ');
00407         if (searchtype)
00408         {
00409             *searchtype++ = '\0';
00410         }
00411         else
00412         {
00413             searchtype = pname;
00414             pname = "";
00415         }
00416     }
00417     else
00418     {
00419         searchtype = "";
00420     }
00421 
00422     // If the player name is quoted, strip the quotes.
00423     //
00424     if (*pname == '\"')
00425     {
00426         size_t k = strlen(pname) - 1;
00427         if (pname[k] == '"')
00428         {
00429             pname[k] = '\0';
00430             pname++;
00431         }
00432     }
00433 
00434     // Strip any range arguments.
00435     //
00436     parse_range(&searchfor, &parm->low_bound, &parm->high_bound);
00437 
00438 
00439     // Set limits on who we search.
00440     //
00441     parm->s_owner = Owner(player);
00442     parm->s_wizard = Search(player);
00443     parm->s_rst_owner = NOTHING;
00444     if (!*pname)
00445     {
00446         parm->s_rst_owner = parm->s_wizard ? ANY_OWNER : player;
00447     }
00448     else if (pname[0] == '#')
00449     {
00450         parm->s_rst_owner = mux_atol(&pname[1]);
00451         if (!Good_obj(parm->s_rst_owner))
00452         {
00453             parm->s_rst_owner = NOTHING;
00454         }
00455         else if (Typeof(parm->s_rst_owner) != TYPE_PLAYER)
00456         {
00457             parm->s_rst_owner = NOTHING;
00458         }
00459 
00460     }
00461     else if (strcmp(pname, "me") == 0)
00462     {
00463         parm->s_rst_owner = player;
00464     }
00465     else
00466     {
00467         parm->s_rst_owner = lookup_player(player, pname, true);
00468     }
00469 
00470     if (parm->s_rst_owner == NOTHING)
00471     {
00472         notify(player, tprintf("%s: No such player", pname));
00473         return false;
00474     }
00475 
00476     // Set limits on what we search for.
00477     //
00478     int err = 0;
00479     parm->s_rst_name = NULL;
00480     parm->s_rst_eval = NULL;
00481     parm->s_rst_type = NOTYPE;
00482     parm->s_parent = NOTHING;
00483     parm->s_zone = NOTHING;
00484     for (int i = FLAG_WORD1; i <= FLAG_WORD3; i++)
00485     {
00486         parm->s_fset.word[i] = 0;
00487     }
00488     parm->s_pset.word1 = 0;
00489     parm->s_pset.word2 = 0;
00490 
00491     switch (searchtype[0])
00492     {
00493     case '\0':
00494 
00495         // The no class requested class  :)
00496         //
00497         break;
00498 
00499     case 'e':
00500 
00501         if (string_prefix("exits", searchtype))
00502         {
00503             parm->s_rst_name = searchfor;
00504             parm->s_rst_type = TYPE_EXIT;
00505         }
00506         else if (string_prefix("evaluate", searchtype))
00507         {
00508             parm->s_rst_eval = searchfor;
00509         }
00510         else if (string_prefix("eplayer", searchtype))
00511         {
00512             parm->s_rst_type = TYPE_PLAYER;
00513             parm->s_rst_eval = searchfor;
00514         }
00515         else if (string_prefix("eroom", searchtype))
00516         {
00517             parm->s_rst_type = TYPE_ROOM;
00518             parm->s_rst_eval = searchfor;
00519         }
00520         else if (string_prefix("eobject", searchtype))
00521         {
00522             parm->s_rst_type = TYPE_THING;
00523             parm->s_rst_eval = searchfor;
00524         }
00525         else if (string_prefix("ething", searchtype))
00526         {
00527             parm->s_rst_type = TYPE_THING;
00528             parm->s_rst_eval = searchfor;
00529         }
00530         else if (string_prefix("eexit", searchtype))
00531         {
00532             parm->s_rst_type = TYPE_EXIT;
00533             parm->s_rst_eval = searchfor;
00534         }
00535         else
00536         {
00537             err = 1;
00538         }
00539         break;
00540 
00541     case 'f':
00542 
00543         if (string_prefix("flags", searchtype))
00544         {
00545             // convert_flags ignores previous values of flag_mask and
00546             // s_rst_type while setting them.
00547             //
00548             if ( !convert_flags( player, searchfor, &parm->s_fset,
00549                                 &parm->s_rst_type) )
00550             {
00551                 return false;
00552             }
00553         }
00554         else
00555         {
00556             err = 1;
00557         }
00558         break;
00559 
00560     case 'n':
00561 
00562         if (string_prefix("name", searchtype))
00563         {
00564             parm->s_rst_name = searchfor;
00565         }
00566         else
00567         {
00568             err = 1;
00569         }
00570         break;
00571 
00572     case 'o':
00573 
00574         if (string_prefix("objects", searchtype))
00575         {
00576             parm->s_rst_name = searchfor;
00577             parm->s_rst_type = TYPE_THING;
00578         }
00579         else
00580         {
00581             err = 1;
00582         }
00583         break;
00584 
00585     case 'p':
00586 
00587         if (string_prefix("players", searchtype))
00588         {
00589             parm->s_rst_name = searchfor;
00590             parm->s_rst_type = TYPE_PLAYER;
00591             if (!*pname)
00592             {
00593                 parm->s_rst_owner = ANY_OWNER;
00594             }
00595         }
00596         else if (string_prefix("parent", searchtype))
00597         {
00598             parm->s_parent = match_controlled(player, searchfor);
00599             if (!Good_obj(parm->s_parent))
00600             {
00601                 return false;
00602             }
00603             if (!*pname)
00604             {
00605                 parm->s_rst_owner = ANY_OWNER;
00606             }
00607         }
00608         else if (string_prefix("power", searchtype))
00609         {
00610             if (!decode_power(player, searchfor, &parm->s_pset))
00611             {
00612                 return false;
00613             }
00614         }
00615         else
00616         {
00617             err = 1;
00618         }
00619         break;
00620 
00621     case 'r':
00622 
00623         if (string_prefix("rooms", searchtype))
00624         {
00625             parm->s_rst_name = searchfor;
00626             parm->s_rst_type = TYPE_ROOM;
00627         }
00628         else
00629         {
00630             err = 1;
00631         }
00632         break;
00633 
00634     case 't':
00635 
00636         if (string_prefix("type", searchtype))
00637         {
00638             if (searchfor[0] == '\0')
00639             {
00640                 break;
00641             }
00642             if (string_prefix("rooms", searchfor))
00643             {
00644                 parm->s_rst_type = TYPE_ROOM;
00645             }
00646             else if (string_prefix("exits", searchfor))
00647             {
00648                 parm->s_rst_type = TYPE_EXIT;
00649             }
00650             else if (string_prefix("objects", searchfor))
00651             {
00652                 parm->s_rst_type = TYPE_THING;
00653             }
00654             else if (string_prefix("things", searchfor))
00655             {
00656                 parm->s_rst_type = TYPE_THING;
00657             }
00658             else if (string_prefix("garbage", searchfor))
00659             {
00660                 parm->s_rst_type = TYPE_GARBAGE;
00661             }
00662             else if (string_prefix("players", searchfor))
00663             {
00664                 parm->s_rst_type = TYPE_PLAYER;
00665                 if (!*pname)
00666                 {
00667                     parm->s_rst_owner = ANY_OWNER;
00668                 }
00669             }
00670             else
00671             {
00672                 notify(player, tprintf("%s: unknown type", searchfor));
00673                 return false;
00674             }
00675         }
00676         else if (string_prefix("things", searchtype))
00677         {
00678             parm->s_rst_name = searchfor;
00679             parm->s_rst_type = TYPE_THING;
00680         }
00681         else
00682         {
00683             err = 1;
00684         }
00685         break;
00686 
00687     case 'z':
00688 
00689         if (string_prefix("zone", searchtype))
00690         {
00691             parm->s_zone = match_controlled(player, searchfor);
00692             if (!Good_obj(parm->s_zone))
00693             {
00694                 return false;
00695             }
00696             if (!*pname)
00697             {
00698                 parm->s_rst_owner = ANY_OWNER;
00699             }
00700         }
00701         else
00702         {
00703             err = 1;
00704         }
00705         break;
00706 
00707     default:
00708 
00709         err = 1;
00710     }
00711 
00712     if (err)
00713     {
00714         notify(player, tprintf("%s: unknown class", searchtype));
00715         return false;
00716     }
00717 
00718     // Make sure player is authorized to do the search.
00719     //
00720     if (  !parm->s_wizard
00721        && (parm->s_rst_type != TYPE_PLAYER)
00722        && (parm->s_rst_owner != player)
00723        && (parm->s_rst_owner != ANY_OWNER))
00724     {
00725         notify(player, "You need a search warrant to do that!");
00726         return false;
00727     }
00728 
00729     // Make sure player has money to do the search.
00730     //
00731     if (!payfor(player, mudconf.searchcost))
00732     {
00733         notify(player,
00734             tprintf("You don't have enough %s to search. (You need %d)",
00735                  mudconf.many_coins, mudconf.searchcost));
00736         return false;
00737     }
00738     return true;
00739 }


Generated on Mon May 28 04:40:20 2007 for MUX by  doxygen 1.4.7