# STAT version 1.0   03 November 1993
#
# Shows additional statistics on server's current role on the net.
#
# Concept, original version:		Twilight1 <pda@engr.engr.uark.edu>
# This version:				Jeremy Nelson (jnelson@acronet.net)
#
# Usage: /stat [server]
#
# Action: /stat  by itself will query the statistics from the local server.
#         /stat with an optional server name will query the remote server for
#         the statistics. 

alias stat {if ([$0]) {rstat $0} {lstat}}

alias lstat {
	start_stat
	^on ^255 * {
		@ lstat.tmp = FLOATING_POINT_MATH
		set floating_point_math ON
		@ remote_users = [$3]
		@ percent = (remote_users / total_users) * 100
		@ average = total_users / total_servers
		set floating_point_math $lstat.tmp
		echo *** User statistics for server $0
		echo *** I have $remote_users of $total_users users on $total_servers servers.
		end_stat
	}
	lusers 
}

alias rstat {
	start_stat
	lusers 
	wait

	^on ^251 * { @remote_users = [$3]+[$6] }
	^on ^255 * {
		@ lstat.tmp = FLOATING_POINT_MATH
		set floating_point_math ON
		@ percent = (remote_users / total_users) * 100
		@ average = total_users / total_servers
		set floating_point_math $lstat.tmp
		echo *** User statistics for server $0
		echo *** I have $local_users of $total_users users on $total_servers servers.
		end_stat
	}
	lusers $remote_server
}
   
alias start_stat {
	stack push on 251
	stack push on 252
	stack push on 254
	stack push on 255
	^on ^251 * {@total_users = [$3]+[$6];@total_servers = [$9]}
	^on ^252 * #
	^on ^254 * #
	^on ^255 * #
}

alias end_stat {
	stack pop on 251
	stack pop on 252
	stack pop on 254
	stack pop on 255
	echo *** That is $percent% of the total number of users on IRC.
	echo *** The average serverload is $average user[s] per server.
}

# Set phasers to stun.
