package server import ( "log" "net/http" "github.com/gorilla/websocket" ) var upgrader = websocket.Upgrader{} // use default options func SocketHandler(w http.ResponseWriter, r *http.Request) { log.Println("SocketHandler invoked") conn, err := upgrader.Upgrade(w, r, nil) if err != nil { log.Print("Error during connection upgrading:", err) return } defer conn.Close() defer log.Println("SocketHandler exited") // Check if first message is the passphrase msg_type, msg, err := conn.ReadMessage() if err != nil { return } if string(msg) != "pw NC4EjHvRcsltY3ibWuYDH9OXbKgDXppfnHNCi1K4jktMspoeZjBnOPExxCpDms7zmxijoKCSaSlZ1fWclfWr7Q32DJnv2k87Z5uM" { conn.WriteMessage(msg_type, []byte("Wrong password. Connection refused")) return } else { conn.WriteMessage(msg_type, []byte("Password correct. Let's play")) } var game = NewChessGame() game.handle(conn) }