rDrama/files/routes/casino.py

232 lines
6.3 KiB
Python
Raw Normal View History

from files.__main__ import app
from files.helpers.wrappers import *
from files.helpers.alerts import *
from files.helpers.get import *
from files.helpers.const import *
from files.helpers.wrappers import *
from files.helpers.casino import *
from files.helpers.slots import *
from files.helpers.twentyone import *
from files.helpers.roulette import *
from files.helpers.lottery import *
@app.get("/casino")
2022-09-11 02:05:50 +00:00
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def casino(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
return render_template("casino/rehab.html", v=v)
2022-10-28 23:39:31 +00:00
return render_template("casino.html", v=v)
2022-09-09 23:55:13 +00:00
@app.get("/casino/<game>")
2022-09-11 02:05:50 +00:00
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def casino_game_page(v, game):
2022-10-28 23:39:31 +00:00
if v.rehab:
return render_template("casino/rehab.html", v=v)
elif game not in CASINO_GAME_KINDS:
abort(404)
2022-10-28 23:39:31 +00:00
feed = json.dumps(get_game_feed(game))
leaderboard = json.dumps(get_game_leaderboard(game))
2022-10-28 23:39:31 +00:00
game_state = ''
if game == 'blackjack':
if get_active_twentyone_game(v):
game_state = json.dumps(get_active_twentyone_game_state(v))
2022-10-28 23:39:31 +00:00
return render_template(
f"casino/{game}_screen.html",
v=v,
game=game,
feed=feed,
leaderboard=leaderboard,
game_state=game_state
)
@app.get("/casino/<game>/feed")
2022-09-11 02:05:50 +00:00
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def casino_game_feed(v, game):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
elif game not in CASINO_GAME_KINDS:
abort(404)
2022-10-28 23:39:31 +00:00
feed = get_game_feed(game)
return {"feed": feed}
# Lottershe
@app.get("/lottershe")
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def lottershe(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
return render_template("casino/rehab.html", v=v)
2022-10-28 23:39:31 +00:00
participants = get_users_participating_in_lottery()
return render_template("lottery.html", v=v, participants=participants)
# Slots
@app.post("/casino/slots")
2022-09-11 02:05:50 +00:00
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def pull_slots(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-09-09 23:55:13 +00:00
2022-10-28 23:39:31 +00:00
try:
wager = int(request.values.get("wager"))
except:
abort(400, "Invalid wager.")
2022-10-28 23:39:31 +00:00
try:
currency = request.values.get("currency")
except:
abort(400, "Invalid currency (expected 'coin' or 'marseybux').")
if (currency == "coins" and wager > v.coins) or (currency == "procoins" and wager > v.procoins):
2022-10-28 23:39:31 +00:00
abort(400, f"Not enough {currency} to make that bet")
game_id, game_state = casino_slot_pull(v, wager, currency)
success = bool(game_id)
2022-10-28 23:39:31 +00:00
if success:
return {"game_state": game_state, "gambler": {"coins": v.coins, "procoins": v.procoins}}
else:
2022-10-29 23:53:09 +00:00
abort(400, f"Wager must be 5 {currency} or more")
# 21
@app.post("/casino/twentyone/deal")
@limiter.limit("1/2 seconds;100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def blackjack_deal_to_player(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-09-09 23:55:13 +00:00
2022-10-28 23:39:31 +00:00
try:
wager = int(request.values.get("wager"))
currency = request.values.get("currency")
create_new_game(v, wager, currency)
state = dispatch_action(v, BlackjackAction.DEAL)
feed = get_game_feed('blackjack')
2022-10-28 23:39:31 +00:00
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except Exception as e:
abort(400, str(e))
@app.post("/casino/twentyone/hit")
@limiter.limit("1/2 seconds;100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def blackjack_player_hit(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-10-28 23:39:31 +00:00
try:
state = dispatch_action(v, BlackjackAction.HIT)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
abort(400, "Unable to hit.")
@app.post("/casino/twentyone/stay")
@limiter.limit("1/2 seconds;100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def blackjack_player_stay(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-10-28 23:39:31 +00:00
try:
state = dispatch_action(v, BlackjackAction.STAY)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
abort(400, "Unable to stay.")
@app.post("/casino/twentyone/double-down")
@limiter.limit("1/2 seconds;100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def blackjack_player_doubled_down(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-10-28 23:39:31 +00:00
try:
state = dispatch_action(v, BlackjackAction.DOUBLE_DOWN)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
abort(400, "Unable to double down.")
@app.post("/casino/twentyone/buy-insurance")
@limiter.limit("1/2 seconds;100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def blackjack_player_bought_insurance(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-10-28 23:39:31 +00:00
try:
state = dispatch_action(v, BlackjackAction.BUY_INSURANCE)
feed = get_game_feed('blackjack')
return {"success": True, "state": state, "feed": feed, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
abort(403, "Unable to buy insurance.")
# Roulette
@app.get("/casino/roulette/bets")
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def roulette_get_bets(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-10-28 23:39:31 +00:00
bets = get_roulette_bets()
2022-10-28 23:39:31 +00:00
return {"success": True, "bets": bets, "gambler": {"coins": v.coins, "procoins": v.procoins}}
@app.post("/casino/roulette/place-bet")
@limiter.limit("100/minute;2000/hour;12000/day")
@auth_required
2022-10-11 07:29:24 +00:00
@feature_required('GAMBLING')
def roulette_player_placed_bet(v):
2022-10-28 23:39:31 +00:00
if v.rehab:
abort(403, "You are under Rehab award effect!")
2022-10-28 23:39:31 +00:00
try:
bet = request.values.get("bet")
which = request.values.get("which")
amount = int(request.values.get("wager"))
currency = request.values.get("currency")
2022-10-28 23:39:31 +00:00
if amount < 5:
abort(400, f"Minimum bet is 5 {currency}.")
2022-10-28 23:39:31 +00:00
gambler_placed_roulette_bet(v, bet, which, amount, currency)
2022-10-28 23:39:31 +00:00
bets = get_roulette_bets()
2022-10-28 23:39:31 +00:00
return {"success": True, "bets": bets, "gambler": {"coins": v.coins, "procoins": v.procoins}}
except:
abort(400, "Unable to place a bet.")