commit 78fd8018460a0a643a0975a61ebdda29904f6e16
parent f53e923efe81f4c37838b68ceb95aa3484691f4c
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sat, 28 Jan 2023 21:15:58 -0800
remove werewolf hack
Diffstat:
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go
@@ -526,6 +526,29 @@ func ChessHandler(c echo.Context) error {
return c.Redirect(http.StatusFound, redirectURL)
}
+func WerewolfHandler(c echo.Context) error {
+ authUser := c.Get("authUser").(*database.User)
+ roomName := "werewolf"
+ message := c.Request().PostFormValue("message")
+ redirectURL := "/api/v1/chat/messages/" + roomName
+ room, _, err := dutils.GetRoomAndKey(c, roomName)
+ if err != nil {
+ return c.Redirect(http.StatusFound, redirectURL+"?error="+err.Error()+"&errorTs="+utils.FormatInt64(time.Now().Unix()))
+ }
+ cmd := &Command{
+ room: room,
+ message: message,
+ authUser: authUser,
+ fromUserID: authUser.ID,
+ redirectQP: url.Values{},
+ }
+ WWInstance.InterceptMsg(cmd)
+ if cmd.err != nil {
+ return c.Redirect(http.StatusFound, redirectURL+"?error="+cmd.err.Error()+"&errorTs="+utils.FormatInt64(time.Now().Unix()))
+ }
+ return c.Redirect(http.StatusFound, redirectURL)
+}
+
func BattleshipHandler(c echo.Context) error {
authUser := c.Get("authUser").(*database.User)
roomName := c.Request().PostFormValue("room")
diff --git a/pkg/web/handlers/api/v1/werewolf.go b/pkg/web/handlers/api/v1/werewolf.go
@@ -546,7 +546,7 @@ func (b *Werewolf) createPickUserForm() string {
arr := b.getAlivePlayersArr(true)
htmlTmpl := `
-<form method="post" action="/api/v1/chat/top-bar/werewolf" target="iframe1">
+<form method="post" action="/api/v1/werewolf">
{{ range $idx, $p := .Arr }}
<input type="radio" ID="player{{ $idx }}" name="message" value="/pm 0 {{ $p }}" /><label for="player{{ $idx }}">{{ $p }}</label><br />
{{ end }}
@@ -564,7 +564,7 @@ func (b *Werewolf) createKillVoteForm() string {
arr := b.getAlivePlayersArr(true)
htmlTmpl := `
-<form method="post" action="/api/v1/chat/top-bar/werewolf" target="iframe1">
+<form method="post" action="/api/v1/werewolf">
{{ range $idx, $p := .Arr }}
<input type="radio" ID="player{{ $idx }}" name="message" value="/pm 0 {{ $p }}" /><label for="player{{ $idx }}">{{ $p }}</label><br />
{{ end }}
@@ -583,7 +583,7 @@ func (b *Werewolf) createWerewolfPickUserForm() string {
arr := b.getAlivePlayersArr(false)
htmlTmpl := `
-<form method="post" action="/api/v1/chat/top-bar/werewolf" target="iframe1">
+<form method="post" action="/api/v1/werewolf">
{{ range $idx, $p := .Arr }}
<input type="radio" ID="player{{ $idx }}" name="message" value="/g werewolf {{ $p }}" /><label for="player{{ $idx }}">{{ $p }}</label><br />
{{ end }}
diff --git a/pkg/web/middlewares/middlewares.go b/pkg/web/middlewares/middlewares.go
@@ -175,7 +175,8 @@ func CSRFMiddleware() echo.MiddlewareFunc {
apiKey := c.Request().Header.Get("DKF_API_KEY")
if (apiKey != "" && strings.HasPrefix(c.Path(), "/api/v1/")) ||
c.Path() == "/api/v1/battleship" ||
- c.Path() == "/api/v1/chess" {
+ c.Path() == "/api/v1/chess" ||
+ c.Path() == "/api/v1/werewolf" {
return true
}
if c.Path() == "/chess/:key" {
diff --git a/pkg/web/web.go b/pkg/web/web.go
@@ -136,6 +136,7 @@ func getMainServer(i18nBundle *i18n.Bundle, renderer *tmp.Templates) echo.Handle
authGroup.POST("/api/v1/chat/:roomID/notifier", v1.RoomNotifierHandler)
authGroup.POST("/api/v1/battleship", v1.BattleshipHandler)
authGroup.POST("/api/v1/chess", v1.ChessHandler)
+ authGroup.POST("/api/v1/werewolf", v1.WerewolfHandler)
authGroup.POST("/api/v1/captcha/solver", v1.CaptchaSolverHandler)
authGroup.GET("/api/v1/chat/top-bar/:roomName", v1.ChatTopBarHandler)
authGroup.POST("/api/v1/chat/top-bar/:roomName", v1.ChatTopBarHandler, middlewares.AuthRateLimitMiddleware(1*time.Second, 3))