Some fixes

This commit is contained in:
fed 2022-10-11 18:29:53 +02:00
parent d3124bf989
commit c0c0d40533
2 changed files with 27 additions and 14 deletions

View File

@ -64,8 +64,13 @@ namespace download
if (now - last_update > 20ms)
{
last_update = std::chrono::high_resolution_clock::now();
const auto fraction = static_cast<float>(static_cast<double>(progress) /
static_cast<double>(std::max(size_t(1), total)));
auto fraction = 0.f;
if (total > 0)
{
fraction = static_cast<float>(static_cast<double>(progress) /
static_cast<double>(total));
}
scheduler::once([=]()
{
ui_scripting::notify("mod_download_progress",

View File

@ -172,19 +172,27 @@ namespace party
void check_download_map(const utils::info_string& info, std::vector<download::file_t>& files)
{
const auto mapname = info.get("mapname");
const auto usermap_hash = info.get("usermaphash");
const auto usermap_load_hash = info.get("usermaploadhash");
const auto check_file = [&](const std::string& key, const std::string& filename)
if (fastfiles::is_stock_map(mapname))
{
if (mapname.contains('.') || mapname.contains("::"))
{
throw std::runtime_error(utils::string::va("Invalid server mapname value %s\n", mapname.data()));
}
return;
}
if (mapname.contains('.') || mapname.contains("::"))
{
throw std::runtime_error(utils::string::va("Invalid server mapname value %s\n", mapname.data()));
}
const auto check_file = [&](const std::string& key, const std::string& ext, bool optional)
{
const auto filename = utils::string::va("usermaps/%s/%s%s", mapname.data(), mapname.data(), ext.data());
const auto source_hash = info.get(key);
if (source_hash.empty())
{
if (!optional)
{
throw std::runtime_error(utils::string::va("Server %s is empty", key.data()));
}
return;
}
@ -196,8 +204,8 @@ namespace party
}
};
check_file("usermaphash", utils::string::va("usermaps/%s/%s.ff", mapname.data(), mapname.data()));
check_file("usermaploadhash", utils::string::va("usermaps/%s/%s_load.ff", mapname.data(), mapname.data()));
check_file("usermaphash", ".ff", false);
check_file("usermaploadhash", "_load.ff", true);
}
bool check_download_mod(const utils::info_string& info, std::vector<download::file_t>& files)
@ -295,7 +303,7 @@ namespace party
if (!fastfiles::is_stock_map(mapname))
{
const auto filename = utils::string::va("usermaps/%s/%s.ff", mapname, mapname);
const auto filename = utils::string::va("usermaps\\%s\\%s.ff", mapname, mapname);
const auto hash = get_file_hash(filename);
if (!hash.has_value() || hash.value() != usermap_hash)
{
@ -338,7 +346,7 @@ namespace party
utils::hook::detour net_out_of_band_print_hook;
void net_out_of_band_print_stub(game::netsrc_t sock, game::netadr_s* addr, const char* data)
{
if (!strstr(data, "loadingnewmap"))
if (!std::strstr(data, "loadingnewmap"))
{
return net_out_of_band_print_hook.invoke<void>(sock, addr, data);
}