Some fixes

This commit is contained in:
Federico Cecchetto 2022-09-11 16:26:11 +02:00
parent 6d2a5bf5bc
commit 0829fa8b01
2 changed files with 19 additions and 22 deletions

View File

@ -66,6 +66,14 @@ namespace download
return 0;
}
void menu_error(const std::string& error)
{
scheduler::once([=]()
{
party::menu_error(error);
}, scheduler::pipeline::lui);
}
}
void start_download(const game::netadr_s& target, const utils::info_string& info)
@ -81,7 +89,7 @@ namespace download
}
return scheduler::cond_continue;
});
}, scheduler::pipeline::main);
return;
}
@ -94,7 +102,7 @@ namespace download
const auto base = info.get("sv_wwwBaseUrl");
if (base.empty())
{
party::menu_error("Download failed: Server doesn't have 'sv_wwwBaseUrl' dvar set.");
menu_error("Download failed: Server doesn't have 'sv_wwwBaseUrl' dvar set.");
return;
}
@ -129,7 +137,7 @@ namespace download
const auto data = utils::http::get_data(url, {}, {}, &progress_callback);
if (!data.has_value())
{
party::menu_error("Download failed: An unknown error occurred, please try again.");
menu_error("Download failed: An unknown error occurred, please try again.");
return;
}
@ -141,7 +149,7 @@ namespace download
const auto& result = data.value();
if (result.code != CURLE_OK)
{
party::menu_error(utils::string::va("Download failed: %s (%i)\n", result.code, curl_easy_strerror(result.code)));
menu_error(utils::string::va("Download failed: %s (%i)\n", result.code, curl_easy_strerror(result.code)));
return;
}
@ -153,7 +161,6 @@ namespace download
ui_scripting::notify("mod_download_done", {});
}, scheduler::pipeline::lui);
// reconnect back to target after download of mod is finished
scheduler::once([=]()
{
party::connect(target);
@ -176,9 +183,8 @@ namespace download
scheduler::once([]()
{
ui_scripting::notify("mod_download_done", {});
}, scheduler::pipeline::lui);
party::menu_error("Download for server mod has been cancelled.");
}, scheduler::pipeline::lui);
}
}

View File

@ -155,7 +155,7 @@ namespace party
const auto server_fs_game = utils::string::to_lower(info.get("fs_game"));
if (!server_fs_game.starts_with("mods/") || server_fs_game.contains('.'))
{
console::info("Invalid server fs_game value %s\n", server_fs_game.data());
menu_error(utils::string::va("Invalid server fs_game value %s\n", server_fs_game.data()));
return true;
}
@ -218,21 +218,14 @@ namespace party
void menu_error(const std::string& error)
{
// print error to console
console::error("%s\n", error.data());
scheduler::once([&]()
{
// check if popup_acceptinginvite is open and close if so
if (game::Menu_IsMenuOpenAndVisible(0, "popup_acceptinginvite"))
{
utils::hook::invoke<void>(0x26BE80_b, 0, "popup_acceptinginvite", 0, *game::hks::lua_state); // LUI_LeaveMenuByName
}
// set ui error information
utils::hook::invoke<void>(0x17D770_b, error.data(), "MENU_NOTICE"); // Com_SetLocalizedErrorMessage
utils::hook::set(0x2ED2F78_b, 1);
}, scheduler::pipeline::lui);
*reinterpret_cast<int*>(0x2ED2F78_b) = 1;
}
void clear_sv_motd()
@ -745,8 +738,6 @@ namespace party
return;
}
// returning true doesn't exactly mean there is a error, but more or less means that we are cancelling the connection for more than one different reason.
// if there is a genuine error that occurs, menu_error is called within the function.
if (download_mod(target, info))
{
return;