@q
@program cmd-@bootme
1 99999 d
i
( bootme.muf  --  6/23/95  by Squirrelly )
(
    @bootme [#idle]  -- Drop all but your least idle connect.  Default.
    @bootme #old     -- Drop all but your most recent conect.
    @bootme #all     -- Drop all of your connections.
    @bootme #list    -- Show a numbered list of your connections.
    @bootme <n>      -- Boot connection{s} <n> from above #list.
    @bootme #help
    @bootme #u=<name>
)
 
$def TMAX 359999
 
lvar USER
lvar MVAL
lvar UNIDLECON
lvar UNIDLESEC
lvar TOT
 
: nsize  ( i-val i-size -- s )
    swap intostr "0000" swap strcat
    dup strlen rot - strcut swap pop
;
 
: do_boot  ( i -- )
    dup "== BootMe Disconenect"
    over condbref ME @ dbcmp not if " by " strcat ME @ name strcat then
    " ==" strcat connotify
    dup conboot
    "--> Booted " over condbref name strcat " connection id # " strcat
    over condescr intostr strcat " (idle " strcat
    swap conidle intostr strcat " seconds)." strcat .tell
    TOT @ 1 + TOT !
;
 
: bt_idle  ( -- )
    0 UNIDLECON !
    mode MVAL ! preempt
    USER @ descriptors
    dup if swap descrcon dup UNIDLECON ! conidle UNIDLESEC ! 1 - then
    begin
        dup while
        swap descrcon
        dup conidle dup UNIDLESEC @ < if
            UNIDLECON @ do_boot
            UNIDLESEC !
            UNIDLECON !
        else
            pop do_boot
        then
        1 -
    repeat
    MVAL @ setmode
    pop
;
 
: bt_old  ( -- )
    mode MVAL ! preempt
    USER @ descriptors
    dup if swap pop 1 - then
    begin
        dup while
        swap descrcon do_boot
        1 -
    repeat
    MVAL @ setmode
    pop
;
 
: bt_all  ( -- )
    mode MVAL ! preempt
    USER @ descriptors
    begin
        dup while
        swap descrcon do_boot
        1 -
    repeat
    MVAL @ setmode
    pop
;
 
: bt_n  ( i -- i )
    mode MVAL ! preempt
    descrcon
    dup if dup condbref USER @ dbcmp not else 1 then if
        "BootMe:  Invalid ID# given." .tell
        MVAL @ setmode
        pop 1 exit
    then
    do_boot
    MVAL @ setmode
    0
;
 
: set_user  ( s -- i )
    dup .pmatch
    dup player? not if
        pop "BootMe:  Player '" swap strcat "' not found." strcat .tell
        1 exit
    then
    swap pop
    ME @ over controls not if
        "BootMe:  You can't select player '" swap name strcat
        "'." strcat .tell
        1 exit
    then
    "BootMe user selected:  " over name strcat .tell
    USER ! 0
;
 
: give_list  ( -- )
    ME @ USER @ dbcmp if "Your" else USER @ name "'s" strcat then
    " connections:" strcat .tell
    "    ID#   On-line  Idle  Host" .tell
    mode MVAL ! preempt
    USER @ descriptors
    begin
        dup while
        swap dup intostr 7 .rstrfmt "   " strcat
        swap descrcon swap
        over contime dup TMAX > if pop TMAX then
        dup 3600 / 2 nsize
        rot swap strcat ":" strcat swap 3600 %
        dup 60 / 2 nsize
        rot swap strcat ":" strcat swap 60 %
        2 nsize strcat "  " strcat
        over conidle dup 9999 > if pop 9999 then
        intostr 4 .rstrfmt strcat "  " strcat
        swap conhost strcat
        .tell
        1 -
    repeat
    MVAL @ setmode
    pop
;
 
: give_help  ( -- )
    "BootMe.muf  --  6/23/95  by Squirrelly" .tell
    "  @bootme [#idle]  -- Drop all but your least idle connect.  Default."
    .tell
    "  @bootme #old     -- Drop all but your most recent conect." .tell
    "  @bootme #list    -- Show a numbered list of your connections."
    .tell
    "  @bootme #all     -- Drop all of your connections." .tell
    "  @bootme <n>      -- Boot connection(s) <n> from above #list."
    .tell
    .me_wiz? if
        "  @bootme #u=<name> - Set target player (Wizard only)." .tell
    then
;
 
: main
    "me" match dup ME ! USER !
    strip tolower
    dup not if pop ME @ "_bootme/def" getpropstr then
    dup not if pop "#idle" then
    0 TOT !
    begin
        dup while
        " " .split swap strip
        dup not if pop continue then
        dup "#idle" strcmp not if pop bt_idle continue then
        dup "#old" strcmp not if pop bt_old continue then
        dup "#all" strcmp not if pop bt_all continue then
        dup "#list" strcmp not if pop give_list continue then
        dup number? if
            atoi bt_n if break else continue then
        then
        dup "#help" strcmp not if pop give_help continue then
        dup "#u=" 3 strncmp not if
            3 strcut swap pop set_user if break else continue then
        then
        "Bootme:  Unknown operation: '" swap strcat "'" strcat .tell
    repeat
    pop
    "Done.  " TOT @ intostr strcat " connection" strcat
    TOT @ 1 = not if "s" strcat then " dropped." strcat .tell
;
.
c
q