2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-04-22 23:04:48 +00:00
|
|
|
#include <base/logger.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
|
2011-03-05 10:46:24 +00:00
|
|
|
#include <engine/console.h>
|
2011-02-27 14:03:57 +00:00
|
|
|
#include <engine/engine.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/shared/config.h>
|
|
|
|
#include <engine/shared/network.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/storage.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-03-02 13:28:37 +00:00
|
|
|
#include <engine/shared/assertion_logger.h>
|
|
|
|
|
2022-02-14 23:32:04 +00:00
|
|
|
CHostLookup::CHostLookup() = default;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2017-11-23 14:47:38 +00:00
|
|
|
CHostLookup::CHostLookup(const char *pHostname, int Nettype)
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2017-11-23 14:47:38 +00:00
|
|
|
str_copy(m_aHostname, pHostname, sizeof(m_aHostname));
|
|
|
|
m_Nettype = Nettype;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHostLookup::Run()
|
|
|
|
{
|
|
|
|
m_Result = net_host_lookup(m_aHostname, &m_Addr, m_Nettype);
|
2010-05-29 07:25:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-27 14:03:57 +00:00
|
|
|
class CEngine : public IEngine
|
2010-05-29 07:25:38 +00:00
|
|
|
{
|
2011-02-27 14:03:57 +00:00
|
|
|
public:
|
2011-03-05 10:46:24 +00:00
|
|
|
IConsole *m_pConsole;
|
|
|
|
IStorage *m_pStorage;
|
|
|
|
bool m_Logging;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-04-22 23:04:48 +00:00
|
|
|
std::shared_ptr<CFutureLogger> m_pFutureLogger;
|
2022-03-02 13:28:37 +00:00
|
|
|
|
|
|
|
char m_aAppName[256];
|
|
|
|
|
2011-08-13 00:11:06 +00:00
|
|
|
static void Con_DbgLognetwork(IConsole::IResult *pResult, void *pUserData)
|
2011-02-27 14:03:57 +00:00
|
|
|
{
|
2011-03-05 10:46:24 +00:00
|
|
|
CEngine *pEngine = static_cast<CEngine *>(pUserData);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-03-05 10:46:24 +00:00
|
|
|
if(pEngine->m_Logging)
|
|
|
|
{
|
|
|
|
CNetBase::CloseLog();
|
|
|
|
pEngine->m_Logging = false;
|
|
|
|
}
|
|
|
|
else
|
2011-04-13 18:37:12 +00:00
|
|
|
{
|
2011-03-05 10:46:24 +00:00
|
|
|
char aBuf[32];
|
|
|
|
str_timestamp(aBuf, sizeof(aBuf));
|
2021-09-13 08:06:34 +00:00
|
|
|
char aFilenameSent[IO_MAX_PATH_LENGTH], aFilenameRecv[IO_MAX_PATH_LENGTH];
|
2011-03-05 10:46:24 +00:00
|
|
|
str_format(aFilenameSent, sizeof(aFilenameSent), "dumps/network_sent_%s.txt", aBuf);
|
|
|
|
str_format(aFilenameRecv, sizeof(aFilenameRecv), "dumps/network_recv_%s.txt", aBuf);
|
|
|
|
CNetBase::OpenLog(pEngine->m_pStorage->OpenFile(aFilenameSent, IOFLAG_WRITE, IStorage::TYPE_SAVE),
|
2020-09-26 19:41:58 +00:00
|
|
|
pEngine->m_pStorage->OpenFile(aFilenameRecv, IOFLAG_WRITE, IStorage::TYPE_SAVE));
|
2011-03-05 10:46:24 +00:00
|
|
|
pEngine->m_Logging = true;
|
|
|
|
}
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-04-22 23:04:48 +00:00
|
|
|
CEngine(bool Test, const char *pAppname, std::shared_ptr<CFutureLogger> pFutureLogger, int Jobs) :
|
|
|
|
m_pFutureLogger(std::move(pFutureLogger))
|
2011-02-27 14:03:57 +00:00
|
|
|
{
|
2022-03-02 13:28:37 +00:00
|
|
|
str_copy(m_aAppName, pAppname, std::size(m_aAppName));
|
2021-04-17 14:05:24 +00:00
|
|
|
if(!Test)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
dbg_msg("engine", "running on %s-%s-%s", CONF_FAMILY_STRING, CONF_PLATFORM_STRING, CONF_ARCH_STRING);
|
2020-09-26 19:41:58 +00:00
|
|
|
#ifdef CONF_ARCH_ENDIAN_LITTLE
|
2021-04-17 14:05:24 +00:00
|
|
|
dbg_msg("engine", "arch is little endian");
|
2020-09-26 19:41:58 +00:00
|
|
|
#elif defined(CONF_ARCH_ENDIAN_BIG)
|
2021-04-17 14:05:24 +00:00
|
|
|
dbg_msg("engine", "arch is big endian");
|
2020-09-26 19:41:58 +00:00
|
|
|
#else
|
2021-04-17 14:05:24 +00:00
|
|
|
dbg_msg("engine", "unknown endian");
|
2020-09-26 19:41:58 +00:00
|
|
|
#endif
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2021-04-17 14:05:24 +00:00
|
|
|
// init the network
|
|
|
|
net_init();
|
|
|
|
CNetBase::Init();
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2018-10-07 10:47:32 +00:00
|
|
|
m_JobPool.Init(Jobs);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-03-05 10:46:24 +00:00
|
|
|
m_Logging = false;
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-03-12 12:48:05 +00:00
|
|
|
~CEngine() override
|
|
|
|
{
|
|
|
|
m_JobPool.Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init() override
|
2011-03-05 10:46:24 +00:00
|
|
|
{
|
|
|
|
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
|
|
|
m_pStorage = Kernel()->RequestInterface<IStorage>();
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-03-05 10:46:24 +00:00
|
|
|
if(!m_pConsole || !m_pStorage)
|
|
|
|
return;
|
|
|
|
|
2022-03-02 13:28:37 +00:00
|
|
|
char aFullPath[IO_MAX_PATH_LENGTH];
|
|
|
|
m_pStorage->GetCompletePath(IStorage::TYPE_SAVE, "dumps/", aFullPath, sizeof(aFullPath));
|
2020-09-26 19:41:58 +00:00
|
|
|
m_pConsole->Register("dbg_lognetwork", "", CFGFLAG_SERVER | CFGFLAG_CLIENT, Con_DbgLognetwork, this, "Log the network");
|
2011-02-27 14:03:57 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-03-12 12:48:05 +00:00
|
|
|
void AddJob(std::shared_ptr<IJob> pJob) override
|
2011-02-27 16:56:03 +00:00
|
|
|
{
|
|
|
|
if(g_Config.m_Debug)
|
|
|
|
dbg_msg("engine", "job added");
|
2017-11-24 09:33:42 +00:00
|
|
|
m_JobPool.Add(std::move(pJob));
|
2011-02-27 14:03:57 +00:00
|
|
|
}
|
2022-04-22 23:04:48 +00:00
|
|
|
|
|
|
|
void SetAdditionalLogger(std::unique_ptr<ILogger> &&pLogger) override
|
|
|
|
{
|
|
|
|
m_pFutureLogger->Set(std::move(pLogger));
|
|
|
|
}
|
2011-02-27 14:03:57 +00:00
|
|
|
};
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2021-03-13 17:10:59 +00:00
|
|
|
void IEngine::RunJobBlocking(IJob *pJob)
|
|
|
|
{
|
|
|
|
CJobPool::RunBlocking(pJob);
|
|
|
|
}
|
|
|
|
|
2022-04-22 23:04:48 +00:00
|
|
|
IEngine *CreateEngine(const char *pAppname, std::shared_ptr<CFutureLogger> pFutureLogger, int Jobs) { return new CEngine(false, pAppname, std::move(pFutureLogger), Jobs); }
|
|
|
|
IEngine *CreateTestEngine(const char *pAppname, int Jobs) { return new CEngine(true, pAppname, nullptr, Jobs); }
|