Cribbage server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

package main
import (
"flag"
"log"
"math/rand"
"net/http"
"time"
)
func main() {
var (
cribPath string
serverAddress string
serverPath string
telnetAddress string
sshAddress string
)
flag.StringVar(&cribPath, "crib", "", "path to crib application (terminal-based client)")
flag.StringVar(&serverAddress, "server", "", "host websocket server on provided address")
flag.StringVar(&serverPath, "path", "/crib", "host websocket server on provided path")
flag.StringVar(&telnetAddress, "telnet", "", "host telnet server on provided address")
flag.StringVar(&sshAddress, "ssh", "", "host SSH server on provided address")
flag.Parse()
if serverAddress == "" {
log.Fatal("failed to start: server listen +address must be specified with --server")
}
rand.Seed(time.Now().UTC().UnixNano())
// TODO debug
go func() {
log.Fatal(http.ListenAndServe(":8880", nil))
}()
if sshAddress != "" {
if cribPath == "" {
cribPath = "crib"
}
listenSSH(sshAddress, cribPath, serverAddress, serverPath)
}
log.Println("CribServer initialized")
cs := CribServer{}
cs.clientqueuealert = make(chan bool)
go cs.matchPlayers()
go cs.listenWebSocket(serverAddress, serverPath)
if telnetAddress != "" {
go cs.listenTelnet(telnetAddress)
}
// TODO
select {}
}