diff --git a/Northstar.Client/mod.json b/Northstar.Client/mod.json index 29473991b6..17a2307aa0 100644 --- a/Northstar.Client/mod.json +++ b/Northstar.Client/mod.json @@ -161,6 +161,10 @@ } }, { + "Path": "ui/_atlas_announcements.nut", + "RunOn": "UI" + }, + { "Path": "ui/ns_client_mod_settings.gnut", "RunOn": "UI", "UICallback":{ diff --git a/Northstar.Client/mod/scripts/vscripts/ui/_atlas_announcements.nut b/Northstar.Client/mod/scripts/vscripts/ui/_atlas_announcements.nut new file mode 100644 index 0000000000..af179811ed --- /dev/null +++ b/Northstar.Client/mod/scripts/vscripts/ui/_atlas_announcements.nut @@ -0,0 +1,75 @@ +untyped + +global function GetAtlasAnnouncement_Threaded + +const string ATLAS_ANNOUNCEMENT_SUFFIX = "/client/announcements" + +void function GetAtlasAnnouncement_Threaded() +{ + // TODO: All Northstar.Client files are loaded before Northstar.Custom currently, so these have to be lambdas because this file is loaded + // before sh_northstar_http_requests so the types used as function parameters cause compile errors. + // A weird quirk of the squirrel compiler seems to be that it gathers global defs first, and compiles them after? So by the time it's compiling the innards of + // GetAtlasAnnouncement_Threaded it knows about the types from sh_northstar_http_requests. + // Anyway a solution to this would be to have sh_northstar_http_requests belong to some + // sort of Northstar.Core or Northstar.Shared. (Same with other APIs such as file IO) + void functionref( HttpRequestResponse ) onRequestSuccess = void function( 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 + } + + // empty announcement + if ( announcement == "" || announcementVersion == "" ) + { + printt( "Found empty announcement data." ) + return + } + + printt( "Successfully got announcement data!" ) + SetConVarString( "announcement", announcement ) + SetConVarString( "announcementVersion", announcementVersion ) + } + + void functionref( HttpRequestFailure ) onRequestFailure = void function( HttpRequestFailure response ) + { + printt( format( "Failed to get announcement data! (Code: %i)\nReceived response: %s", response.errorCode, response.errorMessage ) ) + } + + while ( true ) + { + 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)" ) + + wait 300 // check for a new announcement every 5 minutes, why not + } +} diff --git a/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut b/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut index 202967ca5f..83431221f3 100644 --- a/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut +++ b/Northstar.Client/mod/scripts/vscripts/ui/_menus.nut @@ -810,6 +810,11 @@ void function UpdateMenusOnConnect( string levelname ) } thread UpdateAnnouncementDialog() + #if !VANILLA + // this ends up messing with announcementVersionSeen in persistence, + // so we should avoid doing that in vanilla + thread GetAtlasAnnouncement_Threaded() + #endif } else { diff --git a/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg b/Northstar.CustomServers/mod/cfg/autoexec_ns_server.cfg index bd42278350..002e4e801b 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