00001
00002
00003
00004
00005 #include "copyright.h"
00006 #include "config.h"
00007
00008 #include "mudconf.h"
00009 #include "config.h"
00010 #include "db.h"
00011 #include "match.h"
00012 #include "interface.h"
00013 #include "externs.h"
00014 #include "flags.h"
00015 #include "powers.h"
00016 #include "attrs.h"
00017 #include "alloc.h"
00018 #include "ansi.h"
00019 #include "p.comsys.h"
00020
00021 extern NAMETAB indiv_attraccess_nametab[];
00022 extern void lower_xp(dbref, int);
00023 extern char *silly_atr_get(int id, int flag);
00024 extern void silly_atr_set(int id, int flag, char *dat);
00025
00026 dbref match_controlled(dbref player, char *name)
00027 {
00028 dbref mat;
00029
00030 init_match(player, name, NOTYPE);
00031 match_everything(MAT_EXIT_PARENTS);
00032 mat = noisy_match_result();
00033 if(Good_obj(mat) && !Controls(player, mat)) {
00034 notify_quiet(player, "Permission denied.");
00035 return NOTHING;
00036 } else {
00037 return (mat);
00038 }
00039 }
00040
00041 dbref match_controlled_quiet(dbref player, char *name)
00042 {
00043 dbref mat;
00044
00045 init_match(player, name, NOTYPE);
00046 match_everything(MAT_EXIT_PARENTS);
00047 mat = match_result();
00048 if(Good_obj(mat) && !Controls(player, mat)) {
00049 return NOTHING;
00050 } else {
00051 return (mat);
00052 }
00053 }
00054
00055 dbref match_affected(dbref player, char *name)
00056 {
00057 dbref mat;
00058
00059 init_match(player, name, NOTYPE);
00060 match_everything(MAT_EXIT_PARENTS);
00061 mat = noisy_match_result();
00062 if(mat != NOTHING && !Affects(player, mat)) {
00063 notify_quiet(player, "Permission denied.");
00064 return NOTHING;
00065 } else {
00066 return (mat);
00067 }
00068 }
00069
00070 dbref match_examinable(dbref player, char *name)
00071 {
00072 dbref mat;
00073
00074 init_match(player, name, NOTYPE);
00075 match_everything(MAT_EXIT_PARENTS);
00076 mat = noisy_match_result();
00077 if(mat != NOTHING && !Examinable(player, mat)) {
00078 notify_quiet(player, "Permission denied.");
00079 return NOTHING;
00080 } else {
00081 return (mat);
00082 }
00083 }
00084
00085 void do_chzone(dbref player, dbref cause, int key, char *name, char *newobj)
00086 {
00087 dbref thing;
00088 dbref zone;
00089
00090 if(!mudconf.have_zones) {
00091 notify(player, "Zones disabled.");
00092 return;
00093 }
00094 init_match(player, name, NOTYPE);
00095 match_everything(0);
00096 if((thing = noisy_match_result()) == NOTHING)
00097 return;
00098
00099 if(!strcasecmp(newobj, "none"))
00100 zone = NOTHING;
00101 else {
00102 init_match(player, newobj, NOTYPE);
00103 match_everything(0);
00104 if((zone = noisy_match_result()) == NOTHING)
00105 return;
00106
00107 if((Typeof(zone) != TYPE_THING) && (Typeof(zone) != TYPE_ROOM)) {
00108 notify(player, "Invalid zone object type.");
00109 return;
00110 }
00111 }
00112
00113 if(!Wizard(player) && !(Controls(player, thing)) &&
00114 !(check_zone_for_player(player, thing)) &&
00115 !(db[player].owner == db[thing].owner)) {
00116 notify(player, "You don't have the power to shift reality.");
00117 return;
00118 }
00119
00120
00121
00122
00123
00124 if((zone != NOTHING) && !Wizard(player) && !(Controls(player, zone))
00125 && !(db[player].owner == db[zone].owner)) {
00126 notify(player, "You cannot move that object to that zone.");
00127 return;
00128 }
00129
00130
00131
00132 if((zone != NOTHING) && (Typeof(zone) == TYPE_ROOM) &&
00133 Typeof(thing) != TYPE_ROOM) {
00134 notify(player, "Only rooms may have parent rooms.");
00135 return;
00136 }
00137
00138
00139
00140 db[thing].zone = zone;
00141 if(Typeof(thing) != TYPE_PLAYER) {
00142
00143
00144
00145
00146
00147
00148 Flags(thing) &= ~WIZARD;
00149 Flags(thing) &= ~ROYALTY;
00150 Flags(thing) &= ~INHERIT;
00151 #ifdef USE_POWERS
00152 Powers(thing) = 0;
00153
00154
00155 #endif
00156 }
00157 notify(player, "Zone changed.");
00158 }
00159
00160 void do_name(dbref player, dbref cause, int key, char *name, char *newname)
00161 {
00162 dbref thing;
00163 char *buff;
00164 char *buff2;
00165 char new[LBUF_SIZE];
00166
00167 if((thing = match_controlled(player, name)) == NOTHING)
00168 return;
00169
00170
00171
00172
00173 strncpy(new, newname, LBUF_SIZE-1);
00174 if((*newname == '\0') || (strlen(strip_ansi_r(new,newname,strlen(newname))) == 0)) {
00175 notify_quiet(player, "Give it what new name?");
00176 return;
00177 }
00178
00179
00180
00181 if(isPlayer(thing)) {
00182
00183 buff = trim_spaces((char *) newname);
00184 if(!ok_player_name(buff) || !badname_check(buff)) {
00185 notify_quiet(player, "You can't use that name.");
00186 free_lbuf(buff);
00187 return;
00188 } else if(string_compare(buff, Name(thing)) &&
00189 (lookup_player(NOTHING, buff, 0) != NOTHING)) {
00190
00191
00192
00193
00194
00195 notify_quiet(player, "That name is already in use.");
00196 free_lbuf(buff);
00197 return;
00198 }
00199
00200 if(player == thing && In_Character(player) && !Wizard(player)) {
00201 buff2 = silly_atr_get(player, A_LASTNAME);
00202 if(!(buff2 && atoi(buff2) &&
00203 ((atoi(buff2) + (mudconf.namechange_days * 86400)) <
00204 mudstate.now)))
00205 lower_xp(player, 900);
00206
00207 silly_atr_set(player, A_LASTNAME, tprintf("%u", mudstate.now));
00208 }
00209
00210
00211
00212 STARTLOG(LOG_SECURITY, "SEC", "CNAME") {
00213 log_name(thing), log_text((char *) " renamed to ");
00214 log_text(buff);
00215 ENDLOG;
00216 }
00217 if(Suspect(thing)) {
00218 send_channel("Suspect", tprintf("%s renamed to %s",
00219 Name(thing), buff));
00220 }
00221 delete_player_name(thing, Name(thing));
00222
00223 s_Name(thing, buff);
00224 add_player_name(thing, Name(thing));
00225 if(!Quiet(player) && !Quiet(thing))
00226 notify_quiet(player, "Name set.");
00227 free_lbuf(buff);
00228 return;
00229 } else {
00230 if(!ok_name(newname)) {
00231 notify_quiet(player, "That is not a reasonable name.");
00232 return;
00233 }
00234
00235
00236
00237 s_Name(thing, newname);
00238 if(!Quiet(player) && !Quiet(thing))
00239 notify_quiet(player, "Name set.");
00240 }
00241 }
00242
00243
00244
00245
00246
00247
00248 void do_alias(dbref player, dbref cause, int key, char *name, char *alias)
00249 {
00250 dbref thing, aowner;
00251 int aflags;
00252 ATTR *ap;
00253 char *oldalias, *trimalias;
00254
00255 if((thing = match_controlled(player, name)) == NOTHING)
00256 return;
00257
00258
00259
00260
00261
00262 ap = atr_num(A_ALIAS);
00263 if(isPlayer(thing)) {
00264
00265
00266
00267
00268
00269 oldalias = atr_pget(thing, A_ALIAS, &aowner, &aflags);
00270 trimalias = trim_spaces(alias);
00271
00272 if(!Controls(player, thing)) {
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 notify_quiet(player, "Permission denied.");
00283 } else if(!*trimalias) {
00284
00285
00286
00287
00288
00289 delete_player_name(thing, oldalias);
00290 atr_clr(thing, A_ALIAS);
00291 if(!Quiet(player))
00292 notify_quiet(player, "Alias removed.");
00293 } else if(lookup_player(NOTHING, trimalias, 0) != NOTHING) {
00294
00295
00296
00297
00298
00299 notify_quiet(player, "That name is already in use.");
00300 } else if(!(badname_check(trimalias) && ok_player_name(trimalias))) {
00301 notify_quiet(player, "That's a silly name for a player!");
00302 } else {
00303
00304
00305
00306
00307
00308 delete_player_name(thing, oldalias);
00309 atr_add(thing, A_ALIAS, trimalias, Owner(player), aflags);
00310 if(add_player_name(thing, trimalias)) {
00311 if(!Quiet(player))
00312 notify_quiet(player, "Alias set.");
00313 } else {
00314 notify_quiet(player,
00315 "That name is already in use or is illegal, alias cleared.");
00316 atr_clr(thing, A_ALIAS);
00317 }
00318 }
00319 free_lbuf(trimalias);
00320 free_lbuf(oldalias);
00321 } else {
00322 atr_pget_info(thing, A_ALIAS, &aowner, &aflags);
00323
00324
00325
00326
00327
00328 if(!Set_attr(player, thing, ap, aflags)) {
00329 notify_quiet(player, "Permission denied.");
00330 } else {
00331 atr_add(thing, A_ALIAS, alias, Owner(player), aflags);
00332 if(!Quiet(player))
00333 notify_quiet(player, "Set.");
00334 }
00335 }
00336 }
00337
00338
00339
00340
00341
00342
00343 void do_lock(dbref player, dbref cause, int key, char *name, char *keytext)
00344 {
00345 dbref thing, aowner;
00346 int atr, aflags;
00347 ATTR *ap;
00348 struct boolexp *okey;
00349
00350 if(parse_attrib(player, name, &thing, &atr)) {
00351 if(atr != NOTHING) {
00352 if(!atr_get_info(thing, atr, &aowner, &aflags)) {
00353 notify_quiet(player, "Attribute not present on object.");
00354 return;
00355 }
00356 ap = atr_num(atr);
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 if(ap && (God(player) || (!God(thing) &&
00368 (Set_attr(player, player, ap, 0)
00369 && (Wizard(player)
00370 || aowner == Owner(player)))))) {
00371 aflags |= AF_LOCK;
00372 atr_set_flags(thing, atr, aflags);
00373 if(!Quiet(player) && !Quiet(thing))
00374 notify_quiet(player, "Attribute locked.");
00375 } else {
00376 notify_quiet(player, "Permission denied.");
00377 }
00378 return;
00379 }
00380 }
00381 init_match(player, name, NOTYPE);
00382 match_everything(MAT_EXIT_PARENTS);
00383 thing = match_result();
00384
00385 switch (thing) {
00386 case NOTHING:
00387 notify_quiet(player, "I don't see what you want to lock!");
00388 return;
00389 case AMBIGUOUS:
00390 notify_quiet(player, "I don't know which one you want to lock!");
00391 return;
00392 default:
00393 if(!controls(player, thing)) {
00394 notify_quiet(player, "You can't lock that!");
00395 return;
00396 }
00397 }
00398
00399 okey = parse_boolexp(player, keytext, 0);
00400 if(okey == TRUE_BOOLEXP) {
00401 notify_quiet(player, "I don't understand that key.");
00402 } else {
00403
00404
00405
00406
00407
00408 if(!key)
00409 key = A_LOCK;
00410 atr_add_raw(thing, key, unparse_boolexp_quiet(player, okey));
00411 if(!Quiet(player) && !Quiet(thing))
00412 notify_quiet(player, "Locked.");
00413 }
00414 free_boolexp(okey);
00415 }
00416
00417
00418
00419
00420
00421
00422 void do_unlock(dbref player, dbref cause, int key, char *name)
00423 {
00424 dbref thing, aowner;
00425 int atr, aflags;
00426 ATTR *ap;
00427
00428 if(parse_attrib(player, name, &thing, &atr)) {
00429 if(atr != NOTHING) {
00430 if(!atr_get_info(thing, atr, &aowner, &aflags)) {
00431 notify_quiet(player, "Attribute not present on object.");
00432 return;
00433 }
00434 ap = atr_num(atr);
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444 if(ap && (God(player) || ((!God(thing)) &&
00445 (Set_attr(player, player, ap, 0)
00446 && (Wizard(player)
00447 || aowner == Owner(player)))))) {
00448 aflags &= ~AF_LOCK;
00449 atr_set_flags(thing, atr, aflags);
00450 if(Owner(player != Owner(thing)))
00451 if(!Quiet(player) && !Quiet(thing))
00452 notify_quiet(player, "Attribute unlocked.");
00453 } else {
00454 notify_quiet(player, "Permission denied.");
00455 }
00456 return;
00457 }
00458 }
00459 if(!key)
00460 key = A_LOCK;
00461 if((thing = match_controlled(player, name)) != NOTHING) {
00462 atr_clr(thing, key);
00463 if(!Quiet(player) && !Quiet(thing))
00464 notify_quiet(player, "Unlocked.");
00465 }
00466 }
00467
00468
00469
00470
00471
00472
00473 void do_unlink(dbref player, dbref cause, int key, char *name)
00474 {
00475 dbref exit;
00476
00477 init_match(player, name, TYPE_EXIT);
00478 match_everything(0);
00479 exit = match_result();
00480
00481 switch (exit) {
00482 case NOTHING:
00483 notify_quiet(player, "Unlink what?");
00484 break;
00485 case AMBIGUOUS:
00486 notify_quiet(player, "I don't know which one you mean!");
00487 break;
00488 default:
00489 if(!controls(player, exit)) {
00490 notify_quiet(player, "Permission denied.");
00491 } else {
00492 switch (Typeof(exit)) {
00493 case TYPE_EXIT:
00494 s_Location(exit, NOTHING);
00495 if(!Quiet(player))
00496 notify_quiet(player, "Unlinked.");
00497 break;
00498 case TYPE_ROOM:
00499 s_Dropto(exit, NOTHING);
00500 if(!Quiet(player))
00501 notify_quiet(player, "Dropto removed.");
00502 break;
00503 default:
00504 notify_quiet(player, "You can't unlink that!");
00505 break;
00506 }
00507 }
00508 }
00509 }
00510
00511
00512
00513
00514
00515
00516 void do_chown(dbref player, dbref cause, int key, char *name, char *newown)
00517 {
00518 dbref thing, owner, aowner;
00519 int atr, aflags, do_it, cost, quota;
00520 ATTR *ap;
00521
00522 if(parse_attrib(player, name, &thing, &atr)) {
00523 if(atr != NOTHING) {
00524 if(!*newown) {
00525 owner = Owner(thing);
00526 } else if(!(string_compare(newown, "me"))) {
00527 owner = Owner(player);
00528 } else {
00529 owner = lookup_player(player, newown, 1);
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542 if(!atr_get_info(thing, atr, &aowner, &aflags)) {
00543 notify_quiet(player, "Attribute not present on object.");
00544 return;
00545 }
00546 do_it = 0;
00547 if(owner == NOTHING) {
00548 notify_quiet(player, "I couldn't find that player.");
00549 } else if(God(thing) && !God(player)) {
00550 notify_quiet(player, "Permission denied.");
00551 } else if(Wizard(player)) {
00552 do_it = 1;
00553 } else if(owner == Owner(player)) {
00554
00555
00556
00557
00558
00559
00560
00561 if(!Controls(player, thing) || (aflags & AF_LOCK)) {
00562 notify_quiet(player, "Permission denied.");
00563 } else {
00564 do_it = 1;
00565 }
00566 } else if(owner == Owner(thing)) {
00567
00568
00569
00570
00571
00572
00573
00574 if((Owner(player) != aowner) || (aflags & AF_LOCK)) {
00575 notify_quiet(player, "Permission denied.");
00576 } else {
00577 do_it = 1;
00578 }
00579 } else {
00580 notify_quiet(player, "Permission denied.");
00581 }
00582
00583 if(!do_it)
00584 return;
00585
00586 ap = atr_num(atr);
00587 if(!ap || !Set_attr(player, player, ap, aflags)) {
00588 notify_quiet(player, "Permission denied.");
00589 return;
00590 }
00591 atr_set_owner(thing, atr, owner);
00592 if(!Quiet(player))
00593 notify_quiet(player, "Attribute owner changed.");
00594 return;
00595 }
00596 }
00597 init_match(player, name, TYPE_THING);
00598 match_possession();
00599 match_here();
00600 match_exit();
00601 match_me();
00602 if(Chown_Any(player)) {
00603 match_player();
00604 match_absolute();
00605 }
00606 switch (thing = match_result()) {
00607 case NOTHING:
00608 notify_quiet(player, "You don't have that!");
00609 return;
00610 case AMBIGUOUS:
00611 notify_quiet(player, "I don't know which you mean!");
00612 return;
00613 }
00614
00615 if(!*newown || !(string_compare(newown, "me"))) {
00616 owner = Owner(player);
00617 } else {
00618 owner = lookup_player(player, newown, 1);
00619 }
00620
00621 cost = 1;
00622 quota = 1;
00623 switch (Typeof(thing)) {
00624 case TYPE_ROOM:
00625 cost = mudconf.digcost;
00626 quota = mudconf.room_quota;
00627 break;
00628 case TYPE_THING:
00629 cost = OBJECT_DEPOSIT(Pennies(thing));
00630 quota = mudconf.thing_quota;
00631 break;
00632 case TYPE_EXIT:
00633 cost = mudconf.opencost;
00634 quota = mudconf.exit_quota;
00635 break;
00636 case TYPE_PLAYER:
00637 cost = mudconf.robotcost;
00638 quota = mudconf.player_quota;
00639 }
00640
00641 if(owner == NOTHING) {
00642 notify_quiet(player, "I couldn't find that player.");
00643 } else if(isPlayer(thing) && !God(player)) {
00644 notify_quiet(player, "Players always own themselves.");
00645 } else if(((!controls(player, thing) && !Chown_Any(player) &&
00646 !Chown_ok(thing)) || (isThing(thing) &&
00647 (Location(thing) != player)
00648 && !Chown_Any(player)))
00649 || (!controls(player, owner))) {
00650 notify_quiet(player, "Permission denied.");
00651 } else if(canpayfees(player, owner, cost, quota)) {
00652 giveto(Owner(thing), cost);
00653 if(mudconf.quotas)
00654 add_quota(Owner(thing), quota);
00655 if(God(player)) {
00656 s_Owner(thing, owner);
00657 } else {
00658 s_Owner(thing, Owner(owner));
00659 }
00660 atr_chown(thing);
00661 s_Flags(thing, (Flags(thing) & ~(CHOWN_OK | INHERIT)) | HALT);
00662 s_Powers(thing, 0);
00663 s_Powers2(thing, 0);
00664 halt_que(NOTHING, thing);
00665 if(!Quiet(player))
00666 notify_quiet(player, "Owner changed.");
00667 }
00668 }
00669
00670
00671
00672
00673
00674
00675 void set_attr_internal(dbref player, dbref thing, int attrnum, char *attrtext,
00676 int key)
00677 {
00678 dbref aowner;
00679 int aflags, could_hear, have_xcode;
00680 ATTR *attr;
00681
00682 attr = atr_num(attrnum);
00683 atr_pget_info(thing, attrnum, &aowner, &aflags);
00684 if(attr && Set_attr(player, thing, attr, aflags)) {
00685 if((attr->check != NULL) &&
00686 (!(*attr->check) (0, player, thing, attrnum, attrtext)))
00687 return;
00688 have_xcode = Hardcode(thing);
00689 atr_add(thing, attrnum, attrtext, Owner(player), aflags);
00690 if(mudconf.have_specials)
00691 handle_xcode(player, thing, have_xcode, Hardcode(thing));
00692 if(!(key & SET_QUIET) && !Quiet(player) && !Quiet(thing))
00693 notify_printf(player, "%s/%s - %s", Name(thing),
00694 attr->name, strlen(attrtext) ? "Set." : "Cleared.");
00695 could_hear = Hearer(thing);
00696 handle_ears(thing, could_hear, Hearer(thing));
00697 } else {
00698 notify_quiet(player, "Permission denied.");
00699 }
00700 }
00701
00702 void do_set(dbref player, dbref cause, int key, char *name, char *flag)
00703 {
00704 dbref thing, thing2, aowner;
00705 char *p, *buff;
00706 int atr, atr2, aflags, clear, flagvalue, could_hear, have_xcode;
00707 ATTR *attr, *attr2;
00708
00709
00710
00711
00712
00713
00714 if(parse_attrib(player, name, &thing, &atr)) {
00715 if(atr != NOTHING) {
00716
00717
00718
00719
00720
00721 if(!flag || !*flag) {
00722 notify_quiet(player, "I don't know what you want to set!");
00723 return;
00724 }
00725
00726
00727
00728
00729 clear = 0;
00730 if(*flag == NOT_TOKEN) {
00731 flag++;
00732 clear = 1;
00733 }
00734
00735
00736
00737
00738 flagvalue =
00739 search_nametab(player, indiv_attraccess_nametab, flag);
00740 if(flagvalue < 0) {
00741 notify_quiet(player, "You can't set that!");
00742 return;
00743 }
00744
00745
00746
00747
00748 if(!atr_get_info(thing, atr, &aowner, &aflags)) {
00749 notify_quiet(player, "Attribute not present on object.");
00750 return;
00751 }
00752
00753
00754
00755
00756 attr = atr_num(atr);
00757 if(!attr || !Set_attr(player, thing, attr, aflags)) {
00758 notify_quiet(player, "Permission denied.");
00759 return;
00760 }
00761
00762
00763
00764
00765 if(clear)
00766 aflags &= ~flagvalue;
00767 else
00768 aflags |= flagvalue;
00769 have_xcode = Hardcode(thing);
00770 atr_set_flags(thing, atr, aflags);
00771
00772
00773
00774
00775
00776 if(mudconf.have_specials)
00777 handle_xcode(player, thing, have_xcode, Hardcode(thing));
00778 if(!(key & SET_QUIET) && !Quiet(player) && !Quiet(thing)) {
00779 NAMETAB *nt;
00780 nt = find_nametab_ent(player, indiv_attraccess_nametab, flag);
00781 notify_printf(player, "%s/%s - %s %s", Name(thing),
00782 attr->name, nt->name,
00783 clear ? "cleared." : "set.");
00784 }
00785 could_hear = Hearer(thing);
00786 handle_ears(thing, could_hear, Hearer(thing));
00787 return;
00788 }
00789 }
00790
00791
00792
00793
00794 if((thing = match_controlled(player, name)) == NOTHING)
00795 return;
00796
00797
00798
00799
00800 for(p = flag; *p && (*p != ':'); p++);
00801
00802 if(*p) {
00803 *p++ = 0;
00804 atr = mkattr(flag);
00805 if(atr <= 0) {
00806 notify_quiet(player, "Couldn't create attribute.");
00807 return;
00808 }
00809 attr = atr_num(atr);
00810 if(!attr) {
00811 notify_quiet(player, "Permission denied.");
00812 return;
00813 }
00814 atr_get_info(thing, atr, &aowner, &aflags);
00815 if(!Set_attr(player, thing, attr, aflags)) {
00816 notify_quiet(player, "Permission denied.");
00817 return;
00818 }
00819 buff = alloc_lbuf("do_set");
00820
00821
00822
00823
00824 if(*p == '_') {
00825 StringCopy(buff, p + 1);
00826 if(!parse_attrib(player, p + 1, &thing2, &atr2) ||
00827 (atr2 == NOTHING)) {
00828 notify_quiet(player, "No match.");
00829 free_lbuf(buff);
00830 return;
00831 }
00832 attr2 = atr_num(atr2);
00833 p = buff;
00834 atr_pget_str(buff, thing2, atr2, &aowner, &aflags);
00835
00836 if(!attr2 || !See_attr(player, thing2, attr2, aowner, aflags)) {
00837 notify_quiet(player, "Permission denied.");
00838 free_lbuf(buff);
00839 return;
00840 }
00841 }
00842
00843
00844
00845
00846 set_attr_internal(player, thing, atr, p, key);
00847 free_lbuf(buff);
00848 return;
00849 }
00850
00851
00852
00853
00854 flag_set(thing, player, flag, key);
00855 }
00856
00857 void do_power(dbref player, dbref cause, int key, char *name, char *flag)
00858 {
00859 dbref thing;
00860
00861 if(!flag || !*flag) {
00862 notify_quiet(player, "I don't know what you want to set!");
00863 return;
00864 }
00865
00866
00867
00868
00869 if((thing = match_controlled(player, name)) == NOTHING)
00870 return;
00871
00872 power_set(thing, player, flag, key);
00873 }
00874
00875 void do_setattr(dbref player, dbref cause, int attrnum, char *name,
00876 char *attrtext)
00877 {
00878 dbref thing;
00879
00880 init_match(player, name, NOTYPE);
00881 match_everything(MAT_EXIT_PARENTS);
00882 thing = noisy_match_result();
00883
00884 if(thing == NOTHING)
00885 return;
00886 set_attr_internal(player, thing, attrnum, attrtext, 0);
00887 }
00888
00889 void do_cpattr(dbref player, dbref cause, int key, char *oldpair,
00890 char *newpair[], int nargs)
00891 {
00892 int i;
00893 char *oldthing, *oldattr, *newthing, *newattr;
00894
00895 if(!*oldpair || !**newpair || !oldpair || !*newpair)
00896 return;
00897
00898 if(nargs < 1)
00899 return;
00900
00901 oldattr = oldpair;
00902 oldthing = parse_to(&oldattr, '/', 1);
00903
00904 for(i = 0; i < nargs; i++) {
00905 newattr = newpair[i];
00906 newthing = parse_to(&newattr, '/', 1);
00907
00908 if(!oldattr) {
00909 if(!newattr) {
00910 do_set(player, cause, 0, newthing, tprintf("%s:_%s/%s",
00911 oldthing, "me",
00912 oldthing));
00913 } else {
00914 do_set(player, cause, 0, newthing, tprintf("%s:_%s/%s",
00915 newattr, "me",
00916 oldthing));
00917 }
00918 } else {
00919 if(!newattr) {
00920 do_set(player, cause, 0, newthing, tprintf("%s:_%s/%s",
00921 oldattr, oldthing,
00922 oldattr));
00923 } else {
00924 do_set(player, cause, 0, newthing, tprintf("%s:_%s/%s",
00925 newattr, oldthing,
00926 oldattr));
00927 }
00928 }
00929 }
00930 }
00931
00932 void do_mvattr(dbref player, dbref cause, int key, char *what, char *args[],
00933 int nargs)
00934 {
00935 dbref thing, aowner, axowner;
00936 ATTR *in_attr, *out_attr;
00937 int i, anum, in_anum, aflags, axflags, no_delete;
00938 char *astr;
00939
00940
00941
00942
00943
00944 if(nargs < 2) {
00945 notify_quiet(player, "Nothing to do.");
00946 return;
00947 }
00948
00949
00950
00951
00952 thing = match_controlled(player, what);
00953 if(thing == NOTHING)
00954 return;
00955
00956
00957
00958
00959
00960
00961 in_anum = -1;
00962 astr = alloc_lbuf("do_mvattr");
00963 in_attr = atr_str(args[0]);
00964 if(in_attr == NULL) {
00965 *astr = '\0';
00966 } else {
00967 atr_get_str(astr, thing, in_attr->number, &aowner, &aflags);
00968 if(!See_attr(player, thing, in_attr, aowner, aflags)) {
00969 *astr = '\0';
00970 } else {
00971 in_anum = in_attr->number;
00972 }
00973 }
00974
00975
00976
00977
00978
00979 no_delete = 0;
00980 for(i = 1; i < nargs; i++) {
00981 anum = mkattr(args[i]);
00982 if(anum <= 0) {
00983 notify_quiet(player,
00984 tprintf
00985 ("%s: That's not a good name for an attribute.",
00986 args[i]));
00987 continue;
00988 }
00989 out_attr = atr_num(anum);
00990 if(!out_attr) {
00991 notify_quiet(player, tprintf("%s: Permission denied.", args[i]));
00992 } else if(out_attr->number == in_anum) {
00993 no_delete = 1;
00994 } else {
00995 atr_get_info(thing, out_attr->number, &axowner, &axflags);
00996 if(!Set_attr(player, thing, out_attr, axflags)) {
00997 notify_quiet(player, tprintf("%s: Permission denied.",
00998 args[i]));
00999 } else {
01000 atr_add(thing, out_attr->number, astr, Owner(player), aflags);
01001 if(!Quiet(player))
01002 notify_printf(player, "%s/%s - Set.", Name(thing),
01003 out_attr->name);
01004 }
01005 }
01006 }
01007
01008
01009
01010
01011
01012 if((in_anum > 0) && !no_delete) {
01013 in_attr = atr_num(in_anum);
01014 if(in_attr && Set_attr(player, thing, in_attr, aflags)) {
01015 atr_clr(thing, in_attr->number);
01016 if(!Quiet(player))
01017 notify_printf(player, "%s/%s - Cleared.", Name(thing),
01018 in_attr->name);
01019 } else {
01020 if(in_attr)
01021 notify_quiet(player,
01022 tprintf
01023 ("%s: Could not remove old attribute. Permission denied.",
01024 in_attr->name));
01025 }
01026 }
01027 free_lbuf(astr);
01028 }
01029
01030
01031
01032
01033
01034
01035 int parse_attrib(dbref player, char *str, dbref * thing, int *atr)
01036 {
01037 ATTR *attr;
01038 char *buff;
01039 dbref aowner;
01040 int aflags;
01041
01042 if(!str)
01043 return 0;
01044
01045
01046
01047
01048
01049 buff = alloc_lbuf("parse_attrib");
01050 StringCopy(buff, str);
01051 if(!parse_thing_slash(player, buff, &str, thing)) {
01052 free_lbuf(buff);
01053 return 0;
01054 }
01055
01056
01057
01058
01059 attr = atr_str(str);
01060 free_lbuf(buff);
01061 if(!attr) {
01062 *atr = NOTHING;
01063 } else {
01064 atr_pget_info(*thing, attr->number, &aowner, &aflags);
01065 if(!See_attr(player, *thing, attr, aowner, aflags)) {
01066 *atr = NOTHING;
01067 } else {
01068 *atr = attr->number;
01069 }
01070 }
01071 return 1;
01072 }
01073
01074 static void find_wild_attrs(dbref player, dbref thing, char *str,
01075 int check_exclude, int hash_insert, int get_locks)
01076 {
01077 ATTR *attr;
01078 char *as;
01079 dbref aowner;
01080 int ca, ok, aflags;
01081
01082
01083
01084
01085
01086 for(ca = atr_head(thing, &as); ca; ca = atr_next(&as)) {
01087 attr = atr_num(ca);
01088
01089
01090
01091
01092
01093 if(!attr)
01094 continue;
01095
01096 if(check_exclude && ((attr->flags & AF_PRIVATE) ||
01097 nhashfind(ca, &mudstate.parent_htab)))
01098 continue;
01099
01100
01101
01102
01103
01104
01105 atr_get_info(thing, ca, &aowner, &aflags);
01106 if(check_exclude && (aflags & AF_PRIVATE))
01107 continue;
01108
01109 if(get_locks)
01110 ok = Read_attr(player, thing, attr, aowner, aflags);
01111 else
01112 ok = See_attr(player, thing, attr, aowner, aflags);
01113
01114
01115
01116
01117
01118 if(ok && (attr->number == A_DESC) && !mudconf.read_rem_desc &&
01119 !Examinable(player, thing) && !nearby(player, thing))
01120 ok = 0;
01121
01122 if(ok && quick_wild(str, (char *) attr->name)) {
01123 olist_add(ca);
01124 if(hash_insert) {
01125 nhashadd(ca, (int *) attr, &mudstate.parent_htab);
01126 }
01127 }
01128 }
01129 }
01130
01131 int parse_attrib_wild(dbref player, char *str, dbref * thing,
01132 int check_parents, int get_locks, int df_star)
01133 {
01134 char *buff;
01135 dbref parent;
01136 int check_exclude, hash_insert, lev;
01137
01138 if(!str)
01139 return 0;
01140
01141 buff = alloc_lbuf("parse_attrib_wild");
01142 StringCopy(buff, str);
01143
01144
01145
01146
01147
01148 if(!parse_thing_slash(player, buff, &str, thing)) {
01149
01150
01151
01152
01153
01154 if(!df_star) {
01155 free_lbuf(buff);
01156 return 0;
01157 }
01158
01159
01160
01161
01162 init_match(player, buff, NOTYPE);
01163 match_everything(MAT_EXIT_PARENTS);
01164 *thing = match_result();
01165
01166 if(!Good_obj(*thing)) {
01167 free_lbuf(buff);
01168 return 0;
01169 }
01170 str = (char *) "*";
01171 }
01172
01173
01174
01175
01176 if(check_parents) {
01177 check_exclude = 0;
01178 hash_insert = check_parents;
01179 nhashflush(&mudstate.parent_htab, 0);
01180 ITER_PARENTS(*thing, parent, lev) {
01181 if(!Good_obj(Parent(parent)))
01182 hash_insert = 0;
01183 find_wild_attrs(player, parent, str, check_exclude,
01184 hash_insert, get_locks);
01185 check_exclude = 1;
01186 }
01187 } else {
01188 find_wild_attrs(player, *thing, str, 0, 0, get_locks);
01189 }
01190 free_lbuf(buff);
01191 return 1;
01192 }
01193
01194
01195
01196
01197
01198
01199 void edit_string(char *src, char **dst, char *from, char *to)
01200 {
01201 char *cp;
01202
01203
01204
01205
01206
01207 if(!strcmp(from, "^")) {
01208
01209
01210
01211
01212 *dst = alloc_lbuf("edit_string.^");
01213 cp = *dst;
01214 safe_str(to, *dst, &cp);
01215 safe_str(src, *dst, &cp);
01216 *cp = '\0';
01217 } else if(!strcmp(from, "$")) {
01218
01219
01220
01221
01222 *dst = alloc_lbuf("edit_string.$");
01223 cp = *dst;
01224 safe_str(src, *dst, &cp);
01225 safe_str(to, *dst, &cp);
01226 *cp = '\0';
01227 } else {
01228
01229
01230
01231
01232
01233 if(((from[0] == '\\') || (from[0] == '%')) && ((from[1] == '$') ||
01234 (from[1] == '^'))
01235 && (from[2] == '\0'))
01236 from++;
01237 *dst = replace_string(from, to, src);
01238 }
01239 }
01240
01241 void edit_string_ansi(char *src, char **dst, char **returnstr, char *from,
01242 char *to)
01243 {
01244 char *cp, *rp;
01245
01246
01247
01248
01249
01250 if(!strcmp(from, "^")) {
01251
01252
01253
01254
01255 *dst = alloc_lbuf("edit_string.^");
01256 cp = *dst;
01257 safe_str(to, *dst, &cp);
01258 safe_str(src, *dst, &cp);
01259 *cp = '\0';
01260
01261
01262
01263
01264 *returnstr = alloc_lbuf("edit_string_ansi.^");
01265 rp = *returnstr;
01266 safe_str(ANSI_HILITE, *returnstr, &rp);
01267 safe_str(to, *returnstr, &rp);
01268 safe_str(ANSI_NORMAL, *returnstr, &rp);
01269 safe_str(src, *returnstr, &rp);
01270 *rp = '\0';
01271
01272 } else if(!strcmp(from, "$")) {
01273
01274
01275
01276
01277 *dst = alloc_lbuf("edit_string.$");
01278 cp = *dst;
01279 safe_str(src, *dst, &cp);
01280 safe_str(to, *dst, &cp);
01281 *cp = '\0';
01282
01283
01284
01285
01286
01287 *returnstr = alloc_lbuf("edit_string_ansi.$");
01288 rp = *returnstr;
01289 safe_str(src, *returnstr, &rp);
01290 safe_str(ANSI_HILITE, *returnstr, &rp);
01291 safe_str(to, *returnstr, &rp);
01292 safe_str(ANSI_NORMAL, *returnstr, &rp);
01293 *rp = '\0';
01294
01295 } else {
01296
01297
01298
01299
01300
01301 if(((from[0] == '\\') || (from[0] == '%')) && ((from[1] == '$') ||
01302 (from[1] == '^'))
01303 && (from[2] == '\0'))
01304 from++;
01305
01306 *dst = replace_string(from, to, src);
01307 *returnstr =
01308 replace_string(from, tprintf("%s%s%s", ANSI_HILITE, to,
01309 ANSI_NORMAL), src);
01310 }
01311 }
01312
01313 void do_edit(dbref player, dbref cause, int key, char *it, char *args[],
01314 int nargs)
01315 {
01316 dbref thing, aowner;
01317 int attr, got_one, aflags, doit;
01318 char *from, *to, *result, *returnstr, *atext;
01319 ATTR *ap;
01320
01321
01322
01323
01324
01325 if((nargs < 1) || !*args[0]) {
01326 notify_quiet(player, "Nothing to do.");
01327 return;
01328 }
01329 from = args[0];
01330 to = (nargs >= 2) ? args[1] : (char *) "";
01331
01332
01333
01334
01335
01336 olist_push();
01337 if(!it || !*it || !parse_attrib_wild(player, it, &thing, 0, 0, 0)) {
01338 notify_quiet(player, "No match.");
01339 olist_pop();
01340 return;
01341 }
01342
01343
01344
01345
01346 got_one = 0;
01347 atext = alloc_lbuf("do_edit.atext");
01348
01349 for(attr = olist_first(); attr != NOTHING; attr = olist_next()) {
01350 ap = atr_num(attr);
01351 if(ap) {
01352
01353
01354
01355
01356
01357 atr_get_str(atext, thing, ap->number, &aowner, &aflags);
01358 if(Set_attr(player, thing, ap, aflags)) {
01359
01360
01361
01362
01363
01364 got_one = 1;
01365 edit_string_ansi(atext, &result, &returnstr, from, to);
01366 if(ap->check != NULL) {
01367 doit =
01368 (*ap->check) (0, player, thing, ap->number, result);
01369 } else {
01370 doit = 1;
01371 }
01372 if(doit) {
01373 atr_add(thing, ap->number, result, Owner(player), aflags);
01374 if(!Quiet(player))
01375 notify_quiet(player, tprintf("Set - %s: %s",
01376 ap->name, returnstr));
01377 }
01378 free_lbuf(result);
01379 free_lbuf(returnstr);
01380 } else {
01381
01382
01383
01384
01385
01386 notify_quiet(player, tprintf("%s: Permission denied.",
01387 ap->name));
01388 }
01389
01390 }
01391 }
01392
01393
01394
01395
01396
01397 free_lbuf(atext);
01398 olist_pop();
01399
01400 if(!got_one) {
01401 notify_quiet(player, "No matching attributes.");
01402 }
01403 }
01404
01405 void do_wipe(dbref player, dbref cause, int key, char *it)
01406 {
01407 dbref thing, aowner;
01408 int attr, got_one, aflags;
01409 ATTR *ap;
01410 char *atext;
01411
01412 olist_push();
01413 if(!it || !*it || !parse_attrib_wild(player, it, &thing, 0, 0, 1)) {
01414 notify_quiet(player, "No match.");
01415 olist_pop();
01416 return;
01417 }
01418
01419
01420
01421
01422 got_one = 0;
01423 atext = alloc_lbuf("do_wipe.atext");
01424 for(attr = olist_first(); attr != NOTHING; attr = olist_next()) {
01425 ap = atr_num(attr);
01426 if(ap) {
01427
01428
01429
01430
01431
01432 atr_get_str(atext, thing, ap->number, &aowner, &aflags);
01433 if(Set_attr(player, thing, ap, aflags)) {
01434 atr_clr(thing, ap->number);
01435 got_one++;
01436 }
01437 }
01438 }
01439
01440
01441
01442
01443 if(!got_one) {
01444 notify_quiet(player, "No matching attributes.");
01445 } else {
01446 if(!Quiet(player))
01447 notify_printf(player, "%s - %d attribute(s) wiped.", Name(thing), got_one);
01448 }
01449
01450 free_lbuf(atext);
01451 olist_pop();
01452
01453 }
01454
01455 void do_trigger(dbref player, dbref cause, int key, char *object,
01456 char *argv[], int nargs)
01457 {
01458 dbref thing;
01459 int attrib;
01460
01461 if(!parse_attrib(player, object, &thing, &attrib) || (attrib == NOTHING)) {
01462 notify_quiet(player, "No match.");
01463 return;
01464 }
01465 if(!controls(player, thing)) {
01466 notify_quiet(player, "Permission denied.");
01467 return;
01468 }
01469 did_it(player, thing, 0, NULL, 0, NULL, attrib, argv, nargs);
01470
01471
01472
01473
01474 if(!(key & TRIG_QUIET) && !Quiet(player))
01475 notify_quiet(player, "Triggered.");
01476
01477 }
01478
01479 void do_use(dbref player, dbref cause, int key, char *object)
01480 {
01481 char *df_use, *df_ouse, *temp;
01482 dbref thing, aowner;
01483 int aflags, doit;
01484
01485 init_match(player, object, NOTYPE);
01486 match_neighbor();
01487 match_possession();
01488 if(Wizard(player)) {
01489 match_absolute();
01490 match_player();
01491 }
01492 match_me();
01493 match_here();
01494 thing = noisy_match_result();
01495 if(thing == NOTHING)
01496 return;
01497
01498
01499
01500
01501
01502 if(!could_doit(player, thing, A_LUSE)) {
01503 did_it(player, thing, A_UFAIL,
01504 "You can't figure out how to use that.", A_OUFAIL, NULL,
01505 A_AUFAIL, (char **) NULL, 0);
01506 return;
01507 }
01508 temp = alloc_lbuf("do_use");
01509 doit = 0;
01510 if(*atr_pget_str(temp, thing, A_USE, &aowner, &aflags))
01511 doit = 1;
01512 else if(*atr_pget_str(temp, thing, A_OUSE, &aowner, &aflags))
01513 doit = 1;
01514 else if(*atr_pget_str(temp, thing, A_AUSE, &aowner, &aflags))
01515 doit = 1;
01516 free_lbuf(temp);
01517
01518 if(doit) {
01519 df_use = alloc_lbuf("do_use.use");
01520 df_ouse = alloc_lbuf("do_use.ouse");
01521 sprintf(df_use, "You use %s", Name(thing));
01522 sprintf(df_ouse, "uses %s", Name(thing));
01523 did_it(player, thing, A_USE, df_use, A_OUSE, df_ouse, A_AUSE,
01524 (char **) NULL, 0);
01525 free_lbuf(df_use);
01526 free_lbuf(df_ouse);
01527 } else {
01528 notify_quiet(player, "You can't figure out how to use that.");
01529 }
01530 }
01531
01532
01533
01534
01535
01536
01537 void do_setvattr(dbref player, dbref cause, int key, char *arg1, char *arg2)
01538 {
01539 char *s;
01540 int anum;
01541
01542 arg1++;
01543
01544
01545 for(s = arg1; *s && !isspace(*s); s++);
01546
01547
01548 if(*s)
01549 *s++ = '\0';
01550
01551
01552
01553 anum = mkattr(arg1);
01554
01555
01556 if(anum <= 0) {
01557 notify_quiet(player, "That's not a good name for an attribute.");
01558 return;
01559 }
01560 do_setattr(player, cause, anum, s, arg2);
01561 }