#! /bin/sh

# warp to the next client of the same class on the same channel
# ignoring hidden and withdrawn clients

(echo clients ; echo clients ; echo quit) | socket localhost 6999 | \

gawk -v W=$1 '

BEGIN { CLASS = ""; }

(CLASS != "" && $3 !~ /.*[HW].*/ && $4 == CLASS && $2 == CHANNEL) {
	print "warp", $1
	print "quit"
	exit;
}

($1 == W) {
	CLASS = $4
	CHANNEL = $2
}
' | socket -q localhost 6999
