@q
@program QuisCustodiet.muf
1 9999 d
i
( QuisCustodiet.muf    v1.1   Jessy @ FurryMUCK     3/97, 7/99
  
  "Quis custodiet ipsos custodes?"
       
                           "Who watches the watchers?"
  
  A utility to see who has you on their watchfor list. Unlike
  some versions, this checks all players, rather than all
  connected players.
  
  Since searching the dbase is computationally expensive, QuisCustodiet.muf
  charges pennies for each use... 500 by default. To change this amount, set
  prop _cost on the program object with the number of pennies to be charged. 
  
  QuisCustodiet.muf may be freely ported or modified. Please comment
  any changes.
)
  
lvar watchers
lvar ourcost
$include $lib/edit
   
: sort-it               (* string -- sortedstring ... sort list of names *)
   strip
   ", " explode
   0 1 EDITsort
   EDITjoin
   ", " " " subst
;
  
: main
    
  "me" match me !
      
  prog "_cost" getpropstr dup if                             (* set cost *)
    atoi ourcost !
  else
    pop 500 ourcost !
  then
   
  me @ pennies ourcost @ < if                                  (* charge *)
    ">>  Sorry, you need " 
    ourcost @ intostr strcat
    " pennies." strcat .tell
    exit 
  else
    me @ 0 ourcost @ - addpennies
  then

  me @ player? not if               (* puppets don't need to be doing this *)
    ">>  Sorry, this command is for players only." .tell exit
  then

  " " watchers !                                 (* init some intial inits *)
  dbtop intostr atoi
  begin                                       (* begin dbase checking loop *)
    dup while
    dup dbref player? not if               (* ... skip if not a player ... *)
      1 - continue
    then
                                  (* ... see if user's name is in list ... *)
    dup dbref "_prefs/con_announce_list" getpropstr
    " " strcat " " swap strcat
    me @ name " " strcat " " swap strcat instr if
      dup dbref name ", " strcat watchers @ strcat watchers !
    then
    1 -
  repeat                                        (* end dbase checking loop *)

  watchers @ strlen 1 = if                                       (* notify *)
    "You are not being watched for." .tell exit
  then
    "You are being watched for by: "
  watchers @ sort-it
  dup ", " rinstr strcut pop
  dup ", " rinstr 1 + strcut "and " swap strcat strcat strcat
  dup strlen 1 - strcut pop "." strcat
  "," ",," subst .tell
;
.
c
q