2016-11-21 04:50:55 -05:00
|
|
|
#include "STDInclude.hpp"
|
|
|
|
|
|
|
|
namespace Utils
|
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
const char* Cache::Urls[] =
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2020-12-09 15:55:28 -05:00
|
|
|
"https://xlabs.dev",
|
|
|
|
"https://raw.githubusercontent.com/XLabsProject/iw4x-client"
|
2019-12-26 04:32:21 -05:00
|
|
|
|
2020-12-09 15:55:28 -05:00
|
|
|
//Links to old onion site - deprecated
|
|
|
|
//"https://iw4xcachep26muba.tor2web.xyz",
|
|
|
|
//"https://iw4xcachep26muba.onion.ws",
|
|
|
|
//"https://iw4xcachep26muba.onion.sh",
|
|
|
|
//"https://iw4xcachep26muba.onion.pet",
|
2018-11-24 20:42:12 -05:00
|
|
|
|
2016-11-21 04:50:55 -05:00
|
|
|
};
|
2016-11-21 14:49:33 -05:00
|
|
|
std::string Cache::ValidUrl;
|
2016-11-21 05:09:42 -05:00
|
|
|
std::mutex Cache::CacheMutex;
|
2016-11-21 04:50:55 -05:00
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
std::string Cache::GetStaticUrl(const std::string& path)
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2016-11-25 08:16:07 -05:00
|
|
|
return Cache::Urls[0] + path;
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
std::string Cache::GetUrl(const std::string& url, const std::string& path)
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
|
|
|
return url + path;
|
|
|
|
}
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
std::string Cache::GetFile(const std::string& path, int timeout, const std::string& useragent)
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
std::lock_guard<std::mutex> _(Cache::CacheMutex);
|
|
|
|
|
|
|
|
if (Cache::ValidUrl.empty())
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2017-06-04 14:51:05 -04:00
|
|
|
InternetSetCookieA("https://onion.casa", "disclaimer_accepted", "1");
|
|
|
|
InternetSetCookieA("https://hiddenservice.net", "disclaimer_accepted", "1");
|
|
|
|
|
2017-04-24 16:33:13 -04:00
|
|
|
for (int i = 0; i < ARRAYSIZE(Cache::Urls); ++i)
|
2016-11-21 04:50:55 -05:00
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
std::string result = Utils::WebIO(useragent, Cache::GetUrl(Cache::Urls[i], path)).setTimeout(timeout)->get();
|
|
|
|
|
2016-11-21 05:09:42 -05:00
|
|
|
if (!result.empty())
|
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
Cache::ValidUrl = Cache::Urls[i];
|
2016-11-21 05:09:42 -05:00
|
|
|
return result;
|
|
|
|
}
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
2016-11-21 14:49:33 -05:00
|
|
|
|
|
|
|
return "";
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
2016-11-21 05:09:42 -05:00
|
|
|
else
|
|
|
|
{
|
2016-11-21 14:49:33 -05:00
|
|
|
return Utils::WebIO(useragent, Cache::GetUrl(Cache::ValidUrl, path)).setTimeout(timeout)->get();
|
2016-11-21 05:09:42 -05:00
|
|
|
}
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|
2017-01-22 14:12:36 -05:00
|
|
|
|
|
|
|
void Cache::Uninitialize()
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> _(Cache::CacheMutex);
|
|
|
|
Cache::ValidUrl.clear();
|
|
|
|
}
|
2016-11-21 04:50:55 -05:00
|
|
|
}
|