forked from rDrama/rDrama
Implement a function to fix bad blackjack games
parent
4e2a220498
commit
3509d6a8b1
|
@ -4,6 +4,7 @@ import random
|
||||||
from math import floor
|
from math import floor
|
||||||
from files.helpers.const import *
|
from files.helpers.const import *
|
||||||
from files.classes.casino_game import Casino_Game
|
from files.classes.casino_game import Casino_Game
|
||||||
|
from files.classes.user import User
|
||||||
from flask import g
|
from flask import g
|
||||||
|
|
||||||
deck_count = 4
|
deck_count = 4
|
||||||
|
@ -12,7 +13,6 @@ suits = ("S", "H", "C", "D")
|
||||||
minimum_bet = 5
|
minimum_bet = 5
|
||||||
maximum_bet = INFINITY
|
maximum_bet = INFINITY
|
||||||
|
|
||||||
|
|
||||||
def build_game(gambler, currency_kind, wager):
|
def build_game(gambler, currency_kind, wager):
|
||||||
casino_game = Casino_Game()
|
casino_game = Casino_Game()
|
||||||
casino_game.user_id = gambler.id
|
casino_game.user_id = gambler.id
|
||||||
|
@ -71,7 +71,6 @@ def get_safe_game_state(game_state):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def apply_blackjack_result(gambler):
|
def apply_blackjack_result(gambler):
|
||||||
game, game_state, _ = get_active_game(gambler)
|
game, game_state, _ = get_active_game(gambler)
|
||||||
|
|
||||||
|
@ -303,4 +302,28 @@ def get_hand_value(hand):
|
||||||
|
|
||||||
return max(possibilities)
|
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
|
# endregion
|
||||||
|
|
|
@ -16,6 +16,15 @@ def casino(v):
|
||||||
participants = get_users_participating_in_lottery()
|
participants = get_users_participating_in_lottery()
|
||||||
return render_template("casino.html", v=v, participants=participants)
|
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")
|
@app.post("/casino/slots")
|
||||||
@limiter.limit("3/second;30/minute;600/hour;12000/day")
|
@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}."}
|
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")
|
@limiter.limit("3/second;30/minute;600/hour;12000/day")
|
||||||
@auth_required
|
@auth_required
|
||||||
def get_player_blackjack_status(v):
|
def get_player_blackjack_status(v):
|
||||||
|
@ -108,3 +117,12 @@ def player_took_blackjack_action(v):
|
||||||
}
|
}
|
||||||
else:
|
else:
|
||||||
return { "active": False }
|
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." }
|
||||||
|
|
|
@ -54,9 +54,10 @@
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
{% if CASINO_ENABLED -%}
|
{% if CASINO_ENABLED -%}
|
||||||
<h4>Lottery</h4>
|
<h4>Casino</h4>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="/admin/lottery/participants">Participants</a></li>
|
<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>
|
</ul>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue