src/walkdb.c File Reference

#include "copyright.h"
#include "config.h"
#include "mudconf.h"
#include "db.h"
#include "interface.h"
#include "match.h"
#include "externs.h"
#include "command.h"
#include "flags.h"
#include "powers.h"
#include "misc.h"
#include "alloc.h"

Include dependency graph for walkdb.c:

Go to the source code of this file.

Defines

#define ANY_OWNER   -2

Functions

static void bind_and_queue (dbref player, dbref cause, char *action, char *argstr, char *cargs[], int ncargs, int number)
void do_dolist (dbref player, dbref cause, int key, char *list, char *command, char *cargs[], int ncargs)
void do_find (dbref player, dbref cause, int key, char *name)
int get_stats (dbref player, dbref who, STATS *info)
void do_stats (dbref player, dbref cause, int key, char *name)
int chown_all (dbref from_player, dbref to_player)
void do_chownall (dbref player, dbref cause, int key, char *from, char *to)
void er_mark_disabled (dbref player)
int search_setup (dbref player, char *searchfor, SEARCH *parm)
void search_perform (dbref player, dbref cause, SEARCH *parm)
void do_search (dbref player, dbref cause, int key, char *arg)
void olist_push (void)
void olist_pop (void)
void olist_add (dbref item)
dbref olist_first (void)
dbref olist_next (void)


Define Documentation

#define ANY_OWNER   -2

Definition at line 311 of file walkdb.c.

Referenced by search_perform(), and search_setup().


Function Documentation

static void bind_and_queue ( dbref  player,
dbref  cause,
char *  action,
char *  argstr,
char *  cargs[],
int  ncargs,
int  number 
) [static]

Bind occurances of the universal var in ACTION to ARG, then run ACTION. Cmds run in low-prio Q after a 1 sec delay for the first one.

Definition at line 27 of file walkdb.c.

References BOUND_VAR, free_lbuf, statedata::global_regs, LISTPLACE_VAR, mudstate, NOTHING, replace_string(), tprintf(), and wait_que().

Referenced by do_dolist().

00030 {
00031         char *command, *command2;       /*
00032 
00033                                                                  * allocated by replace_string  
00034                                                                  */
00035 
00036         command = replace_string(BOUND_VAR, argstr, action), command2 =
00037                 replace_string(LISTPLACE_VAR, tprintf("%d", number), command);
00038         wait_que(player, cause, 0, NOTHING, 0, command2, cargs, ncargs,
00039                          mudstate.global_regs);
00040         free_lbuf(command);
00041         free_lbuf(command2);
00042 }

int chown_all ( dbref  from_player,
dbref  to_player 
)

Transfers ownership of all a player's objects to another player.

Definition at line 233 of file walkdb.c.

References add_quota(), CHOWN_OK, DO_WHOLE_DB, confdata::exit_quota, Flags, HALT, INHERIT, mudconf, Owner, confdata::player_quota, confdata::room_quota, s_Flags, s_Owner, confdata::thing_quota, TYPE_EXIT, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, and Typeof.

Referenced by destroy_player(), do_chownall(), and do_toad().

00234 {
00235         int i, count, quota_out, quota_in;
00236 
00237         if(Typeof(from_player) != TYPE_PLAYER)
00238                 from_player = Owner(from_player);
00239         if(Typeof(to_player) != TYPE_PLAYER)
00240                 to_player = Owner(to_player);
00241         count = 0;
00242         quota_out = 0;
00243         quota_in = 0;
00244         DO_WHOLE_DB(i) {
00245                 if((Owner(i) == from_player) && (Owner(i) != i)) {
00246                         switch (Typeof(i)) {
00247                         case TYPE_PLAYER:
00248                                 s_Owner(i, i);
00249                                 quota_out += mudconf.player_quota;
00250                                 break;
00251                         case TYPE_THING:
00252                                 s_Owner(i, to_player);
00253                                 quota_out += mudconf.thing_quota;
00254                                 quota_in -= mudconf.thing_quota;
00255                                 break;
00256                         case TYPE_ROOM:
00257                                 s_Owner(i, to_player);
00258                                 quota_out += mudconf.room_quota;
00259                                 quota_in -= mudconf.room_quota;
00260                                 break;
00261                         case TYPE_EXIT:
00262                                 s_Owner(i, to_player);
00263                                 quota_out += mudconf.exit_quota;
00264                                 quota_in -= mudconf.exit_quota;
00265                                 break;
00266                         default:
00267                                 s_Owner(i, to_player);
00268                         }
00269                         s_Flags(i, (Flags(i) & ~(CHOWN_OK | INHERIT)) | HALT);
00270                         count++;
00271                 }
00272         }
00273         add_quota(from_player, quota_out);
00274         add_quota(to_player, quota_in);
00275         return count;
00276 }

void do_chownall ( dbref  player,
dbref  cause,
int  key,
char *  from,
char *  to 
)

Transfers ownership of all a player's objects to another player. Used in

Definition at line 282 of file walkdb.c.

References chown_all(), init_match(), match_absolute(), match_neighbor(), match_player(), noisy_match_result(), NOTHING, notify_printf(), Quiet, and TYPE_PLAYER.

00283 {
00284         int count;
00285         dbref victim, recipient;
00286 
00287         init_match(player, from, TYPE_PLAYER);
00288         match_neighbor();
00289         match_absolute();
00290         match_player();
00291         if((victim = noisy_match_result()) == NOTHING)
00292                 return;
00293 
00294         if((to != NULL) && *to) {
00295                 init_match(player, to, TYPE_PLAYER);
00296                 match_neighbor();
00297                 match_absolute();
00298                 match_player();
00299                 if((recipient = noisy_match_result()) == NOTHING)
00300                         return;
00301         } else {
00302                 recipient = player;
00303         }
00304 
00305         count = chown_all(victim, recipient);
00306         if(!Quiet(player)) {
00307                 notify_printf(player, "%d objects @chowned.", count);
00308         }
00309 }

void do_dolist ( dbref  player,
dbref  cause,
int  key,
char *  list,
char *  command,
char *  cargs[],
int  ncargs 
)

Iterates through a delimited string. Used in .

Definition at line 47 of file walkdb.c.

References bind_and_queue(), DOLIST_DELIMIT, EV_STRIP, notify, number, and parse_to().

00049 {
00050         char *curr, *objstring, delimiter = ' ';
00051         int number = 0;
00052 
00053         if(!list || *list == '\0') {
00054                 notify(player,
00055                            "That's terrific, but what should I do with the list?");
00056                 return;
00057         }
00058         curr = list;
00059 
00060         if(key == DOLIST_DELIMIT) {
00061                 char *tempstr;
00062 
00063                 if(strlen((tempstr = parse_to(&curr, ' ', EV_STRIP))) > 1) {
00064                         notify(player, "The delimiter must be a single character!");
00065                         return;
00066                 }
00067                 delimiter = *tempstr;
00068         }
00069         while (curr && *curr) {
00070                 while (*curr == delimiter)
00071                         curr++;
00072                 if(*curr) {
00073                         number++;
00074                         objstring = parse_to(&curr, delimiter, EV_STRIP);
00075                         bind_and_queue(player, cause, command, objstring, cargs,
00076                                                    ncargs, number);
00077                 }
00078         }
00079 }

void do_find ( dbref  player,
dbref  cause,
int  key,
char *  name 
)

Regular command

Definition at line 84 of file walkdb.c.

References controls, free_lbuf, confdata::many_coins, mudconf, notify, notify_quiet, parse_range(), payfor(), PureName(), confdata::searchcost, string_match(), tprintf(), TYPE_EXIT, Typeof, and unparse_object().

00085 {
00086         dbref i, low_bound, high_bound;
00087         char *buff;
00088 
00089         if(!payfor(player, mudconf.searchcost)) {
00090                 notify_quiet(player, tprintf("You don't have enough %s.",
00091                                                                          mudconf.many_coins));
00092                 return;
00093         }
00094         parse_range(&name, &low_bound, &high_bound);
00095         for(i = low_bound; i <= high_bound; i++) {
00096                 if((Typeof(i) != TYPE_EXIT) && controls(player, i) && (!*name ||
00097                                                                                                                            string_match
00098                                                                                                                            (PureName(i),
00099                                                                                                                                 name))) {
00100                         buff = unparse_object(player, i, 0);
00101                         notify(player, buff);
00102                         free_lbuf(buff);
00103                 }
00104         }
00105         notify(player, "***End of List***");
00106 }

void do_search ( dbref  player,
dbref  cause,
int  key,
char *  arg 
)

Definition at line 683 of file walkdb.c.

References alloc_lbuf, Exits, flag, free_lbuf, Location, NOTHING, notify, NOTYPE, olist_first(), olist_next(), olist_pop(), olist_push(), Owner, search_type::s_rst_type, search_type::s_wizard, safe_chr, safe_str, search_perform(), search_setup(), TYPE_EXIT, TYPE_GARBAGE, TYPE_PLAYER, TYPE_ROOM, TYPE_THING, Typeof, and unparse_object().

00684 {
00685         int flag, destitute;
00686         int rcount, ecount, tcount, pcount, gcount;
00687         char *buff, *outbuf, *bp;
00688         dbref thing, from, to;
00689         SEARCH searchparm;
00690 
00691         if(!search_setup(player, arg, &searchparm))
00692                 return;
00693         olist_push();
00694         search_perform(player, cause, &searchparm);
00695         destitute = 1;
00696 
00697         outbuf = alloc_lbuf("do_search.outbuf");
00698 
00699         rcount = ecount = tcount = pcount = gcount = 0;
00700 
00701         /*
00702          * room search 
00703          */
00704         if(searchparm.s_rst_type == TYPE_ROOM || searchparm.s_rst_type == NOTYPE) {
00705                 flag = 1;
00706                 for(thing = olist_first(); thing != NOTHING; thing = olist_next()) {
00707                         if(Typeof(thing) != TYPE_ROOM)
00708                                 continue;
00709                         if(flag) {
00710                                 flag = 0;
00711                                 destitute = 0;
00712                                 notify(player, "\nROOMS:");
00713                         }
00714                         buff = unparse_object(player, thing, 0);
00715                         notify(player, buff);
00716                         free_lbuf(buff);
00717                         rcount++;
00718                 }
00719         }
00720         /*
00721          * exit search 
00722          */
00723         if(searchparm.s_rst_type == TYPE_EXIT || searchparm.s_rst_type == NOTYPE) {
00724                 flag = 1;
00725                 for(thing = olist_first(); thing != NOTHING; thing = olist_next()) {
00726                         if(Typeof(thing) != TYPE_EXIT)
00727                                 continue;
00728                         if(flag) {
00729                                 flag = 0;
00730                                 destitute = 0;
00731                                 notify(player, "\nEXITS:");
00732                         }
00733                         from = Exits(thing);
00734                         to = Location(thing);
00735 
00736                         bp = outbuf;
00737                         buff = unparse_object(player, thing, 0);
00738                         safe_str(buff, outbuf, &bp);
00739                         free_lbuf(buff);
00740 
00741                         safe_str((char *) " [from ", outbuf, &bp);
00742                         buff = unparse_object(player, from, 0);
00743                         safe_str(((from == NOTHING) ? "NOWHERE" : buff), outbuf, &bp);
00744                         free_lbuf(buff);
00745 
00746                         safe_str((char *) " to ", outbuf, &bp);
00747                         buff = unparse_object(player, to, 0);
00748                         safe_str(((to == NOTHING) ? "NOWHERE" : buff), outbuf, &bp);
00749                         free_lbuf(buff);
00750 
00751                         safe_chr(']', outbuf, &bp);
00752                         *bp = '\0';
00753                         notify(player, outbuf);
00754                         ecount++;
00755                 }
00756         }
00757         /*
00758          * object search 
00759          */
00760         if(searchparm.s_rst_type == TYPE_THING || searchparm.s_rst_type == NOTYPE) {
00761                 flag = 1;
00762                 for(thing = olist_first(); thing != NOTHING; thing = olist_next()) {
00763                         if(Typeof(thing) != TYPE_THING)
00764                                 continue;
00765                         if(flag) {
00766                                 flag = 0;
00767                                 destitute = 0;
00768                                 notify(player, "\nOBJECTS:");
00769                         }
00770                         bp = outbuf;
00771                         buff = unparse_object(player, thing, 0);
00772                         safe_str(buff, outbuf, &bp);
00773                         free_lbuf(buff);
00774 
00775                         safe_str((char *) " [owner: ", outbuf, &bp);
00776                         buff = unparse_object(player, Owner(thing), 0);
00777                         safe_str(buff, outbuf, &bp);
00778                         free_lbuf(buff);
00779 
00780                         safe_chr(']', outbuf, &bp);
00781                         *bp = '\0';
00782                         notify(player, outbuf);
00783                         tcount++;
00784                 }
00785         }
00786         /*
00787          * garbage search 
00788          */
00789         if(searchparm.s_rst_type == TYPE_GARBAGE ||
00790            searchparm.s_rst_type == NOTYPE) {
00791                 flag = 1;
00792                 for(thing = olist_first(); thing != NOTHING; thing = olist_next()) {
00793                         if(Typeof(thing) != TYPE_GARBAGE)
00794                                 continue;
00795                         if(flag) {
00796                                 flag = 0;
00797                                 destitute = 0;
00798                                 notify(player, "\nGARBAGE:");
00799                         }
00800                         bp = outbuf;
00801                         buff = unparse_object(player, thing, 0);
00802                         safe_str(buff, outbuf, &bp);
00803                         free_lbuf(buff);
00804 
00805                         safe_str((char *) " [owner: ", outbuf, &bp);
00806                         buff = unparse_object(player, Owner(thing), 0);
00807                         safe_str(buff, outbuf, &bp);
00808                         free_lbuf(buff);
00809 
00810                         safe_chr(']', outbuf, &bp);
00811                         *bp = '\0';
00812                         notify(player, outbuf);
00813                         gcount++;
00814                 }
00815         }
00816         /*
00817          * player search 
00818          */
00819         if(searchparm.s_rst_type == TYPE_PLAYER ||
00820            searchparm.s_rst_type == NOTYPE) {
00821                 flag = 1;
00822                 for(thing = olist_first(); thing != NOTHING; thing = olist_next()) {
00823                         if(Typeof(thing) != TYPE_PLAYER)
00824                                 continue;
00825                         if(flag) {
00826                                 flag = 0;
00827                                 destitute = 0;
00828                                 notify(player, "\nPLAYERS:");
00829                         }
00830                         bp = outbuf;
00831                         buff = unparse_object(player, thing, 0);
00832                         safe_str(buff, outbuf, &bp);
00833                         free_lbuf(buff);
00834                         if(searchparm.s_wizard) {
00835                                 safe_str((char *) " [location: ", outbuf, &bp);
00836                                 buff = unparse_object(player, Location(thing), 0);
00837                                 safe_str(buff, outbuf, &bp);
00838                                 free_lbuf(buff);
00839                                 safe_chr(']', outbuf, &bp);
00840                         }
00841                         *bp = '\0';
00842                         notify(player, outbuf);
00843                         pcount++;
00844                 }
00845         }
00846         /*
00847          * if nothing found matching search criteria 
00848          */
00849 
00850         if(destitute) {
00851                 notify(player, "Nothing found.");
00852         } else {
00853                 sprintf(outbuf,
00854                                 "\nFound:  Rooms...%d  Exits...%d  Objects...%d  Players...%d  Garbage...%d",
00855                                 rcount, ecount, tcount, pcount, gcount);
00856                 notify(player, outbuf);
00857         }
00858         free_lbuf(outbuf);
00859         olist_pop();
00860 }

void do_stats ( dbref  player,
dbref  cause,
int  key,
char *  name 
)

Definition at line 170 of file walkdb.c.

References statedata::db_top, get_stats(), lookup_player(), mudstate, NOTHING, notify, notify_printf(), Owner, stats_type::s_exits, stats_type::s_garbage, stats_type::s_players, stats_type::s_rooms, stats_type::s_things, stats_type::s_total, STAT_ALL, STAT_ME, STAT_PLAYER, and Wizard.

00171 {
00172         dbref owner;
00173         STATS statinfo;
00174 
00175         switch (key) {
00176         case STAT_ALL:
00177                 owner = NOTHING;
00178                 break;
00179         case STAT_ME:
00180                 owner = Owner(player);
00181                 break;
00182         case STAT_PLAYER:
00183                 if(!(name && *name)) {
00184                         notify_printf(player, "The universe contains %d objects.",
00185                                                   mudstate.db_top);
00186                         return;
00187                 }
00188                 owner = lookup_player(player, name, 1);
00189                 if(owner == NOTHING) {
00190                         notify(player, "Not found.");
00191                         return;
00192                 }
00193                 break;
00194         default:
00195                 notify(player, "Illegal combination of switches.");
00196                 return;
00197         }
00198 
00199         if(!get_stats(player, owner, &statinfo))
00200                 return;
00201         notify_printf(player,
00202                                   "%d objects = %d rooms, %d exits, %d things, %d players. (%d garbage)",
00203                                   statinfo.s_total, statinfo.s_rooms, statinfo.s_exits,
00204                                   statinfo.s_things, statinfo.s_players, statinfo.s_garbage);
00205 
00206 #ifdef TEST_MALLOC
00207         if(Wizard(player))
00208                 notify_printf(player, "Malloc count = %d.", malloc_count);
00209 #endif /*
00210             * TEST_MALLOC 
00211             */
00212 #ifdef MCHECK
00213         if(Wizard(player)) {
00214                 struct mstats mval;
00215 
00216                 mval = mstats();
00217                 notify_printf(player, "Total size of the heap: %d", mval.bytes_total);
00218                 notify_printf(player,
00219                                           "Chunks allocated: %d -- Total size of allocated chunks: %d",
00220                                           mval.chunks_used, mval.bytes_used);
00221                 notify_printf(player,
00222                                           "Chunks free: %d -- Total size of free chunks: %d",
00223                                           mval.chunks_free, mval.bytes_free);
00224         }
00225 #endif /*
00226             * MCHECK 
00227             */
00228 }

void er_mark_disabled ( dbref  player  ) 

Definition at line 313 of file walkdb.c.

References notify.

00314 {
00315         notify(player,
00316                    "The mark commands are not allowed while DB cleaning is enabled.");
00317         notify(player,
00318                    "Use the '@disable cleaning' command to disable automatic cleaning.");
00319         notify(player,
00320                    "Remember to '@unmark_all' before re-enabling automatic cleaning.");
00321 }

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 olist_add ( dbref  item  ) 

Add an entry to the object list

Definition at line 906 of file walkdb.c.

References alloc_lbuf, objlist_stack::count, objlist_block::data, objlist_stack::head, mudstate, objlist_block::next, OBLOCK_SIZE, statedata::olist, and objlist_stack::tail.

Referenced by find_wild_attrs(), and search_perform().

00907 {
00908         OBLOCK *op;
00909 
00910         if(!mudstate.olist->head) {
00911                 op = (OBLOCK *) alloc_lbuf("olist_add.first");
00912                 mudstate.olist->head = mudstate.olist->tail = op;
00913                 mudstate.olist->count = 0;
00914                 op->next = NULL;
00915         } else if(mudstate.olist->count >= OBLOCK_SIZE) {
00916                 op = (OBLOCK *) alloc_lbuf("olist_add.next");
00917                 mudstate.olist->tail->next = op;
00918                 mudstate.olist->tail = op;
00919                 mudstate.olist->count = 0;
00920                 op->next = NULL;
00921         } else {
00922                 op = mudstate.olist->tail;
00923         }
00924         op->data[mudstate.olist->count++] = item;
00925 }

dbref olist_first ( void   ) 

Return the first entry in the object list

Definition at line 930 of file walkdb.c.

References objlist_stack::cblock, objlist_stack::citm, objlist_stack::count, objlist_block::data, objlist_stack::head, mudstate, NOTHING, statedata::olist, and objlist_stack::tail.

Referenced by do_decomp(), do_edit(), do_search(), do_wipe(), exam_wildattrs(), fun_lattr(), fun_search(), and grep_util().

00931 {
00932         if(!mudstate.olist->head)
00933                 return NOTHING;
00934         if((mudstate.olist->head == mudstate.olist->tail) &&
00935            (mudstate.olist->count == 0))
00936                 return NOTHING;
00937         mudstate.olist->cblock = mudstate.olist->head;
00938         mudstate.olist->citm = 0;
00939         return mudstate.olist->cblock->data[mudstate.olist->citm++];
00940 }

dbref olist_next ( void   ) 

Definition at line 942 of file walkdb.c.

References objlist_stack::cblock, objlist_stack::citm, objlist_stack::count, objlist_block::data, mudstate, objlist_block::next, NOTHING, OBLOCK_SIZE, statedata::olist, and objlist_stack::tail.

Referenced by do_decomp(), do_edit(), do_search(), do_wipe(), exam_wildattrs(), fun_lattr(), fun_search(), and grep_util().

00943 {
00944         dbref thing;
00945 
00946         if(!mudstate.olist->cblock)
00947                 return NOTHING;
00948         if((mudstate.olist->cblock == mudstate.olist->tail) &&
00949            (mudstate.olist->citm >= mudstate.olist->count))
00950                 return NOTHING;
00951         thing = mudstate.olist->cblock->data[mudstate.olist->citm++];
00952         if(mudstate.olist->citm >= OBLOCK_SIZE) {
00953                 mudstate.olist->cblock = mudstate.olist->cblock->next;
00954                 mudstate.olist->citm = 0;
00955         }
00956         return thing;
00957 }

void olist_pop ( void   ) 

Pop one entire list off the object list stack

Definition at line 888 of file walkdb.c.

References free_lbuf, objlist_stack::head, mudstate, objlist_block::next, objlist_stack::next, statedata::olist, and XFREE.

Referenced by do_decomp(), do_edit(), do_examine(), do_search(), do_wipe(), fun_lattr(), fun_search(), and grep_util().

00889 {
00890         OLSTK *ol;
00891         OBLOCK *op, *onext;
00892 
00893         ol = mudstate.olist->next;
00894 
00895         for(op = mudstate.olist->head; op != NULL; op = onext) {
00896                 onext = op->next;
00897                 free_lbuf(op);
00898         }
00899         XFREE(mudstate.olist, "olist_pop");
00900         mudstate.olist = ol;
00901 }

void olist_push ( void   ) 

Create a new object list at the top of the object list stack

Definition at line 870 of file walkdb.c.

References objlist_stack::cblock, objlist_stack::citm, objlist_stack::count, objlist_stack::head, mudstate, objlist_stack::next, statedata::olist, objlist_stack::tail, and XMALLOC.

Referenced by do_decomp(), do_edit(), do_examine(), do_search(), do_wipe(), fun_lattr(), fun_search(), and grep_util().

00871 {
00872         OLSTK *ol;
00873 
00874         ol = (OLSTK *) XMALLOC(sizeof(OLSTK), "olist_push");
00875         ol->next = mudstate.olist;
00876         mudstate.olist = ol;
00877 
00878         ol->head = NULL;
00879         ol->tail = NULL;
00880         ol->cblock = NULL;
00881         ol->count = 0;
00882         ol->citm = 0;
00883 }

void search_perform ( dbref  player,
dbref  cause,
SEARCH parm 
)

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, powerset::word1, flagset::word1, powerset::word2, flagset::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, powerset::word1, flagset::word1, powerset::word2, flagset::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:48 2007 for BattletechMUX by  doxygen 1.4.7