From fdc2fe1fbc2b08398c1ecc7b31925598be6682eb Mon Sep 17 00:00:00 2001 From: Neerti Date: Tue, 10 Jan 2017 04:36:38 -0500 Subject: [PATCH] Adds new Server News Adds ability for admins with R_SERVER perms to be able to set a persistant 'news' announcement that works similarly to admin memos, but for the public. This is ideal for telling the public things such as when an event is scheduled, directing people to a forum thread, new lore changes, new policies, etc. The news window allows to define a title, and the body of the text, using an admin verb. The author and date are added automatically. Any players can read the news window in the lobby. The button will bold itself, and display (NEW!), if the player has not seen the news before. This is done by comparing a hash of the body that the client remembers verses a hash the current news body. --- code/modules/admin/admin_verbs.dm | 3 +- code/modules/admin/news.dm | 42 +++++++++++++++++++++++ code/modules/mob/new_player/new_player.dm | 27 +++++++++++++++ polaris.dme | 1 + 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 code/modules/admin/news.dm diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 0c059517d3..91a504f421 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -160,7 +160,8 @@ var/list/admin_verbs_server = list( /datum/admins/proc/toggle_space_ninja, /client/proc/toggle_random_events, /client/proc/check_customitem_activity, - /client/proc/nanomapgen_DumpImage + /client/proc/nanomapgen_DumpImage, + /client/proc/modify_server_news ) var/list/admin_verbs_debug = list( /client/proc/getruntimelog, //allows us to access runtime logs to somebody, diff --git a/code/modules/admin/news.dm b/code/modules/admin/news.dm new file mode 100644 index 0000000000..7881febe3a --- /dev/null +++ b/code/modules/admin/news.dm @@ -0,0 +1,42 @@ +#define NEWSFILE "data/news.sav" //where the memos are saved + +/client/ + var/last_news_hash = null // Stores a hash of the last news window it saw, which gets compared to the current one to see if it is different. + +// Returns true if news was updated since last seen. +/client/proc/check_for_new_server_news() + var/savefile/F = get_server_news() + if(F) + if(md5(F["body"]) != last_news_hash) + return TRUE + return FALSE + +/client/proc/modify_server_news() + set name = "Modify Public News" + set category = "Server" + + if(!check_rights(0)) + return + + var/savefile/F = new(NEWSFILE) + if(F) + var/title = F["title"] + var/body = F["body"] + var/new_title = sanitize(input(src,"Write a good title for the news update. Note: HTML is NOT supported.","Write News", title) as null|text, extra = 0) + if(!new_title) + return + var/new_body = sanitize(input(src,"Write the body of the news update here. Note: HTML is NOT supported.","Write News", body) as null|message, extra = 0) + if(findtext(new_body,"[new_title]
[new_body]") + +/proc/get_server_news() + var/savefile/F = new(NEWSFILE) + if(F) + return F + +#undef NEWSFILE \ No newline at end of file diff --git a/code/modules/mob/new_player/new_player.dm b/code/modules/mob/new_player/new_player.dm index 76226220b4..40a1793eed 100644 --- a/code/modules/mob/new_player/new_player.dm +++ b/code/modules/mob/new_player/new_player.dm @@ -60,6 +60,11 @@ else output += "

Show Player Polls

" + if(client.check_for_new_server_news()) + output += "

Show News (NEW!)

" + else + output += "

Show News

" + output += "" panel = new(src, "Welcome","Welcome", 210, 280, src) @@ -277,6 +282,28 @@ if(!isnull(href_list["option_[optionid]"])) //Test if this optionid was selected vote_on_poll(pollid, optionid, 1) + if(href_list["shownews"]) + handle_server_news() + return + +/mob/new_player/proc/handle_server_news() + if(!client) + return + var/savefile/F = get_server_news() + if(F) + client.last_news_hash = md5(F["body"]) + + var/dat = "
" + dat += "

[F["title"]]

" + dat += "
" + dat += "[F["body"]]" + dat += "
" + dat += "Last written by [F["author"]], on [F["timestamp"]]." + dat += "
" + var/datum/browser/popup = new(src, "Server News", "Server News", 450, 300, src) + popup.set_content(dat) + popup.open() + /mob/new_player/proc/IsJobAvailable(rank) var/datum/job/job = job_master.GetJob(rank) if(!job) return 0 diff --git a/polaris.dme b/polaris.dme index 413a2fd1ca..bc843912f0 100644 --- a/polaris.dme +++ b/polaris.dme @@ -1032,6 +1032,7 @@ #include "code\modules\admin\IsBanned.dm" #include "code\modules\admin\map_capture.dm" #include "code\modules\admin\NewBan.dm" +#include "code\modules\admin\news.dm" #include "code\modules\admin\player_notes.dm" #include "code\modules\admin\player_panel.dm" #include "code\modules\admin\topic.dm"