Update main.go
This commit is contained in:
parent
26129be3e5
commit
726fb4381b
1 changed files with 16 additions and 4 deletions
20
main.go
20
main.go
|
|
@ -42,7 +42,8 @@ func reader(conn *websocket.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func wsEndpoint(w http.ResponseWriter, r *http.Request) {
|
// Websocket for when a user wants to queue
|
||||||
|
func matchmakingWs(w http.ResponseWriter, r *http.Request) {
|
||||||
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
|
upgrader.CheckOrigin = func(r *http.Request) bool { return true }
|
||||||
|
|
||||||
// upgrade this connection to a WebSocket
|
// upgrade this connection to a WebSocket
|
||||||
|
|
@ -52,16 +53,27 @@ func wsEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helpful log statement to show connections
|
//Parameters
|
||||||
log.Println("Client Connected")
|
playerID := r.URL.Query().Get("player_id")
|
||||||
|
if playerID == "" {
|
||||||
|
err := ws.Close()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("User Connected: %s\n", playerID)
|
||||||
err = ws.WriteMessage(1, []byte("Connected"))
|
err = ws.WriteMessage(1, []byte("Connected"))
|
||||||
|
//Add them to the "match making pool"
|
||||||
|
|
||||||
reader(ws)
|
reader(ws)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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
|
||||||
|
|
||||||
func setupRoutes() {
|
func setupRoutes() {
|
||||||
http.HandleFunc("/", homePage)
|
http.HandleFunc("/", homePage)
|
||||||
http.HandleFunc("/ws", wsEndpoint)
|
http.HandleFunc("/queue", matchmakingWs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue