From f0c9a354e9ee470411d637bba90d68a9c9641e91 Mon Sep 17 00:00:00 2001 From: TLSM Date: Wed, 18 May 2022 00:54:05 -0400 Subject: [PATCH] Implement better double XP infrastructure. Double XP now has a constant for unixtime to start. Logic around DXP is designed to only apply to votes made after DOUBLE_XP_ENABLED. This prevents an exploit in the old implementation where spam voting/ unvoting a post made prior to the DXP start could farm 300 DC/hr/alt. Also it's more maintainable and comports with the coin_delta changes to prevent self-vote coin changes. --- files/helpers/const.py | 2 ++ files/routes/votes.py | 26 ++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index 38c56bc7f..33acd583e 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -678,6 +678,8 @@ AWARDS3 = {} for k, val in AWARDS2.items(): if val['price'] == 300: AWARDS3[k] = val +DOUBLE_XP_ENABLED = -1 # set to unixtime for when DXP begins, -1 to disable + TROLLTITLES = [ "how will @{username} ever recover?", "@{username} BTFO", diff --git a/files/routes/votes.py b/files/routes/votes.py index 84aee852d..ebb8fbe0e 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -72,17 +72,24 @@ def api_vote_post(post_id, new, v): if v.id == post.author.id: coin_delta = 0 + coin_mult = 1 + if DOUBLE_XP_ENABLED > 0: + if not existing and int(time.time()) > DOUBLE_XP_ENABLED: + coin_mult = 2 + elif existing and existing.created_utc > DOUBLE_XP_ENABLED: + coin_mult = 2 + if existing and existing.vote_type == new: return "", 204 if existing: if existing.vote_type == 0 and new != 0: - post.author.coins += coin_delta + post.author.coins += coin_delta * coin_mult post.author.truecoins += coin_delta g.db.add(post.author) existing.vote_type = new g.db.add(existing) elif existing.vote_type != 0 and new == 0: - post.author.coins -= coin_delta + post.author.coins -= coin_delta * coin_mult post.author.truecoins -= coin_delta g.db.add(post.author) g.db.delete(existing) @@ -90,7 +97,7 @@ def api_vote_post(post_id, new, v): existing.vote_type = new g.db.add(existing) elif new != 0: - post.author.coins += coin_delta + post.author.coins += coin_delta * coin_mult post.author.truecoins += coin_delta g.db.add(post.author) @@ -141,17 +148,24 @@ def api_vote_comment(comment_id, new, v): if v.id == comment.author_id: coin_delta = 0 + coin_mult = 1 + if DOUBLE_XP_ENABLED > 0: + if not existing and int(time.time()) > DOUBLE_XP_ENABLED: + coin_mult = 2 + elif existing and existing.created_utc > DOUBLE_XP_ENABLED: + coin_mult = 2 + if existing and existing.vote_type == new: return "", 204 if existing: if existing.vote_type == 0 and new != 0: - comment.author.coins += coin_delta + comment.author.coins += coin_delta * coin_mult comment.author.truecoins += coin_delta g.db.add(comment.author) existing.vote_type = new g.db.add(existing) elif existing.vote_type != 0 and new == 0: - comment.author.coins -= coin_delta + comment.author.coins -= coin_delta * coin_mult comment.author.truecoins -= coin_delta g.db.add(comment.author) g.db.delete(existing) @@ -159,7 +173,7 @@ def api_vote_comment(comment_id, new, v): existing.vote_type = new g.db.add(existing) elif new != 0: - comment.author.coins += coin_delta + comment.author.coins += coin_delta * coin_mult comment.author.truecoins += coin_delta g.db.add(comment.author)