From 5f475bf113314d0c065aededae9ae95d6b77d742 Mon Sep 17 00:00:00 2001 From: ASpoonPlaysGames <66967891+ASpoonPlaysGames@users.noreply.github.com> Date: Sun, 3 Sep 2023 16:14:38 +0100 Subject: [PATCH] Get lobby announcement from Atlas --- Northstar.Client/mod.json | 3 + .../mod/scripts/vscripts/ui/_menus.nut | 4 ++ Northstar.Custom/mod.json | 4 ++ .../scripts/vscripts/_atlas_announcements.nut | 57 +++++++++++++++++++ .../mod/cfg/autoexec_ns_server.cfg | 3 - 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 Northstar.Custom/mod/scripts/vscripts/_atlas_announcements.nut diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json index 8040c14c4..ca8e5193a 100644 --- a/Northstar.Client/mod.json +++ b/Northstar.Client/mod.json @@ -130,6 +130,9 @@ "RunOn": "UI" } ], + "Dependencies": { + "HAS_NORTHSTAR_CUSTOM": "Northstar.Custom" + }, "Localisation": [ "resource/northstar_client_localisation_%language%.txt" ] diff --git a/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut b/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut index c83381fdb..5b1b47467 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut @@ -813,6 +813,10 @@ void function UpdateMenusOnConnect( string levelname ) } thread UpdateAnnouncementDialog() + #if HAS_NORTHSTAR_CUSTOM + // relies on script HTTP which is in Northstar.Custom + thread GetAtlasAnnouncement_Threaded() + #endif // HAS_NORTHSTAR_CUSTOM } else { diff --git a/Northstar.Custom/mod.json b/Northstar.Custom/mod.json index 22f9c45fd..aca6601e9 100644 --- a/Northstar.Custom/mod.json +++ b/Northstar.Custom/mod.json @@ -434,6 +434,10 @@ { "Path": "sh_northstar_safe_io.gnut", "RunOn": "CLIENT || SERVER || UI" + }, + { + "Path": "_atlas_announcements.nut", + "RunOn": "UI" } ], diff --git a/Northstar.Custom/mod/scripts/vscripts/_atlas_announcements.nut b/Northstar.Custom/mod/scripts/vscripts/_atlas_announcements.nut new file mode 100644 index 000000000..8a48a3cb6 --- /dev/null +++ b/Northstar.Custom/mod/scripts/vscripts/_atlas_announcements.nut @@ -0,0 +1,57 @@ +untyped + +global function GetAtlasAnnouncement_Threaded + +const string ATLAS_ANNOUNCEMENT_SUFFIX = "/client/announcement" + +void function GetAtlasAnnouncement_Threaded() +{ + string url = format( "%s%s", GetConVarString( "ns_masterserver_hostname" ), ATLAS_ANNOUNCEMENT_SUFFIX ) + printt( format( "Getting announcement data from %s", url ) ) + + if ( !NSHttpGet( url, {}, OnRequestSuccess, OnRequestFailure ) ) + printt( "Failed to get announcement data! (request failed to start)" ) +} + +void function OnRequestSuccess( HttpRequestResponse response ) +{ + if ( response.statusCode != 200 ) + { + printt( format( "Failed to get announcement data! (Code: %i)\nReceived response: %s", response.statusCode, response.body ) ) + return + } + + string announcement + string announcementVersion + + table responseBody = DecodeJSON( response.body ) + + if ( "announcement" in responseBody && typeof( responseBody[ "announcement" ] ) == "string" ) + { + announcement = expect string( responseBody[ "announcement" ] ) + } + else + { + printt( "Failed to parse announcement data! Couldnt parse \"announcement\" field,\n", response.body ) + return + } + + if ( "announcementVersion" in responseBody && typeof( responseBody[ "announcementVersion" ] ) == "string" ) + { + announcementVersion = expect string( responseBody[ "announcementVersion" ] ) + } + else + { + printt( "Failed to parse announcement data! Couldnt parse \"announcementVersion\" field,\n", response.body ) + return + } + + printt( "Successfully got announcement data!" ) + SetConVarString( "announcement", announcement ) + SetConVarString( "announcementVersion", announcementVersion ) +} + +void function OnRequestFailure( HttpRequestFailure response ) +{ + printt( format( "Failed to get announcement data! (Code: %i)\nReceived response: %s", response.errorCode, response.errorMessage ) ) +} diff --git a/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg b/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg index bd4227835..002e4e801 100644 --- a/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg +++ b/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg @@ -22,6 +22,3 @@ sv_minupdaterate 20 // unsure if this actually works, but if it does, should set sv_max_snapshots_multiplayer 300 // this needs to be updaterate * 15, or clients will dc in killreplay net_data_block_enabled 0 // not really sure on this, have heard datablock could have security issues? doesn't seem to have any adverse effects being disabled host_skip_client_dll_crc 1 // allow people to run modded client dlls, this is mainly so people running pilot visor colour mods can keep those, since they use a client.dll edit - -announcementVersion 1 -announcement #PROGRESSION_ANNOUNCEMENT_BODY \ No newline at end of file