@q
@program ActivityCheck.muf
1 9999 d
i
( ActivityCheck.muf    v1.0    Jessy @ FurryMUCK    4/97 
  
  A simple utility for checking how many and which players have or 
  have not logged on in the past X days.
  
  INSTALLATION:
  
  Create an action with a name such as 'idlecheck;activecheck' and link 
  it to the program. One alias of the action needs to include the string
  'active'. Link an action to the program. Ensure that the program is set 
  M3 or W. ActivityCheck requires lib-edit and lib-mucktools, and a .tell
  macro.
  
  USE:
  
  Enter '<cmd> <number of days> If <cmd> includes the
  string 'active', ActivityCheck reports the players who *have* logged
  on the in past <number> days. Otherwise, it reports the players
  who *have not*.
  
  ActivityCheck may be freely ported. Please comment any changes.
)
  
$include $lib/mucktools
$include $lib/edit
lvar ourCounter
lvar ourString
lvar ourTally
lvar ourCount
lvar ourBoolean
  
: TallyLine       (  --  )  (* show total number of positive results *)
    
    "Total: " ourTally @ intostr strcat
    " out of " strcat
    #-1 stats pop swap pop swap pop swap pop swap pop swap pop
    intostr strcat
    " players have " strcat ourBoolean @ not if
        "not " strcat
    then
    "logged on in the past " strcat
    ourString @ intostr strcat 
    " days." strcat .tell
    "Numbers in parentheses indicate usecount." .tell
;
  
: main
    "me" match me !
    me @ "W" flag? not if                              (* check perm *)
        "Permission denied." .tell exit
    then
    
    command @ tolower "active" instr if
       1 ourBoolean !
    then
    
    1 ourCounter !
    dup number? not if                               (* check syntax *)
        ">>  Syntax: '" command @ strcat " <number of days>" 
        strcat .tell
        exit
    then
    atoi ourString !
    0 ourTally !
    " " .tell
    "Scanning database for " ourBoolean @ if
        "active"
    else
        "idle"
    then
    strcat " players..." strcat .tell
    " " .tell
    background                         (* get process out of the way *)
    begin                                 (* go check those players! *)
        ourCounter @ dbref dbtop dbcmp not while
        ourCounter @ dbref dup player? if
            dup timestamps ourCount ! swap pop swap pop
            systime swap - 86400 /
            ourString @ ourBoolean @ if
                <
            else
                > 
            then
            if
                       (* found one... put data on stack as a string *)
                name " (" strcat ourCount @ intostr strcat ")" strcat
                ourTally @ 1 + ourTally !
                else
                    pop
            then
            else
                pop
        then
        depth 500 > if
            "Impending stack overflow! Here's what we have up to 500... "
            .tell break
        then
        ourCounter @ 1 + ourCounter !
    repeat
    depth not if                       (* tally what we came up with *)
        TallyLine exit
    then
    depth 0 0 EDITsort
    3-col
    " " .tell
    TallyLine
;
.
c
q