Implement a function to fix bad blackjack games

remotes/1693045480750635534/spooky-22
Outrun Colors 2022-09-05 15:59:42 -05:00
parent 4e2a220498
commit 3509d6a8b1
3 changed files with 46 additions and 4 deletions

View File

@ -4,6 +4,7 @@ import random
from math import floor
from files.helpers.const import *
from files.classes.casino_game import Casino_Game
from files.classes.user import User
from flask import g
deck_count = 4
@ -12,7 +13,6 @@ suits = ("S", "H", "C", "D")
minimum_bet = 5
maximum_bet = INFINITY
def build_game(gambler, currency_kind, wager):
casino_game = Casino_Game()
casino_game.user_id = gambler.id
@ -71,7 +71,6 @@ def get_safe_game_state(game_state):
}
def apply_blackjack_result(gambler):
game, game_state, _ = get_active_game(gambler)
@ -303,4 +302,28 @@ def get_hand_value(hand):
return max(possibilities)
def purge_bad_games():
# If for whatever reason a game is marked as active but has concluded, this will clear it up.
games = g.db.query(Casino_Game) \
.filter(Casino_Game.active == True,
Casino_Game.kind == 'blackjack').all()
for game in games:
game_state = json.loads(game.game_state)
if (game_state.status != "active"):
game.active = False
g.db.add(game)
# Victims of this status should have their currency refunded.
user = g.db.query(User).filter(User.id == game.user_id)
if user:
user.winnings += game.wager
currencyBeforeFix = getattr(user, game.currency, 0)
setattr(user, game.currency, currencyBeforeFix + game.wager)
g.db.add(user)
g.db.commit()
g.db.flush()
# endregion

View File

@ -16,6 +16,15 @@ def casino(v):
participants = get_users_participating_in_lottery()
return render_template("casino.html", v=v, participants=participants)
@app.get("/casino/<game>")
@auth_required
def casino_game_page(v, game):
return render_template(
f"casino/{game}_screen.html",
v=v,
game=game
)
@app.post("/casino/slots")
@limiter.limit("3/second;30/minute;600/hour;12000/day")
@ -42,7 +51,7 @@ def pull_slots(v):
return {"error": "Wager must be more than 100 {currency}."}
@app.get("/casino/blackjack")
@app.get("/casino/blackjack/status")
@limiter.limit("3/second;30/minute;600/hour;12000/day")
@auth_required
def get_player_blackjack_status(v):
@ -108,3 +117,12 @@ def player_took_blackjack_action(v):
}
else:
return { "active": False }
@app.post("/casino/blackjack/purge")
@auth_required
def fix_blackjack_games(v):
if v.admin_level < 3:
return { "success": False, "error": "Insufficient permissions." }
else:
purge_bad_games()
return { "success": True, "message": "Successfully purged bad blackjack games." }

View File

@ -54,9 +54,10 @@
{%- endif %}
{% if CASINO_ENABLED -%}
<h4>Lottery</h4>
<h4>Casino</h4>
<ul>
<li><a href="/admin/lottery/participants">Participants</a></li>
<button class="btn btn-primary mt-3" onclick="post_toast(this,'/casino/blackjack/purge');" style="margin-bottom: 2em;">PURGE BAD BLACKJACK GAMES</button>
</ul>
{%- endif %}