mux/src/flags.cpp

Go to the documentation of this file.
00001 // flags.cpp -- Flag manipulation routines.
00002 //
00003 // $Id: flags.cpp,v 1.25 2006/10/02 02:43:41 sdennis Exp $
00004 //
00005 
00006 #include "copyright.h"
00007 #include "autoconf.h"
00008 #include "config.h"
00009 #include "externs.h"
00010 
00011 #include "command.h"
00012 #include "powers.h"
00013 
00014 /* ---------------------------------------------------------------------------
00015  * fh_any: set or clear indicated bit, no security checking
00016  */
00017 
00018 static bool fh_any(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00019 {
00020     // Never let God drop his/her own wizbit.
00021     //
00022     if (  God(target)
00023        && reset
00024        && flag == WIZARD
00025        && fflags == FLAG_WORD1)
00026     {
00027         notify(player, "You cannot make God mortal.");
00028         return false;
00029     }
00030 
00031     // Otherwise we can go do it.
00032     //
00033     if (reset)
00034     {
00035         db[target].fs.word[fflags] &= ~flag;
00036     }
00037     else
00038     {
00039         db[target].fs.word[fflags] |= flag;
00040     }
00041     return true;
00042 }
00043 
00044 /* ---------------------------------------------------------------------------
00045  * fh_god: only GOD may set or clear the bit
00046  */
00047 
00048 static bool fh_god(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00049 {
00050     if (!God(player))
00051     {
00052         return false;
00053     }
00054     return (fh_any(target, player, flag, fflags, reset));
00055 }
00056 
00057 /*
00058  * ---------------------------------------------------------------------------
00059  * * fh_wiz: only WIZARDS (or GOD) may set or clear the bit
00060  */
00061 
00062 static bool fh_wiz(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00063 {
00064     if (!Wizard(player))
00065     {
00066         return false;
00067     }
00068     return (fh_any(target, player, flag, fflags, reset));
00069 }
00070 
00071 /*
00072  * ---------------------------------------------------------------------------
00073  * * fh_wizroy: only WIZARDS, ROYALTY, (or GOD) may set or clear the bit
00074  */
00075 
00076 static bool fh_wizroy(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00077 {
00078     if (!WizRoy(player))
00079     {
00080         return false;
00081     }
00082     return (fh_any(target, player, flag, fflags, reset));
00083 }
00084 
00085 /*
00086  * ---------------------------------------------------------------------------
00087  * * fh_restrict_player (renamed from fh_fixed): Only Wizards can set
00088  * * this on players, but ordinary players can set it on other types
00089  * * of objects.
00090  */
00091 static bool fh_restrict_player
00092 (
00093     dbref target,
00094     dbref player,
00095     FLAG flag,
00096     int fflags,
00097     bool reset
00098 )
00099 {
00100     if (  isPlayer(target)
00101        && !Wizard(player))
00102     {
00103         return false;
00104     }
00105     return (fh_any(target, player, flag, fflags, reset));
00106 }
00107 
00108 /* ---------------------------------------------------------------------------
00109  * fh_privileged: You can set this flag on a non-player object, if you
00110  * yourself have this flag and are a player who owns themselves (i.e.,
00111  * no robots). Only God can set this on a player.
00112  */
00113 static bool fh_privileged
00114 (
00115     dbref target,
00116     dbref player,
00117     FLAG flag,
00118     int fflags,
00119     bool reset
00120 )
00121 {
00122     if (!God(player))
00123     {
00124         if (  !isPlayer(player)
00125            || player != Owner(player)
00126            || isPlayer(target)
00127            || (db[player].fs.word[fflags] & flag) == 0)
00128         {
00129             return false;
00130         }
00131     }
00132     return (fh_any(target, player, flag, fflags, reset));
00133 }
00134 
00135 /*
00136  * ---------------------------------------------------------------------------
00137  * * fh_inherit: only players may set or clear this bit.
00138  */
00139 
00140 static bool fh_inherit(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00141 {
00142     if (!Inherits(player))
00143     {
00144         return false;
00145     }
00146     return (fh_any(target, player, flag, fflags, reset));
00147 }
00148 
00149 /*
00150  * ---------------------------------------------------------------------------
00151  * * fh_dark_bit: manipulate the dark bit. Nonwizards may not set on players.
00152  */
00153 
00154 static bool fh_dark_bit(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00155 {
00156     if (  !reset
00157        && isPlayer(target)
00158        && !(  (target == player)
00159            && Can_Hide(player))
00160        && !Wizard(player))
00161     {
00162         return false;
00163     }
00164     return (fh_any(target, player, flag, fflags, reset));
00165 }
00166 
00167 /*
00168  * ---------------------------------------------------------------------------
00169  * * fh_going_bit: manipulate the going bit.  Non-gods may only clear.
00170  */
00171 
00172 static bool fh_going_bit(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00173 {
00174     if (  Going(target)
00175        && reset
00176        && (Typeof(target) != TYPE_GARBAGE))
00177     {
00178         notify(player, "Your object has been spared from destruction.");
00179         return (fh_any(target, player, flag, fflags, reset));
00180     }
00181     if (!God(player))
00182     {
00183         return false;
00184     }
00185 
00186     // Even God should not be allowed set protected dbrefs GOING.
00187     //
00188     if (  !reset
00189        && (  target == 0
00190           || God(target)
00191           || target == mudconf.start_home
00192           || target == mudconf.start_room
00193           || target == mudconf.default_home
00194           || target == mudconf.master_room))
00195     {
00196         return false;
00197     }
00198     return (fh_any(target, player, flag, fflags, reset));
00199 }
00200 
00201 /*
00202  * ---------------------------------------------------------------------------
00203  * * fh_hear_bit: set or clear bits that affect hearing.
00204  */
00205 
00206 static bool fh_hear_bit(dbref target, dbref player, FLAG flag, int fflags, bool reset)
00207 {
00208     if (isPlayer(target) && (flag & MONITOR))
00209     {
00210         if (Can_Monitor(player))
00211         {
00212             return (fh_any(target, player, flag, fflags, reset));
00213         }
00214         else
00215         {
00216             return false;
00217         }
00218     }
00219 
00220     bool could_hear = Hearer(target);
00221     bool result = fh_any(target, player, flag, fflags, reset);
00222     handle_ears(target, could_hear, Hearer(target));
00223     return result;
00224 }
00225 
00226 
00227 /* ---------------------------------------------------------------------------
00228  * fh_player_bit: Can set and reset this on everything but players.
00229  */
00230 static bool fh_player_bit
00231 (
00232     dbref target,
00233     dbref player,
00234     FLAG flag,
00235     int fflags,
00236     bool reset
00237 )
00238 {
00239     if (isPlayer(target))
00240     {
00241         return false;
00242     }
00243     return (fh_any(target, player, flag, fflags, reset));
00244 }
00245 
00246 /* ---------------------------------------------------------------------------
00247  * fh_staff: only STAFF, WIZARDS, ROYALTY, (or GOD) may set or clear
00248  * the bit.
00249  */
00250 static bool fh_staff
00251 (
00252     dbref target,
00253     dbref player,
00254     FLAG flag,
00255     int fflags,
00256     bool reset
00257 )
00258 {
00259     if (!Staff(player) && !God(player))
00260     {
00261         return false;
00262     }
00263     return (fh_any(target, player, flag, fflags, reset));
00264 }
00265 
00266 static FLAGBITENT fbeAbode          = { ABODE,        'A',    FLAG_WORD2, 0,                    fh_any};
00267 static FLAGBITENT fbeAnsi           = { ANSI,         'X',    FLAG_WORD2, 0,                    fh_any};
00268 static FLAGBITENT fbeAudible        = { HEARTHRU,     'a',    FLAG_WORD1, 0,                    fh_hear_bit};
00269 static FLAGBITENT fbeAuditorium     = { AUDITORIUM,   'b',    FLAG_WORD2, 0,                    fh_any};
00270 static FLAGBITENT fbeBlind          = { BLIND,        'B',    FLAG_WORD2, 0,                    fh_wiz};
00271 static FLAGBITENT fbeChownOk        = { CHOWN_OK,     'C',    FLAG_WORD1, 0,                    fh_any};
00272 static FLAGBITENT fbeConnected      = { CONNECTED,    'c',    FLAG_WORD2, CA_NO_DECOMP,         fh_god};
00273 static FLAGBITENT fbeDark           = { DARK,         'D',    FLAG_WORD1, 0,                    fh_dark_bit};
00274 static FLAGBITENT fbeDestroyOk      = { DESTROY_OK,   'd',    FLAG_WORD1, 0,                    fh_any};
00275 static FLAGBITENT fbeEnterOk        = { ENTER_OK,     'e',    FLAG_WORD1, 0,                    fh_any};
00276 static FLAGBITENT fbeFixed          = { FIXED,        'f',    FLAG_WORD2, 0,                    fh_restrict_player};
00277 static FLAGBITENT fbeFloating       = { FLOATING,     'F',    FLAG_WORD2, 0,                    fh_any};
00278 static FLAGBITENT fbeGagged         = { GAGGED,       'j',    FLAG_WORD2, 0,                    fh_wiz};
00279 static FLAGBITENT fbeGoing          = { GOING,        'G',    FLAG_WORD1, CA_NO_DECOMP,         fh_going_bit};
00280 static FLAGBITENT fbeHalted         = { HALT,         'h',    FLAG_WORD1, 0,                    fh_any};
00281 static FLAGBITENT fbeHasDaily       = { HAS_DAILY,    '*',    FLAG_WORD2, CA_GOD|CA_NO_DECOMP,  fh_god};
00282 static FLAGBITENT fbeHasForwardList = { HAS_FWDLIST,  '&',    FLAG_WORD2, CA_GOD|CA_NO_DECOMP,  fh_god};
00283 static FLAGBITENT fbeHasListen      = { HAS_LISTEN,   '@',    FLAG_WORD2, CA_GOD|CA_NO_DECOMP,  fh_god};
00284 static FLAGBITENT fbeHasStartup     = { HAS_STARTUP,  '+',    FLAG_WORD1, CA_GOD|CA_NO_DECOMP,  fh_god};
00285 static FLAGBITENT fbeHaven          = { HAVEN,        'H',    FLAG_WORD1, 0,                    fh_any};
00286 static FLAGBITENT fbeHead           = { HEAD_FLAG,    '?',    FLAG_WORD2, 0,                    fh_wiz};
00287 static FLAGBITENT fbeHtml           = { HTML,         '(',    FLAG_WORD2, 0,                    fh_any};
00288 static FLAGBITENT fbeImmortal       = { IMMORTAL,     'i',    FLAG_WORD1, 0,                    fh_wiz};
00289 static FLAGBITENT fbeInherit        = { INHERIT,      'I',    FLAG_WORD1, 0,                    fh_inherit};
00290 static FLAGBITENT fbeJumpOk         = { JUMP_OK,      'J',    FLAG_WORD1, 0,                    fh_any};
00291 static FLAGBITENT fbeKeepAlive      = { CKEEPALIVE,   'k',    FLAG_WORD2, 0,                    fh_any};
00292 static FLAGBITENT fbeKey            = { KEY,          'K',    FLAG_WORD2, 0,                    fh_any};
00293 static FLAGBITENT fbeLight          = { LIGHT,        'l',    FLAG_WORD2, 0,                    fh_any};
00294 static FLAGBITENT fbeLinkOk         = { LINK_OK,      'L',    FLAG_WORD1, 0,                    fh_any};
00295 static FLAGBITENT fbeMonitor        = { MONITOR,      'M',    FLAG_WORD1, 0,                    fh_hear_bit};
00296 static FLAGBITENT fbeMyopic         = { MYOPIC,       'm',    FLAG_WORD1, 0,                    fh_any};
00297 static FLAGBITENT fbeNoCommand      = { NO_COMMAND,   'n',    FLAG_WORD2, 0,                    fh_any};
00298 static FLAGBITENT fbeNoAccents      = { NOACCENTS,    '~',    FLAG_WORD2, 0,                    fh_any};
00299 static FLAGBITENT fbeNoBleed        = { NOBLEED,      '-',    FLAG_WORD2, 0,                    fh_any};
00300 static FLAGBITENT fbeNoSpoof        = { NOSPOOF,      'N',    FLAG_WORD1, 0,                    fh_any};
00301 static FLAGBITENT fbeOpaque         = { TM_OPAQUE,    'O',    FLAG_WORD1, 0,                    fh_any};
00302 static FLAGBITENT fbeOpenOk         = { OPEN_OK,      'z',    FLAG_WORD2, 0,                    fh_wiz};
00303 static FLAGBITENT fbeParentOk       = { PARENT_OK,    'Y',    FLAG_WORD2, 0,                    fh_any};
00304 static FLAGBITENT fbePlayerMails    = { PLAYER_MAILS, ' ',    FLAG_WORD2, CA_GOD|CA_NO_DECOMP,  fh_god};
00305 static FLAGBITENT fbePuppet         = { PUPPET,       'p',    FLAG_WORD1, 0,                    fh_hear_bit};
00306 static FLAGBITENT fbeQuiet          = { QUIET,        'Q',    FLAG_WORD1, 0,                    fh_any};
00307 static FLAGBITENT fbeRobot          = { ROBOT,        'r',    FLAG_WORD1, 0,                    fh_player_bit};
00308 static FLAGBITENT fbeRoyalty        = { ROYALTY,      'Z',    FLAG_WORD1, 0,                    fh_wiz};
00309 static FLAGBITENT fbeSafe           = { SAFE,         's',    FLAG_WORD1, 0,                    fh_any};
00310 static FLAGBITENT fbeSlave          = { SLAVE,        'x',    FLAG_WORD2, CA_WIZARD,            fh_wiz};
00311 static FLAGBITENT fbeStaff          = { STAFF,        'w',    FLAG_WORD2, 0,                    fh_wiz};
00312 static FLAGBITENT fbeSticky         = { STICKY,       'S',    FLAG_WORD1, 0,                    fh_any};
00313 static FLAGBITENT fbeSuspect        = { SUSPECT,      'u',    FLAG_WORD2, CA_WIZARD,            fh_wiz};
00314 static FLAGBITENT fbeTerse          = { TERSE,        'q',    FLAG_WORD1, 0,                    fh_any};
00315 static FLAGBITENT fbeTrace          = { TRACE,        'T',    FLAG_WORD1, 0,                    fh_any};
00316 static FLAGBITENT fbeTransparent    = { SEETHRU,      't',    FLAG_WORD1, 0,                    fh_any};
00317 static FLAGBITENT fbeUnfindable     = { UNFINDABLE,   'U',    FLAG_WORD2, 0,                    fh_any};
00318 static FLAGBITENT fbeUninspected    = { UNINSPECTED,  'g',    FLAG_WORD2, 0,                    fh_wizroy};
00319 static FLAGBITENT fbeVacation       = { VACATION,     '|',    FLAG_WORD2, 0,                    fh_restrict_player};
00320 static FLAGBITENT fbeVerbose        = { VERBOSE,      'v',    FLAG_WORD1, 0,                    fh_any};
00321 static FLAGBITENT fbeVisual         = { VISUAL,       'V',    FLAG_WORD1, 0,                    fh_any};
00322 static FLAGBITENT fbeWizard         = { WIZARD,       'W',    FLAG_WORD1, 0,                    fh_god};
00323 static FLAGBITENT fbeSitemon        = { SITEMON,      '$',    FLAG_WORD3, 0,                    fh_wiz};
00324 #ifdef WOD_REALMS
00325 static FLAGBITENT fbeFae            = { FAE,          '0',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00326 static FLAGBITENT fbeChimera        = { CHIMERA,      '1',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00327 static FLAGBITENT fbePeering        = { PEERING,      '2',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00328 static FLAGBITENT fbeUmbra          = { UMBRA,        '3',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00329 static FLAGBITENT fbeShroud         = { SHROUD,       '4',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00330 static FLAGBITENT fbeMatrix         = { MATRIX,       '5',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00331 static FLAGBITENT fbeObf            = { OBF,          '6',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00332 static FLAGBITENT fbeHss            = { HSS,          '7',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00333 static FLAGBITENT fbeMedium         = { MEDIUM,       '8',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00334 static FLAGBITENT fbeDead           = { DEAD,         '9',    FLAG_WORD3, CA_STAFF,             fh_wizroy};
00335 static FLAGBITENT fbeMarker0        = { MARK_0,       ' ',    FLAG_WORD3, 0,                    fh_god};
00336 static FLAGBITENT fbeMarker1        = { MARK_1,       ' ',    FLAG_WORD3, 0,                    fh_god};
00337 static FLAGBITENT fbeMarker2        = { MARK_2,       ' ',    FLAG_WORD3, 0,                    fh_god};
00338 static FLAGBITENT fbeMarker3        = { MARK_3,       ' ',    FLAG_WORD3, 0,                    fh_god};
00339 static FLAGBITENT fbeMarker4        = { MARK_4,       ' ',    FLAG_WORD3, 0,                    fh_god};
00340 static FLAGBITENT fbeMarker5        = { MARK_5,       ' ',    FLAG_WORD3, 0,                    fh_god};
00341 static FLAGBITENT fbeMarker6        = { MARK_6,       ' ',    FLAG_WORD3, 0,                    fh_god};
00342 static FLAGBITENT fbeMarker7        = { MARK_7,       ' ',    FLAG_WORD3, 0,                    fh_god};
00343 static FLAGBITENT fbeMarker8        = { MARK_8,       ' ',    FLAG_WORD3, 0,                    fh_god};
00344 static FLAGBITENT fbeMarker9        = { MARK_9,       ' ',    FLAG_WORD3, 0,                    fh_god};
00345 #else // WOD_REALMS
00346 static FLAGBITENT fbeMarker0        = { MARK_0,       '0',    FLAG_WORD3, 0,                    fh_god};
00347 static FLAGBITENT fbeMarker1        = { MARK_1,       '1',    FLAG_WORD3, 0,                    fh_god};
00348 static FLAGBITENT fbeMarker2        = { MARK_2,       '2',    FLAG_WORD3, 0,                    fh_god};
00349 static FLAGBITENT fbeMarker3        = { MARK_3,       '3',    FLAG_WORD3, 0,                    fh_god};
00350 static FLAGBITENT fbeMarker4        = { MARK_4,       '4',    FLAG_WORD3, 0,                    fh_god};
00351 static FLAGBITENT fbeMarker5        = { MARK_5,       '5',    FLAG_WORD3, 0,                    fh_god};
00352 static FLAGBITENT fbeMarker6        = { MARK_6,       '6',    FLAG_WORD3, 0,                    fh_god};
00353 static FLAGBITENT fbeMarker7        = { MARK_7,       '7',    FLAG_WORD3, 0,                    fh_god};
00354 static FLAGBITENT fbeMarker8        = { MARK_8,       '8',    FLAG_WORD3, 0,                    fh_god};
00355 static FLAGBITENT fbeMarker9        = { MARK_9,       '9',    FLAG_WORD3, 0,                    fh_god};
00356 #endif // WOD_REALMS
00357 
00358 FLAGNAMEENT gen_flag_names[] =
00359 {
00360     {"ABODE",           true, &fbeAbode          },
00361     {"ACCENTS",        false, &fbeNoAccents      },
00362     {"ANSI",            true, &fbeAnsi           },
00363     {"AUDIBLE",         true, &fbeAudible        },
00364     {"AUDITORIUM",      true, &fbeAuditorium     },
00365     {"BLEED",          false, &fbeNoBleed        },
00366     {"BLIND",           true, &fbeBlind          },
00367     {"COMMANDS",       false, &fbeNoCommand      },
00368     {"CHOWN_OK",        true, &fbeChownOk        },
00369     {"CONNECTED",       true, &fbeConnected      },
00370     {"DARK",            true, &fbeDark           },
00371     {"DESTROY_OK",      true, &fbeDestroyOk      },
00372     {"ENTER_OK",        true, &fbeEnterOk        },
00373     {"FIXED",           true, &fbeFixed          },
00374     {"FLOATING",        true, &fbeFloating       },
00375     {"GAGGED",          true, &fbeGagged         },
00376     {"GOING",           true, &fbeGoing          },
00377     {"HALTED",          true, &fbeHalted         },
00378     {"HAS_DAILY",       true, &fbeHasDaily       },
00379     {"HAS_FORWARDLIST", true, &fbeHasForwardList },
00380     {"HAS_LISTEN",      true, &fbeHasListen      },
00381     {"HAS_STARTUP",     true, &fbeHasStartup     },
00382     {"HAVEN",           true, &fbeHaven          },
00383     {"HEAD",            true, &fbeHead           },
00384     {"HTML",            true, &fbeHtml           },
00385     {"IMMORTAL",        true, &fbeImmortal       },
00386     {"INHERIT",         true, &fbeInherit        },
00387     {"JUMP_OK",         true, &fbeJumpOk         },
00388     {"KEEPALIVE",       true, &fbeKeepAlive      },
00389     {"KEY",             true, &fbeKey            },
00390     {"LIGHT",           true, &fbeLight          },
00391     {"LINK_OK",         true, &fbeLinkOk         },
00392     {"MARKER0",         true, &fbeMarker0        },
00393     {"MARKER1",         true, &fbeMarker1        },
00394     {"MARKER2",         true, &fbeMarker2        },
00395     {"MARKER3",         true, &fbeMarker3        },
00396     {"MARKER4",         true, &fbeMarker4        },
00397     {"MARKER5",         true, &fbeMarker5        },
00398     {"MARKER6",         true, &fbeMarker6        },
00399     {"MARKER7",         true, &fbeMarker7        },
00400     {"MARKER8",         true, &fbeMarker8        },
00401     {"MARKER9",         true, &fbeMarker9        },
00402     {"MONITOR",         true, &fbeMonitor        },
00403     {"MYOPIC",          true, &fbeMyopic         },
00404     {"NO_COMMAND",      true, &fbeNoCommand      },
00405     {"NOACCENTS",       true, &fbeNoAccents      },
00406     {"NOBLEED",         true, &fbeNoBleed        },
00407     {"NOSPOOF",         true, &fbeNoSpoof        },
00408     {"OPAQUE",          true, &fbeOpaque         },
00409     {"OPEN_OK",         true, &fbeOpenOk         },
00410     {"PARENT_OK",       true, &fbeParentOk       },
00411     {"PLAYER_MAILS",    true, &fbePlayerMails    },
00412     {"PUPPET",          true, &fbePuppet         },
00413     {"QUIET",           true, &fbeQuiet          },
00414     {"ROBOT",           true, &fbeRobot          },
00415     {"ROYALTY",         true, &fbeRoyalty        },
00416     {"SAFE",            true, &fbeSafe           },
00417     {"SITEMON",         true, &fbeSitemon        },
00418     {"SLAVE",           true, &fbeSlave          },
00419     {"SPOOF",          false, &fbeNoSpoof        },
00420     {"STAFF",           true, &fbeStaff          },
00421     {"STICKY",          true, &fbeSticky         },
00422     {"SUSPECT",         true, &fbeSuspect        },
00423     {"TERSE",           true, &fbeTerse          },
00424     {"TRACE",           true, &fbeTrace          },
00425     {"TRANSPARENT",     true, &fbeTransparent    },
00426     {"UNFINDABLE",      true, &fbeUnfindable     },
00427     {"UNINSPECTED",     true, &fbeUninspected    },
00428     {"VACATION",        true, &fbeVacation       },
00429     {"VERBOSE",         true, &fbeVerbose        },
00430     {"VISUAL",          true, &fbeVisual         },
00431     {"WIZARD",          true, &fbeWizard         },
00432 #ifdef WOD_REALMS
00433     {"FAE",             true, &fbeFae            },
00434     {"CHIMERA",         true, &fbeChimera        },
00435     {"PEERING",         true, &fbePeering        },
00436     {"UMBRA",           true, &fbeUmbra          },
00437     {"SHROUD",          true, &fbeShroud         },
00438     {"MATRIX",          true, &fbeMatrix         },
00439     {"OBF",             true, &fbeObf            },
00440     {"HSS",             true, &fbeHss            },
00441     {"MEDIUM",          true, &fbeMedium         },
00442     {"DEAD",            true, &fbeDead           },
00443 #endif // WOD_REALMS
00444     {NULL,             false, NULL}
00445 };
00446 
00447 OBJENT object_types[8] =
00448 {
00449     {"ROOM",    'R', CA_PUBLIC, OF_CONTENTS|OF_EXITS|OF_DROPTO|OF_HOME},
00450     {"THING",   ' ', CA_PUBLIC, OF_CONTENTS|OF_LOCATION|OF_EXITS|OF_HOME|OF_SIBLINGS},
00451     {"EXIT",    'E', CA_PUBLIC, OF_SIBLINGS},
00452     {"PLAYER",  'P', CA_PUBLIC, OF_CONTENTS|OF_LOCATION|OF_EXITS|OF_HOME|OF_OWNER|OF_SIBLINGS},
00453     {"TYPE5",   '+', CA_GOD,    0},
00454     {"GARBAGE", '-', CA_PUBLIC, OF_CONTENTS|OF_LOCATION|OF_EXITS|OF_HOME|OF_SIBLINGS},
00455     {"GARBAGE", '#', CA_GOD,    0}
00456 };
00457 
00458 /* ---------------------------------------------------------------------------
00459  * init_flagtab: initialize flag hash tables.
00460  */
00461 
00462 void init_flagtab(void)
00463 {
00464     char *nbuf = alloc_sbuf("init_flagtab");
00465     for (FLAGNAMEENT *fp = gen_flag_names; fp->pOrigName; fp++)
00466     {
00467         fp->flagname = fp->pOrigName;
00468         strncpy(nbuf, fp->pOrigName, SBUF_SIZE);
00469         nbuf[SBUF_SIZE-1] = '\0';
00470         mux_strlwr(nbuf);
00471         if (!hashfindLEN(nbuf, strlen(nbuf), &mudstate.flags_htab))
00472         {
00473             hashaddLEN(nbuf, strlen(nbuf), fp, &mudstate.flags_htab);
00474         }
00475     }
00476     free_sbuf(nbuf);
00477 }
00478 
00479 /* ---------------------------------------------------------------------------
00480  * display_flags: display available flags.
00481  */
00482 
00483 void display_flagtab(dbref player)
00484 {
00485     char *buf, *bp;
00486     FLAGNAMEENT *fp;
00487 
00488     bp = buf = alloc_lbuf("display_flagtab");
00489     safe_str("Flags:", buf, &bp);
00490     for (fp = gen_flag_names; fp->flagname; fp++)
00491     {
00492         FLAGBITENT *fbe = fp->fbe;
00493         if (  (  (fbe->listperm & CA_WIZARD)
00494               && !Wizard(player))
00495            || (  (fbe->listperm & CA_GOD)
00496               && !God(player)))
00497         {
00498             continue;
00499         }
00500         safe_chr(' ', buf, &bp);
00501         safe_str(fp->flagname, buf, &bp);
00502         if (fbe->flaglett != ' ')
00503         {
00504             safe_chr('(', buf, &bp);
00505             if (!fp->bPositive)
00506             {
00507                 safe_chr('!', buf, &bp);
00508             }
00509             safe_chr(fbe->flaglett, buf, &bp);
00510             safe_chr(')', buf, &bp);
00511         }
00512     }
00513     *bp = '\0';
00514     notify(player, buf);
00515     free_lbuf(buf);
00516 }
00517 
00518 char *MakeCanonicalFlagName
00519 (
00520     const char *pName,
00521     int *pnName,
00522     bool *pbValid
00523 )
00524 {
00525     static char buff[SBUF_SIZE];
00526     char *p = buff;
00527     int nName = 0;
00528 
00529     while (*pName && nName < SBUF_SIZE)
00530     {
00531         *p = mux_tolower(*pName);
00532         p++;
00533         pName++;
00534         nName++;
00535     }
00536     *p = '\0';
00537     if (nName < SBUF_SIZE)
00538     {
00539         *pnName = nName;
00540         *pbValid = true;
00541         return buff;
00542     }
00543     else
00544     {
00545         *pnName = 0;
00546         *pbValid = false;
00547         return NULL;
00548     }
00549 }
00550 
00551 static FLAGNAMEENT *find_flag(char *flagname)
00552 {
00553     // Convert flagname to canonical lowercase format.
00554     //
00555     int nName;
00556     bool bValid;
00557     char *pName = MakeCanonicalFlagName(flagname, &nName, &bValid);
00558     FLAGNAMEENT *fe = NULL;
00559     if (bValid)
00560     {
00561         fe = (FLAGNAMEENT *)hashfindLEN(pName, nName, &mudstate.flags_htab);
00562     }
00563     return fe;
00564 }
00565 
00566 // ---------------------------------------------------------------------------
00567 // flag_set: Set or clear a specified flag on an object.
00568 //
00569 void flag_set(dbref target, dbref player, char *flag, int key)
00570 {
00571     bool bDone = false;
00572 
00573     do
00574     {
00575         // Trim spaces, and handle the negation character.
00576         //
00577         while (mux_isspace(*flag))
00578         {
00579             flag++;
00580         }
00581 
00582         bool bNegate = false;
00583         if (*flag == '!')
00584         {
00585             bNegate = true;
00586             do
00587             {
00588                 flag++;
00589             } while (mux_isspace(*flag));
00590         }
00591 
00592         // Beginning of flag name is now 'flag'.
00593         //
00594         char *nflag = flag;
00595         while (  *nflag != '\0'
00596               && !mux_isspace(*nflag))
00597         {
00598             nflag++;
00599         }
00600         if (*nflag == '\0')
00601         {
00602             bDone = true;
00603         }
00604         else
00605         {
00606             *nflag = '\0';
00607         }
00608 
00609         // Make sure a flag name was specified.
00610         //
00611         if (*flag == '\0')
00612         {
00613             if (bNegate)
00614             {
00615                 notify(player, "You must specify a flag to clear.");
00616             }
00617             else
00618             {
00619                 notify(player, "You must specify a flag to set.");
00620             }
00621         }
00622         else
00623         {
00624             FLAGNAMEENT *fp = find_flag(flag);
00625             if (!fp)
00626             {
00627                 notify(player, "I do not understand that flag.");
00628             }
00629             else
00630             {
00631                 FLAGBITENT *fbe = fp->fbe;
00632 
00633                 bool bClearSet = bNegate;
00634                 if (!fp->bPositive)
00635                 {
00636                     bNegate = !bNegate;
00637                 }
00638 
00639                 // Invoke the flag handler, and print feedback.
00640                 //
00641                 if (!fbe->handler(target, player, fbe->flagvalue, fbe->flagflag, bNegate))
00642                 {
00643                     notify(player, NOPERM_MESSAGE);
00644                 }
00645                 else if (!(key & SET_QUIET) && !Quiet(player))
00646                 {
00647                     notify(player, (bClearSet ? "Cleared." : "Set."));
00648                 }
00649             }
00650         }
00651         flag = nflag + 1;
00652 
00653     } while (!bDone);
00654 }
00655 
00656 /*
00657  * ---------------------------------------------------------------------------
00658  * * decode_flags: converts a flags word into corresponding letters.
00659  */
00660 
00661 char *decode_flags(dbref player, FLAGSET *fs)
00662 {
00663     char *buf, *bp;
00664     buf = bp = alloc_sbuf("decode_flags");
00665     *bp = '\0';
00666 
00667     if (!Good_obj(player))
00668     {
00669         strcpy(buf, "#-2 ERROR");
00670         return buf;
00671     }
00672     int flagtype = fs->word[FLAG_WORD1] & TYPE_MASK;
00673     bool bNeedColon = true;
00674     if (object_types[flagtype].lett != ' ')
00675     {
00676         safe_sb_chr(object_types[flagtype].lett, buf, &bp);
00677         bNeedColon = false;
00678     }
00679 
00680     FLAGNAMEENT *fp;
00681     for (fp = gen_flag_names; fp->flagname; fp++)
00682     {
00683         FLAGBITENT *fbe = fp->fbe;
00684         if (  !fp->bPositive
00685            || fbe->flaglett == ' ')
00686         {
00687             // Only look at positive-sense entries that have non-space flag
00688             // letters.
00689             //
00690             continue;
00691         }
00692         if (fs->word[fbe->flagflag] & fbe->flagvalue)
00693         {
00694             if (  (  (fbe->listperm & CA_STAFF)
00695                   && !Staff(player))
00696                || (  (fbe->listperm & CA_ADMIN)
00697                   && !WizRoy(player))
00698                || (  (fbe->listperm & CA_WIZARD)
00699                   && !Wizard(player))
00700                || (  (fbe->listperm & CA_GOD)
00701                   && !God(player)))
00702             {
00703                 continue;
00704             }
00705 
00706             // Don't show CONNECT on dark wizards to mortals
00707             //
00708             if (  flagtype == TYPE_PLAYER
00709                && fbe->flagflag == FLAG_WORD2
00710                && fbe->flagvalue == CONNECTED
00711                && (fs->word[FLAG_WORD1] & (WIZARD | DARK)) == (WIZARD | DARK)
00712                && !See_Hidden(player))
00713             {
00714                 continue;
00715             }
00716 
00717             if (  bNeedColon
00718                && mux_isdigit(fbe->flaglett))
00719             {
00720                 // We can't allow numerical digits at the beginning.
00721                 //
00722                 safe_sb_chr(':', buf, &bp);
00723             }
00724             safe_sb_chr(fbe->flaglett, buf, &bp);
00725             bNeedColon = false;
00726         }
00727     }
00728     *bp = '\0';
00729     return buf;
00730 }
00731 
00732 /*
00733  * ---------------------------------------------------------------------------
00734  * * has_flag: does object have flag visible to player?
00735  */
00736 
00737 bool has_flag(dbref player, dbref it, char *flagname)
00738 {
00739     FLAGNAMEENT *fp = find_flag(flagname);
00740     if (!fp)
00741     {
00742         return false;
00743     }
00744     FLAGBITENT *fbe = fp->fbe;
00745 
00746     if (  (  fp->bPositive
00747           && (db[it].fs.word[fbe->flagflag] & fbe->flagvalue))
00748        || (  !fp->bPositive
00749           && (db[it].fs.word[fbe->flagflag] & fbe->flagvalue) == 0))
00750     {
00751         if (  (  (fbe->listperm & CA_STAFF)
00752               && !Staff(player))
00753            || (  (fbe->listperm & CA_ADMIN)
00754               && !WizRoy(player))
00755            || (  (fbe->listperm & CA_WIZARD)
00756               && !Wizard(player))
00757            || (  (fbe->listperm & CA_GOD)
00758               && !God(player)))
00759         {
00760             return false;
00761         }
00762 
00763         // Don't show CONNECT on dark wizards to mortals
00764         //
00765         if (  isPlayer(it)
00766            && (fbe->flagvalue == CONNECTED)
00767            && (fbe->flagflag == FLAG_WORD2)
00768            && Hidden(it)
00769            && !See_Hidden(player))
00770         {
00771             return false;
00772         }
00773         return true;
00774     }
00775     return false;
00776 }
00777 
00778 /*
00779  * ---------------------------------------------------------------------------
00780  * * flag_description: Return an mbuf containing the type and flags on thing.
00781  */
00782 
00783 char *flag_description(dbref player, dbref target)
00784 {
00785     // Allocate the return buffer.
00786     //
00787     int otype = Typeof(target);
00788     char *buff = alloc_mbuf("flag_description");
00789     char *bp = buff;
00790 
00791     // Store the header strings and object type.
00792     //
00793     safe_mb_str("Type: ", buff, &bp);
00794     safe_mb_str(object_types[otype].name, buff, &bp);
00795     safe_mb_str(" Flags:", buff, &bp);
00796     if (object_types[otype].perm != CA_PUBLIC)
00797     {
00798         *bp = '\0';
00799         return buff;
00800     }
00801 
00802     // Store the type-invariant flags.
00803     //
00804     FLAGNAMEENT *fp;
00805     for (fp = gen_flag_names; fp->flagname; fp++)
00806     {
00807         if (!fp->bPositive)
00808         {
00809             continue;
00810         }
00811         FLAGBITENT *fbe = fp->fbe;
00812         if (db[target].fs.word[fbe->flagflag] & fbe->flagvalue)
00813         {
00814             if (  (  (fbe->listperm & CA_STAFF)
00815                   && !Staff(player))
00816                || (  (fbe->listperm & CA_ADMIN)
00817                   && !WizRoy(player))
00818                || (  (fbe->listperm & CA_WIZARD)
00819                   && !Wizard(player))
00820                || (  (fbe->listperm & CA_GOD)
00821                   && !God(player)))
00822             {
00823                 continue;
00824             }
00825 
00826             // Don't show CONNECT on dark wizards to mortals.
00827             //
00828             if (  isPlayer(target)
00829                && (fbe->flagvalue == CONNECTED)
00830                && (fbe->flagflag == FLAG_WORD2)
00831                && Hidden(target)
00832                && !See_Hidden(player))
00833             {
00834                 continue;
00835             }
00836             safe_mb_chr(' ', buff, &bp);
00837             safe_mb_str(fp->flagname, buff, &bp);
00838         }
00839     }
00840 
00841     // Terminate the string, and return the buffer to the caller.
00842     //
00843     *bp = '\0';
00844     return buff;
00845 }
00846 
00847 /*
00848  * ---------------------------------------------------------------------------
00849  * * Return an lbuf containing the name and number of an object
00850  */
00851 
00852 char *unparse_object_numonly(dbref target)
00853 {
00854     char *buf = alloc_lbuf("unparse_object_numonly");
00855     if (target < 0)
00856     {
00857         strcpy(buf, aszSpecialDBRefNames[-target]);
00858     }
00859     else if (!Good_obj(target))
00860     {
00861         sprintf(buf, "*ILLEGAL*(#%d)", target);
00862     }
00863     else
00864     {
00865         // Leave 100 bytes on the end for the dbref.
00866         //
00867         int vw;
00868         size_t nLen = ANSI_TruncateToField(Name(target), LBUF_SIZE-100,
00869             buf, LBUF_SIZE, &vw, ANSI_ENDGOAL_NORMAL);
00870         char *bp = buf + nLen;
00871 
00872         safe_str("(#", buf, &bp);
00873         safe_ltoa(target, buf, &bp);
00874         safe_chr(')', buf, &bp);
00875         *bp = '\0';
00876     }
00877     return buf;
00878 }
00879 
00880 /*
00881  * ---------------------------------------------------------------------------
00882  * * Return an lbuf pointing to the object name and possibly the db# and flags
00883  */
00884 char *unparse_object(dbref player, dbref target, bool obey_myopic)
00885 {
00886     char *buf = alloc_lbuf("unparse_object");
00887     if (NOPERM <= target && target < 0)
00888     {
00889         strcpy(buf, aszSpecialDBRefNames[-target]);
00890     }
00891     else if (!Good_obj(target))
00892     {
00893         sprintf(buf, "*ILLEGAL*(#%d)", target);
00894     }
00895     else
00896     {
00897         bool exam;
00898         if (obey_myopic)
00899         {
00900             exam = MyopicExam(player, target);
00901         }
00902         else
00903         {
00904             exam = Examinable(player, target);
00905         }
00906         if (  exam
00907            || (Flags(target) & (CHOWN_OK | JUMP_OK | LINK_OK | DESTROY_OK))
00908            || (Flags2(target) & ABODE))
00909         {
00910             // show everything
00911             //
00912             char *fp = decode_flags(player, &(db[target].fs));
00913 
00914             // Leave 100 bytes on the end for the dbref and flags.
00915             //
00916             int vw;
00917             size_t nLen = ANSI_TruncateToField(Moniker(target), LBUF_SIZE-100,
00918                 buf, LBUF_SIZE, &vw, ANSI_ENDGOAL_NORMAL);
00919             char *bp = buf + nLen;
00920 
00921             safe_str("(#", buf, &bp);
00922             safe_ltoa(target, buf, &bp);
00923             safe_str(fp, buf, &bp);
00924             safe_chr(')', buf, &bp);
00925             *bp = '\0';
00926 
00927             free_sbuf(fp);
00928         }
00929         else
00930         {
00931             // show only the name.
00932             //
00933             strcpy(buf, Moniker(target));
00934         }
00935     }
00936     return buf;
00937 }
00938 
00939 /* ---------------------------------------------------------------------------
00940  * cf_flag_access: Modify who can set a flag.
00941  */
00942 
00943 CF_HAND(cf_flag_access)
00944 {
00945     UNUSED_PARAMETER(vp);
00946     UNUSED_PARAMETER(pExtra);
00947     UNUSED_PARAMETER(nExtra);
00948 
00949     MUX_STRTOK_STATE tts;
00950     mux_strtok_src(&tts, str);
00951     mux_strtok_ctl(&tts, " \t=,");
00952     char *fstr = mux_strtok_parse(&tts);
00953     char *permstr = mux_strtok_parse(&tts);
00954 
00955     if (!fstr || !*fstr)
00956     {
00957         return -1;
00958     }
00959 
00960     FLAGNAMEENT *fp;
00961     if ((fp = find_flag(fstr)) == NULL)
00962     {
00963         cf_log_notfound(player, cmd, "No such flag", fstr);
00964         return -1;
00965     }
00966     FLAGBITENT *fbe = fp->fbe;
00967 
00968     // Don't change the handlers on special things.
00969     //
00970     if (  (fbe->handler != fh_any)
00971        && (fbe->handler != fh_wizroy)
00972        && (fbe->handler != fh_wiz)
00973        && (fbe->handler != fh_god)
00974        && (fbe->handler != fh_restrict_player)
00975        && (fbe->handler != fh_privileged))
00976     {
00977         STARTLOG(LOG_CONFIGMODS, "CFG", "PERM");
00978         log_text("Cannot change access for flag: ");
00979         log_text(fp->flagname);
00980         ENDLOG;
00981         return -1;
00982     }
00983 
00984     if (!strcmp(permstr, "any"))
00985     {
00986         fbe->handler = fh_any;
00987     }
00988     else if (!strcmp(permstr, "royalty"))
00989     {
00990         fbe->handler = fh_wizroy;
00991     }
00992     else if (!strcmp(permstr, "wizard"))
00993     {
00994         fbe->handler = fh_wiz;
00995     }
00996     else if (!strcmp(permstr, "god"))
00997     {
00998         fbe->handler = fh_god;
00999     }
01000     else if (!strcmp(permstr, "restrict_player"))
01001     {
01002         fbe->handler = fh_restrict_player;
01003     }
01004     else if (!strcmp(permstr, "privileged"))
01005     {
01006         fbe->handler = fh_privileged;
01007     }
01008     else if (!strcmp(permstr, "staff"))
01009     {
01010         fbe->handler = fh_staff;
01011     }
01012     else
01013     {
01014         cf_log_notfound(player, cmd, "Flag access", permstr);
01015         return -1;
01016     }
01017     return 0;
01018 }
01019 
01020 /*
01021  * ---------------------------------------------------------------------------
01022  * * convert_flags: convert a list of flag letters into its bit pattern.
01023  * * Also set the type qualifier if specified and not already set.
01024  */
01025 
01026 bool convert_flags(dbref player, char *flaglist, FLAGSET *fset, FLAG *p_type)
01027 {
01028     FLAG type = NOTYPE;
01029     FLAGSET flagmask;
01030     flagmask.word[FLAG_WORD1] = 0;
01031     flagmask.word[FLAG_WORD2] = 0;
01032     flagmask.word[FLAG_WORD3] = 0;
01033     int i;
01034 
01035     char *s;
01036     bool handled;
01037     for (s = flaglist; *s; s++)
01038     {
01039         handled = false;
01040 
01041         // Check for object type.
01042         //
01043         for (i = 0; i <= 7 && !handled; i++)
01044         {
01045             if (  object_types[i].lett == *s
01046                && !(  (  (object_types[i].perm & CA_STAFF)
01047                       && !Staff(player))
01048                    || (  (object_types[i].perm & CA_ADMIN)
01049                       && !WizRoy(player))
01050                    || (  (object_types[i].perm & CA_WIZARD)
01051                       && !Wizard(player))
01052                    || (  (object_types[i].perm & CA_GOD)
01053                       && !God(player))))
01054             {
01055                 if (  type != NOTYPE
01056                    && type != i)
01057                 {
01058                     char *p = tprintf("%c: Conflicting type specifications.",
01059                         *s);
01060                     notify(player, p);
01061                     return false;
01062                 }
01063                 type = i;
01064                 handled = true;
01065             }
01066         }
01067 
01068         // Check generic flags.
01069         //
01070         if (handled)
01071         {
01072             continue;
01073         }
01074         FLAGNAMEENT *fp;
01075         for (fp = gen_flag_names; fp->flagname && !handled; fp++)
01076         {
01077             FLAGBITENT *fbe = fp->fbe;
01078             if (  !fp->bPositive
01079                || fbe->flaglett == ' ')
01080             {
01081                 continue;
01082             }
01083             if (  fbe->flaglett == *s
01084                && !(  (  (fbe->listperm & CA_STAFF)
01085                       && !Staff(player))
01086                    || (  (fbe->listperm & CA_ADMIN)
01087                       && !WizRoy(player))
01088                    || (  (fbe->listperm & CA_WIZARD)
01089                       && !Wizard(player))
01090                    || (  (fbe->listperm & CA_GOD)
01091                       && !God(player))))
01092             {
01093                 flagmask.word[fbe->flagflag] |= fbe->flagvalue;
01094                 handled = true;
01095             }
01096         }
01097 
01098         if (!handled)
01099         {
01100             notify(player,
01101                    tprintf("%c: Flag unknown or not valid for specified object type",
01102                        *s));
01103             return false;
01104         }
01105     }
01106 
01107     // Return flags to search for and type.
01108     //
01109     *fset = flagmask;
01110     *p_type = type;
01111     return true;
01112 }
01113 
01114 /*
01115  * ---------------------------------------------------------------------------
01116  * * decompile_flags: Produce commands to set flags on target.
01117  */
01118 
01119 void decompile_flags(dbref player, dbref thing, char *thingname)
01120 {
01121     // Report generic flags.
01122     //
01123     FLAGNAMEENT *fp;
01124     for (fp = gen_flag_names; fp->flagname; fp++)
01125     {
01126         FLAGBITENT *fbe = fp->fbe;
01127 
01128         // Only handle positive-sense entries.
01129         // Skip if we shouldn't decompile this flag.
01130         // Skip if this flag isn't set.
01131         // Skip if we can't see this flag.
01132         //
01133         if (  !fp->bPositive
01134            || (fbe->listperm & CA_NO_DECOMP)
01135            || (db[thing].fs.word[fbe->flagflag] & fbe->flagvalue) == 0
01136            || !check_access(player, fbe->listperm))
01137         {
01138             continue;
01139         }
01140 
01141         // Report this flag.
01142         //
01143         notify(player, tprintf("@set %s=%s", strip_ansi(thingname),
01144             fp->flagname));
01145     }
01146 }
01147 
01148 // do_flag: Rename flags or remove flag aliases.
01149 // Based on RhostMUSH code.
01150 //
01151 static bool flag_rename(char *alias, char *newname)
01152 {
01153     int nAlias;
01154     bool bValidAlias;
01155     char *pCheckedAlias = MakeCanonicalFlagName(alias, &nAlias, &bValidAlias);
01156     if (!bValidAlias)
01157     {
01158         return false;
01159     }
01160     char *pAlias = alloc_sbuf("flag_rename.old");
01161     memcpy(pAlias, pCheckedAlias, nAlias+1);
01162 
01163     int nNewName;
01164     bool bValidNewName;
01165     char *pCheckedNewName = MakeCanonicalFlagName(newname, &nNewName, &bValidNewName);
01166     if (!bValidNewName)
01167     {
01168         free_sbuf(pAlias);
01169         return false;
01170     }
01171     char *pNewName = alloc_sbuf("flag_rename.new");
01172     memcpy(pNewName, pCheckedNewName, nNewName+1);
01173 
01174     FLAGNAMEENT *flag1;
01175     flag1 = (FLAGNAMEENT *)hashfindLEN(pAlias, nAlias, &mudstate.flags_htab);
01176     if (flag1 != NULL)
01177     {
01178         FLAGNAMEENT *flag2;
01179         flag2 = (FLAGNAMEENT *)hashfindLEN(pNewName, nNewName, &mudstate.flags_htab);
01180         if (flag2 == NULL)
01181         {
01182             hashaddLEN(pNewName, nNewName, flag1, &mudstate.flags_htab);
01183 
01184             if (flag1->flagname != flag1->pOrigName)
01185             {
01186                 MEMFREE(flag1->flagname);
01187             }
01188             flag1->flagname = StringCloneLen(pNewName, nNewName);
01189             mux_strupr(flag1->flagname);
01190 
01191             free_sbuf(pAlias);
01192             free_sbuf(pNewName);
01193             return true;
01194         }
01195     }
01196     free_sbuf(pAlias);
01197     free_sbuf(pNewName);
01198     return false;
01199 }
01200 
01201 void do_flag(dbref executor, dbref caller, dbref enactor, int key, int nargs,
01202              char *flag1, char *flag2)
01203 {
01204     UNUSED_PARAMETER(caller);
01205     UNUSED_PARAMETER(enactor);
01206 
01207     if (key & FLAG_REMOVE)
01208     {
01209         if (nargs == 2)
01210         {
01211             notify(executor, "Extra argument ignored.");
01212         }
01213         int nAlias;
01214         bool bValidAlias;
01215         char *pCheckedAlias = MakeCanonicalFlagName(flag1, &nAlias, &bValidAlias);
01216         if (bValidAlias)
01217         {
01218             FLAGNAMEENT *lookup;
01219             lookup = (FLAGNAMEENT *)hashfindLEN(pCheckedAlias, nAlias, &mudstate.flags_htab);
01220             if (lookup)
01221             {
01222                 if (  lookup->flagname != lookup->pOrigName
01223                    && mux_stricmp(lookup->flagname, pCheckedAlias) == 0)
01224                 {
01225                     MEMFREE(lookup->flagname);
01226                     lookup->flagname = lookup->pOrigName;
01227                     hashdeleteLEN(pCheckedAlias, nAlias, &mudstate.flags_htab);
01228                     notify(executor, tprintf("Flag name '%s' removed from the hash table.", pCheckedAlias));
01229                 }
01230                 else
01231                 {
01232                     notify(executor, "Error: You can't remove the present flag name from the hash table.");
01233                 }
01234             }
01235         }
01236     }
01237     else
01238     {
01239         if (nargs < 2)
01240         {
01241             notify(executor, "You must specify a flag and a name.");
01242             return;
01243         }
01244         if (flag_rename(flag1, flag2))
01245         {
01246             notify(executor, "Flag name changed.");
01247         }
01248         else
01249         {
01250             notify(executor, "Error: Bad flagname given or flag not found.");
01251         }
01252     }
01253 }
01254 
01255 /* ---------------------------------------------------------------------------
01256  * cf_flag_name: Rename a flag. Counterpart to @flag.
01257  */
01258 
01259 CF_HAND(cf_flag_name)
01260 {
01261     UNUSED_PARAMETER(vp);
01262     UNUSED_PARAMETER(pExtra);
01263     UNUSED_PARAMETER(nExtra);
01264     UNUSED_PARAMETER(player);
01265     UNUSED_PARAMETER(cmd);
01266 
01267     MUX_STRTOK_STATE tts;
01268     mux_strtok_src(&tts, str);
01269     mux_strtok_ctl(&tts, " \t=,");
01270     char *flagstr = mux_strtok_parse(&tts);
01271     char *namestr = mux_strtok_parse(&tts);
01272 
01273     if (  !flagstr
01274        || !*flagstr
01275        || !namestr
01276        || !*namestr)
01277     {
01278         return -1;
01279     }
01280 
01281     if (flag_rename(flagstr, namestr))
01282     {
01283         return 0;
01284     }
01285     else
01286     {
01287         return -1;
01288     }
01289 }

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