@q
@program cmd-autosweep
1 99999 d
i
( AutoSweep - A way of sending you home automatically - By Madra Rua        )
( )
( Setup as a global: @act autosweep;as=#0 / @link as=#<dbref program>       )
(                    @set #0=_connect/autosweep:<dbref program>             )
(                    @set #0=_disconnect/autosweep:<dbref program>          )
( )
( Setup as a personal program:  Same as above, but replace '#0' with 'me'   )
$define aswpid "autosweep/id" $enddef
$define aswpdelay "autosweep/delay" $enddef
$define aswptime "300" $enddef
$define aswpmode "autosweep/mode" $enddef
$define aswpdisc "autosweep/disc" $enddef
$define aswpodisc "autosweep/odisc" $enddef
$define aswpswept "autosweep/swept" $enddef
$define aswpfast "autosweep/fast" $enddef
$define aswpconn "autosweep/conn" $enddef
: split
  over swap instr
  dup 1 > if
    1 - strcut 1 strcut swap pop 1
  then
;
: tell
  me @ swap notify
;
: otell
  me @ name " " strcat swap strcat me @ location swap me @ swap notify_except
;
: awakestuff
  dup "#help" stringcmp not if
    "AutoSweep Help:" tell
    "  #help - This list." tell
    "  #stat - Shows current settings." tell
    "  #on   - Turns AutoSweep on." tell
    "  #off  - Turns AutoSweep off." tell
    "  #skip - Turns AutoSweep off only for the next disconnect." tell
    "  #fast - Sets AutoSweep to instantly sweep on the next disconnect." tell
    "  #delay=<time> - Sets the sweep delay to <time> seconds." tell
    "  #disc=<msg> - Sets the message displayed when you disconnect." tell
    "  #odisc=<msg> - Sets the alternate message displayed when you" tell
    "          disconnect AND you have AutoSweep active." tell
    "  #swept=<msg> - Sets the message displayed when you get swept." tell
    "  #fast=<msg> - Sets the message when you get swept in fast mode." tell
    "  #conn=<msg> - Sets the message displayed when you connect." tell
    "  ( If the <time> or <msg> is blank, value gets set to the default." tell
    "    Each <msg> is automatcally prepended with your name. )" tell
    exit
  then
  dup "#stat" stringcmp not if
    "AutoSweep Status: " tell
    "  Mode: "
    me @ aswpmode getpropstr
    dup strlen 0 = if pop "(OFF)" then
    strcat tell
    "  Delay: "
    me @ aswpdelay getpropstr
    dup strlen 0 = if pop "(300)" then
    strcat " seconds" strcat tell
    "  Disconnect message: "
    me @ aswpdisc getpropstr
    dup strlen 0 = if
      pop "(none)"
    else
      "(" me @ name strcat ") " strcat swap strcat
    then
    strcat tell
    "  Alternate disconnect message: "
    me @ aswpodisc getpropstr
    dup strlen 0 = if
      pop "(none)"
    else
      "(" me @ name strcat ") " strcat swap strcat
    then
    strcat tell
    "  Swept Message: (" me @ name strcat
    me @ aswpswept getpropstr
    dup strlen 0 = if
      pop " is automatically sent home.)"
    else
      ") " swap strcat
    then
    strcat tell
    "  Fast Swept Msg: (" me @ name strcat
    me @ aswpfast getpropstr
    dup strlen 0 = if
      pop " is automatically sent home immediately.)"
    else
      ") " swap strcat
    then
    strcat tell
    "  Connect message: "
    me @ aswpconn getpropstr
    dup strlen 0 = if
      pop "(none)"
    else
      "(" me @ name strcat ") " strcat swap strcat
    then
    strcat tell
    exit
  then
  dup "#on" stringcmp not if
    "AutoSweep: Turned on." tell
    me @ aswpmode "ON" 0 addprop
    exit
  then
  dup "#off" stringcmp not if
    "AutoSweep: Turned off." tell
    me @ aswpmode "OFF" 0 addprop
    exit
  then
  dup "#skip" stringcmp not if
    "AutoSweep: Skipping the next disconnection." tell
    me @ aswpmode "SKIP" 0 addprop
    exit
  then
  dup "#delay" instr 1 = if
    "=" split
    0 = if
      "AutoSweep: Delay time NOT set." tell
    else
      dup dup strlen 0 = swap atoi 0 = or if
        pop me @ aswpdelay remove_prop
        "AutoSweep: Delay time reset." tell
      else
        me @ swap aswpdelay swap 0 addprop
        "AutoSweep: Delay time set." tell
      then
    then
    exit
  then
  dup "#disc" instr 1 = if
    "=" split
    0 = if
      "AutoSweep: Disconnect message NOT set." tell
    else
      dup strlen 0 = if
        pop me @ aswpdisc remove_prop
        "AutoSweep: Disconnect message reset." tell
      else
        me @ swap aswpdisc swap 0 addprop
        "AutoSweep: Disconnect message set." tell
      then
    then
    exit
  then
  dup "#odisc" instr 1 = if
    "=" split
    0 = if
      "AutoSweep: Alternate disconnect message NOT set." tell
    else
      dup strlen 0 = if
        pop me @ aswpodisc remove_prop
        "AutoSweep: Alternate disconnect message reset." tell
      else
        me @ swap aswpodisc swap 0 addprop
        "AutoSweep: Alternate disconnect message set." tell
      then
    then
    exit
  then
  dup "#swept" instr 1 = if
    "=" split
    0 = if
      "AutoSweep: Swept message NOT set." tell
    else
      dup strlen 0 = if
        pop me @ aswpswept remove_prop
        "AutoSweep: Swept message reset." tell
      else
        me @ swap aswpswept swap 0 addprop
        "AutoSweep: Swept message set." tell
      then
    then
    exit
  then
  dup "#fast" instr 1 = if
    "=" split
    0 = if
      "AutoSweep: Fast sweep on next disconnection." tell
      me @ aswpmode "FAST" 0 addprop
    else
      dup strlen 0 = if
        pop me @ aswpfast remove_prop
        "AutoSweep: Fas Sweep message reset." tell
      else
        me @ swap aswpfast swap 0 addprop
        "AutoSweep: Fast Sweep message set." tell
      then
    then
    exit
  then
  dup "#conn" instr 1 = if
    "=" split
    0 = if
      "AutoSweep: Connect message NOT set." tell
    else
      dup strlen 0 = if
        pop me @ aswpconn remove_prop
        "AutoSweep: Connect message reset." tell
      else
        me @ swap aswpconn swap 0 addprop
        "AutoSweep: Connect message set." tell
      then
    then
    exit
  then
  "AutoSweep: Type 'autosweep #help' for help." tell
  "  AutoSweep is used to automatically send you home after a given" tell
  "  amount of time when you disconnect.  It also gives to the ability" tell
  "  to set custom messages to display when you connect or disconnect." tell
;
: objectsweep
  me @ contents
  begin
    dup #-1 dbcmp if break then
    dup next swap
    dup "_autosweep?" getpropstr "" stringcmp if
      #-3 moveto
    else
      pop
    then
  repeat
;
: main
  "me" match me !
  dup "Connect" strcmp not if
    pop
    me @ aswpconn getpropstr
    dup strlen 0 = not if otell else pop then
    me @ aswpid getpropval
    dup ispid? if kill then
    pop exit
  then
  dup "Disconnect" strcmp if
    awakestuff pop exit
  then pop
  objectsweep
  me @ aswpmode getpropstr
  dup strlen 0 = if pop "OFF" then
  dup "OFF" stringcmp not if
    me @ aswpdisc getpropstr
    dup strlen 0 = not if otell else pop then
    exit
  then
  dup "SKIP" stringcmp not if
    me @ aswpmode "ON" 0 addprop exit
  then pop
  me @ aswpid "" pid addprop
  me @ aswpmode getpropstr
  dup "FAST" stringcmp not if
    me @ aswpmode "ON" 0 addprop
  else
    me @ aswpodisc getpropstr
    dup strlen 0 = not if
      otell
    else
      pop
      me @ aswpdisc getpropstr
      dup strlen 0 = not if
        otell
      else
        pop
      then
    then
(   me @ awake? not if )
      background
      me @ aswpdelay getpropstr
      dup strlen 0 = if pop "300" then
      atoi
      dup 0 < if pop 0 then
      dup 3600 > if pop 3600 then
      sleep
(   then )
  then
  me @ awake? not me @ getlink me @ location dbcmp not and if
    "FAST" stringcmp not if
      me @ aswpfast getpropstr
      dup strlen 0 = if
        pop "is automatically sent home immediately."
      then otell
    else
      me @ aswpswept getpropstr
      dup strlen 0 = if
        pop "is automatically sent home."
      then otell
    then
    me @ #-3 moveto
  then
;
.
c
q