Skip to content

Commit

Permalink
Merge pull request #1788 from tgstation/DMAPIFixup [DMDeploy][APIDepl…
Browse files Browse the repository at this point in the history
…oy][NugetDeploy]

DMAPI Custom Events. Fix potential missing `/home` directory in `.deb`. Standardize DMAPI sleeps. Add support for `file2text` redefinitions in DMAPI. Fix event script priorities. Fix creating invalid `trusted.txt` on Linux
  • Loading branch information
Cyberboss authored Feb 22, 2024
2 parents 4d64466 + bab8f93 commit a031710
Show file tree
Hide file tree
Showing 58 changed files with 610 additions and 216 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ sudo dpkg --add-architecture i386 \
&& sudo systemctl start tgstation-server
```

The service will execute as the newly created user: `tgstation-server`.
The service will execute as the newly created user: `tgstation-server`. You should, ideally, store your instances somewhere under `/home/tgstation-server`.

##### Manual Setup

Expand Down
6 changes: 3 additions & 3 deletions build/TestCommon.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- Usage: Hard to say what exactly this is for, but not including it removes the test icon and breaks vstest.console.exe for some reason -->
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" Condition="'$(TgsTestNoSdk)' != 'true'" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" Condition="'$(TgsTestNoSdk)' != 'true'" />
<!-- Usage: Dependency mocking for tests -->
<!-- Pinned: Be VERY careful about updating https://github.com/moq/moq/issues/1372 -->
<PackageReference Include="Moq" Version="4.20.70" />
<!-- Usage: MSTest execution -->
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.1" />
<!-- Usage: MSTest asserts etc... -->
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.1" />
</ItemGroup>

</Project>
14 changes: 7 additions & 7 deletions build/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
<!-- Integration tests will ensure they match across the board -->
<Import Project="WebpanelVersion.props" />
<PropertyGroup>
<TgsCoreVersion>6.2.0</TgsCoreVersion>
<TgsCoreVersion>6.3.0</TgsCoreVersion>
<TgsConfigVersion>5.1.0</TgsConfigVersion>
<TgsApiVersion>10.1.0</TgsApiVersion>
<TgsApiVersion>10.2.0</TgsApiVersion>
<TgsCommonLibraryVersion>7.0.0</TgsCommonLibraryVersion>
<TgsApiLibraryVersion>13.1.0</TgsApiLibraryVersion>
<TgsClientVersion>15.1.0</TgsClientVersion>
<TgsDmapiVersion>7.0.2</TgsDmapiVersion>
<TgsInteropVersion>5.8.0</TgsInteropVersion>
<TgsApiLibraryVersion>13.2.0</TgsApiLibraryVersion>
<TgsClientVersion>15.2.0</TgsClientVersion>
<TgsDmapiVersion>7.1.0</TgsDmapiVersion>
<TgsInteropVersion>5.9.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.4.1</TgsHostWatchdogVersion>
<TgsContainerScriptVersion>1.2.1</TgsContainerScriptVersion>
<TgsMigratorVersion>2.0.0</TgsMigratorVersion>
<TgsNugetNetFramework>netstandard2.0</TgsNugetNetFramework>
<TgsNetMajorVersion>8</TgsNetMajorVersion>
<!-- Update this frequently with dotnet runtime patches. MAJOR MUST MATCH ABOVE! -->
<TgsDotnetRedistUrl>https://download.visualstudio.microsoft.com/download/pr/016c6447-764a-4210-a260-bf7a2880d5c0/a5746437a3862d7803284ae8c2290200/dotnet-hosting-8.0.1-win.exe</TgsDotnetRedistUrl>
<TgsDotnetRedistUrl>https://download.visualstudio.microsoft.com/download/pr/98ff0a08-a283-428f-8e54-19841d97154c/8c7d5f9600eadf264f04c82c813b7aab/dotnet-hosting-8.0.2-win.exe</TgsDotnetRedistUrl>
<TgsMariaDBRedistVersion>10.11.6</TgsMariaDBRedistVersion>
<TgsYarnVersion>1.22.21</TgsYarnVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion build/WebpanelVersion.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- This is in it's own file to help incremental building, changing it causes a complete rebuild of the web panel -->
<TgsWebpanelVersion>5.5.0</TgsWebpanelVersion>
<TgsWebpanelVersion>5.5.1</TgsWebpanelVersion>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion build/package/deb/debian/postinst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh -e

if [ -z "$2" ]; then
adduser --system tgstation-server
adduser --system --home /home/tgstation-server tgstation-server
mkdir -m 754 -p /var/log/tgstation-server
chown -R tgstation-server /etc/tgstation-server
chown -R tgstation-server /opt/tgstation-server/lib
Expand Down
2 changes: 1 addition & 1 deletion build/package/winget/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"wix": {
"version": "4.0.2",
"version": "4.0.4",
"commands": [
"wix"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="WixToolset.Sdk/4.0.2" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Project Sdk="WixToolset.Sdk/4.0.4" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">
<Import Project="../../../Common.props" />
<PropertyGroup>
<DefineConstants>ProductVersion=$(TgsCoreVersion);NetMajorVersion=$(TgsNetMajorVersion);DotnetRedistUrl=$(TgsDotnetRedistUrl);MariaDBRedistUrl=https://github.com/tgstation/tgstation-server/releases/download/tgstation-server-v$(TgsCoreVersion)/mariadb-$(TgsMariaDBRedistVersion)-winx64.msi</DefineConstants>
Expand All @@ -24,8 +24,8 @@
<Content Include="Theme.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Bal.wixext" Version="4.0.2" />
<PackageReference Include="WixToolset.Netfx.wixext" Version="4.0.2" />
<PackageReference Include="WixToolset.Bal.wixext" Version="4.0.4" />
<PackageReference Include="WixToolset.Netfx.wixext" Version="4.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tgstation.Server.Host.Service.Wix\Tgstation.Server.Host.Service.Wix.wixproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WixToolset.Dtf.CustomAction" Version="4.0.2" />
<PackageReference Include="WixToolset.Dtf.CustomAction" Version="4.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="WixToolset.Sdk/4.0.2">
<Project Sdk="WixToolset.Sdk/4.0.4">
<Import Project="../../../Common.props" />
<PropertyGroup>
<DefineConstants>ProductVersion=$(TgsCoreVersion)</DefineConstants>
Expand All @@ -25,8 +25,8 @@
</HarvestDirectory>
</ItemGroup>
<ItemGroup>
<PackageReference Include="WixToolset.Heat" Version="4.0.2" />
<PackageReference Include="WixToolset.Util.wixext" Version="4.0.2" />
<PackageReference Include="WixToolset.Heat" Version="4.0.4" />
<PackageReference Include="WixToolset.Util.wixext" Version="4.0.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tgstation.Server.Host.Service.Wix.Extensions\Tgstation.Server.Host.Service.Wix.Extensions.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Installers:
Publisher: /tg/station 13
ReleaseDate: 2023-06-24 # Do not change. Set before publish by push_manifest.ps1
ManifestType: installer
ManifestVersion: 1.5.0
ManifestVersion: 1.6.0
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ Documentations:
ReleaseNotesUrl: https://github.com/tgstation/tgstation-server/releases/tag/tgstation-server-v0.22.475
PurchaseUrl: https://github.com/sponsors/Cyberboss
ManifestType: defaultLocale
ManifestVersion: 1.5.0
ManifestVersion: 1.6.0
2 changes: 1 addition & 1 deletion build/package/winget/manifest/Tgstation.Server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ PackageIdentifier: Tgstation.Server
PackageVersion: 0.22.475 # Do not change. Set before publish by push_manifest.ps1
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.5.0
ManifestVersion: 1.6.0
19 changes: 18 additions & 1 deletion src/DMAPI/tgs.dm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// tgstation-server DMAPI

#define TGS_DMAPI_VERSION "7.0.2"
#define TGS_DMAPI_VERSION "7.1.0"

// All functions and datums outside this document are subject to change with any version and should not be relied on.

Expand Down Expand Up @@ -50,6 +50,13 @@

#endif

#ifndef TGS_FILE2TEXT_NATIVE
#ifdef file2text
#error Your codebase is re-defining the BYOND proc file2text. The DMAPI requires the native version to read the result of world.Export(). You can fix this by adding "#define TGS_FILE2TEXT_NATIVE file2text" before your override of file2text to allow the DMAPI to use the native version. This will only be used for world.Export(), not regular file accesses
#endif
#define TGS_FILE2TEXT_NATIVE file2text
#endif

// EVENT CODES

/// Before a reboot mode change, extras parameters are the current and new reboot mode enums.
Expand Down Expand Up @@ -489,6 +496,16 @@
/// Returns a list of connected [/datum/tgs_chat_channel]s if TGS is present, null otherwise. This function may sleep if the call to [/world/proc/TgsNew] is sleeping!
/world/proc/TgsChatChannelInfo()
return

/**
* Trigger an event in TGS. Requires TGS version >= 6.3.0. Returns [TRUE] if the event was triggered successfully, [FALSE] otherwise. This function may sleep!
*
* event_name - The name of the event to trigger
* parameters - Optional list of string parameters to pass as arguments to the event script. The first parameter passed to a script will always be the running game's directory followed by these parameters.
* wait_for_completion - If set, this function will not return until the event has run to completion.
*/
/world/proc/TgsTriggerEvent(event_name, list/parameters, wait_for_completion = FALSE)
return

/*
The MIT License
Expand Down
8 changes: 8 additions & 0 deletions src/DMAPI/tgs/core/core.dm
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,11 @@
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
if(api)
return api.Visibility()

/world/TgsTriggerEvent(event_name, list/parameters, wait_for_completion = FALSE)
var/datum/tgs_api/api = TGS_READ_GLOBAL(tgs)
if(api)
if(!istype(parameters, /list))
parameters = list()

return api.TriggerEvent(event_name, parameters, wait_for_completion)
5 changes: 4 additions & 1 deletion src/DMAPI/tgs/core/datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TGS_DEFINE_AND_SET_GLOBAL(tgs, null)
world.sleep_offline = FALSE // https://www.byond.com/forum/post/2894866
del(world)
world.sleep_offline = FALSE // just in case, this is BYOND after all...
sleep(1)
sleep(world.tick_lag)
TGS_DEBUG_LOG("BYOND DIDN'T TERMINATE THE WORLD!!! TICK IS: [world.time], sleep_offline: [world.sleep_offline]")

/datum/tgs_api/latest
Expand Down Expand Up @@ -69,3 +69,6 @@ TGS_PROTECT_DATUM(/datum/tgs_api)

/datum/tgs_api/proc/Visibility()
return TGS_UNIMPLEMENTED

/datum/tgs_api/proc/TriggerEvent(event_name, list/parameters, wait_for_completion)
return FALSE
6 changes: 3 additions & 3 deletions src/DMAPI/tgs/v4/api.dm
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
var/json = json_encode(data)

while(requesting_new_port && !override_requesting_new_port)
sleep(1)
sleep(world.tick_lag)

//we need some port open at this point to facilitate return communication
if(!world.port)
Expand Down Expand Up @@ -209,15 +209,15 @@
requesting_new_port = FALSE

while(export_lock)
sleep(1)
sleep(world.tick_lag)
export_lock = TRUE

last_interop_response = null
fdel(server_commands_json_path)
text2file(json, server_commands_json_path)

for(var/I = 0; I < EXPORT_TIMEOUT_DS && !last_interop_response; ++I)
sleep(1)
sleep(world.tick_lag)

if(!last_interop_response)
TGS_ERROR_LOG("Failed to get export result for: [json]")
Expand Down
2 changes: 1 addition & 1 deletion src/DMAPI/tgs/v5/__interop_version.dm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"5.8.0"
"5.9.0"
9 changes: 9 additions & 0 deletions src/DMAPI/tgs/v5/_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#define DMAPI5_BRIDGE_COMMAND_KILL 4
#define DMAPI5_BRIDGE_COMMAND_CHAT_SEND 5
#define DMAPI5_BRIDGE_COMMAND_CHUNK 6
#define DMAPI5_BRIDGE_COMMAND_EVENT 7

#define DMAPI5_PARAMETER_ACCESS_IDENTIFIER "accessIdentifier"
#define DMAPI5_PARAMETER_CUSTOM_COMMANDS "customCommands"
Expand All @@ -34,6 +35,7 @@
#define DMAPI5_BRIDGE_PARAMETER_VERSION "version"
#define DMAPI5_BRIDGE_PARAMETER_CHAT_MESSAGE "chatMessage"
#define DMAPI5_BRIDGE_PARAMETER_MINIMUM_SECURITY_LEVEL "minimumSecurityLevel"
#define DMAPI5_BRIDGE_PARAMETER_EVENT_INVOCATION "eventInvocation"

#define DMAPI5_BRIDGE_RESPONSE_NEW_PORT "newPort"
#define DMAPI5_BRIDGE_RESPONSE_RUNTIME_INFORMATION "runtimeInformation"
Expand Down Expand Up @@ -81,6 +83,7 @@
#define DMAPI5_TOPIC_COMMAND_SEND_CHUNK 9
#define DMAPI5_TOPIC_COMMAND_RECEIVE_CHUNK 10
#define DMAPI5_TOPIC_COMMAND_RECEIVE_BROADCAST 11
#define DMAPI5_TOPIC_COMMAND_COMPLETE_EVENT 12

#define DMAPI5_TOPIC_PARAMETER_COMMAND_TYPE "commandType"
#define DMAPI5_TOPIC_PARAMETER_CHAT_COMMAND "chatCommand"
Expand Down Expand Up @@ -116,3 +119,9 @@
#define DMAPI5_CUSTOM_CHAT_COMMAND_NAME "name"
#define DMAPI5_CUSTOM_CHAT_COMMAND_HELP_TEXT "helpText"
#define DMAPI5_CUSTOM_CHAT_COMMAND_ADMIN_ONLY "adminOnly"

#define DMAPI5_EVENT_ID "eventId"

#define DMAPI5_EVENT_INVOCATION_NAME "eventName"
#define DMAPI5_EVENT_INVOCATION_PARAMETERS "parameters"
#define DMAPI5_EVENT_INVOCATION_NOTIFY_COMPLETION "notifyCompletion"
38 changes: 37 additions & 1 deletion src/DMAPI/tgs/v5/api.dm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
var/chunked_requests = 0
var/list/chunked_topics = list()

var/list/pending_events = list()

var/detached = FALSE

/datum/tgs_api/v5/New()
Expand Down Expand Up @@ -125,7 +127,7 @@
TGS_DEBUG_LOG("RequireInitialBridgeResponse: Starting sleep")
logged = TRUE

sleep(1)
sleep(world.tick_lag)

TGS_DEBUG_LOG("RequireInitialBridgeResponse: Passed")

Expand Down Expand Up @@ -249,6 +251,40 @@
WaitForReattach(TRUE)
return chat_channels.Copy()

/datum/tgs_api/v5/TriggerEvent(event_name, list/parameters, wait_for_completion)
RequireInitialBridgeResponse()
WaitForReattach(TRUE)

if(interop_version.minor < 9)
TGS_WARNING_LOG("Interop version too low for custom events!")
return FALSE

var/str_parameters = list()
for(var/i in parameters)
str_parameters += "[i]"

var/list/response = Bridge(DMAPI5_BRIDGE_COMMAND_EVENT, list(DMAPI5_BRIDGE_PARAMETER_EVENT_INVOCATION = list(DMAPI5_EVENT_INVOCATION_NAME = event_name, DMAPI5_EVENT_INVOCATION_PARAMETERS = str_parameters, DMAPI5_EVENT_INVOCATION_NOTIFY_COMPLETION = wait_for_completion)))
if(!response)
return FALSE

var/event_id = response[DMAPI5_EVENT_ID]
if(!event_id)
return FALSE

TGS_DEBUG_LOG("Created event ID: [event_id]")
if(!wait_for_completion)
return TRUE

TGS_DEBUG_LOG("Waiting for completion of event ID: [event_id]")

while(!pending_events[event_id])
sleep(world.tick_lag)

TGS_DEBUG_LOG("Completed wait on event ID: [event_id]")
pending_events -= event_id

return TRUE

/datum/tgs_api/v5/proc/DecodeChannels(chat_update_json)
TGS_DEBUG_LOG("DecodeChannels()")
var/list/chat_channels_json = chat_update_json[DMAPI5_CHAT_UPDATE_CHANNELS]
Expand Down
7 changes: 5 additions & 2 deletions src/DMAPI/tgs/v5/bridge.dm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
if(detached)
// Wait up to one minute
for(var/i in 1 to 600)
sleep(1)
sleep(world.tick_lag)
if(!detached && (!require_channels || length(chat_channels)))
break

Expand All @@ -77,8 +77,11 @@
/datum/tgs_api/v5/proc/PerformBridgeRequest(bridge_request)
WaitForReattach(FALSE)

TGS_DEBUG_LOG("Bridge request start")
// This is an infinite sleep until we get a response
var/export_response = world.Export(bridge_request)
TGS_DEBUG_LOG("Bridge request complete")

if(!export_response)
TGS_ERROR_LOG("Failed bridge request: [bridge_request]")
return
Expand All @@ -88,7 +91,7 @@
TGS_ERROR_LOG("Failed bridge request, missing content!")
return

var/response_json = file2text(content)
var/response_json = TGS_FILE2TEXT_NATIVE(content)
if(!response_json)
TGS_ERROR_LOG("Failed bridge request, failed to load content!")
return
Expand Down
12 changes: 12 additions & 0 deletions src/DMAPI/tgs/v5/topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@
var/list/reattach_response = TopicResponse(error_message)
reattach_response[DMAPI5_PARAMETER_CUSTOM_COMMANDS] = ListCustomCommands()
reattach_response[DMAPI5_PARAMETER_TOPIC_PORT] = GetTopicPort()

pending_events.Cut()

return reattach_response

if(DMAPI5_TOPIC_COMMAND_SEND_CHUNK)
Expand Down Expand Up @@ -276,6 +279,15 @@
TGS_WORLD_ANNOUNCE(message)
return TopicResponse()

if(DMAPI5_TOPIC_COMMAND_COMPLETE_EVENT)
var/event_id = topic_parameters[DMAPI5_EVENT_ID]
if (!istext(event_id))
return TopicResponse("Invalid or missing [DMAPI5_EVENT_ID]")

TGS_DEBUG_LOG("Completing event ID [event_id]...")
pending_events[event_id] = TRUE
return TopicResponse()

return TopicResponse("Unknown command: [command]")

/datum/tgs_api/v5/proc/WorldBroadcast(message)
Expand Down
Loading

0 comments on commit a031710

Please sign in to comment.