From 5f4b341a4b16442d1bdff7ba44b7afc47c112fe2 Mon Sep 17 00:00:00 2001 From: Jordie0608 Date: Mon, 21 Mar 2016 16:32:27 +1100 Subject: [PATCH] fixes and user notification --- code/modules/mob/new_player/new_player.dm | 27 +++++++++-- code/modules/mob/new_player/poll.dm | 55 +++++++++++++++-------- 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/code/modules/mob/new_player/new_player.dm b/code/modules/mob/new_player/new_player.dm index fbb56386da3..55d3ee7370d 100644 --- a/code/modules/mob/new_player/new_player.dm +++ b/code/modules/mob/new_player/new_player.dm @@ -204,10 +204,16 @@ switch(votetype) if(POLLTYPE_OPTION) var/optionid = text2num(href_list["voteoptionid"]) - vote_on_poll(pollid, optionid) + if(vote_on_poll(pollid, optionid)) + usr << "Vote successful." + else + usr << "Vote failed, please try again or contact an administrator." if(POLLTYPE_TEXT) var/replytext = href_list["replytext"] - log_text_poll_reply(pollid, replytext) + if(log_text_poll_reply(pollid, replytext)) + usr << "Feedback logging successful." + else + usr << "Feedback logging failed, please try again or contact an administrator." if(POLLTYPE_RATING) var/id_min = text2num(href_list["minid"]) var/id_max = text2num(href_list["maxid"]) @@ -226,7 +232,10 @@ if(!isnum(rating) || !IsInteger(rating)) return - vote_on_numval_poll(pollid, optionid, rating) + if(!vote_on_numval_poll(pollid, optionid, rating)) + usr << "Vote failed, please try again or contact an administrator." + return + usr << "Vote successful." if(POLLTYPE_MULTI) var/id_min = text2num(href_list["minoptionid"]) var/id_max = text2num(href_list["maxoptionid"]) @@ -237,7 +246,17 @@ for(var/optionid = id_min; optionid <= id_max; optionid++) if(!isnull(href_list["option_[optionid]"])) //Test if this optionid was selected - vote_on_multi_poll(pollid, optionid) + var/i = vote_on_multi_poll(pollid, optionid) + switch(i) + if(0) + continue + if(1) + usr << "Vote failed, please try again or contact an administrator." + return + if(2) + usr << "Maximum replies reached." + break + usr << "Vote successful." /mob/new_player/proc/IsJobAvailable(rank) var/datum/job/job = SSjob.GetJob(rank) diff --git a/code/modules/mob/new_player/poll.dm b/code/modules/mob/new_player/poll.dm index 7ebd9e6fd9e..64fc6aac532 100644 --- a/code/modules/mob/new_player/poll.dm +++ b/code/modules/mob/new_player/poll.dm @@ -254,64 +254,81 @@ var/err = query_insert.ErrorMsg() log_game("SQL ERROR adding vote to table. Error : \[[err]\]\n") return - usr << "Vote successful." usr << browse(null,"window=playerpoll") + return 1 /mob/new_player/proc/log_text_poll_reply(pollid, replytext) - if(!pollid || !replytext) + if(!pollid) + return + if(!replytext) + usr << "The text you entered was blank. Please correct the text and submit again." return var/adminrank = poll_check_voted(pollid, "poll_textreply") if(!adminrank) return replytext = sanitizeSQL(replytext) - if(!length(replytext) > 0 || !length(replytext) <= 8000) - usr << "The text you entered was blank or too long. Please correct the text and submit again." + if(!(length(replytext) > 0) || !(length(replytext) <= 8000)) + usr << "The text you entered was invalid or too long. Please correct the text and submit again." return var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO [format_table_name("poll_textreply")] (datetime ,pollid ,ckey ,ip ,replytext ,adminrank) VALUES (Now(), [pollid], '[ckey]', '[client.address]', '[replytext]', '[adminrank]')") if(!query_insert.Execute()) var/err = query_insert.ErrorMsg() log_game("SQL ERROR adding text reply to table. Error : \[[err]\]\n") return - usr << "Feedback logging successful." usr << browse(null,"window=playerpoll") + return 1 /mob/new_player/proc/vote_on_numval_poll(pollid, optionid, rating) if(!pollid || !optionid || !rating) return - var/adminrank = poll_check_voted(pollid, "poll_vote") - if(!adminrank) + if(!dbcon.IsConnected()) + usr << "Failed to establish database connection." return + var/DBQuery/query_hasvoted = dbcon.NewQuery("SELECT id FROM [format_table_name("poll_vote")] WHERE optionid = [optionid] AND ckey = '[ckey]'") + if(!query_hasvoted.Execute()) + var/err = query_hasvoted.ErrorMsg() + log_game("SQL ERROR obtaining id from poll_vote table. Error : \[[err]\]\n") + return + if(query_hasvoted.NextRow()) + usr << "You've already replied to this poll." + return + var/adminrank = "Player" + if(client.holder) + adminrank = client.holder.rank var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO [format_table_name("poll_vote")] (datetime ,pollid ,optionid ,ckey ,ip ,adminrank, rating) VALUES (Now(), [pollid], [optionid], '[ckey]', '[client.address]', '[adminrank]', [(isnull(rating)) ? "null" : rating])") if(!query_insert.Execute()) var/err = query_insert.ErrorMsg() log_game("SQL ERROR adding vote to table. Error : \[[err]\]\n") return - usr << "Vote successful." usr << browse(null,"window=playerpoll") + return 1 /mob/new_player/proc/vote_on_multi_poll(pollid, optionid) if(!pollid || !optionid) - return + return 1 if(!dbcon.IsConnected()) usr << "Failed to establish database connection." - return - var/DBQuery/query_get_choicelen = dbcon.NewQuery("SELECT multiplechoiceoptions FROM [format_table_name("poll_question")] WHERE pollid = [pollid]") + return 1 + var/DBQuery/query_get_choicelen = dbcon.NewQuery("SELECT multiplechoiceoptions FROM [format_table_name("poll_question")] WHERE id = [pollid]") if(!query_get_choicelen.Execute()) var/err = query_get_choicelen.ErrorMsg() log_game("SQL ERROR obtaining multiplechoiceoptions from poll_question table. Error : \[[err]\]\n") - return - var/i = text2num(query_get_choicelen.item[1]) + return 1 + var/i + if(query_get_choicelen.NextRow()) + i = text2num(query_get_choicelen.item[1]) var/DBQuery/query_hasvoted = dbcon.NewQuery("SELECT id FROM [format_table_name("poll_vote")] WHERE pollid = [pollid] AND ckey = '[ckey]'") if(!query_hasvoted.Execute()) var/err = query_hasvoted.ErrorMsg() log_game("SQL ERROR obtaining id from poll_vote table. Error : \[[err]\]\n") - return + return 1 while(i) if(query_hasvoted.NextRow()) i-- + else + break if(!i) - usr << "Maximum replies reached." - return + return 2 var/adminrank = "Player" if(client.holder) adminrank = client.holder.rank @@ -319,6 +336,6 @@ if(!query_insert.Execute()) var/err = query_insert.ErrorMsg() log_game("SQL ERROR adding vote to table. Error : \[[err]\]\n") - return - usr << "Vote successful." - usr << browse(null,"window=playerpoll") \ No newline at end of file + return 1 + usr << browse(null,"window=playerpoll") + return 0 \ No newline at end of file