#!/usr/bin/perl -w

# moo.pl
# Jacek Fedorynski <jfedor@ids.pl>
# Thu May  4 00:39:45 CEST 2000
#
# This script will moo every time a packet is completed (just like the old
# win32 GUI client). You will need a moo sound, the ones that I use are the
# original sounds from the old win32 clients, you can get them from this URL:
# ftp://ftp.distributed.net/pub/dcti/unsupported/moo.zip
# You also need to change the paths below to match your setup. This script
# uses the client log to check if a packet has been completed so you have
# to enable logging in the client configuration. If you don't use esd
# (The Enlightened Sound Daemon) you will also have to change "esdplay"
# in $MOO_COMMAND to something that works on your system (try "play" from
# the sox package). Have fun.

$LOG_FILENAME = "/home/jfedor/distributed.net/log.txt";
$MOO_COMMAND = "esdplay /home/jfedor/distributed.net/Cow-1.wav";
$SLEEP_INTERVAL = 10;		# in seconds

open(LOG, $LOG_FILENAME) or die "Cannot open log file";

seek(LOG, 0, 2);

# The following is taken from man perlfaq5:

while (1) {
	for ($curpos = tell(LOG); <LOG>; $curpos = tell(LOG)) {
		if (/Completed/) {
			system($MOO_COMMAND);
		}
	}
	sleep($SLEEP_INTERVAL);
	seek(LOG, $curpos, 0);
}
