mirror of
https://github.com/VOREStation/VOREStation.git
synced 2026-08-30 15:38:02 +01:00
Add code to enable communication with VGS
VGS provides a subset of TGS functionality, mostly just the discord bot. It extends TGS datums and adds a little bit. Right now its done in parallel to TGS's code to minimize impact of not having the rest of DMAPI v5 impemented.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "v5\_defines.dm"
|
||||
#include "v5\api.dm"
|
||||
#include "v5\api_vgs.dm" // VOREStation Edit - Include here so it has access to v5 defines
|
||||
#include "v5\commands.dm"
|
||||
#include "v5\chat_commands.dm"
|
||||
#include "v5\undef.dm"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define DMAPI5_BRIDGE_COMMAND_REBOOT 3
|
||||
#define DMAPI5_BRIDGE_COMMAND_KILL 4
|
||||
#define DMAPI5_BRIDGE_COMMAND_CHAT_SEND 5
|
||||
#define DMAPI5_BRIDGE_COMMAND_ADD_MEMBER_ROLE 6 // VOREStation Edit
|
||||
|
||||
#define DMAPI5_PARAMETER_ACCESS_IDENTIFIER "accessIdentifier"
|
||||
#define DMAPI5_RESPONSE_ERROR_MESSAGE "errorMessage"
|
||||
@@ -20,6 +21,7 @@
|
||||
#define DMAPI5_BRIDGE_PARAMETER_CHAT_MESSAGE "chatMessage"
|
||||
#define DMAPI5_BRIDGE_PARAMETER_CUSTOM_COMMANDS "customCommands"
|
||||
#define DMAPI5_BRIDGE_PARAMETER_MINIMUM_SECURITY_LEVEL "minimumSecurityLevel"
|
||||
#define DMAPI5_BRIDGE_PARAMETER_CHAT_USER_ID "chatUserId" // VOREStation Edit
|
||||
|
||||
#define DMAPI5_BRIDGE_RESPONSE_NEW_PORT "newPort"
|
||||
#define DMAPI5_BRIDGE_RESPONSE_RUNTIME_INFORMATION "runtimeInformation"
|
||||
@@ -64,6 +66,7 @@
|
||||
#define DMAPI5_TOPIC_COMMAND_SERVER_PORT_UPDATE 6
|
||||
#define DMAPI5_TOPIC_COMMAND_HEARTBEAT 7
|
||||
#define DMAPI5_TOPIC_COMMAND_WATCHDOG_REATTACH 8
|
||||
#define DMAPI5_TOPIC_COMMAND_GET_CHAT_COMMANDS 9 // VOREStation Edit
|
||||
|
||||
#define DMAPI5_TOPIC_PARAMETER_COMMAND_TYPE "commandType"
|
||||
#define DMAPI5_TOPIC_PARAMETER_CHAT_COMMAND "chatCommand"
|
||||
|
||||
@@ -125,6 +125,11 @@
|
||||
if(!result)
|
||||
result = TopicResponse("Error running chat command!")
|
||||
return result
|
||||
// VOREStation Edit Start - GetChatCommands command
|
||||
if(DMAPI5_TOPIC_COMMAND_GET_CHAT_COMMANDS)
|
||||
var/topic_response = list(DMAPI5_BRIDGE_PARAMETER_CUSTOM_COMMANDS = ListCustomCommands())
|
||||
return json_encode(topic_response)
|
||||
// VOREStation Edit - End
|
||||
if(DMAPI5_TOPIC_COMMAND_EVENT_NOTIFICATION)
|
||||
intercepted_message_queue = list()
|
||||
var/list/event_notification = topic_parameters[DMAPI5_TOPIC_PARAMETER_EVENT_NOTIFICATION]
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// We currently isolate ourselves in a different variable so that only the specific APIs we choose will be active.
|
||||
// Eventually it would be good to handle all the TGS Apis properly and we can use the same.
|
||||
GLOBAL_DATUM(vgs, /datum/tgs_api)
|
||||
|
||||
// Supply our own New functionality so we can read from config instead of world params
|
||||
/world/proc/VgsNew(datum/tgs_event_handler/event_handler)
|
||||
var/current_api = GLOB.vgs
|
||||
if(current_api)
|
||||
TGS_ERROR_LOG("API datum already set (\ref[current_api] ([current_api]))! Was TgsNew() called more than once?")
|
||||
return
|
||||
|
||||
// If we don't have a configured access identifier we aren't meant to use VGS
|
||||
if(!config.vgs_access_identifier)
|
||||
TGS_INFO_LOG("Skipping VGS: No access identifier configured")
|
||||
return
|
||||
|
||||
var/datum/tgs_api/api_datum = /datum/tgs_api/v5/vgs1
|
||||
TGS_INFO_LOG("Activating API for version [api_datum]")
|
||||
|
||||
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)
|
||||
GLOB.vgs = new_api
|
||||
|
||||
var/result = new_api.OnWorldNew()
|
||||
if(!result || result == TGS_UNIMPLEMENTED)
|
||||
GLOB.vgs = null
|
||||
TGS_ERROR_LOG("Failed to activate API!")
|
||||
|
||||
/world/proc/VgsTopic(T)
|
||||
var/datum/tgs_api/api = GLOB.vgs
|
||||
if(api)
|
||||
var/result = api.OnTopic(T)
|
||||
if(result != TGS_UNIMPLEMENTED)
|
||||
return result
|
||||
|
||||
/world/proc/VgsAddMemberRole(chat_user_id)
|
||||
var/datum/tgs_api/v5/vgs1/api = GLOB.vgs
|
||||
if(api)
|
||||
api.AddMemberRole(chat_user_id)
|
||||
|
||||
/datum/tgs_api/v5/vgs1
|
||||
server_port = 8080 // Default port
|
||||
|
||||
// Override to prevent error messages from the lack of revision/test_merge information, and to use config isntead of params.
|
||||
/datum/tgs_api/v5/vgs1/OnWorldNew()
|
||||
if(config.vgs_server_port)
|
||||
server_port = config.vgs_server_port
|
||||
access_identifier = config.vgs_access_identifier
|
||||
|
||||
var/list/bridge_response = Bridge(DMAPI5_BRIDGE_COMMAND_STARTUP, list(DMAPI5_BRIDGE_PARAMETER_CUSTOM_COMMANDS = ListCustomCommands()))
|
||||
if(!istype(bridge_response))
|
||||
TGS_ERROR_LOG("Failed initial bridge request!")
|
||||
return FALSE
|
||||
|
||||
var/list/runtime_information = bridge_response[DMAPI5_BRIDGE_RESPONSE_RUNTIME_INFORMATION]
|
||||
if(!istype(runtime_information))
|
||||
TGS_ERROR_LOG("Failed to decode runtime information from bridge response: [json_encode(bridge_response)]!")
|
||||
return FALSE
|
||||
|
||||
version = new /datum/tgs_version(runtime_information[DMAPI5_RUNTIME_INFORMATION_SERVER_VERSION])
|
||||
instance_name = runtime_information[DMAPI5_RUNTIME_INFORMATION_INSTANCE_NAME]
|
||||
|
||||
chat_channels = list()
|
||||
DecodeChannels(runtime_information)
|
||||
|
||||
return TRUE
|
||||
|
||||
/datum/tgs_api/v5/vgs1/proc/AddMemberRole(chat_user_id)
|
||||
Bridge(DMAPI5_BRIDGE_COMMAND_ADD_MEMBER_ROLE, list(DMAPI5_BRIDGE_PARAMETER_CHAT_USER_ID = chat_user_id))
|
||||
|
||||
// /datum/tgs_api/v5/vgs1/RequireInitialBridgeResponse()
|
||||
// while(!instance_name)
|
||||
// sleep(1)
|
||||
Reference in New Issue
Block a user