mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Implemented basic GLOB and TGS3's DMAPI
This commit is contained in:
72
code/modules/DMAPI/st_commands.dm
Normal file
72
code/modules/DMAPI/st_commands.dm
Normal file
@@ -0,0 +1,72 @@
|
||||
/datum/server_tools_command
|
||||
var/name = "" //the string to trigger this command on a chat bot. e.g. TGS3_BOT: do_this_command
|
||||
var/help_text = "" //help text for this command
|
||||
var/required_parameters = 0 //number of parameters required for this command
|
||||
var/admin_only = FALSE //set to TRUE if this command should only be usable by registered chat admins
|
||||
|
||||
//override to implement command
|
||||
//sender is the display name of who sent the command
|
||||
//params is the trimmed string following the command name
|
||||
/datum/server_tools_command/proc/Run(sender, params)
|
||||
CRASH("[type] has no implementation for Run()")
|
||||
|
||||
/world/proc/ListServiceCustomCommands(warnings_only)
|
||||
if(!warnings_only)
|
||||
. = list()
|
||||
var/list/command_name_types = list()
|
||||
var/list/warned_command_names = warnings_only ? list() : null
|
||||
for(var/I in typesof(/datum/server_tools_command) - /datum/server_tools_command)
|
||||
var/datum/server_tools_command/stc = I
|
||||
var/command_name = initial(stc.name)
|
||||
var/static/list/warned_server_tools_names = list()
|
||||
if(!command_name || findtext(command_name, " ") || findtext(command_name, "'") || findtext(command_name, "\""))
|
||||
if(warnings_only && !warned_command_names[command_name])
|
||||
SERVER_TOOLS_LOG("WARNING: Custom command [command_name] cannot be used as it is empty or contains illegal characters!")
|
||||
warned_command_names[command_name] = TRUE
|
||||
continue
|
||||
|
||||
if(command_name_types[command_name])
|
||||
if(warnings_only)
|
||||
SERVER_TOOLS_LOG("WARNING: Custom commands [command_name_types[command_name]] and [stc] have the same name only [command_name_types[command_name]] will be available!")
|
||||
continue
|
||||
command_name_types[stc] = command_name
|
||||
|
||||
if(!warnings_only)
|
||||
.[command_name] = list(SERVICE_JSON_PARAM_HELPTEXT = initial(stc.help_text), SERVICE_JSON_PARAM_ADMINONLY = initial(stc.admin_only), SERVICE_JSON_PARAM_REQUIREDPARAMETERS = initial(stc.required_parameters))
|
||||
|
||||
/world/proc/HandleServiceCustomCommand(command, sender, params)
|
||||
var/static/list/cached_custom_server_tools_commands
|
||||
if(!cached_custom_server_tools_commands)
|
||||
cached_custom_server_tools_commands = list()
|
||||
for(var/I in typesof(/datum/server_tools_command) - /datum/server_tools_command)
|
||||
var/datum/server_tools_command/stc = I
|
||||
cached_custom_server_tools_commands[lowertext(initial(stc.name))] = stc
|
||||
|
||||
var/command_type = cached_custom_server_tools_commands[command]
|
||||
if(!command_type)
|
||||
return FALSE
|
||||
var/datum/server_tools_command/stc = new command_type
|
||||
return stc.Run(sender, params) || TRUE
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
131
code/modules/DMAPI/st_interface.dm
Normal file
131
code/modules/DMAPI/st_interface.dm
Normal file
@@ -0,0 +1,131 @@
|
||||
SERVER_TOOLS_DEFINE_AND_SET_GLOBAL(reboot_mode, REBOOT_MODE_NORMAL)
|
||||
SERVER_TOOLS_DEFINE_AND_SET_GLOBAL(server_tools_api_compatible, FALSE)
|
||||
|
||||
/proc/GetTestMerges()
|
||||
if(RunningService(TRUE) && fexists(SERVICE_PR_TEST_JSON))
|
||||
. = json_decode(file2text(SERVICE_PR_TEST_JSON))
|
||||
if(.)
|
||||
return
|
||||
return list()
|
||||
|
||||
/world/proc/ServiceInit()
|
||||
if(!RunningService(TRUE))
|
||||
return
|
||||
ListServiceCustomCommands(TRUE)
|
||||
ExportService("[SERVICE_REQUEST_API_VERSION] [SERVER_TOOLS_API_VERSION]", TRUE)
|
||||
|
||||
/proc/RunningService(skip_compat_check = FALSE)
|
||||
if(!skip_compat_check && !SERVER_TOOLS_READ_GLOBAL(server_tools_api_compatible))
|
||||
return FALSE
|
||||
. = world.params[SERVICE_WORLD_PARAM] != null
|
||||
if(. && world.system_type != MS_WINDOWS)
|
||||
SERVER_TOOLS_LOG("Warning: Server tools world parameter detected but not running on Windows. Aborting initialization!")
|
||||
return FALSE
|
||||
|
||||
/proc/ServiceVersion()
|
||||
if(RunningService(TRUE))
|
||||
return world.params[SERVICE_VERSION_PARAM]
|
||||
|
||||
/proc/ServiceAPIVersion()
|
||||
return SERVICE_API_VERSION_STRING
|
||||
|
||||
/world/proc/ExportService(command, skip_compat_check = FALSE)
|
||||
. = FALSE
|
||||
if(!RunningService(skip_compat_check))
|
||||
return
|
||||
if(skip_compat_check && !fexists(SERVICE_INTERFACE_DLL))
|
||||
CRASH("Service parameter present but no interface DLL detected. This is symptomatic of running a service less than version 3.1! Please upgrade.")
|
||||
var/instance = params[SERVICE_INSTANCE_PARAM]
|
||||
if(!instance)
|
||||
instance = "TG Station Server" //maybe just upgraded
|
||||
call(SERVICE_INTERFACE_DLL, SERVICE_INTERFACE_FUNCTION)(instance, command) //trust no retval
|
||||
return TRUE
|
||||
|
||||
/world/proc/ChatBroadcast(message)
|
||||
ExportService("[SERVICE_REQUEST_IRC_BROADCAST] [message]")
|
||||
|
||||
/world/proc/AdminBroadcast(message)
|
||||
ExportService("[SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE] [message]")
|
||||
|
||||
/world/proc/ServiceEndProcess(silent = FALSE)
|
||||
SERVER_TOOLS_LOG("Sending shutdown request!");
|
||||
sleep(world.tick_lag) //flush the buffers
|
||||
ExportService(silent ? SERVICE_REQUEST_KILL_PROCESS_SILENT : SERVICE_REQUEST_KILL_PROCESS)
|
||||
|
||||
//called at the exact moment the world is supposed to reboot
|
||||
/world/proc/ServiceReboot()
|
||||
switch(SERVER_TOOLS_READ_GLOBAL(reboot_mode))
|
||||
if(REBOOT_MODE_HARD)
|
||||
SERVER_TOOLS_WORLD_ANNOUNCE("gay")//Hard reboot triggered, you will automatically reconnect...")
|
||||
ServiceEndProcess()
|
||||
if(REBOOT_MODE_SHUTDOWN)
|
||||
SERVER_TOOLS_WORLD_ANNOUNCE("The server is shutting down...")
|
||||
ServiceEndProcess()
|
||||
else
|
||||
ExportService(SERVICE_REQUEST_WORLD_REBOOT) //just let em know
|
||||
|
||||
/world/proc/ServiceCommand(list/params)
|
||||
var/their_sCK = params[SERVICE_CMD_PARAM_KEY]
|
||||
if(!their_sCK || !RunningService(TRUE))
|
||||
return FALSE //continue world/Topic
|
||||
|
||||
var/sCK = world.params[SERVICE_WORLD_PARAM]
|
||||
if(their_sCK != sCK)
|
||||
return "Invalid comms key!";
|
||||
|
||||
var/command = params[SERVICE_CMD_PARAM_COMMAND]
|
||||
if(!command)
|
||||
return "No command!"
|
||||
|
||||
switch(command)
|
||||
if(SERVICE_CMD_API_COMPATIBLE)
|
||||
SERVER_TOOLS_WRITE_GLOBAL(server_tools_api_compatible, TRUE)
|
||||
return SERVICE_RETURN_SUCCESS
|
||||
if(SERVICE_CMD_HARD_REBOOT)
|
||||
if(SERVER_TOOLS_READ_GLOBAL(reboot_mode) != REBOOT_MODE_HARD)
|
||||
SERVER_TOOLS_WRITE_GLOBAL(reboot_mode, REBOOT_MODE_HARD)
|
||||
SERVER_TOOLS_LOG("Hard reboot requested by service")
|
||||
SERVER_TOOLS_NOTIFY_ADMINS("The world will hard reboot at the end of the game. Requested by service.")
|
||||
if(SERVICE_CMD_GRACEFUL_SHUTDOWN)
|
||||
if(SERVER_TOOLS_READ_GLOBAL(reboot_mode) != REBOOT_MODE_SHUTDOWN)
|
||||
SERVER_TOOLS_WRITE_GLOBAL(reboot_mode, REBOOT_MODE_SHUTDOWN)
|
||||
SERVER_TOOLS_LOG("Shutdown requested by service")
|
||||
message_admins("The world will shutdown at the end of the game. Requested by service.")
|
||||
if(SERVICE_CMD_WORLD_ANNOUNCE)
|
||||
var/msg = params["message"]
|
||||
if(!istext(msg) || !msg)
|
||||
return "No message set!"
|
||||
SERVER_TOOLS_WORLD_ANNOUNCE(msg)
|
||||
return SERVICE_RETURN_SUCCESS
|
||||
if(SERVICE_CMD_PLAYER_COUNT)
|
||||
return "[SERVER_TOOLS_CLIENT_COUNT]"
|
||||
if(SERVICE_CMD_LIST_CUSTOM)
|
||||
return json_encode(ListServiceCustomCommands(FALSE))
|
||||
else
|
||||
var/custom_command_result = HandleServiceCustomCommand(lowertext(command), params[SERVICE_CMD_PARAM_SENDER], params[SERVICE_CMD_PARAM_CUSTOM])
|
||||
if(custom_command_result)
|
||||
return istext(custom_command_result) ? custom_command_result : SERVICE_RETURN_SUCCESS
|
||||
return "Unknown command: [command]"
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
Reference in New Issue
Block a user