iw4x-client/src/Components/Modules/News.cpp

77 lines
1.5 KiB
C++
Raw Normal View History

#include "STDInclude.hpp"
2015-12-30 18:55:08 -05:00
#define NEWS_MOTD_DEFUALT "Welcome to ReactIW4x Multiplayer!"
2015-12-30 18:55:08 -05:00
namespace Components
{
std::thread* News::Thread = nullptr;
bool News::UnitTest()
{
bool result = true;
if (News::Thread)
{
Logger::Print("Awaiting thread termination...\n");
News::Thread->join();
delete News::Thread;
News::Thread = nullptr;
if (!strlen(Localization::Get("MPUI_CHANGELOG_TEXT")))
{
Logger::Print("Failed to fetch changelog!\n");
result = false;
}
else
{
Logger::Print("Successfully fetched changelog.\n");
}
if (!strcmp(Localization::Get("MPUI_MOTD_TEXT"), NEWS_MOTD_DEFUALT))
{
Logger::Print("Failed to fetch motd!\n");
result = false;
}
else
{
Logger::Print("Successfully fetched motd.\n");
}
}
return result;
}
2015-12-30 18:55:08 -05:00
News::News()
{
2016-01-11 18:48:27 -05:00
Localization::Set("MPUI_CHANGELOG_TEXT", "");
Localization::Set("MPUI_MOTD_TEXT", NEWS_MOTD_DEFUALT);
2016-01-11 18:48:27 -05:00
2016-01-26 18:50:20 -05:00
News::Thread = new std::thread([] ()
2015-12-30 18:55:08 -05:00
{
2016-02-04 18:33:06 -05:00
Localization::Set("MPUI_CHANGELOG_TEXT", Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/changelog.txt").SetTimeout(5000)->Get().data());
2016-01-26 18:50:20 -05:00
2016-02-04 18:33:06 -05:00
std::string data = Utils::WebIO("IW4x", "https://iw4xcachep26muba.onion.to/iw4/motd.txt").SetTimeout(5000)->Get();
2015-12-30 18:55:08 -05:00
if (!data.empty())
2016-01-26 18:50:20 -05:00
{
Localization::Set("MPUI_MOTD_TEXT", data.data());
}
2016-01-07 18:59:59 -05:00
2016-01-26 18:50:20 -05:00
// TODO: Implement update checks here!
});
}
News::~News()
{
if (News::Thread)
{
News::Thread->join();
delete News::Thread;
News::Thread = nullptr;
2016-01-26 18:50:20 -05:00
}
2015-12-30 18:55:08 -05:00
}
}