From 923642771362eb4ff3440fd0a8075dfcb0717ee3 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 25 Sep 2018 15:08:55 -0400 Subject: [PATCH 1/3] Lock the V3 DMAPI behind a define to fix #717 --- src/DMAPI/tgs.dm | 4 ++++ src/DMAPI/tgs/core/core.dm | 8 ++++++++ src/DMAPI/tgs/includes.dm | 2 ++ 3 files changed, 14 insertions(+) diff --git a/src/DMAPI/tgs.dm b/src/DMAPI/tgs.dm index 6645ce51ff..2f4c8a4040 100644 --- a/src/DMAPI/tgs.dm +++ b/src/DMAPI/tgs.dm @@ -7,6 +7,10 @@ //create this define if you want to do configuration outside of this file #ifndef TGS_EXTERNAL_CONFIGURATION +//Uncomment this if you wish to allow the game to interact with TGS 3 +//This will raise the minimum required security level of your game to TGS_SECURITY_TRUSTED due to it utilizing call()() +//#define TGS_V3_API + //Comment this out once you've filled in the below #error TGS API unconfigured diff --git a/src/DMAPI/tgs/core/core.dm b/src/DMAPI/tgs/core/core.dm index e0495aba4e..34b1329950 100644 --- a/src/DMAPI/tgs/core/core.dm +++ b/src/DMAPI/tgs/core/core.dm @@ -4,6 +4,10 @@ TGS_ERROR_LOG("TgsNew(): TGS API datum already set ([current_api])!") return +#ifdef TGS_V3_API + minimum_required_security_level = TGS_SECURITY_TRUSTED +#endif + var/tgs_version = world.params[TGS_VERSION_PARAMETER] if(!tgs_version) return @@ -36,9 +40,13 @@ switch(super) if(3) +#ifndef TGS_V3_API + TGS_ERROR_LOG("Detected V3 API but TGS_V3_API isn't defined!") +#else switch(major) if(2) return /datum/tgs_api/v3210 +#endif if(4) switch(major) if(0) diff --git a/src/DMAPI/tgs/includes.dm b/src/DMAPI/tgs/includes.dm index 2fdd5ed1e0..e145394015 100644 --- a/src/DMAPI/tgs/includes.dm +++ b/src/DMAPI/tgs/includes.dm @@ -2,7 +2,9 @@ #include "core\core.dm" #include "core\datum.dm" #include "core\default_event_handler.dm" +#ifdef TGS_V3_API #include "v3210\api.dm" #include "v3210\commands.dm" +#endif #include "v4\api.dm" #include "v4\commands.dm" From 557745970f319ef10f9ced91d51cf056ff91588d Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 25 Sep 2018 15:12:26 -0400 Subject: [PATCH 2/3] Remove default_event_handler Waste of typespace --- src/DMAPI/tgs/core/core.dm | 2 +- src/DMAPI/tgs/core/default_event_handler.dm | 30 --------------------- src/DMAPI/tgs/includes.dm | 1 - src/DMAPI/tgs/v4/api.dm | 6 ++--- tgstation-server.sln | 1 - 5 files changed, 4 insertions(+), 36 deletions(-) delete mode 100644 src/DMAPI/tgs/core/default_event_handler.dm diff --git a/src/DMAPI/tgs/core/core.dm b/src/DMAPI/tgs/core/core.dm index 34b1329950..f63cc84eea 100644 --- a/src/DMAPI/tgs/core/core.dm +++ b/src/DMAPI/tgs/core/core.dm @@ -22,7 +22,7 @@ TGS_WRITE_GLOBAL(tgs, new_api) - var/result = new_api.OnWorldNew(event_handler ? event_handler : new /datum/tgs_event_handler/tgs_default, minimum_required_security_level) + var/result = new_api.OnWorldNew(event_handler, minimum_required_security_level) if(!result || result == TGS_UNIMPLEMENTED) TGS_WRITE_GLOBAL(tgs, null) TGS_ERROR_LOG("Failed to activate API!") diff --git a/src/DMAPI/tgs/core/default_event_handler.dm b/src/DMAPI/tgs/core/default_event_handler.dm deleted file mode 100644 index 716715bb26..0000000000 --- a/src/DMAPI/tgs/core/default_event_handler.dm +++ /dev/null @@ -1,30 +0,0 @@ -/datum/tgs_event_handler/tgs_default/HandleEvent(event_code) - //TODO - return - -/* -The MIT License - -Copyright (c) 2017 Jordan Brown - -Permission is hereby granted, free of charge, -to any person obtaining a copy of this software and -associated documentation files (the "Software"), to -deal in the Software without restriction, including -without limitation the rights to use, copy, modify, -merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom -the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ diff --git a/src/DMAPI/tgs/includes.dm b/src/DMAPI/tgs/includes.dm index e145394015..a3f10b29f5 100644 --- a/src/DMAPI/tgs/includes.dm +++ b/src/DMAPI/tgs/includes.dm @@ -1,7 +1,6 @@ #include "core\_definitions.dm" #include "core\core.dm" #include "core\datum.dm" -#include "core\default_event_handler.dm" #ifdef TGS_V3_API #include "v3210\api.dm" #include "v3210\commands.dm" diff --git a/src/DMAPI/tgs/v4/api.dm b/src/DMAPI/tgs/v4/api.dm index aedcf1429e..bf17051d90 100644 --- a/src/DMAPI/tgs/v4/api.dm +++ b/src/DMAPI/tgs/v4/api.dm @@ -150,7 +150,7 @@ if(event_parameters) event_call += event_parameters - event_handler.HandleEvent(arglist(event_call)) + event_handler?.HandleEvent(arglist(event_call)) . = json_encode(intercepted_message_queue) intercepted_message_queue = null @@ -165,13 +165,13 @@ //the topic still completes, miraculously //I honestly didn't believe byond could do it - event_handler.HandleEvent(TGS_EVENT_PORT_SWAP, new_port) + event_handler?.HandleEvent(TGS_EVENT_PORT_SWAP, new_port) if(!world.OpenPort(new_port)) return "Port change failed!" return if(TGS4_TOPIC_CHANGE_REBOOT_MODE) var/new_reboot_mode = text2num(params[TGS4_PARAMETER_DATA]) - event_handler.HandleEvent(TGS_EVENT_REBOOT_MODE_CHANGE, reboot_mode, new_reboot_mode) + event_handler?.HandleEvent(TGS_EVENT_REBOOT_MODE_CHANGE, reboot_mode, new_reboot_mode) reboot_mode = new_reboot_mode return diff --git a/tgstation-server.sln b/tgstation-server.sln index e3faccff88..a7fb21ff65 100644 --- a/tgstation-server.sln +++ b/tgstation-server.sln @@ -64,7 +64,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{DCCBA9DA-4 src\DMAPI\tgs\core\_definitions.dm = src\DMAPI\tgs\core\_definitions.dm src\DMAPI\tgs\core\core.dm = src\DMAPI\tgs\core\core.dm src\DMAPI\tgs\core\datum.dm = src\DMAPI\tgs\core\datum.dm - src\DMAPI\tgs\core\default_event_handler.dm = src\DMAPI\tgs\core\default_event_handler.dm EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "v3210", "v3210", "{1B228ACB-60C3-4DF9-B716-9F0BD31F6766}" From d64aa9be248ce5523da0d9c31d5763c1faf573f5 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Tue, 25 Sep 2018 16:46:00 -0400 Subject: [PATCH 3/3] Remove null propagation --- src/DMAPI/tgs/v4/api.dm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/DMAPI/tgs/v4/api.dm b/src/DMAPI/tgs/v4/api.dm index bf17051d90..9d74610f9c 100644 --- a/src/DMAPI/tgs/v4/api.dm +++ b/src/DMAPI/tgs/v4/api.dm @@ -150,7 +150,8 @@ if(event_parameters) event_call += event_parameters - event_handler?.HandleEvent(arglist(event_call)) + if(event_handler != null) + event_handler.HandleEvent(arglist(event_call)) . = json_encode(intercepted_message_queue) intercepted_message_queue = null @@ -165,13 +166,15 @@ //the topic still completes, miraculously //I honestly didn't believe byond could do it - event_handler?.HandleEvent(TGS_EVENT_PORT_SWAP, new_port) + if(event_handler != null) + event_handler.HandleEvent(TGS_EVENT_PORT_SWAP, new_port) if(!world.OpenPort(new_port)) return "Port change failed!" return if(TGS4_TOPIC_CHANGE_REBOOT_MODE) var/new_reboot_mode = text2num(params[TGS4_PARAMETER_DATA]) - event_handler?.HandleEvent(TGS_EVENT_REBOOT_MODE_CHANGE, reboot_mode, new_reboot_mode) + if(event_handler != null) + event_handler.HandleEvent(TGS_EVENT_REBOOT_MODE_CHANGE, reboot_mode, new_reboot_mode) reboot_mode = new_reboot_mode return