# Debugging
function send(msg) {
- print msg
- fflush()
+ print msg |& socket
+ print " > " msg
+}
+function recv(msg) {
+ print msg |& child
+ print " < " msg
}
-
function debug(msg) {
print " # " msg > "/dev/stderr"
- fflush()
}
function set() {
socket = "/inet/tcp/0/" SERVER "/" PORT
debug("Starting server");
-
- status = system();
- while (status)
- status = system("awk -f rhawk -v CHILD=1");
-
- #print " > " msg > "/dev/stderr"
- print msg
- #print "" > "/dev/stderr"
- #print " < " $0 > "/dev/stderr"
- fflush()
-
- exit(0);
+ while (running) {
+ printf "" |& child
+ printf "" |& socket
+
+ while (connected) {
+ if (!(fd = select("from", child, socket))) {
+ print "timeout"
+ continue
+ }
+ if (!(st = fd |& getline line)) {
+ print "broken pipe"
+ close(fd)
+ break
+ }
+ if (fd == socket)
+ recv(line)
+ if (fd == child)
+ send(line)
+ fflush()
+ }
+ }
} else {
if (first)
setup()
!sp_valid &&
(sp_state "bid" || sp_state == "play") &&
-/^\.(bid|play)\>$/ {
+/^\.(bid|play)\>/ {
if (FROM in sp_players)
say(".slap " FROM ", it is not your turn.")
else
say("There is no game in progress")
}
if (sp_state == "join") {
- say("Waiting for palyers: " \
+ say("Waiting for players: " \
sp_order[0] " " sp_order[1] " " \
sp_order[2] " " sp_order[3])
}