# EPIC's mud client, 1998
# Based on the old 1994-vintage script by the same name
# This script requires EPIC4pre1.050 or better
# Here's the plan:
#
# Usage:  newmud keyword hostname portnum
#     registers "keyword" in the mud array
#
# Usage:  mud
#     shows you the muds in the array
#
# Usage:  mud keyword
#     logs you into that mud
#
alias mud {
        if ([$0])
        {
                if (mud[$encode($0)][name])
                {
                        if (mud[$encode($0)][mark])
                        {
                                echo *** Already connected to that mud!
                        }
                        {c_mud $0 $mud[$encode($0)][name] $mud[$encode($0)][port]}
                }
                {echo *** No such mud on file}
        }
        {
                foreach mud i
                {
                        echo *** MUD: $decode($i) - $mud[$i][name] $mud[$i][port]
                }
        }
}
alias c_mud {
        @ keyw = [$0]
        @ mudcon = mudcon + 1
        if (mudcon == 5)
        {
                @ mudcon = mudcon - 1
                echo *** Too many muds open (limit of 4)
        }
        {
                window new name $keyw level NONE

		@ fd = mud[$encode($0)][fd] = connect($1 $2)
		^on ^dcc_raw "$fd % d *" \{xecho -w $keyw $$chop($3-)\}
		^on ^dcc_raw "$fd % c" {
			on dcc_raw -"$0 % c"
			on dcc_raw -"$0 % d *"
			@ mudcon = mudcon - 1
		}
		window query =$fd
        }
}
bind ^W next_window

alias newmud {
        @ mud[$encode($0)][name] = [$1]
        @ mud[$encode($0)][port] = [$2]
}

newmud onyx stimpy.cs.iastate.edu 3456
newmud moo lambda.moo.mud.org 8888
@ mudcon = 0

#hop'98
