00001
00002
00003
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
00016
00017
00018 static bool ph_any(dbref target, dbref player, POWER power, int fpowers, bool reset)
00019 {
00020 UNUSED_PARAMETER(player);
00021
00022 if (fpowers & POWER_EXT)
00023 {
00024 if (reset)
00025 {
00026 s_Powers2(target, Powers2(target) & ~power);
00027 }
00028 else
00029 {
00030 s_Powers2(target, Powers2(target) | power);
00031 }
00032 }
00033 else
00034 {
00035 if (reset)
00036 {
00037 s_Powers(target, Powers(target) & ~power);
00038 }
00039 else
00040 {
00041 s_Powers(target, Powers(target) | power);
00042 }
00043 }
00044 return true;
00045 }
00046
00047
00048
00049
00050
00051 static bool ph_god(dbref target, dbref player, POWER power, int fpowers, bool reset)
00052 {
00053 if (!God(player))
00054 {
00055 return false;
00056 }
00057 return (ph_any(target, player, power, fpowers, reset));
00058 }
00059
00060
00061
00062
00063
00064 static bool ph_wiz(dbref target, dbref player, POWER power, int fpowers, bool reset)
00065 {
00066 if (!Wizard(player))
00067 {
00068 return false;
00069 }
00070 return (ph_any(target, player, power, fpowers, reset));
00071 }
00072
00073 #if 0
00074
00075
00076
00077
00078
00079 bool ph_wizroy(dbref target, dbref player, POWER power, int fpowers, bool reset)
00080 {
00081 if (!WizRoy(player))
00082 {
00083 return false;
00084 }
00085 return (ph_any(target, player, power, fpowers, reset));
00086 }
00087
00088
00089
00090
00091
00092 bool ph_inherit(dbref target, dbref player, POWER power, int fpowers, bool reset)
00093 {
00094 if (!Inherits(player))
00095 {
00096 return false;
00097 }
00098 return (ph_any(target, player, power, fpowers, reset));
00099 }
00100 #endif
00101
00102 static POWERENT gen_powers[] =
00103 {
00104 {"announce", POW_ANNOUNCE, 0, 0, ph_wiz},
00105 {"boot", POW_BOOT, 0, 0, ph_wiz},
00106 {"builder", POW_BUILDER, POWER_EXT, 0, ph_wiz},
00107 {"chown_anything", POW_CHOWN_ANY, 0, 0, ph_wiz},
00108 {"comm_all", POW_COMM_ALL, 0, 0, ph_wiz},
00109 {"control_all", POW_CONTROL_ALL,0, 0, ph_god},
00110 {"expanded_who", POW_WIZARD_WHO, 0, 0, ph_wiz},
00111 {"find_unfindable", POW_FIND_UNFIND,0, 0, ph_wiz},
00112 {"free_money", POW_FREE_MONEY, 0, 0, ph_wiz},
00113 {"free_quota", POW_FREE_QUOTA, 0, 0, ph_wiz},
00114 {"guest", POW_GUEST, 0, 0, ph_god},
00115 {"halt", POW_HALT, 0, 0, ph_wiz},
00116 {"hide", POW_HIDE, 0, 0, ph_wiz},
00117 {"idle", POW_IDLE, 0, 0, ph_wiz},
00118 #ifdef FIRANMUX
00119 {"immutable", POW_IMMUTABLE, POWER_EXT, 0, ph_wiz},
00120 #endif
00121 {"long_fingers", POW_LONGFINGERS,0, 0, ph_wiz},
00122 {"monitor", POW_MONITOR, 0, 0, ph_wiz},
00123 {"no_destroy", POW_NO_DESTROY, 0, 0, ph_wiz},
00124 {"pass_locks", POW_PASS_LOCKS, 0, 0, ph_wiz},
00125 {"poll", POW_POLL, 0, 0, ph_wiz},
00126 {"prog", POW_PROG, 0, 0, ph_wiz},
00127 {"quota", POW_CHG_QUOTAS, 0, 0, ph_wiz},
00128 {"search", POW_SEARCH, 0, 0, ph_wiz},
00129 {"see_all", POW_EXAM_ALL, 0, 0, ph_wiz},
00130 {"see_hidden", POW_SEE_HIDDEN, 0, 0, ph_wiz},
00131 {"see_queue", POW_SEE_QUEUE, 0, 0, ph_wiz},
00132 {"siteadmin", POW_SITEADMIN, 0, 0, ph_wiz},
00133 {"stat_any", POW_STAT_ANY, 0, 0, ph_wiz},
00134 {"steal_money", POW_STEAL, 0, 0, ph_wiz},
00135 {"tel_anything", POW_TEL_UNRST, 0, 0, ph_wiz},
00136 {"tel_anywhere", POW_TEL_ANYWHR, 0, 0, ph_wiz},
00137 {"unkillable", POW_UNKILLABLE, 0, 0, ph_wiz},
00138 {NULL, 0, 0, 0, 0}
00139 };
00140
00141
00142
00143
00144
00145 void init_powertab(void)
00146 {
00147 POWERENT *fp;
00148 char *nbuf = alloc_sbuf("init_powertab");
00149
00150 for (fp = gen_powers; fp->powername; fp++)
00151 {
00152 strncpy(nbuf, fp->powername, SBUF_SIZE);
00153 nbuf[SBUF_SIZE-1] = '\0';
00154 mux_strlwr(nbuf);
00155
00156 if (!hashfindLEN(nbuf, strlen(nbuf), &mudstate.powers_htab))
00157 {
00158 hashaddLEN(nbuf, strlen(nbuf), fp, &mudstate.powers_htab);
00159 }
00160 }
00161 free_sbuf(nbuf);
00162 }
00163
00164
00165
00166
00167
00168 void display_powertab(dbref player)
00169 {
00170 char *buf, *bp;
00171 POWERENT *fp;
00172
00173 bp = buf = alloc_lbuf("display_powertab");
00174 safe_str("Powers:", buf, &bp);
00175 for (fp = gen_powers; fp->powername; fp++)
00176 {
00177 if ((fp->listperm & CA_WIZARD) && !Wizard(player))
00178 {
00179 continue;
00180 }
00181 if ((fp->listperm & CA_GOD) && !God(player))
00182 {
00183 continue;
00184 }
00185 safe_chr(' ', buf, &bp);
00186 safe_str(fp->powername, buf, &bp);
00187 }
00188 *bp = '\0';
00189 notify(player, buf);
00190 free_lbuf(buf);
00191 }
00192
00193 static POWERENT *find_power(dbref thing, char *powername)
00194 {
00195 UNUSED_PARAMETER(thing);
00196
00197
00198
00199 char *buff = alloc_sbuf("find_power");
00200 strncpy(buff, powername, SBUF_SIZE);
00201 buff[SBUF_SIZE-1] = '\0';
00202 mux_strlwr(buff);
00203 POWERENT *p = (POWERENT *)hashfindLEN(buff, strlen(buff), &mudstate.powers_htab);
00204 free_sbuf(buff);
00205 return p;
00206 }
00207
00208 bool decode_power(dbref player, char *powername, POWERSET *pset)
00209 {
00210 pset->word1 = 0;
00211 pset->word2 = 0;
00212
00213 POWERENT *pent = (POWERENT *)hashfindLEN(powername, strlen(powername), &mudstate.powers_htab);
00214 if (!pent)
00215 {
00216 notify(player, tprintf("%s: Power not found.", powername));
00217 return false;
00218 }
00219 if (pent->powerpower & POWER_EXT)
00220 {
00221 pset->word2 = pent->powervalue;
00222 }
00223 else
00224 {
00225 pset->word1 = pent->powervalue;
00226 }
00227 return true;
00228 }
00229
00230
00231
00232
00233
00234 void power_set(dbref target, dbref player, char *power, int key)
00235 {
00236
00237
00238 while (mux_isspace(*power))
00239 {
00240 power++;
00241 }
00242
00243 bool negate = false;
00244 if (*power == '!')
00245 {
00246 negate = true;
00247 power++;
00248 }
00249 while (mux_isspace(*power))
00250 {
00251 power++;
00252 }
00253
00254
00255
00256 if (*power == '\0')
00257 {
00258 if (negate)
00259 {
00260 notify(player, "You must specify a power to clear.");
00261 }
00262 else
00263 {
00264 notify(player, "You must specify a power to set.");
00265 }
00266 return;
00267 }
00268 POWERENT *fp = find_power(target, power);
00269 if (fp == NULL)
00270 {
00271 notify(player, "I don't understand that power.");
00272 return;
00273 }
00274
00275
00276
00277 bool result = fp->handler(target, player, fp->powervalue,
00278 fp->powerpower, negate);
00279 if (!result)
00280 {
00281 notify(player, NOPERM_MESSAGE);
00282 }
00283 else if (!(key & SET_QUIET) && !Quiet(player))
00284 {
00285 notify(player, (negate ? "Cleared." : "Set."));
00286 }
00287 }
00288
00289
00290
00291
00292
00293 bool has_power(dbref player, dbref it, char *powername)
00294 {
00295 POWERENT *fp = find_power(it, powername);
00296 if (!fp)
00297 {
00298 return false;
00299 }
00300
00301 POWER fv;
00302 if (fp->powerpower & POWER_EXT)
00303 {
00304 fv = Powers2(it);
00305 }
00306 else
00307 {
00308 fv = Powers(it);
00309 }
00310
00311 if (fv & fp->powervalue)
00312 {
00313 if ((fp->listperm & CA_WIZARD) && !Wizard(player))
00314 {
00315 return false;
00316 }
00317 if ((fp->listperm & CA_GOD) && !God(player))
00318 {
00319 return false;
00320 }
00321 return true;
00322 }
00323 return false;
00324 }
00325
00326
00327
00328
00329
00330 char *powers_list(dbref player, dbref target)
00331 {
00332
00333
00334 char *buff = alloc_lbuf("powers_list");
00335 char *bp = buff;
00336
00337 bool bFirst = true;
00338 POWERENT *fp;
00339 for (fp = gen_powers; fp->powername; fp++)
00340 {
00341 POWER fv;
00342 if (fp->powerpower & POWER_EXT)
00343 {
00344 fv = Powers2(target);
00345 }
00346 else
00347 {
00348 fv = Powers(target);
00349 }
00350
00351 if (fv & fp->powervalue)
00352 {
00353 if ( (fp->listperm & CA_WIZARD)
00354 && !Wizard(player))
00355 {
00356 continue;
00357 }
00358 if ( (fp->listperm & CA_GOD)
00359 && !God(player))
00360 {
00361 continue;
00362 }
00363 if (bFirst)
00364 {
00365 bFirst = false;
00366 }
00367 else
00368 {
00369 safe_chr(' ', buff, &bp);
00370 }
00371 safe_str(fp->powername, buff, &bp);
00372 }
00373 }
00374
00375
00376
00377 *bp = '\0';
00378 return buff;
00379 }
00380
00381
00382
00383
00384
00385
00386 void decompile_powers(dbref player, dbref thing, char *thingname)
00387 {
00388 POWERENT *fp;
00389
00390
00391
00392 POWER f1 = Powers(thing);
00393 POWER f2 = Powers2(thing);
00394
00395 for (fp = gen_powers; fp->powername; fp++)
00396 {
00397
00398
00399 if (fp->listperm & CA_NO_DECOMP)
00400 {
00401 continue;
00402 }
00403
00404
00405
00406 if (fp->powerpower & POWER_EXT)
00407 {
00408 if (!(f2 & fp->powervalue))
00409 {
00410 continue;
00411 }
00412 }
00413 else
00414 {
00415 if (!(f1 & fp->powervalue))
00416 {
00417 continue;
00418 }
00419 }
00420
00421
00422
00423 if (!check_access(player, fp->listperm))
00424 {
00425 continue;
00426 }
00427
00428
00429
00430 notify(player, tprintf("@power %s=%s", strip_ansi(thingname), fp->powername));
00431 }
00432 }