commit adcbe002b68dcc6a7ee0ed317d8695f8f280ec84
parent 7158730ff153d691c0d21ed260ff16612bc96b64
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sat, 16 Dec 2023 16:36:42 -0500
join
Diffstat:
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -832,7 +832,41 @@ func PokerHomeHandler(c echo.Context) error {
return c.Render(http.StatusOK, "poker", data)
}
- if formName == "reset_chips" {
+ if formName == "join_table" {
+ pokerTableSlug := c.Request().PostFormValue("table_slug")
+ playerBuyIn := database.PokerChip(utils.DoParseUint64(c.Request().PostFormValue("buy_in")))
+ tx := db.Begin()
+ pokerTable, _ := tx.GetPokerTableBySlug(pokerTableSlug)
+ if playerBuyIn < pokerTable.MinBuyIn {
+ tx.Rollback()
+ data.Error = "buy in too small"
+ return c.Render(http.StatusOK, "poker", data)
+ }
+ if playerBuyIn > pokerTable.MaxBuyIn {
+ tx.Rollback()
+ data.Error = "buy in too high"
+ return c.Render(http.StatusOK, "poker", data)
+ }
+ userChips := authUser.ChipsTest
+ if !pokerTable.IsTest {
+ userChips = authUser.XmrBalance.ToPokerChip()
+ }
+ if userChips < playerBuyIn {
+ tx.Rollback()
+ data.Error = "not enough chips to buy-in"
+ return c.Render(http.StatusOK, "poker", data)
+ }
+ tableAccount, _ := tx.GetPokerTableAccount(authUser.ID, pokerTable.ID)
+ tableAccount.Amount += playerBuyIn
+ if pokerTable.IsTest {
+ authUser.ChipsTest -= playerBuyIn
+ } else {
+ authUser.XmrBalance -= playerBuyIn.ToPiconero()
+ }
+ authUser.DoSave(tx)
+ tx.Commit()
+
+ } else if formName == "reset_chips" {
authUser.ChipsTest = 1000
authUser.DoSave(db)
return c.Redirect(http.StatusFound, c.Request().Referer())
diff --git a/pkg/web/public/views/pages/poker.gohtml b/pkg/web/public/views/pages/poker.gohtml
@@ -93,9 +93,12 @@
<td class="text-center align-middle">{{ .MinBet }}</td>
<td class="text-center align-middle">{{ if .IsTest }}FREE{{ else }}XMR{{ end }}</td>
<td class="text-right">
- <form method="get" action="/poker/{{ .Slug }}" class="d-inline-block">
+ <form method="post" class="d-inline-block">
+ <input type="hidden" name="csrf" value="{{ .CSRF }}" />
+ <input type="hidden" name="form_name" value="join_table" />
+ <input type="hidden" name="table_slug" value="{{ .Slug }}" />
<div class="input-group">
- <input type="number" min="{{ .MinBuyIn.Raw }}" max="{{ .MaxBuyIn.Raw }}" name="buy-in" value="{{ .MinBuyIn.Raw }}" class="form-control form-control-sm" style="width: 100px; -moz-appearance:textfield;" />
+ <input type="number" min="{{ .MinBuyIn.Raw }}" max="{{ .MaxBuyIn.Raw }}" name="buy_in" value="{{ .MinBuyIn.Raw }}" class="form-control form-control-sm" style="width: 100px; -moz-appearance:textfield;" />
<div class="input-group-append">
<button class="btn btn-primary btn-sm">Join</button>
</div>