}
}
-func run() error {
- l, err := net.Listen("tcp", "127.0.0.1:8443")
- if err != nil {
- return err
- }
- log.Printf("listening on ws://%v", l.Addr())
-
- cs := game.NewMonopolyServer()
- s := &http.Server{
- Handler: cs,
- ReadTimeout: time.Second * 10,
- WriteTimeout: time.Second * 10,
- }
-
-const UUID = "abc" // TODO: UUID in cookie
-
-func (r *Room) rollDiceHandler(w http.ResponseWriter, req *http.Request) {
- if r.gameCtx.ValidateCanRoll(UUID) {
- r.gameCtx.RollDice()
- r.gameCtx.ProcessMovement()
- }
-}
-
-func (r *Room) endTurnHandler(w http.ResponseWriter, req *http.Request) {
- if r.gameCtx.ValidateCanEndTurn(UUID) {
- r.gameCtx.EndTurn()
- }
-}
-
-func (r *Room) exitJailHandler(w http.ResponseWriter, req *http.Request) {
- err := req.ParseForm()
- if err != nil {
- http.Error(w, "Bad Request: Failed to parse form data", http.StatusBadRequest)
- return
- }
-
- if !r.gameCtx.ValidateCanExitJail(UUID) {
- w.WriteHeader(http.StatusForbidden)
- w.Write([]byte(`{"status": "forbidden", "message": "Not your turn or not in jail"}`))
- }
-
- method := req.PostForm.Get("method")
-
- switch method {
- case "buyout":
- err = r.gameCtx.JailBuyout()
- if err == game.ErrNotEnoughMoney {
- http.Error(w, "error: Insufficient funds", http.StatusUnprocessableEntity)
- }
-
- case "jail_free_card":
- err = r.gameCtx.JailUseCard()
- if err == game.ErrNotEnoughJailCards {
- http.Error(w, "error: Insufficient jail cards", http.StatusUnprocessableEntity)
- }
- default:
- w.WriteHeader(http.StatusBadRequest)
- w.Write([]byte(`{"status": "bad req", "message": "escape jail method does not exist"}`))
- return
- }
-
- w.WriteHeader(http.StatusOK)
- w.Write([]byte(`{"status": "success", "message": "Action processed"}`))
-}
-
-func main() {
- log.SetFlags(0)
-
- err := run()
- if err != nil {
- log.Fatal(err)
- }
-}
-
func run() error {
l, err := net.Listen("tcp", "127.0.0.1:8443")
if err != nil {
return s.Shutdown(ctx)
}
+
+// func (r *Room) rollDiceHandler(w http.ResponseWriter, req *http.Request) {
+// if r.gameCtx.ValidateCanRoll(UUID) {
+// r.gameCtx.RollDice()
+// r.gameCtx.ProcessMovement()
+// }
+// }
+//
+// func (r *Room) endTurnHandler(w http.ResponseWriter, req *http.Request) {
+// if r.gameCtx.ValidateCanEndTurn(UUID) {
+// r.gameCtx.EndTurn()
+// }
+// }
+//
+// func (r *Room) exitJailHandler(w http.ResponseWriter, req *http.Request) {
+// err := req.ParseForm()
+// if err != nil {
+// http.Error(w, "Bad Request: Failed to parse form data", http.StatusBadRequest)
+// return
+// }
+//
+// if !r.gameCtx.ValidateCanExitJail(UUID) {
+// w.WriteHeader(http.StatusForbidden)
+// w.Write([]byte(`{"status": "forbidden", "message": "Not your turn or not in jail"}`))
+// }
+//
+// method := req.PostForm.Get("method")
+//
+// switch method {
+// case "buyout":
+// err = r.gameCtx.JailBuyout()
+// if err == game.ErrNotEnoughMoney {
+// http.Error(w, "error: Insufficient funds", http.StatusUnprocessableEntity)
+// }
+//
+// case "jail_free_card":
+// err = r.gameCtx.JailUseCard()
+// if err == game.ErrNotEnoughJailCards {
+// http.Error(w, "error: Insufficient jail cards", http.StatusUnprocessableEntity)
+// }
+// default:
+// w.WriteHeader(http.StatusBadRequest)
+// w.Write([]byte(`{"status": "bad req", "message": "escape jail method does not exist"}`))
+// return
+// }
+//
+// w.WriteHeader(http.StatusOK)
+// w.Write([]byte(`{"status": "success", "message": "Action processed"}`))
+// }
+//