tmuck2.4/
tmuck2.4/admin/scripts/
tmuck2.4/docs/
tmuck2.4/minimal-db/
tmuck2.4/minimal-db/data/
tmuck2.4/minimal-db/logs/
tmuck2.4/minimal-db/muf/
tmuck2.4/old/
tmuck2.4/src/
tmuck2.4/src/compile/
tmuck2.4/src/editor/
tmuck2.4/src/game/
tmuck2.4/src/interface/
tmuck2.4/src/scripts/
tmuck2.4/src/utilprogs/
#!/bin/sh

# Goes through a status log and generates the last login time for a
# player.
# Should sortof work with old pre2.3 status logs, since it sets a dummy
# time of 0 for those.  However, sort isn't stable so they might get
# thrown out of order.  Oh well.  Not much can be done about that.

# laston,v 2.6 1994/12/04 22:25:47 dmoore Exp

if [ $# -ne 2 -o ! -f "$1" -o ! -f "$2" ]; then
    echo "usage: $0 <database> <status-log>"
    exit 1
fi


set $1 $2 -1


# Output of this section looks like 'DB: dbref name objcnt'
# Which is a list of pairs of player dbrefs and names from the database.
# The state variable holds what we are looking for next.

awk '
BEGIN	{ FS = ""; state = "dbref"; }
	{
	  if (state == "dbref") {
	    if ($0 ~ /^#[0-9][0-9]*$/) {
	      dbref = $0;
	      state = "flags";
	    }
	  } else if (state == "flags") {
	    if ($0 ~ /^PLAYER/) {
	      players[cnt++] = dbref;
	      player = 1;
	    } else {
	      player = 0;
	    }
	    state = "name";
	  } else if (state == "name") {
	    if (player) {
	      name[dbref] = $0;
	    }
	    state = "location";
	  } else if (state == "location") {
	    state = "owner";
	  } else if (state == "owner") {
	    owns["#" $0] += 1;
	    state = "prop end";
	  } else if (state == "prop end") {
	    if ($0 ~ /^$/) {
	      state = "dbref";
	    }
	  }
	}
END	{
	  for (i in players) {
	    who = players[i];
	    printf("%s	%s	%d\n", who, name[who], owns[who]);
	  }
	}
' < $1 |\
sed -e 's/^#\(.*\)$/DB:	\1/' > /tmp/.laston$$a



# Output of his sed looks like 'LOG: dbref timestamp timestr*'
# Information is gleaned from the status log.

egrep ': CONNECTED:|: CREATED:' $2 |\
egrep ']$' |\
sed -e 's/\([^]]\)$/\1 --[0]/' \
    -e 's/^\([^:]*:[^:]*\):[^:]*: \([^ ]*\) from [^ ]* on fd [0-9]*\. --\[\([0-9]*\)\]$/\1	\3	\2/' \
    -e 's/^\([^	]*\)	\([0-9]*\)	.*(#\([0-9]*\)[^(]*)$/LOG:	\3	\2	\1/' \
    > /tmp/.laston$$b



cat /tmp/.laston$$a /tmp/.laston$$b |\
awk '
BEGIN		{ FS = "	"; mintimestamp = '"$3"'; }
/^DB:/		{
		  dbrefs[cnt++] = $2;
		  name[$2] = $3;
		  objcnt[$2] = $4;
		}
/^LOG:/	{
		  if (!name[$2]) continue;
		  if (timestamp[$2] <= $3) {
		    timestamp[$2] = $3;
		    timestr[$2] = $4;
		  }
		}
END		{
		  for (i in dbrefs) {
		    who = dbrefs[i];
		    if (timestamp[who] >= mintimestamp) {
		      printf("%s	%s	", who, name[who]);
		      if (length(name[who]) < 8) printf("	");
		      if (length(name[who]) < 16) printf("	");
		      printf("%d	", objcnt[who]);
		      printf("%d	", timestamp[who]);
		      printf("%s\n", timestr[who]);
		    }
		  }
		}
' | sort +3n

rm /tmp/.laston$$a /tmp/.laston$$b