2022-09-04 20:53:34 +00:00
|
|
|
import json
|
|
|
|
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.blackjack import *
|
|
|
|
from files.helpers.slots import *
|
|
|
|
from files.helpers.lottery import *
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/casino")
|
|
|
|
@auth_required
|
|
|
|
def casino(v):
|
2022-09-04 23:15:37 +00:00
|
|
|
participants = get_users_participating_in_lottery()
|
|
|
|
return render_template("casino.html", v=v, participants=participants)
|
2022-09-04 20:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/casino/slots")
|
2022-09-05 00:01:16 +00:00
|
|
|
@limiter.limit("3/second;30/minute;600/hour;12000/day")
|
2022-09-04 20:53:34 +00:00
|
|
|
@auth_required
|
|
|
|
def pull_slots(v):
|
2022-09-04 23:15:37 +00:00
|
|
|
try:
|
|
|
|
wager = int(request.values.get("wager"))
|
|
|
|
except:
|
|
|
|
return {"error": "Invalid wager."}
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
try:
|
|
|
|
currency = request.values.get("currency")
|
|
|
|
except:
|
|
|
|
return {"error": "Invalid currency (expected 'dramacoin' or 'marseybux')."}
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
if (currency == "dramacoin" and wager > v.coins) or (currency == "marseybux" and wager > v.procoins):
|
|
|
|
return {"error": f"Not enough {currency} to make that bet."}
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
success, game_state = casino_slot_pull(v, wager, currency)
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-04 23:15:37 +00:00
|
|
|
if success:
|
|
|
|
return {"game_state": game_state, "gambler": { "coins": v.coins, "procoins": v.procoins }}
|
|
|
|
else:
|
|
|
|
return {"error": "Wager must be more than 100 {currency}."}
|
2022-09-04 20:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.get("/casino/blackjack")
|
2022-09-05 00:01:16 +00:00
|
|
|
@limiter.limit("3/second;30/minute;600/hour;12000/day")
|
2022-09-04 20:53:34 +00:00
|
|
|
@auth_required
|
|
|
|
def get_player_blackjack_status(v):
|
2022-09-05 18:27:00 +00:00
|
|
|
game, _, safe_state = get_active_game(v)
|
2022-09-04 20:53:34 +00:00
|
|
|
|
2022-09-05 18:27:00 +00:00
|
|
|
if game:
|
|
|
|
return { "active": True, "game_state": safe_state }
|
2022-09-04 23:15:37 +00:00
|
|
|
else:
|
2022-09-05 18:27:00 +00:00
|
|
|
return { "active": False }
|
2022-09-04 20:53:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@app.post("/casino/blackjack/action")
|
2022-09-05 00:01:16 +00:00
|
|
|
@limiter.limit("3/second;30/minute;600/hour;12000/day")
|
2022-09-04 20:53:34 +00:00
|
|
|
@auth_required
|
|
|
|
def player_took_blackjack_action(v):
|
2022-09-04 23:15:37 +00:00
|
|
|
try:
|
|
|
|
action = request.values.get("action")
|
|
|
|
except:
|
2022-09-05 18:27:00 +00:00
|
|
|
return { "error": "Invalid action." }
|
2022-09-04 23:15:37 +00:00
|
|
|
|
|
|
|
was_successful = False
|
|
|
|
state = None
|
|
|
|
|
2022-09-05 18:27:00 +00:00
|
|
|
if action == 'deal':
|
|
|
|
try:
|
|
|
|
currency = request.values.get("currency")
|
|
|
|
wager = int(request.values.get("wager"))
|
|
|
|
except:
|
|
|
|
return { "error": "Missing either currency or wager values." }
|
|
|
|
|
|
|
|
existing_game, _, _ = get_active_game(v)
|
|
|
|
|
|
|
|
if (currency == "dramacoin" and wager > v.coins) or (currency == "marseybux" and wager > v.procoins):
|
|
|
|
return {"error": f"Not enough {currency} to make that bet."}
|
|
|
|
elif existing_game:
|
|
|
|
return { "error": "Cannot start a new game while an existing game persists." }
|
|
|
|
else:
|
|
|
|
success, game_state = gambler_dealt(v, currency, wager)
|
|
|
|
was_successful = success
|
|
|
|
state = game_state
|
|
|
|
elif action == 'hit':
|
2022-09-04 23:15:37 +00:00
|
|
|
success, game_state = gambler_hit(v)
|
|
|
|
was_successful = success
|
|
|
|
state = game_state
|
|
|
|
elif action == 'stay':
|
|
|
|
success, game_state = gambler_stayed(v)
|
|
|
|
was_successful = success
|
|
|
|
state = game_state
|
|
|
|
elif action == 'double_down':
|
|
|
|
success, game_state = gambler_doubled_down(v)
|
|
|
|
was_successful = success
|
|
|
|
state = game_state
|
|
|
|
elif action == 'insure':
|
|
|
|
success, game_state = gambler_purchased_insurance(v)
|
|
|
|
was_successful = success
|
|
|
|
state = game_state
|
|
|
|
|
|
|
|
if was_successful:
|
2022-09-05 18:27:00 +00:00
|
|
|
return {
|
|
|
|
"active": True,
|
|
|
|
"game_state": state,
|
|
|
|
"gambler": { "coins": v.coins, "procoins": v.procoins }
|
|
|
|
}
|
2022-09-04 23:15:37 +00:00
|
|
|
else:
|
2022-09-05 18:27:00 +00:00
|
|
|
return { "active": False }
|