[Download]: Log Mongoose stuff properly (#879)
This commit is contained in:
parent
c45fd2d5e6
commit
6224728d4b
@ -26,6 +26,8 @@ namespace Components
|
|||||||
volatile bool Download::Terminate;
|
volatile bool Download::Terminate;
|
||||||
bool Download::ServerRunning;
|
bool Download::ServerRunning;
|
||||||
|
|
||||||
|
std::string Download::MongooseLogBuffer;
|
||||||
|
|
||||||
#pragma region Client
|
#pragma region Client
|
||||||
|
|
||||||
void Download::InitiateMapDownload(const std::string& map, bool needPassword)
|
void Download::InitiateMapDownload(const std::string& map, bool needPassword)
|
||||||
@ -416,6 +418,19 @@ namespace Components
|
|||||||
|
|
||||||
#pragma region Server
|
#pragma region Server
|
||||||
|
|
||||||
|
void Download::LogFn(char c, [[maybe_unused]] void* param)
|
||||||
|
{
|
||||||
|
// Truncate & print if buffer is 1024 characters in length or otherwise only print when we reached a 'new line'
|
||||||
|
if (!std::isprint(static_cast<unsigned char>(c)) || MongooseLogBuffer.size() == 1024)
|
||||||
|
{
|
||||||
|
Logger::Print(Game::CON_CHANNEL_NETWORK, "{}\n", MongooseLogBuffer);
|
||||||
|
MongooseLogBuffer.clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MongooseLogBuffer.push_back(c);
|
||||||
|
}
|
||||||
|
|
||||||
static std::string InfoHandler()
|
static std::string InfoHandler()
|
||||||
{
|
{
|
||||||
const auto status = ServerInfo::GetInfo();
|
const auto status = ServerInfo::GetInfo();
|
||||||
@ -462,7 +477,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
info["players"] = players;
|
info["players"] = players;
|
||||||
return {nlohmann::json(info).dump()};
|
return nlohmann::json(info).dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string ListHandler()
|
static std::string ListHandler()
|
||||||
@ -508,7 +523,7 @@ namespace Components
|
|||||||
jsonList = fileList;
|
jsonList = fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {jsonList.dump()};
|
return jsonList.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string MapHandler()
|
static std::string MapHandler()
|
||||||
@ -552,7 +567,7 @@ namespace Components
|
|||||||
jsonList = fileList;
|
jsonList = fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {jsonList.dump()};
|
return jsonList.dump();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FileHandler(mg_connection* c, const mg_http_message* hm)
|
static void FileHandler(mg_connection* c, const mg_http_message* hm)
|
||||||
@ -668,6 +683,13 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (!Flags::HasFlag("disable-mongoose"))
|
if (!Flags::HasFlag("disable-mongoose"))
|
||||||
{
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
mg_log_set(MG_LL_INFO);
|
||||||
|
#else
|
||||||
|
mg_log_set(MG_LL_ERROR);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mg_log_set_fn(LogFn, nullptr);
|
||||||
mg_mgr_init(&Mgr);
|
mg_mgr_init(&Mgr);
|
||||||
|
|
||||||
Network::OnStart([]
|
Network::OnStart([]
|
||||||
|
@ -91,10 +91,14 @@ namespace Components
|
|||||||
static volatile bool Terminate;
|
static volatile bool Terminate;
|
||||||
static bool ServerRunning;
|
static bool ServerRunning;
|
||||||
|
|
||||||
|
static std::string MongooseLogBuffer;
|
||||||
|
|
||||||
static void DownloadProgress(FileDownload* fDownload, std::size_t bytes);
|
static void DownloadProgress(FileDownload* fDownload, std::size_t bytes);
|
||||||
|
|
||||||
static void ModDownloader(ClientDownload* download);
|
static void ModDownloader(ClientDownload* download);
|
||||||
static bool ParseModList(ClientDownload* download, const std::string& list);
|
static bool ParseModList(ClientDownload* download, const std::string& list);
|
||||||
static bool DownloadFile(ClientDownload* download, unsigned int index);
|
static bool DownloadFile(ClientDownload* download, unsigned int index);
|
||||||
|
|
||||||
|
static void LogFn(char c, void* param);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,12 @@ namespace Components
|
|||||||
|
|
||||||
void Logger::MessagePrint(const int channel, const std::string& msg)
|
void Logger::MessagePrint(const int channel, const std::string& msg)
|
||||||
{
|
{
|
||||||
if (Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests())
|
static const auto shouldPrint = []() -> bool
|
||||||
|
{
|
||||||
|
return Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests();
|
||||||
|
}();
|
||||||
|
|
||||||
|
if (shouldPrint)
|
||||||
{
|
{
|
||||||
std::printf("%s", msg.data());
|
std::printf("%s", msg.data());
|
||||||
std::fflush(stdout);
|
std::fflush(stdout);
|
||||||
|
Loading…
Reference in New Issue
Block a user