From ce8dba6062e9888b0ad31c3749e0aadad7a734bc Mon Sep 17 00:00:00 2001 From: tgstation-server Date: Sat, 7 Nov 2020 00:37:22 +0000 Subject: [PATCH] Update TGS DMAPI --- code/__DEFINES/tgs.dm | 5 +++- code/modules/tgs/core/datum.dm | 2 +- code/modules/tgs/v3210/api.dm | 4 +-- code/modules/tgs/v3210/commands.dm | 6 +++++ code/modules/tgs/v4/api.dm | 9 +------ code/modules/tgs/v5/api.dm | 21 ++++++++-------- tools/json_verifier.py | 40 +++++++++++++++--------------- 7 files changed, 44 insertions(+), 43 deletions(-) diff --git a/code/__DEFINES/tgs.dm b/code/__DEFINES/tgs.dm index 7c0811ec59..a0a5df4290 100644 --- a/code/__DEFINES/tgs.dm +++ b/code/__DEFINES/tgs.dm @@ -1,6 +1,6 @@ // tgstation-server DMAPI -#define TGS_DMAPI_VERSION "5.2.1" +#define TGS_DMAPI_VERSION "5.2.7" // All functions and datums outside this document are subject to change with any version and should not be relied on. @@ -95,6 +95,8 @@ #define TGS_EVENT_WATCHDOG_SHUTDOWN 15 /// Before the watchdog detaches for a TGS update/restart. No parameters. #define TGS_EVENT_WATCHDOG_DETACH 16 +// We don't actually implement this value as the DMAPI can never receive it +// #define TGS_EVENT_WATCHDOG_LAUNCH 17 // OTHER ENUMS @@ -127,6 +129,7 @@ * Call this when your initializations are complete and your game is ready to play before any player interactions happen. * * This may use [/world/var/sleep_offline] to make this happen so ensure no changes are made to it while this call is running. + * Afterwards, consider explicitly setting it to what you want to avoid this BYOND bug: http://www.byond.com/forum/post/2575184 * Before this point, note that any static files or directories may be in use by another server. Your code should account for this. * This function should not be called before ..() in [/world/proc/New]. */ diff --git a/code/modules/tgs/core/datum.dm b/code/modules/tgs/core/datum.dm index ef6d3a4fe5..4d37ed662d 100644 --- a/code/modules/tgs/core/datum.dm +++ b/code/modules/tgs/core/datum.dm @@ -50,7 +50,7 @@ TGS_PROTECT_DATUM(/datum/tgs_api) /datum/tgs_api/proc/ChatTargetedBroadcast(message, admin_only) return TGS_UNIMPLEMENTED -/datum/tgs_api/proc/ChatPrivateMessage(message, admin_only) +/datum/tgs_api/proc/ChatPrivateMessage(message, datum/tgs_chat_user/user) return TGS_UNIMPLEMENTED /datum/tgs_api/proc/SecurityLevel() diff --git a/code/modules/tgs/v3210/api.dm b/code/modules/tgs/v3210/api.dm index e0d00ad15d..5b41e6a89d 100644 --- a/code/modules/tgs/v3210/api.dm +++ b/code/modules/tgs/v3210/api.dm @@ -39,7 +39,7 @@ var/warned_custom_commands = FALSE /datum/tgs_api/v3210/ApiVersion() - return new /datum/tgs_version("3.2.1.0") + return new /datum/tgs_version("3.2.1.3") /datum/tgs_api/v3210/proc/trim_left(text) for (var/i = 1 to length(text)) @@ -180,7 +180,7 @@ ExportService(SERVICE_REQUEST_KILL_PROCESS) /datum/tgs_api/v3210/ChatChannelInfo() - return list() + return list() // :omegalul: /datum/tgs_api/v3210/ChatBroadcast(message, list/channels) if(channels) diff --git a/code/modules/tgs/v3210/commands.dm b/code/modules/tgs/v3210/commands.dm index a1949da444..4ccfc1a8a6 100644 --- a/code/modules/tgs/v3210/commands.dm +++ b/code/modules/tgs/v3210/commands.dm @@ -42,5 +42,11 @@ var/datum/tgs_chat_command/stc = new command_type var/datum/tgs_chat_user/user = new user.friendly_name = sender + + // Discord hack, fix the mention if it's only numbers (fuck you IRC trolls) + var/regex/discord_id_regex = regex(@"^[0-9]+$") + if(findtext(sender, discord_id_regex)) + sender = "<@[sender]>" + user.mention = sender return stc.Run(user, params) || TRUE diff --git a/code/modules/tgs/v4/api.dm b/code/modules/tgs/v4/api.dm index 1dc98f811e..081543828e 100644 --- a/code/modules/tgs/v4/api.dm +++ b/code/modules/tgs/v4/api.dm @@ -114,13 +114,6 @@ /datum/tgs_api/v4/OnInitializationComplete() Export(TGS4_COMM_SERVER_PRIMED) - var/tgs4_secret_sleep_offline_sauce = 24051994 - var/old_sleep_offline = world.sleep_offline - world.sleep_offline = tgs4_secret_sleep_offline_sauce - sleep(1) - if(world.sleep_offline == tgs4_secret_sleep_offline_sauce) //if not someone changed it - world.sleep_offline = old_sleep_offline - /datum/tgs_api/v4/OnTopic(T) var/list/params = params2list(T) var/their_sCK = params[TGS4_INTEROP_ACCESS_IDENTIFIER] @@ -255,7 +248,7 @@ return instance_name /datum/tgs_api/v4/TestMerges() - return cached_test_merges + return cached_test_merges.Copy() /datum/tgs_api/v4/EndProcess() Export(TGS4_COMM_END_PROCESS) diff --git a/code/modules/tgs/v5/api.dm b/code/modules/tgs/v5/api.dm index 8ca85faf05..466a986237 100644 --- a/code/modules/tgs/v5/api.dm +++ b/code/modules/tgs/v5/api.dm @@ -15,8 +15,10 @@ var/datum/tgs_revision_information/revision var/list/chat_channels + var/initialized = FALSE + /datum/tgs_api/v5/ApiVersion() - return new /datum/tgs_version("5.2.1") + return new /datum/tgs_version(TGS_DMAPI_VERSION) /datum/tgs_api/v5/OnWorldNew(minimum_required_security_level) server_port = world.params[DMAPI5_PARAM_SERVER_PORT] @@ -79,6 +81,7 @@ chat_channels = list() DecodeChannels(runtime_information) + initialized = TRUE return TRUE /datum/tgs_api/v5/proc/RequireInitialBridgeResponse() @@ -88,13 +91,6 @@ /datum/tgs_api/v5/OnInitializationComplete() Bridge(DMAPI5_BRIDGE_COMMAND_PRIME) - var/tgs4_secret_sleep_offline_sauce = 29051994 - var/old_sleep_offline = world.sleep_offline - world.sleep_offline = tgs4_secret_sleep_offline_sauce - sleep(1) - if(world.sleep_offline == tgs4_secret_sleep_offline_sauce) //if not someone changed it - world.sleep_offline = old_sleep_offline - /datum/tgs_api/v5/proc/TopicResponse(error_message = null) var/list/response = list() response[DMAPI5_RESPONSE_ERROR_MESSAGE] = error_message @@ -102,10 +98,13 @@ return json_encode(response) /datum/tgs_api/v5/OnTopic(T) + if(!initialized) + return FALSE //continue world/Topic + var/list/params = params2list(T) var/json = params[DMAPI5_TOPIC_DATA] if(!json) - return FALSE //continue world/Topic + return FALSE var/list/topic_parameters = json_decode(json) if(!topic_parameters) @@ -282,7 +281,7 @@ /datum/tgs_api/v5/TestMerges() RequireInitialBridgeResponse() - return test_merges + return test_merges.Copy() /datum/tgs_api/v5/EndProcess() Bridge(DMAPI5_BRIDGE_COMMAND_KILL) @@ -327,7 +326,7 @@ /datum/tgs_api/v5/ChatChannelInfo() RequireInitialBridgeResponse() - return chat_channels + return chat_channels.Copy() /datum/tgs_api/v5/proc/DecodeChannels(chat_update_json) var/list/chat_channels_json = chat_update_json[DMAPI5_CHAT_UPDATE_CHANNELS] diff --git a/tools/json_verifier.py b/tools/json_verifier.py index dbba811205..aa74620667 100644 --- a/tools/json_verifier.py +++ b/tools/json_verifier.py @@ -1,20 +1,20 @@ -import sys -import json - -if len(sys.argv) <= 1: - exit(1) - -status = 0 - -for file in sys.argv[1:]: - with open(file, encoding="ISO-8859-1") as f: - try: - json.load(f) - except ValueError as exception: - print("JSON error in {}".format(file)) - print(exception) - status = 1 - else: - print("Valid {}".format(file)) - -exit(status) +import sys +import json + +if len(sys.argv) <= 1: + exit(1) + +status = 0 + +for file in sys.argv[1:]: + with open(file, encoding="ISO-8859-1") as f: + try: + json.load(f) + except ValueError as exception: + print("JSON error in {}".format(file)) + print(exception) + status = 1 + else: + print("Valid {}".format(file)) + +exit(status)