#!/bin/csh -f # BINARY set BATTLER = battler set noglob # system variable set MYNAME = `whoami` set TMP = /tmp/battler.$$ set FIGHT = EXERC set GETUSERCMD = ypmatch set CAT = ypcat set PASSWD = passwd onintr clean while (1) if( $#argv == 0 ) then break endif switch ($argv[1]) case "-h": case "-help": echo passwordbattler '[options]' echo ' options:' echo '-nonis specify if your domain does not use NIS' echo '-CHAMP championship(all your domain)' echo '-EXERC exercise (display your score)' echo '-MATCH enemy match (you vs. enemy)' exit 1 case "-nonis": set GETUSERCMD = grep set CAT = cat set PASSWD = /etc/passwd # shift breaksw case "-CHAMP": set FIGHT = CHAMP breaksw case "-EXERC": set FIGHT = EXERC breaksw case "-MATCH": set FIGHT = MATCH set ENEMY = $argv[2] shift breaksw default: echo passwordbattler ':' $argv[1] 'Unknown option..' exit 1 endsw shift end switch ($FIGHT) case "CHAMP": goto champ breaksw case "EXERC": goto exerc breaksw case "MATCH": goto match breaksw end champ: $CAT $PASSWD | head -1000 > $TMP set USER = `cat $TMP | awk -F: '{if( $2 != "" && $2 != "*" ){print $1}}'` set PASS = `cat $TMP | awk -F: '{if( $2 != "" && $2 != "*" ){print $2}}'` set SCORE = () @ n = 1 foreach i ($USER) echo -n . set TMPSCORE = `$BATTLER $PASS[$n]` set SCORE = ($SCORE $TMPSCORE) @ n ++ end echo " " set HIGHSCORE = (BEST1 0 BEST2 0 BEST3 0) set LOWSCORE = (WORST1 999999 WORST2 999999 WORST3 999999) @ n = 1 foreach i ($SCORE) if( $HIGHSCORE[2] < $i ) then set HIGHSCORE[6] = $HIGHSCORE[4] set HIGHSCORE[5] = $HIGHSCORE[3] set HIGHSCORE[4] = $HIGHSCORE[2] set HIGHSCORE[3] = $HIGHSCORE[1] set HIGHSCORE[2] = $i set HIGHSCORE[1] = $USER[$n] else if( $HIGHSCORE[4] < $i ) then set HIGHSCORE[6] = $HIGHSCORE[4] set HIGHSCORE[5] = $HIGHSCORE[3] set HIGHSCORE[4] = $i set HIGHSCORE[3] = $USER[$n] else if( $HIGHSCORE[6] < $i ) then set HIGHSCORE[6] = $i set HIGHSCORE[5] = $USER[$n] else if( $LOWSCORE[2] > $i ) then set LOWSCORE[6] = $LOWSCORE[4] set LOWSCORE[5] = $LOWSCORE[3] set LOWSCORE[4] = $LOWSCORE[2] set LOWSCORE[3] = $LOWSCORE[1] set LOWSCORE[2] = $i set LOWSCORE[1] = $USER[$n] else if( $LOWSCORE[4] > $i ) then set LOWSCORE[6] = $LOWSCORE[4] set LOWSCORE[5] = $LOWSCORE[3] set LOWSCORE[4] = $i set LOWSCORE[3] = $USER[$n] else if( $LOWSCORE[6] > $i ) then set LOWSCORE[6] = $i set LOWSCORE[5] = $USER[$n] endif @ n ++ end echo "BEST3:" $HIGHSCORE echo "WORST3:" $LOWSCORE goto clean match: set PASS = `$GETUSERCMD $ENEMY $PASSWD|awk -F: '{if( $2 != "" && $2 != "*" ){print $2}}'` set ENESCO = `$BATTLER $PASS` echo "ENEMY("$ENEMY") SCORE is " $ENESCO set PASS = `$GETUSERCMD $MYNAME $PASSWD|awk -F: '{if( $2 != "" && $2 != "*" ){print $2}}'` set MYSCO = `$BATTLER $PASS` echo "YOUR SCORE is " $MYSCO if( $MYSCO > $ENESCO ) then echo "YOU WIN." else echo "YOU DIED." endif goto clean exerc: set PASS = `$GETUSERCMD $MYNAME $PASSWD|awk -F: '{if( $2 != "" && $2 != "*" ){print $2}}'` set MYSCO = `$BATTLER $PASS` echo "YOUR SCORE is " $MYSCO clean: /bin/rm -f $TMP