mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-27 14:08:44 +01:00
Merge pull request #7838 from VOREStation/aro-dmapi
Upgrade DMAPI to 5.1.0
This commit is contained in:
+34
-28
@@ -1,6 +1,6 @@
|
||||
//tgstation-server DMAPI
|
||||
|
||||
#define TGS_DMAPI_VERSION "5.0.0"
|
||||
#define TGS_DMAPI_VERSION "5.1.0"
|
||||
|
||||
//All functions and datums outside this document are subject to change with any version and should not be relied on
|
||||
|
||||
@@ -54,7 +54,8 @@
|
||||
|
||||
#define TGS_EVENT_REBOOT_MODE_CHANGE -1 //Before a reboot mode change, extras parameters are the current and new reboot mode enums
|
||||
#define TGS_EVENT_PORT_SWAP -2 //Before a port change is about to happen, extra parameters is new port
|
||||
#define TGS_EVENT_INSTANCE_RENAMED -3 //Before the instance is renamed, extra prameter is the new name
|
||||
#define TGS_EVENT_INSTANCE_RENAMED -3 //Before the instance is renamed, extra parameter is the new name
|
||||
#define TGS_EVENT_WATCHDOG_REATTACH -4 //After the watchdog reattaches to DD, extra parameter is the new /datum/tgs_version of the server
|
||||
|
||||
//See the descriptions for the parameters of these codes here: https://github.com/tgstation/tgstation-server/blob/master/src/Tgstation.Server.Host/Components/EventType.cs
|
||||
#define TGS_EVENT_REPO_RESET_ORIGIN 0
|
||||
@@ -70,7 +71,10 @@
|
||||
#define TGS_EVENT_COMPILE_FAILURE 10
|
||||
#define TGS_EVENT_COMPILE_COMPLETE 11 // Note, this event fires before the new .dmb is loaded into the watchdog. Consider using the TGS_EVENT_DEPLOYMENT_COMPLETE instead
|
||||
#define TGS_EVENT_INSTANCE_AUTO_UPDATE_START 12
|
||||
#define TGS_EVENT_DEPLOYMENT_COMPLETE 13
|
||||
#define TGS_EVENT_REPO_MERGE_CONFLICT 13
|
||||
#define TGS_EVENT_DEPLOYMENT_COMPLETE 14
|
||||
#define TGS_EVENT_WATCHDOG_SHUTDOWN 15
|
||||
#define TGS_EVENT_WATCHDOG_DETACH 16
|
||||
|
||||
//OTHER ENUMS
|
||||
|
||||
@@ -85,7 +89,7 @@
|
||||
//REQUIRED HOOKS
|
||||
|
||||
//Call this somewhere in /world/New() that is always run
|
||||
//IMPORTANT: This function may sleep! Other TGS functions will not succeed until it completes
|
||||
//IMPORTANT: This function may sleep!
|
||||
//event_handler: optional user defined event handler. The default behaviour is to broadcast the event in english to all connected admin channels
|
||||
//minimum_required_security_level: The minimum required security level to run the game in which the DMAPI is integrated
|
||||
/world/proc/TgsNew(datum/tgs_event_handler/event_handler, minimum_required_security_level = TGS_SECURITY_ULTRASAFE)
|
||||
@@ -193,6 +197,32 @@
|
||||
/world/proc/TgsAvailable()
|
||||
return
|
||||
|
||||
//Forces a hard reboot of BYOND by ending the process
|
||||
//unlike del(world) clients will try to reconnect
|
||||
//If the service has not requested a shutdown, the next server will take over
|
||||
/world/proc/TgsEndProcess()
|
||||
return
|
||||
|
||||
//Send a message to non-admin connected chats
|
||||
//message: The message to send
|
||||
//admin_only: If TRUE, message will instead be sent to only admin connected chats
|
||||
/world/proc/TgsTargetedChatBroadcast(message, admin_only)
|
||||
return
|
||||
|
||||
//Send a private message to a specific user
|
||||
//message: The message to send
|
||||
//user: The /datum/tgs_chat_user to send to
|
||||
/world/proc/TgsChatPrivateMessage(message, datum/tgs_chat_user/user)
|
||||
return
|
||||
|
||||
//The following functions will sleep if a call to TgsNew() is sleeping
|
||||
|
||||
//Sends a message to connected game chats
|
||||
//message: The message to send
|
||||
//channels: optional channels to limit the broadcast to
|
||||
/world/proc/TgsChatBroadcast(message, list/channels)
|
||||
return
|
||||
|
||||
//Gets the current /datum/tgs_version of the server tools running the server
|
||||
/world/proc/TgsVersion()
|
||||
return
|
||||
@@ -217,34 +247,10 @@
|
||||
/world/proc/TgsTestMerges()
|
||||
return
|
||||
|
||||
//Forces a hard reboot of BYOND by ending the process
|
||||
//unlike del(world) clients will try to reconnect
|
||||
//If the service has not requested a shutdown, the next server will take over
|
||||
/world/proc/TgsEndProcess()
|
||||
return
|
||||
|
||||
//Gets a list of connected tgs_chat_channel
|
||||
/world/proc/TgsChatChannelInfo()
|
||||
return
|
||||
|
||||
//Sends a message to connected game chats
|
||||
//message: The message to send
|
||||
//channels: optional channels to limit the broadcast to
|
||||
/world/proc/TgsChatBroadcast(message, list/channels)
|
||||
return
|
||||
|
||||
//Send a message to non-admin connected chats
|
||||
//message: The message to send
|
||||
//admin_only: If TRUE, message will instead be sent to only admin connected chats
|
||||
/world/proc/TgsTargetedChatBroadcast(message, admin_only)
|
||||
return
|
||||
|
||||
//Send a private message to a specific user
|
||||
//message: The message to send
|
||||
//user: The /datum/tgs_chat_user to send to
|
||||
/world/proc/TgsChatPrivateMessage(message, datum/tgs_chat_user/user)
|
||||
return
|
||||
|
||||
/*
|
||||
The MIT License
|
||||
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
/world/TgsNew(datum/tgs_event_handler/event_handler, minimum_required_security_level = TGS_SECURITY_ULTRASAFE)
|
||||
var/current_api = TGS_READ_GLOBAL(tgs)
|
||||
if(current_api)
|
||||
TGS_ERROR_LOG("TgsNew(): TGS API datum already set ([current_api])! Was TgsNew() called more than once?")
|
||||
TGS_ERROR_LOG("API datum already set (\ref[current_api] ([current_api]))! Was TgsNew() called more than once?")
|
||||
return
|
||||
|
||||
if(!(minimum_required_security_level in list(TGS_SECURITY_ULTRASAFE, TGS_SECURITY_SAFE, TGS_SECURITY_TRUSTED)))
|
||||
TGS_ERROR_LOG("Invalid minimum_required_security_level: [minimum_required_security_level]!")
|
||||
return
|
||||
|
||||
#ifdef TGS_V3_API
|
||||
minimum_required_security_level = TGS_SECURITY_TRUSTED
|
||||
if(minimum_required_security_level != TGS_SECURITY_TRUSTED)
|
||||
TGS_WARNING_LOG("V3 DMAPI requires trusted security!")
|
||||
minimum_required_security_level = TGS_SECURITY_TRUSTED
|
||||
#endif
|
||||
var/raw_parameter = world.params[TGS_VERSION_PARAMETER]
|
||||
if(!raw_parameter)
|
||||
@@ -13,7 +19,7 @@
|
||||
|
||||
var/datum/tgs_version/version = new(raw_parameter)
|
||||
if(!version.Valid(FALSE))
|
||||
TGS_ERROR_LOG("Failed to validate TGS version parameter: [raw_parameter]!")
|
||||
TGS_ERROR_LOG("Failed to validate DMAPI version parameter: [raw_parameter]!")
|
||||
return
|
||||
|
||||
var/api_datum
|
||||
@@ -21,6 +27,7 @@
|
||||
if(3)
|
||||
#ifndef TGS_V3_API
|
||||
TGS_ERROR_LOG("Detected V3 API but TGS_V3_API isn't defined!")
|
||||
return
|
||||
#else
|
||||
switch(version.minor)
|
||||
if(2)
|
||||
@@ -43,11 +50,16 @@
|
||||
return
|
||||
|
||||
TGS_INFO_LOG("Activating API for version [version.deprefixed_parameter]")
|
||||
var/datum/tgs_api/new_api = new api_datum(version)
|
||||
|
||||
if(event_handler && !istype(event_handler))
|
||||
TGS_ERROR_LOG("Invalid parameter for event_handler: [event_handler]")
|
||||
event_handler = null
|
||||
|
||||
var/datum/tgs_api/new_api = new api_datum(event_handler, version)
|
||||
|
||||
TGS_WRITE_GLOBAL(tgs, new_api)
|
||||
|
||||
var/result = new_api.OnWorldNew(event_handler, minimum_required_security_level)
|
||||
var/result = new_api.OnWorldNew(minimum_required_security_level)
|
||||
if(!result || result == TGS_UNIMPLEMENTED)
|
||||
TGS_WRITE_GLOBAL(tgs, null)
|
||||
TGS_ERROR_LOG("Failed to activate API!")
|
||||
|
||||
@@ -2,9 +2,11 @@ TGS_DEFINE_AND_SET_GLOBAL(tgs, null)
|
||||
|
||||
/datum/tgs_api
|
||||
var/datum/tgs_version/version
|
||||
var/datum/tgs_event_handler/event_handler
|
||||
|
||||
/datum/tgs_api/New(datum/tgs_version/version)
|
||||
/datum/tgs_api/New(datum/tgs_event_handler/event_handler, datum/tgs_version/version)
|
||||
. = ..()
|
||||
src.event_handler = version
|
||||
src.version = version
|
||||
|
||||
/datum/tgs_api/latest
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
/datum/tgs_api/v3210/proc/file2list(filename)
|
||||
return splittext(trim_left(trim_right(file2text(filename))), "\n")
|
||||
|
||||
/datum/tgs_api/v3210/OnWorldNew(datum/tgs_event_handler/event_handler, minimum_required_security_level) //don't use event handling in this version
|
||||
/datum/tgs_api/v3210/OnWorldNew(minimum_required_security_level)
|
||||
. = FALSE
|
||||
|
||||
comms_key = world.params[SERVICE_WORLD_PARAM]
|
||||
|
||||
@@ -43,15 +43,13 @@
|
||||
var/list/cached_test_merges
|
||||
var/datum/tgs_revision_information/cached_revision
|
||||
|
||||
var/datum/tgs_event_handler/event_handler
|
||||
|
||||
var/export_lock = FALSE
|
||||
var/list/last_interop_response
|
||||
|
||||
/datum/tgs_api/v4/ApiVersion()
|
||||
return new /datum/tgs_version("4.0.0.0")
|
||||
|
||||
/datum/tgs_api/v4/OnWorldNew(datum/tgs_event_handler/event_handler, minimum_required_security_level)
|
||||
/datum/tgs_api/v4/OnWorldNew(minimum_required_security_level)
|
||||
json_path = world.params[TGS4_PARAM_INFO_JSON]
|
||||
if(!json_path)
|
||||
TGS_ERROR_LOG("Missing [TGS4_PARAM_INFO_JSON] world parameter!")
|
||||
@@ -76,7 +74,6 @@
|
||||
security_level = cached_json["securityLevel"]
|
||||
chat_channels_json_path = cached_json["chatChannelsJson"]
|
||||
chat_commands_json_path = cached_json["chatCommandsJson"]
|
||||
src.event_handler = event_handler
|
||||
instance_name = cached_json["instanceName"]
|
||||
|
||||
ListCustomCommands()
|
||||
|
||||
@@ -62,6 +62,8 @@
|
||||
#define DMAPI5_TOPIC_COMMAND_INSTANCE_RENAMED 4
|
||||
#define DMAPI5_TOPIC_COMMAND_CHAT_CHANNELS_UPDATE 4
|
||||
#define DMAPI5_TOPIC_COMMAND_SERVER_PORT_UPDATE 5
|
||||
#define DMAPI5_TOPIC_COMMAND_HEARTBEAT 6
|
||||
#define DMAPI5_TOPIC_COMMAND_WATCHDOG_REATTACH 7
|
||||
|
||||
#define DMAPI5_TOPIC_PARAMETER_COMMAND_TYPE "commandType"
|
||||
#define DMAPI5_TOPIC_PARAMETER_CHAT_COMMAND "chatCommand"
|
||||
@@ -70,6 +72,7 @@
|
||||
#define DMAPI5_TOPIC_PARAMETER_NEW_REBOOT_STATE "newRebootState"
|
||||
#define DMAPI5_TOPIC_PARAMETER_NEW_INSTANCE_NAME "newInstanceName"
|
||||
#define DMAPI5_TOPIC_PARAMETER_CHAT_UPDATE "chatUpdate"
|
||||
#define DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION "newServerVersion"
|
||||
|
||||
#define DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE_MESSAGE "commandResponseMessage"
|
||||
#define DMAPI5_TOPIC_RESPONSE_CHAT_RESPONSES "chatResponses"
|
||||
|
||||
@@ -15,18 +15,15 @@
|
||||
var/datum/tgs_revision_information/revision
|
||||
var/list/chat_channels
|
||||
|
||||
var/datum/tgs_event_handler/event_handler
|
||||
|
||||
/datum/tgs_api/v5/ApiVersion()
|
||||
return new /datum/tgs_version("5.0.0")
|
||||
|
||||
/datum/tgs_api/v5/OnWorldNew(datum/tgs_event_handler/event_handler, minimum_required_security_level)
|
||||
src.event_handler = event_handler
|
||||
return new /datum/tgs_version("5.1.0")
|
||||
|
||||
/datum/tgs_api/v5/OnWorldNew(minimum_required_security_level)
|
||||
server_port = world.params[DMAPI5_PARAM_SERVER_PORT]
|
||||
access_identifier = world.params[DMAPI5_PARAM_ACCESS_IDENTIFIER]
|
||||
|
||||
var/datum/tgs_version/api_version = ApiVersion()
|
||||
version = null
|
||||
var/list/bridge_response = Bridge(DMAPI5_BRIDGE_COMMAND_STARTUP, list(DMAPI5_BRIDGE_PARAMETER_MINIMUM_SECURITY_LEVEL = minimum_required_security_level, DMAPI5_BRIDGE_PARAMETER_VERSION = api_version.raw_parameter, DMAPI5_BRIDGE_PARAMETER_CUSTOM_COMMANDS = ListCustomCommands()))
|
||||
if(!istype(bridge_response))
|
||||
TGS_ERROR_LOG("Failed initial bridge request!")
|
||||
@@ -41,9 +38,9 @@
|
||||
TGS_INFO_LOG("DMAPI validation, exiting...")
|
||||
del(world)
|
||||
|
||||
version = new /datum/tgs_version(runtime_information[DMAPI5_RUNTIME_INFORMATION_SERVER_VERSION])
|
||||
security_level = runtime_information[DMAPI5_RUNTIME_INFORMATION_SECURITY_LEVEL]
|
||||
instance_name = runtime_information[DMAPI5_RUNTIME_INFORMATION_INSTANCE_NAME]
|
||||
version = new /datum/tgs_version(runtime_information[DMAPI5_RUNTIME_INFORMATION_SERVER_VERSION])
|
||||
|
||||
var/list/revisionData = runtime_information[DMAPI5_RUNTIME_INFORMATION_REVISION]
|
||||
if(istype(revisionData))
|
||||
@@ -84,6 +81,10 @@
|
||||
|
||||
return TRUE
|
||||
|
||||
/datum/tgs_api/v5/proc/RequireInitialBridgeResponse()
|
||||
while(!version)
|
||||
sleep(1)
|
||||
|
||||
/datum/tgs_api/v5/OnInitializationComplete()
|
||||
Bridge(DMAPI5_BRIDGE_COMMAND_PRIME)
|
||||
|
||||
@@ -197,6 +198,20 @@
|
||||
|
||||
server_port = new_port
|
||||
return TopicResponse()
|
||||
if(DMAPI5_TOPIC_COMMAND_HEARTBEAT)
|
||||
return TopicResponse()
|
||||
if(DMAPI5_TOPIC_COMMAND_WATCHDOG_REATTACH)
|
||||
var/new_version_string = topic_parameters[DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION]
|
||||
if (!istext(new_version_string))
|
||||
return TopicResponse("Invalid or missing [DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION]]")
|
||||
|
||||
var/datum/tgs_version/new_version = new(new_version_string)
|
||||
if (event_handler)
|
||||
event_handler.HandleEvent(TGS_EVENT_WATCHDOG_REATTACH, new_version)
|
||||
|
||||
version = new_version
|
||||
|
||||
return TopicResponse()
|
||||
|
||||
return TopicResponse("Unknown command: [command]")
|
||||
|
||||
@@ -252,15 +267,18 @@
|
||||
TGS_ERROR_LOG("Unable to set port to [port]!")
|
||||
|
||||
/datum/tgs_api/v5/InstanceName()
|
||||
RequireInitialBridgeResponse()
|
||||
return instance_name
|
||||
|
||||
/datum/tgs_api/v5/TestMerges()
|
||||
RequireInitialBridgeResponse()
|
||||
return test_merges
|
||||
|
||||
/datum/tgs_api/v5/EndProcess()
|
||||
Bridge(DMAPI5_BRIDGE_COMMAND_KILL)
|
||||
|
||||
/datum/tgs_api/v5/Revision()
|
||||
RequireInitialBridgeResponse()
|
||||
return revision
|
||||
|
||||
/datum/tgs_api/v5/ChatBroadcast(message, list/channels)
|
||||
@@ -298,6 +316,7 @@
|
||||
Bridge(DMAPI5_BRIDGE_COMMAND_CHAT_SEND, list(DMAPI5_BRIDGE_PARAMETER_CHAT_MESSAGE = message))
|
||||
|
||||
/datum/tgs_api/v5/ChatChannelInfo()
|
||||
RequireInitialBridgeResponse()
|
||||
return chat_channels
|
||||
|
||||
/datum/tgs_api/v5/proc/DecodeChannels(chat_update_json)
|
||||
@@ -322,6 +341,7 @@
|
||||
return channel
|
||||
|
||||
/datum/tgs_api/v5/SecurityLevel()
|
||||
RequireInitialBridgeResponse()
|
||||
return security_level
|
||||
|
||||
/*
|
||||
|
||||
@@ -62,6 +62,8 @@
|
||||
#undef DMAPI5_TOPIC_COMMAND_INSTANCE_RENAMED
|
||||
#undef DMAPI5_TOPIC_COMMAND_CHAT_CHANNELS_UPDATE
|
||||
#undef DMAPI5_TOPIC_COMMAND_SERVER_PORT_UPDATE
|
||||
#undef DMAPI5_TOPIC_COMMAND_HEARTBEAT
|
||||
#undef DMAPI5_TOPIC_COMMAND_WATCHDOG_REATTACH
|
||||
|
||||
#undef DMAPI5_TOPIC_PARAMETER_COMMAND_TYPE
|
||||
#undef DMAPI5_TOPIC_PARAMETER_CHAT_COMMAND
|
||||
@@ -70,6 +72,7 @@
|
||||
#undef DMAPI5_TOPIC_PARAMETER_NEW_REBOOT_STATE
|
||||
#undef DMAPI5_TOPIC_PARAMETER_NEW_INSTANCE_NAME
|
||||
#undef DMAPI5_TOPIC_PARAMETER_CHAT_UPDATE
|
||||
#undef DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION
|
||||
|
||||
#undef DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE_MESSAGE
|
||||
#undef DMAPI5_TOPIC_RESPONSE_CHAT_RESPONSES
|
||||
|
||||
Reference in New Issue
Block a user