/* * A simple datum for storing notifications for dispaly. */ /datum/client_notification var/datum/preferences/owner = null var/list/note_wrapper = list() var/note_text = "" var/proc_src = null var/proc_name = "" var/proc_args = null var/persistent = 0 /datum/client_notification/New(var/datum/preferences/prefs, var/list/new_wrapper, var/new_text, var/new_persistence) if (!prefs) qdel(src) return if (!new_wrapper || new_wrapper.len != 2) qdel(src) return if (!new_text) qdel(src) return owner = prefs note_wrapper = new_wrapper note_text = new_text note_text = replacetextEx(note_text, ":src_ref", REF(src)) note_wrapper[1] = replacetextEx(note_wrapper[1], ":src_ref", REF(src)) if (new_persistence) persistent = new_persistence /datum/client_notification/Destroy() if (owner) owner.notifications -= src owner = null return ..() /* * Associates a callback to be executed whenever a notification is dismissed. */ /datum/client_notification/proc/tie_callback(var/dismiss_proc_src, var/dismiss_proc, var/dismiss_proc_args) if (!dismiss_proc_src || !dismiss_proc) return proc_src = dismiss_proc_src proc_name = dismiss_proc if (dismiss_proc_args) proc_args = dismiss_proc_args /* * Returns the HTML required to display this alert. */ /datum/client_notification/proc/get_html() var/html = "
[note_wrapper[1]]" if (!persistent) html += "×" html += note_text html += "[note_wrapper[2]]
" return html /* * Dismisses the notification, executing the proc that was set up as necessary. */ /datum/client_notification/proc/dismiss() if (proc_src && proc_name) call(proc_src, proc_name)(proc_args) if (!persistent) qdel(src) /* * Adds a new notification datum for later processing. */ /datum/preferences/proc/new_notification(var/type, var/text, var/persistent, var/callback_src, var/callback_proc, var/callback_args) if (!text) return var/list/wrapper switch (type) if ("success") wrapper = list("
", "
") if ("info") wrapper = list("
", "
") if ("warning") wrapper = list("
", "
") if ("danger") wrapper = list("
", "
") else wrapper = list("
", "
") var/datum/client_notification/note = new(src, wrapper, text, persistent) if (callback_src && callback_proc) note.tie_callback(callback_src, callback_proc, callback_args) notifications += note /* * Gathers all notifications relevant to the client. */ /datum/preferences/proc/gather_notifications(var/client/user) if (!user) return if (user.byond_version < GLOB.config.client_warn_version) var/version_warn = "" version_warn += "Your version of BYOND may be out of date!
" version_warn += GLOB.config.client_warn_message version_warn += "Your version: [user.byond_version].
" version_warn += "Required version to remove this message: [GLOB.config.client_warn_version] or later.
" version_warn += "Visit http://www.byond.com/download/ to get the latest version of BYOND." new_notification("danger", version_warn) if (GLOB.custom_event_msg && GLOB.custom_event_msg != "") var/custom_event_warn = "
A custom event is taking place!

" custom_event_warn += "OOC Info:
[GLOB.custom_event_msg]" new_notification("danger", custom_event_warn) if (lastchangelog != GLOB.changelog_hash) winset(user, "infowindow.changelog", "background-color=#eaeaea;font-style=bold") if (GLOB.config.aggressive_changelog) new_notification("info", "You have unread updates in the changelog.", callback_src = user, callback_proc = "changes") else new_notification("info", "You have unread updates in the changelog.") if (GLOB.config.sql_enabled) user.warnings_gather() user.gather_linking_requests() count_ccia_actions(user) add_active_notifications(user) /datum/preferences/proc/add_active_notifications(var/client/user) if (!user) return if (!SSdbcore.Connect()) return var/datum/db_query/query = SSdbcore.NewQuery( "SELECT message, type, id FROM ss13_player_notifications WHERE acked_at IS NULL AND ckey = :ckey", list("ckey" = user.ckey)) query.SetSuccessCallback(CALLBACK(src, PROC_REF(_add_active_notifications_cb), user)) query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel))) query.ExecuteNoSleep(TRUE) /datum/preferences/proc/_add_active_notifications_cb(var/client/user, datum/db_query/query) var/chat_notification = 0 var/panel_notification = 0 var/notification_count = 0 while (query.NextRow()) var/autoack = 0 switch(query.item[2]) if("player_greeting") panel_notification = 1 notification_count++ if("player_greeting_chat") chat_notification = 1 panel_notification = 1 notification_count++ if("admin") SSdiscord.send_to_admins("Server Notification for [user.ckey]: [query.item[1]]") SSdiscord.post_webhook_event(WEBHOOK_ADMIN, list("title"="Server Notification for: [user.ckey]", "message"="Server Notification Triggered for [user.ckey]: [query.item[1]]")) autoack = 1 if("ccia") SSdiscord.send_to_cciaa("Server Notification for [user.ckey]: [query.item[1]]") SSdiscord.post_webhook_event(WEBHOOK_CCIAA_EMERGENCY_MESSAGE, list("title"="Server Notification for: [user.ckey]", "message"="Server Notification Triggered for [user.ckey]: [query.item[1]]")) autoack = 1 if (autoack) var/datum/db_query/ackquery = SSdbcore.NewQuery( "UPDATE ss13_player_notifications SET acked_by = 'autoack-server', acked_at = NOW() WHERE id = :id", list("id" = query.item[3])) ackquery.SetSuccessCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel))) ackquery.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel))) ackquery.ExecuteNoSleep(TRUE) qdel(query) if (panel_notification) new_notification("warning", "You have [notification_count] unread notifications! Click here to review and acknowledge them!") if (chat_notification) to_chat(user, SPAN_WARNING("You have unacknowledged notifications.
Click here to review and acknowledge them!")) /* * Helper proc for getting a count of active CCIA actions against the player's characters. */ /datum/preferences/proc/count_ccia_actions(var/client/user) if (!user) return if (!SSdbcore.Connect()) return var/datum/db_query/actions_query = SSdbcore.NewQuery( {"SELECT COUNT(act_chr.action_id) AS action_count FROM ss13_ccia_action_char act_chr JOIN ss13_characters chr ON act_chr.char_id = chr.id JOIN ss13_ccia_actions act ON act_chr.action_id = act.id WHERE chr.ckey = :ckey AND (act.expires_at IS NULL OR act.expires_at >= CURRENT_DATE()) AND act.deleted_at IS NULL;"}, list("ckey" = user.ckey)) actions_query.SetSuccessCallback(CALLBACK(src, PROC_REF(_count_ccia_actions_cb))) actions_query.SetFailCallback(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(qdel))) actions_query.ExecuteNoSleep(TRUE) /datum/preferences/proc/_count_ccia_actions_cb(datum/db_query/query) if (query.NextRow()) var/action_count = text2num(query.item[1]) if (action_count > 0) new_notification("info", "There are [action_count] active CCIA actions currently active against your character(s).") qdel(query)