From 06f4ca40145613c84ee40e3a4a9749e78c30f974 Mon Sep 17 00:00:00 2001 From: AnturK Date: Sun, 26 Aug 2018 20:27:45 +0200 Subject: [PATCH 1/3] Allows revoting on text polls. --- code/modules/mob/dead/new_player/poll.dm | 55 ++++++++++++++---------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/code/modules/mob/dead/new_player/poll.dm b/code/modules/mob/dead/new_player/poll.dm index 5ac1b4adb50..2e7d793c5a4 100644 --- a/code/modules/mob/dead/new_player/poll.dm +++ b/code/modules/mob/dead/new_player/poll.dm @@ -103,23 +103,20 @@ var/output = "
Player poll
" output += "Question: [pollquestion]
" output += "Feedback gathering runs from [pollstarttime] until [pollendtime]

" - if(!vote_text) - output += "

" - output += "" - output += "" - output += "" - output += "Please provide feedback below. You can use any letters of the English alphabet, numbers and the symbols: . , ! ? : ; -
" - output += "" - output += "

" - output += "
" - output += "" - output += "" - output += "" - output += "" - output += "
" - else - vote_text = replacetext(vote_text, "\n", "
") - output += "[vote_text]" + output += "
" + output += "" + output += "" + output += "" + output += "Please provide feedback below. You can use any letters of the English alphabet, numbers and the symbols: . , ! ? : ; -
" + output += "" + output += "

" + output += "
" + output += "" + output += "" + output += "" + output += "" + output += "
" + src << browse(null ,"window=playerpolllist") src << browse(output,"window=playerpoll;size=500x500") if(POLLTYPE_RATING) @@ -348,6 +345,7 @@ src << browse(output,"window=playerpoll;size=500x500") return +//Returns null on failure, TRUE if already voted, FALSE if not voted yet. /mob/dead/new_player/proc/poll_check_voted(pollid, text = FALSE) var/table = "poll_vote" if (text) @@ -362,12 +360,15 @@ if(query_hasvoted.NextRow()) qdel(query_hasvoted) to_chat(usr, "You've already replied to this poll.") - return + return TRUE qdel(query_hasvoted) + return FALSE + +//Returns adminrank for use in polls. +/mob/dead/new_player/proc/poll_rank() . = "Player" if(client.holder) . = client.holder.rank.name - return . /mob/dead/new_player/proc/vote_rig_check() @@ -487,7 +488,10 @@ //validate the poll if (!vote_valid_check(pollid, client.holder, POLLTYPE_OPTION)) return 0 - var/adminrank = sanitizeSQL(poll_check_voted(pollid)) + var/voted = poll_check_voted() + if(isnull(voted) || voted) //Failed or already voted. + return + var/adminrank = sanitizeSQL(poll_rank()) if(!adminrank) return var/datum/DBQuery/query_option_vote = SSdbcore.NewQuery("INSERT INTO [format_table_name("poll_vote")] (datetime, pollid, optionid, ckey, ip, adminrank) VALUES (Now(), [pollid], [optionid], '[ckey]', INET_ATON('[client.address]'), '[adminrank]')") @@ -513,14 +517,21 @@ if(!replytext) to_chat(usr, "The text you entered was blank. Please correct the text and submit again.") return - var/adminrank = sanitizeSQL(poll_check_voted(pollid, TRUE)) + var/voted = poll_check_voted(pollid, TRUE) + if(isnull(voted)) + return + var/adminrank = sanitizeSQL(poll_rank()) if(!adminrank) return replytext = sanitizeSQL(replytext) if(!(length(replytext) > 0) || !(length(replytext) <= 8000)) to_chat(usr, "The text you entered was invalid or too long. Please correct the text and submit again.") return - var/datum/DBQuery/query_text_vote = SSdbcore.NewQuery("INSERT INTO [format_table_name("poll_textreply")] (datetime ,pollid ,ckey ,ip ,replytext ,adminrank) VALUES (Now(), [pollid], '[ckey]', INET_ATON('[client.address]'), '[replytext]', '[adminrank]')") + var/datum/DBQuery/query_text_vote + if(!voted) + query_text_vote = SSdbcore.NewQuery("INSERT INTO [format_table_name("poll_textreply")] (datetime ,pollid ,ckey ,ip ,replytext ,adminrank) VALUES (Now(), [pollid], '[ckey]', INET_ATON('[client.address]'), '[replytext]', '[adminrank]')") + else + query_text_vote = SSdbcore.NewQuery("UPDATE [format_table_name("poll_textreply")] SET datetime = Now(), ip = INET_ATON('[client.address]'), replytext = '[replytext]' WHERE pollid = '[pollid]' AND ckey = '[ckey]'") if(!query_text_vote.warn_execute()) qdel(query_text_vote) return From 620e0487196d2b1e9cee58a04a4e4a83cc0d91e4 Mon Sep 17 00:00:00 2001 From: AnturK Date: Mon, 27 Aug 2018 09:54:23 +0200 Subject: [PATCH 2/3] Keeps quiet on repeats. --- code/modules/mob/dead/new_player/poll.dm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/code/modules/mob/dead/new_player/poll.dm b/code/modules/mob/dead/new_player/poll.dm index 2e7d793c5a4..618425077bf 100644 --- a/code/modules/mob/dead/new_player/poll.dm +++ b/code/modules/mob/dead/new_player/poll.dm @@ -346,7 +346,7 @@ return //Returns null on failure, TRUE if already voted, FALSE if not voted yet. -/mob/dead/new_player/proc/poll_check_voted(pollid, text = FALSE) +/mob/dead/new_player/proc/poll_check_voted(pollid, text = FALSE, silent = FALSE) var/table = "poll_vote" if (text) table = "poll_textreply" @@ -359,7 +359,8 @@ return if(query_hasvoted.NextRow()) qdel(query_hasvoted) - to_chat(usr, "You've already replied to this poll.") + if(!silent) + to_chat(usr, "You've already replied to this poll.") return TRUE qdel(query_hasvoted) return FALSE @@ -517,7 +518,7 @@ if(!replytext) to_chat(usr, "The text you entered was blank. Please correct the text and submit again.") return - var/voted = poll_check_voted(pollid, TRUE) + var/voted = poll_check_voted(pollid, text = TRUE, silent = TRUE) if(isnull(voted)) return var/adminrank = sanitizeSQL(poll_rank()) From 25a95a51b83b8a8b7aea34a428714e2f10a8158d Mon Sep 17 00:00:00 2001 From: AnturK Date: Sat, 1 Sep 2018 11:46:33 +0200 Subject: [PATCH 3/3] That was serious mistake. --- code/modules/mob/dead/new_player/poll.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/modules/mob/dead/new_player/poll.dm b/code/modules/mob/dead/new_player/poll.dm index 618425077bf..04a28f6b5a2 100644 --- a/code/modules/mob/dead/new_player/poll.dm +++ b/code/modules/mob/dead/new_player/poll.dm @@ -489,7 +489,7 @@ //validate the poll if (!vote_valid_check(pollid, client.holder, POLLTYPE_OPTION)) return 0 - var/voted = poll_check_voted() + var/voted = poll_check_voted(pollid) if(isnull(voted) || voted) //Failed or already voted. return var/adminrank = sanitizeSQL(poll_rank())