Skip to content

Commit

Permalink
move DapDebugServer into GameState for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinEady committed Mar 12, 2023
1 parent bb9a19c commit e9856c3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
26 changes: 11 additions & 15 deletions pol-core/pol/dap/server.cpp
Expand Up @@ -285,35 +285,31 @@ void DapDebugClientThread::run()
POLLOG_INFO << "Debug client thread closing.\n";
}

void DapDebugServer::initialize()
DapDebugServer::DapDebugServer()
{
if ( Plib::systemstate.config.dap_debug_port )
{
Core::gamestate.dap_debug_server = dap::net::Server::create();
_server = dap::net::Server::create();

// If DebugLocalOnly, bind to localhost which allows connections only from local addresses.
// Otherwise, bind to any address to also allow remote connections.
auto address = Plib::systemstate.config.debug_local_only ? "localhost" : "0.0.0.0";

auto started = Core::gamestate.dap_debug_server->start(
address, Plib::systemstate.config.dap_debug_port,
[]( const std::shared_ptr<dap::ReaderWriter>& rw )
{
auto client = std::make_shared<DapDebugClientThread>( rw );
Core::networkManager.auxthreadpool->push( [=]() { client->run(); } );
} );
auto started =
_server->start( address, Plib::systemstate.config.dap_debug_port,
[]( const std::shared_ptr<dap::ReaderWriter>& rw )
{
auto client = std::make_shared<DapDebugClientThread>( rw );
Core::networkManager.auxthreadpool->push( [=]() { client->run(); } );
} );

if ( !started )
{
POLLOG_ERROR << "Failed to start DAP server.\n";
Core::gamestate.dap_debug_server.reset();
_server.reset();
}
}
}

void DapDebugServer::deinitialize()
{
Core::gamestate.dap_debug_server.reset();
}
} // namespace DapDebugServer
} // namespace Network
} // namespace Pol
8 changes: 6 additions & 2 deletions pol-core/pol/dap/server.h
@@ -1,15 +1,19 @@
#ifndef POLDBGDAP_H
#define POLDBGDAP_H

#include <dap/network.h>

namespace Pol
{
namespace Network
{
class DapDebugServer
{
public:
static void initialize();
static void deinitialize();
DapDebugServer();

private:
std::unique_ptr<dap::net::Server> _server;
};
} // namespace Network
} // namespace Pol
Expand Down
4 changes: 3 additions & 1 deletion pol-core/pol/globals/uvars.cpp
Expand Up @@ -17,7 +17,6 @@

#include <algorithm>
#include <string.h>
#include <dap/network.h>

#include "../../bscript/bobject.h"
#include "../../clib/boostutils.h"
Expand All @@ -29,6 +28,7 @@
#include "../accounts/accounts.h"
#include "../checkpnt.h"
#include "../console.h"
#include "../dap/server.h"
#include "../guilds.h"
#include "../item/equipmnt.h"
#include "../item/itemdesc.h"
Expand Down Expand Up @@ -207,6 +207,8 @@ void GameState::deinitialize()
{
INFO_PRINT << "Initiating POL Cleanup....\n";

Core::gamestate.dap_debug_server.reset();

networkManager.deinialize();
deinit_ipc_vars();

Expand Down
11 changes: 2 additions & 9 deletions pol-core/pol/globals/uvars.h
Expand Up @@ -36,14 +36,6 @@
#include "base/vector.h"
#include "regions/region.h"

namespace dap
{
namespace net
{
class Server;
}
} // namespace dap

namespace Pol
{
namespace Realms
Expand All @@ -64,6 +56,7 @@ class Attribute;
namespace Network
{
class Client;
class DapDebugServer;
}
namespace Multi
{
Expand Down Expand Up @@ -261,7 +254,7 @@ class GameState
Core::Vec2d update_range; // maximum update range (client view range/multi footprint) used as
// "pre-filtering" of objects

std::unique_ptr<dap::net::Server> dap_debug_server;
std::unique_ptr<Network::DapDebugServer> dap_debug_server;

private:
void cleanup_vars();
Expand Down
3 changes: 1 addition & 2 deletions pol-core/pol/pol.cpp
Expand Up @@ -1170,7 +1170,7 @@ int xmain_inner( bool testing )
Core::checkpoint( "starting threads" );
Core::start_threads();
Network::start_aux_services();
Network::DapDebugServer::initialize();
Core::gamestate.dap_debug_server = std::make_unique<Network::DapDebugServer>();

#ifdef _WIN32
Core::console_thread();
Expand All @@ -1193,7 +1193,6 @@ int xmain_inner( bool testing )
Core::pol_sleep_ms( 1000 );
}
Core::checkpoint( "child threads have shut down" );
Network::DapDebugServer::deinitialize();
Core::cancel_all_trades();
Core::stop_gameclock();
POLLOG_INFO << "Shutting down...\n";
Expand Down

0 comments on commit e9856c3

Please sign in to comment.