Draft: poop

This commit is contained in:
2025-11-10 13:16:29 +08:00
parent dbd2ed6469
commit 30fb3d8c73
18 changed files with 503 additions and 44 deletions

View File

@@ -0,0 +1,14 @@
package workflows
import (
"inp2025/middlewares"
"inp2025/tcp"
)
func DatabaseServer() *tcp.Router {
router := tcp.NewRouter().
Use(middlewares.ErrorHandler).
Use(middlewares.AccessLog)
return router
}

14
workflows/gameClient.go Normal file
View File

@@ -0,0 +1,14 @@
package workflows
import (
"inp2025/stages"
tea "github.com/charmbracelet/bubbletea"
)
func GameClient() error {
program := tea.NewProgram(
stages.NewGameModel())
_, err := program.Run()
return err
}

24
workflows/gameServer.go Normal file
View File

@@ -0,0 +1,24 @@
package workflows
import (
"inp2025/handlers/game"
"inp2025/middlewares"
"inp2025/tcp"
)
func GameServer() *tcp.Router {
router := tcp.NewRouter().
Use(middlewares.ErrorHandler).
Use(middlewares.AccessLog)
handlers := game.NewHandlers()
// before start
router.POST("/ready", handlers.PostReady)
// game start
router.POST("/move", handlers.PostMove)
router.SOCKET("/state", handlers.SocketState)
return router
}

55
workflows/lobbyServer.go Normal file
View File

@@ -0,0 +1,55 @@
package workflows
import (
"fmt"
"inp2025/middlewares"
"inp2025/tcp"
"io"
"time"
"go.uber.org/zap"
)
func pongHandler(w tcp.ResponseWriter, req *tcp.Request) error {
w.WriteHeader(tcp.StatusOK)
_, err := io.WriteString(w, string(req.Params["msg"]))
return err
}
func tickHandler(w tcp.ResponseWriter, req *tcp.Request) error {
zap.L().Info("Run tickHandler")
for {
w.SocketSendString(fmt.Sprintf("time: %s", time.Now().String()))
time.Sleep(time.Second)
}
return nil
}
func LobbyServer() *tcp.Router {
router := tcp.NewRouter().
Use(middlewares.ErrorHandler).
Use(middlewares.AccessLog)
// test
test := router.Group("/test").
Use(middlewares.NMSL)
test.SOCKET("/tick", tickHandler)
test.GET("/ping", pongHandler)
/*
auth := router.Group("/auth")
auth.POST("/register")
auth.POST("/login")
auth.POST("/logout")
api := router.Group("/api")
api.GET("/online-users")
api.GET("/rooms")
api.GET("/invitations")
api.GET("/current-invitation")
api.POST("/invite")
api.POST("/accept-invitition")
*/
return router
}