Factor player balance check into IsBetValid and make min/max bets optional

This commit is contained in:
moneromooo 2015-01-22 18:26:29 +00:00
parent 6d1136b459
commit cf122d032b
3 changed files with 7 additions and 20 deletions

View file

@ -43,10 +43,15 @@ def IsBetValid(link,amount,minbet,maxbet,potential_loss,max_loss,max_loss_ratio)
units=long(amount*coinspecs.atomic_units)
if units <= 0:
return False, "Invalid amount"
if amount > maxbet:
if maxbet != None and amount > maxbet:
return False, "Max bet is %s" % AmountToString(maxbet * coinspecs.atomic_units)
if amount < minbet:
if minbet != None and amount < minbet:
return False, "Min bet is %s" % AmountToString(minbet * coinspecs.atomic_units)
enough, reason = IsPlayerBalanceAtLeast(link,units)
if not enough:
return False, reason
if potential_loss > 0:
if potential_loss > max_loss:
return False, "Max potential loss is %s" % AmountToString(max_loss * coinspecs.atomic_units)

View file

@ -575,10 +575,6 @@ def Blackjack(link,cmd):
log_info("Dice: %s's bet refused: %s" % (identity, reason))
link.send("%s: %s" % (link.user.nick, reason))
return
enough, reason = IsPlayerBalanceAtLeast(link,total_units_wagered)
if not enough:
link.send("%s: %s" % (link.user.nick, reason))
return
try:
rolls, seed = GetNewShuffleSeed(link)

View file

@ -74,20 +74,6 @@ def Dice(link,cmd):
link.send("%s: %s" % (link.user.nick, reason))
return
try:
balance = redis_hget("balances",identity)
if balance == None:
balance = 0
balance=long(balance)
if units > balance:
log_error ('%s does not have enough balance' % identity)
link.send("You only have %s" % (AmountToString(balance)))
return
except Exception,e:
log_error ('failed to query balance')
link.send("Failed to query balance")
return
try:
rolls, roll = Roll(link)
except: