From e18a62dfeebff597e9cc4fa2b3ad21bf0647d721 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Fri, 5 Mar 2021 22:43:09 +0100 Subject: [PATCH] [MIRROR] Partial revert of datum poll creation, fixes duplicated irv votes (#3903) * Partial revert of datum poll creation, fixes duplicated irv votes (#57462) * Partial revert of datum poll creation + stops duplicated votes from being trusted from clients Reverts the part of jordies poll refactor that allowed a duplicated vote in the db to make it back on the client's vote screen. Also fixes the code that would allowed duplicated votes to be passed from the client. (not from jordie's poll refactor pr.) The race condition still exists, thats harder to fix, counting code handles this correctly * Update poll.dm * Update poll.dm * Partial revert of datum poll creation, fixes duplicated irv votes Co-authored-by: Kyle Spier-Swenson --- code/modules/mob/dead/new_player/poll.dm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/code/modules/mob/dead/new_player/poll.dm b/code/modules/mob/dead/new_player/poll.dm index 3d03b5e582c..7436fc14c9d 100644 --- a/code/modules/mob/dead/new_player/poll.dm +++ b/code/modules/mob/dead/new_player/poll.dm @@ -238,16 +238,14 @@ var/list/prepared_options = list() //if they've already voted we use the order they voted in plus a shuffle of any options they haven't voted for, if any if(length(voted_for)) + var/list/option_copy = poll.options.Copy() for(var/vote_id in voted_for) - for(var/o in poll.options) + for(var/o in option_copy) var/datum/poll_option/option = o if(option.option_id == vote_id) prepared_options += option - var/list/shuffle_options = poll.options - prepared_options - if(length(shuffle_options)) - shuffle_options = shuffle(shuffle_options) - for(var/shuffled in shuffle_options) - prepared_options += shuffled + option_copy -= option + prepared_options += shuffle(option_copy) //otherwise just shuffle the options else prepared_options = shuffle(poll.options) @@ -547,9 +545,12 @@ "ip" = "INET_ATON(?)", ) - var/sql_votes = list() + var/list/sql_votes = list() + var/list/option_copy = poll.options.Copy() for(var/o in votelist) - var/datum/poll_option/option = locate(o) in poll.options + var/datum/poll_option/option = locate(o) in option_copy + if (!option) + to_chat(src, "invalid votes were trimmed from your ballot, please revote .") sql_votes += list(list( "pollid" = sql_poll_id, "optionid" = option.option_id,