diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-06-12 21:41:41 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2025-06-13 20:22:51 +0800 |
| commit | 6f7b994684032060f0a2d7af82f4f3572293b8d6 (patch) | |
| tree | 793d328cbcd6761365267550b55db45aee9b21fc /src/core/chatServer.cpp | |
| parent | 6a51ab4525c59e9fe2bdbd92493019b0a98c6b94 (diff) | |
internal!: organized internal structure, using cmake now
Diffstat (limited to 'src/core/chatServer.cpp')
| -rw-r--r-- | src/core/chatServer.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/core/chatServer.cpp b/src/core/chatServer.cpp new file mode 100644 index 0000000..4a16c56 --- /dev/null +++ b/src/core/chatServer.cpp @@ -0,0 +1,68 @@ +#include "chatServer.hpp" +#include "../io/IOManager.hpp" +#include "chatManager.hpp" +#include "../command/commandHandler.hpp" +#include "../command/commands.hpp" +#include "../io/inputManager.hpp" +#include "../debug/log.hpp" +#include "../io/renderManager.hpp" +#include "server.hpp" +#include "sessionManager.hpp" + +CChatServer::CChatServer(uint16_t port) + : m_port(port) { + if (std::atexit([]() { g_pChatServer->cleanup(); })) + log(ERR, "Failed to register CChatServer atexit handler, dtors will not be called"); + + log(LOG, "ChatServer: initialized"); +}; + +CChatServer::~CChatServer() { + cleanup(); + log(SYS, "ChatServer: bye"); +} + +void CChatServer::cleanup() { + if (g_pSessionManager) { + g_pSessionManager->shutdownSessions(); + g_pSessionManager.reset(); + } + + g_pChatManager.reset(); + g_pServer.reset(); + g_pCommandHandler.reset(); + g_pInputManager.reset(); + g_pIOManager.reset(); + g_pRenderManager.reset(); +} + +void CChatServer::initManagers() { + log(LOG, "ChatServer: initializing managers"); + + log(LOG, "Creating RenderManager"); + g_pRenderManager = std::make_unique<CRenderManager>(); + log(LOG, "Creating InputManager"); + g_pInputManager = std::make_unique<CInputManager>(); + log(LOG, "Creating Server"); + g_pServer = std::make_unique<CServer>(m_port); + log(LOG, "Creating IOManager"); + g_pIOManager = std::make_unique<CIOManager>(); + log(LOG, "Creating SessionManager"); + g_pSessionManager = std::make_shared<CSessionManager>(); + log(LOG, "Creating ChatManager"); + g_pChatManager = std::make_unique<CChatManager>(); +} + +void CChatServer::start() { + initManagers(); + + log(LOG, "Creating CommandHandler"); + g_pCommandHandler = std::make_unique<CCommandHandler>(); + registerCommands(); + + // will await while waiting for accept() to return a new client + m_sessionManagerThread = std::jthread(&CSessionManager::run, g_pSessionManager.get()); + m_sessionManagerThread.detach(); + + g_pInputManager->inputLoop(); +} |
