Protect play with hard-coded password.
This commit is contained in:
parent
38ac32e460
commit
609d5f3833
@ -46,8 +46,13 @@ func parseMove(received string) (*chessMove, error) {
|
||||
}
|
||||
|
||||
func moveToString(move chessMove) string {
|
||||
|
||||
str := fmt.Sprint(move.startSquare.col) + fmt.Sprint(move.startSquare.row) +
|
||||
var str string
|
||||
if !move.realMove {
|
||||
str = "just checking: "
|
||||
} else {
|
||||
str = "move done: "
|
||||
}
|
||||
str = str + fmt.Sprint(move.startSquare.col) + fmt.Sprint(move.startSquare.row) +
|
||||
" " + fmt.Sprint(move.endSquare.col) + fmt.Sprint(move.endSquare.row)
|
||||
|
||||
return str
|
||||
|
@ -18,6 +18,20 @@ func SocketHandler(w http.ResponseWriter, r *http.Request) {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user