feat: add cards templete

This commit is contained in:
2026-06-24 10:47:54 +03:30
parent 60494946d6
commit b1c7bfdd06
124 changed files with 422 additions and 30 deletions
+6 -1
View File
@@ -16,6 +16,7 @@ import (
"hakemsho/internal/config"
"hakemsho/internal/economy"
"hakemsho/internal/httpx"
"hakemsho/internal/static"
"hakemsho/internal/store"
"hakemsho/internal/user"
"hakemsho/internal/ws"
@@ -80,8 +81,11 @@ func main() {
// WebSocket بازی (احراز هویت با توکن در ?token= یا هدر Authorization)
r.Get("/ws", hub.ServeWS)
// تصاویرِ کارت (هر اسکین یک پوشه) — از backend سرویس می‌شود تا اپ سبک بماند.
r.Handle("/cards/*", static.CardsHandler(cfg.CardsDir))
// پنل ادمین (HTML سرور‌ساید، پشت Basic Auth)
r.Mount("/admin", admin.New(st.DB, eco).Routes(cfg.AdminUser, cfg.AdminPass))
r.Mount("/admin", admin.New(st.DB, eco, cfg.CardsDir).Routes(cfg.AdminUser, cfg.AdminPass))
r.Route("/api", func(r chi.Router) {
r.Route("/auth", func(r chi.Router) {
@@ -97,6 +101,7 @@ func main() {
// کیف‌پول و فروشگاه
r.Get("/wallet", ecoH.Wallet)
r.Get("/stats", ecoH.Stats)
r.Get("/leaderboard", ecoH.Leaderboard)
r.Get("/tables/info", ecoH.TablesInfo)
r.Get("/shop", ecoH.Shop)
r.Post("/shop/buy-card", ecoH.BuyCard)
+20
View File
@@ -41,6 +41,17 @@ func (g gameSettler) AwardWinner(userID int64, tier string) {
}
}
// AwardRank امتیازِ رتبه را در میزِ رتبه‌بندی به‌روزرسانی می‌کند.
func (g gameSettler) AwardRank(userID int64, tier string, won bool) {
t := g.eco.FindTier(tier)
if t == nil || t.RankReward <= 0 {
return
}
if err := g.eco.AwardRank(context.Background(), userID, t.RankReward, won); err != nil {
slog.Error("award rank", "user", userID, "err", err)
}
}
func (g gameSettler) RecordGame(room, playersJSON string, winnerTeam int, kot bool) {
if err := g.eco.RecordGame(context.Background(), room, playersJSON, winnerTeam, kot); err != nil {
slog.Error("record game", "room", room, "err", err)
@@ -62,6 +73,15 @@ func (g gameSettler) RecordGameResult(userID int64, won bool) {
g.eco.RecordGameResult(context.Background(), userID, won)
}
// PlayerProfile سکه و نشانِ رتبه‌ی بازیکن را برای نمایش سرِ میز برمی‌گرداند.
func (g gameSettler) PlayerProfile(userID int64) (int64, string) {
p, err := g.eco.GetProfile(context.Background(), userID)
if err != nil || p == nil {
return 0, ""
}
return p.Coins, p.RankTier
}
// ChargePrivateTable یک میز خصوصیِ رایگان را برای کاربر مصرف می‌کند.
func (g gameSettler) ChargePrivateTable(userID int64) error {
return g.eco.ConsumePrivateTable(context.Background(), userID)