Exemplo n.º 1
0
func LogoutHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "https://dartpad.dartlang.org")
	playerList := model.GetPlayerList()
	clientName := DeleteCookie(w, r, CLIENT_COOKIE)

	playerList.Remove(model.FindPlayer(playerList, clientName))

}
Exemplo n.º 2
0
func ClientHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "https://dartpad.dartlang.org")
	w.Header().Set("Access-Control-Request-Method", "POST")
	playerList := model.GetPlayerList()
	clientName := r.PostFormValue("name")
	SetCookie(w, CLIENT_COOKIE, clientName)
	client := &model.Player{clientName, nil, true, false, false, nil, ""}
	playerList.PushFront(*client)

}
Exemplo n.º 3
0
func MainHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "https://dartpad.dartlang.org")
	playerList := model.GetPlayerList()
	if playerList.Len() == 0 {
		DeleteCookie(w, r, CLIENT_COOKIE)
		DeleteCookie(w, r, OPPOSITE_COOKIE)
	}
	t, _ := template.ParseFiles(MAIN_TEMPLATE)

	if playerList.Len() > 0 {
		resultArr := model.ListToArr(playerList)
		t.Execute(w, resultArr)
	} else {
		t.Execute(w, 0)

	}
}
Exemplo n.º 4
0
func UpdatePlayersHandler(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Access-Control-Allow-Origin", "https://dartpad.dartlang.org")
	playerList := model.GetPlayerList()
	clientName := GetCookie(r, CLIENT_COOKIE)
	type Page1 struct {
		Val  string
		List []model.Player
	}

	page := Page1{clientName, model.ListToArr(playerList)}
	template.ParseFiles()
	t, _ := template.ParseFiles(PLAYERS_TEMPLATE)
	//fmt.Println(page.List)

	t.ExecuteTemplate(w, "T", page)

}
Exemplo n.º 5
0
func main() {

	playerList := *model.GetPlayerList()
	r := mux.NewRouter()
	r.HandleFunc("/newClient", controller.ClientHandler)
	r.HandleFunc("/", controller.MainHandler)
	r.HandleFunc("/logout", controller.LogoutHandler)
	r.HandleFunc("/updatePlayers", controller.UpdatePlayersHandler)
	r.HandleFunc("/confirm", controller.ConfirmHandler)
	r.HandleFunc("/ws", controller.ServeWs)
	r.HandleFunc("/getTable", controller.GetTableHandler)
	r.PathPrefix("/").Handler(http.FileServer(http.Dir(STATIC_DIR)))

	fmt.Println(playerList.Len())
	//generate_cert()
	http.Handle("/", r)
	fmt.Println("Open localhost:8090 to see webpage")
	http.ListenAndServe(PORT, nil)
	//err :=http.ListenAndServeTLS(HTTPS_PORT, "cert.pem", "key.pem", nil)
	//if err != nil {
	//	fmt.Println("ListenAndServe: ", err)
	//}
}