Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only fetch MAD manifesto on server join #821

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/nativefuncs.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,13 @@
"returnTypeString":"array<string>",
"argTypes":"string modName"
},
{
"name": "NSFetchVerifiedModsManifesto",
"helpText": "Retrieves the verified mods list from the central authority (GitHub).",
"returnTypeString": "void",
"argTypes": ""

},
{
"name": "NSIsModDownloadable",
"helpText": "checks whether a mod is verified and can be auto-downloaded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ Press Yes if you agree to this. This choice can be changed in the mods menu at a
"WRONG_MOD_VERSION" "Server has mod \"%s1\" v%s2 while you have v%s3"
"MOD_NOT_VERIFIED" "(mod is not verified, and couldn't be downloaded automatically)"
"MOD_DL_DISABLED" "(automatic mod downloading is disabled)"
"MANIFESTO_FETCHING_TITLE" "Setting up mod download"
"MANIFESTO_FETCHING_TEXT" "Retrieving the list of verified mods..."
"DOWNLOADING_MOD_TITLE" "Downloading mod"
"DOWNLOADING_MOD_TITLE_W_PROGRESS" "Downloading mod (%s1%)"
"DOWNLOADING_MOD_TEXT" "Downloading %s1 v%s2..."
Expand Down
37 changes: 36 additions & 1 deletion Northstar.Client/mod/scripts/vscripts/ui/menu_ns_moddownload.nut
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
global function DownloadMod
global function DisplayModDownloadErrorDialog
global function FetchVerifiedModsManifesto

global enum eModInstallStatus
{
MANIFESTO_FETCHING,
DOWNLOADING,
CHECKSUMING,
EXTRACTING,
Expand All @@ -18,7 +20,36 @@ global enum eModInstallStatus

const int MB = 1024*1000;

bool function DownloadMod( RequiredModInfo mod )

void function FetchVerifiedModsManifesto()
{
print("Start fetching verified mods manifesto from the Internet")

// Fetching UI
DialogData dialogData
dialogData.header = Localize( "#MANIFESTO_FETCHING_TITLE" )
dialogData.message = Localize( "#MANIFESTO_FETCHING_TEXT" )
dialogData.showSpinner = true;

// Prevent user from closing dialog
dialogData.forceChoice = true;
OpenDialog( dialogData )

// Do the actual fetching
NSFetchVerifiedModsManifesto()

ModInstallState state = NSGetModInstallState()
while ( state.status == eModInstallStatus.MANIFESTO_FETCHING )
{
state = NSGetModInstallState()
WaitFrame()
}

// Close dialog when manifesto has been received
CloseActiveMenu()
}

bool function DownloadMod( RequiredModInfo mod, string serverName )
{
// Downloading mod UI
DialogData dialogData
Expand Down Expand Up @@ -58,6 +89,10 @@ void function UpdateModDownloadDialog( RequiredModInfo mod, ModInstallState stat
{
switch ( state.status )
{
case eModInstallStatus.MANIFESTO_FETCHING:
Hud_SetText( header, Localize( "#MANIFESTO_FETCHING_TITLE" ) )
Hud_SetText( body, Localize( "#MANIFESTO_FETCHING_TEXT" ) )
break
case eModInstallStatus.DOWNLOADING:
Hud_SetText( header, Localize( "#DOWNLOADING_MOD_TITLE_W_PROGRESS", string( state.ratio ) ) )
Hud_SetText( body, Localize( "#DOWNLOADING_MOD_TEXT_W_PROGRESS", mod.name, mod.version, floor( state.progress / MB ), floor( state.total / MB ) ) )
Expand Down
81 changes: 56 additions & 25 deletions Northstar.Client/mod/scripts/vscripts/ui/menu_ns_serverbrowser.nut
Original file line number Diff line number Diff line change
Expand Up @@ -967,49 +967,80 @@ void function OnServerSelected_Threaded( var button )
bool autoDownloadAllowed = GetConVarBool( "allow_mod_auto_download" )
int downloadedMods = 0;

// Check out if there's any server-required mod that is not locally installed
array<string> modNames = NSGetModNames()
bool uninstalledModFound = false
foreach ( requiredModInfo in server.requiredMods )
{
if ( !modNames.contains( requiredModInfo.name ) )
{
uninstalledModFound = true
break
}
}
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved

// If yes, we fetch the verified mods manifesto, to check whether uninstalled
// mods can be installed through auto-download
if ( uninstalledModFound && autoDownloadAllowed )
{
print("Auto-download is allowed, checking if missing mods can be installed automatically.")
FetchVerifiedModsManifesto()
}

foreach ( RequiredModInfo mod in server.requiredMods )
{
if ( !NSGetModNames().contains( mod.name ) )
{
// Check if mod can be auto-downloaded
bool modIsVerified = NSIsModDownloadable( mod.name, mod.version )
// Auto-download mod
if ( autoDownloadAllowed )
{
bool modIsVerified = NSIsModDownloadable( mod.name, mod.version )

// Display error message if mod is not verified
if ( !modIsVerified )
{
DialogData dialogData
dialogData.header = "#ERROR"
dialogData.message = Localize( "#MISSING_MOD", mod.name, mod.version )
dialogData.message += "\n" + Localize( "#MOD_NOT_VERIFIED" )
dialogData.image = $"ui/menu/common/dialog_error"

AddDialogButton( dialogData, "#DISMISS" )
AddDialogFooter( dialogData, "#A_BUTTON_SELECT" )
AddDialogFooter( dialogData, "#B_BUTTON_DISMISS_RUI" )

OpenDialog( dialogData )
return
}
else
{
if ( DownloadMod( mod, server.name ) )
{
downloadedMods++
}
else
{
DisplayModDownloadErrorDialog( mod.name )
return
}
}
}

// Display an error message if not
if ( !modIsVerified || !autoDownloadAllowed )
// Mod not found, display error message
else
{
DialogData dialogData
dialogData.header = "#ERROR"
dialogData.message = Localize( "#MISSING_MOD", mod.name, mod.version )
dialogData.image = $"ui/menu/common/dialog_error"

// Specify error (only if autoDownloadAllowed is set)
if ( autoDownloadAllowed )
{
dialogData.message += "\n" + Localize( "#MOD_NOT_VERIFIED" )
}

AddDialogButton( dialogData, "#DISMISS" )

AddDialogFooter( dialogData, "#A_BUTTON_SELECT" )
AddDialogFooter( dialogData, "#B_BUTTON_DISMISS_RUI" )

OpenDialog( dialogData )

return
}

else // Launch download
{
if ( DownloadMod( mod ) )
{
downloadedMods++
}
else
{
DisplayModDownloadErrorDialog( mod.name )
return
}
}
}
else
{
Expand Down
Loading