@q
@program spoof.muf
1 9999 d
i
(  Spooof.muf    v1.1     Jessy @ FurryMUCK    8/96, 7/99
   
   A spoof program with several configurable options.
   
   INSTALLATION:
   
   Set spoof.muf M3. Create an action and link it to the program.
   
   CONFIGURATION:
   
   By default, spoofs are enclosed in parentheses. The parenthese can be 
   replaced by whatever string you like, by setting props _pref and _suf 
   on the trigger.
      
      @set <action> =_pref:[ 
      @set <action> =_suf:]
   
   Or you can allow 'freespoofs'... spoofs with no indicating brackets.
   To do so, set the trigger _freespoof.
      
      @set <action> = _freespoof : yes
      
   Freespoofs beginning with the name of an online player other than the 
   will be put in brackets.
   
   Wizards may see who is spoofing by setting themselves _prefs/nospoof.
      
      @set me = _prefs/nospoof : yes
   
   To allow all players to set themselves _prefs/nospoof, set the 
   _nospoof prop on the trigger:
      
      @set <action> = _nospoof : yes
   
   To disallow specific prefixes, edit list _noprefs on the trigger,
   with a disallowed prefix on each line. Example:
      
      lsedit @emit=_noprefs
      You
      >>
      .end
      
   This example will put spoofs/@emits beginning with the strings 'You'
   or '>>' in parentheses. These matches are case-insensitive.
   
   This program may be freely ported. Please comment any changes.
)
  
$define tell me @ swap notify $enddef
$define line me @ " " notify $enddef
  
lvar counter
lvar ourString
lvar pName?
  
: Help
    
    "------------------------------------------------------------------------"
    tell
    "Spoof.muf (#" prog intostr strcat ")" strcat tell line
    "To spoof a message, simply type '" command @ strcat " <message>'" strcat
    tell line
    "Configuration Options:" tell line
    "By default, spoofs are bracketed in parentheses. There are two options "
    "for reformatting spoofs. The parentheses can be replaced by setting a "
    "'preface' and 'suffix' prop on the trigger." 
    strcat strcat tell line
    "    @set <trigger> = _pref:<string to preceed spoof string>" tell
    "    @set <trigger> = _suf:<string to follow spoof string>" tell line
    "Or, 'freespoofs', with no parentheses or other signals, will be emitted "
    "if the trigger is set _freespoof" strcat tell line
    "    @set <trigger> = _freespoof:yes" tell line
    "Spoofs beginning with a player's name will always be bracketed." tell
    trig "_nospoof" getpropstr if
        line
        "To see who is spoofing, set yourself _prefs/nospoof." tell
        line
        "    @set me=_prefs/nospoof:yes" tell
    then
    line
    "For Wizards: To who is spoofing, set yourself _nospoof." tell line
    "    @set me = _prefs/nospoof : yes" tell line
    "To allow all players to do this, set the trigger _nospoof." tell line
    "    @set " command @ strcat
    " = _nospoof:yes" strcat tell line
    "To disallow specific prefixes in freespoofs, edit list _noprefs on" tell 
    "the trigger, entering one prefix per line." tell
    "------------------------------------------------------------------------"
    tell
;   
    
: TellSpoof  (  --  )                    ( format spoof for bracketed output )
    
    trig "_pref" getpropstr dup not if
        pop "( "
    then
    ourString @ strcat
    trig "_suf" getpropstr dup not if
        pop " )"
    then
    strcat ourString !
;
  
: FreeSpoof  (  --  )                       ( format spoof for 'free' output )
    
                             ( check for spoofs beginning with player names
                               or disallowed prefixes. For these, format with 
                               parens; others, leave spoof string unchanged. ) 
    trig "_noprefs#/" nextprop dup if
      begin
        dup while
        trig over getpropstr 
        ourString @ swap stringpfx if
          TellSpoof exit
        then
        trig swap nextprop
      repeat
    then
    pop
    
    ourString @ dup " " instr dup if
        1 - strcut pop strip pName? !
    else
        pop pop 
	ourString @ pName? !
    then
    
    pName? @ .pmatch not
    pName? @ "I" smatch 
    pName? @ "me" smatch or or if
      exit
    then
  
    pName? @ .pmatch
  
    dup  #-1 dbcmp
    over #-2 dbcmp or if
      exit
    then
    
    name pName? @ smatch if
      pName? @ me @ name smatch not if
        TellSpoof
      then
    then
;
  
: main
    
    "me" match me !                                       ( make sure I'm me )
    dup not if                                  ( bail out for null messages )
        exit
    then
    strip ourString !                                  ( store spoof message )
    
    "#help" ourString @ stringpfx if               ( check: user wants help? )
        Help exit
    then
     
    trig "_freespoof" getpropstr not if                     ( format message )
        TellSpoof
    else
        Freespoof
    then
    
    loc @ contents counter !                ( set up loop of players to tell )
    begin                                        ( begin player-telling loop )
        counter @ while
        counter @ player? not if                   ( skip non-player objects )
            counter @ next counter ! continue
        else
            counter @ awake? not if                          ( skip sleepers )
                counter @ next counter ! continue
            then
        then
        counter @ ourString @ notify            ( notify player with message )
        trig "_nospoof" getpropstr if             ( check: show who spoofed? )
            1
        else
            counter @ "W" flag?
        then
        counter @ "_prefs/nospoof" getpropstr and if
            counter @ "* Spoofed by " me @ name strcat " *" strcat notify
        then
        counter @ next counter !
    repeat                                         ( end player-telling loop )
;
.
c
q