diff --git a/code/modules/admin/sql_message_system.dm b/code/modules/admin/sql_message_system.dm index 7aedd0dd027..6f6b9cf9629 100644 --- a/code/modules/admin/sql_message_system.dm +++ b/code/modules/admin/sql_message_system.dm @@ -38,8 +38,6 @@ text = input(usr,"Write your [type]","Create [type]") as null|message if(!text) return - if(!timestamp) - timestamp = SQLtime() if(!server) var/ssqlname = CONFIG_GET(string/serversqlname) if (ssqlname) @@ -76,15 +74,11 @@ note_severity = input("Set the severity of the note.", "Severity", null, null) as null|anything in list("High", "Medium", "Minor", "None") if(!note_severity) return - var/datum/db_query/query_create_message = SSdbcore.NewQuery({" - INSERT INTO [format_table_name("messages")] (type, targetckey, adminckey, text, timestamp, server, server_ip, server_port, round_id, secret, expire_timestamp, severity, playtime) - VALUES (:type, :target_ckey, :admin_ckey, :text, :timestamp, :server, INET_ATON(:internet_address), :port, :round_id, :secret, :expiry, :note_severity, (SELECT `minutes` FROM [format_table_name("role_time")] WHERE `ckey` = :target_ckey AND `job` = 'Living')) - "}, list( + var/list/parameters = list( "type" = type, "target_ckey" = target_ckey, "admin_ckey" = admin_ckey, "text" = text, - "timestamp" = timestamp, "server" = server, "internet_address" = world.internet_address || "0", "port" = "[world.port]", @@ -92,7 +86,13 @@ "secret" = secret, "expiry" = expiry || null, "note_severity" = note_severity, - )) + ) + if(timestamp) + parameters["timestamp"] = timestamp + var/datum/db_query/query_create_message = SSdbcore.NewQuery({" + INSERT INTO [format_table_name("messages")] (type, targetckey, adminckey, text, timestamp, server, server_ip, server_port, round_id, secret, expire_timestamp, severity, playtime) + VALUES (:type, :target_ckey, :admin_ckey, :text, [timestamp? ":timestamp" : "Now()"], :server, INET_ATON(:internet_address), :port, :round_id, :secret, :expiry, :note_severity, (SELECT `minutes` FROM [format_table_name("role_time")] WHERE `ckey` = :target_ckey AND `job` = 'Living')) + "}, parameters) var/pm = "[key_name(usr)] has created a [type][(type == "note" || type == "message" || type == "watchlist entry") ? " for [target_key]" : ""]: [text]" var/header = "[key_name_admin(usr)] has created a [type][(type == "note" || type == "message" || type == "watchlist entry") ? " for [target_key]" : ""]" if(!query_create_message.warn_execute()) @@ -627,13 +627,19 @@ browser.set_content(jointext(output, "")) browser.open() -/proc/get_message_output(type, target_ckey) +/proc/get_message_output(type, target_ckey, show_secret = TRUE, after_timestamp) if(!SSdbcore.Connect()) to_chat(usr, span_danger("Failed to establish database connection."), confidential = TRUE) return if(!type) return var/output + var/list/parameters = list( + "targetckey" = target_ckey, + "type" = type, + ) + if(after_timestamp) + parameters["after_timestamp"] = after_timestamp var/datum/db_query/query_get_message_output = SSdbcore.NewQuery({" SELECT id, @@ -646,7 +652,9 @@ AND deleted = 0 AND (expire_timestamp > NOW() OR expire_timestamp IS NULL) AND ((type != 'message' AND type != 'watchlist entry') OR targetckey = :targetckey) - "}, list("targetckey" = target_ckey, "type" = type)) + [after_timestamp? "AND timestamp > :after_timestamp": ""] + [!show_secret? "AND secret = 0": ""] + "}, parameters) if(!query_get_message_output.warn_execute()) qdel(query_get_message_output) return @@ -669,6 +677,9 @@ qdel(query_message_read) return qdel(query_message_read) + if("note") + output += "Note left by [span_prefix("[admin_key]")] on [timestamp]" + output += "
[text]
" if("watchlist entry") message_admins("Notice: [key_name_admin(target_ckey)] has been on the watchlist since [timestamp] and has just connected - Reason: [text]") send2tgs_adminless_only("Watchlist", "[key_name(target_ckey)] is on the watchlist and has just connected - Reason: [text]") diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index e390061f2a2..01fff405322 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -406,6 +406,20 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( if (!stealth_admin) deadchat_broadcast(" has reconnected.", "[mob][mob.get_realname_string()]", follow_target = mob, turf_target = get_turf(mob), message_type = DEADCHAT_LOGIN_LOGOUT, admin_only=!announce_leave) add_verbs_from_config() + + // This needs to be before the client age from db is updated as it'll be updated by then. + var/datum/db_query/query_last_connected = SSdbcore.NewQuery( + "SELECT lastseen FROM [format_table_name("player")] WHERE ckey = :ckey", + list("ckey" = ckey) + ) + if(query_last_connected.warn_execute() && length(query_last_connected.rows)) + query_last_connected.NextRow() + var/time_stamp = query_last_connected.item[1] + var/unread_notes = get_message_output("note", ckey, FALSE, time_stamp) + if(unread_notes) + to_chat(src, unread_notes) + qdel(query_last_connected) + var/cached_player_age = set_client_age_from_db(tdata) //we have to cache this because other shit may change it and we need it's current value now down below. if (isnum(cached_player_age) && cached_player_age == -1) //first connection player_age = 0