package server import ( "log" "net/http" "github.com/gorilla/websocket" ) var player_number = 0 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 } // 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")) } GetLobby().registerPlayer(NewPlayer(player_number, conn)) player_number = player_number + 1 }