forked from rDrama/rDrama
1
0
Fork 0

Apply double-spend fix to hats.

master
Snakes 2022-09-16 04:58:12 -04:00
parent 54cae4b570
commit f1153031cc
Signed by: Snakes
GPG Key ID: E745A82778055C7E
2 changed files with 18 additions and 10 deletions

View File

@ -65,19 +65,23 @@ def buy(v, award):
price = int(og_price * v.discount) price = int(og_price * v.discount)
if request.values.get("mb"): if request.values.get("mb"):
if v.procoins < price: return {"error": "Not enough marseybux."}, 400 if award == "grass":
if award == "grass": return {"error": "You can't buy the grass award with marseybux."}, 403 return {"error": "You can't buy the grass award with marseybux."}, 403
v.charge_account('procoins', price)
charged = v.charge_account('procoins', price)
if not charged:
return {"error": "Not enough marseybux."}, 400
else: else:
if v.coins < price: return {"error": "Not enough coins."}, 400 charged = v.charge_account('coins', price)
v.charge_account('coins', price) if not charged:
return {"error": "Not enough coins."}, 400
v.coins_spent += price v.coins_spent += price
if v.coins_spent >= 1000000: if v.coins_spent >= 1000000:
badge_grant(badge_id=73, user=v) badge_grant(badge_id=73, user=v)
elif v.coins_spent >= 500000: elif v.coins_spent >= 500000:
badge_grant(badge_id=72, user=v) badge_grant(badge_id=72, user=v)
elif v.coins_spent >= 250000: elif v.coins_spent >= 250000:
badge_grant(badge_id=71, user=v) badge_grant(badge_id=71, user=v)
elif v.coins_spent >= 100000: elif v.coins_spent >= 100000:
badge_grant(badge_id=70, user=v) badge_grant(badge_id=70, user=v)

View File

@ -47,13 +47,17 @@ def buy_hat(v, hat_id):
if existing: return {"error": "You already own this hat!"}, 400 if existing: return {"error": "You already own this hat!"}, 400
if request.values.get("mb"): if request.values.get("mb"):
if v.procoins < hat.price: return {"error": "Not enough marseybux."}, 400 charged = v.charge_account('procoins', hat.price)
v.procoins -= hat.price if not charged:
return {"error": "Not enough marseybux."}, 400
hat.author.procoins += hat.price * 0.1 hat.author.procoins += hat.price * 0.1
currency = "marseybux" currency = "marseybux"
else: else:
if v.coins < hat.price: return {"error": "Not enough coins."}, 400 charged = v.charge_account('coins', price)
v.coins -= hat.price if not charged:
return {"error": "Not enough coins."}, 400
v.coins_spent_on_hats += hat.price v.coins_spent_on_hats += hat.price
hat.author.coins += hat.price * 0.1 hat.author.coins += hat.price * 0.1
currency = "coins" currency = "coins"