Move enet initialisation into STKHost.

This commit is contained in:
hiker 2015-10-27 16:58:40 +11:00
parent 10f8f6b3a5
commit e212276dd2
3 changed files with 22 additions and 11 deletions

View File

@ -59,14 +59,6 @@ NetworkConsole::~NetworkConsole()
// ----------------------------------------------------------------------------
void NetworkConsole::run()
{
if (enet_initialize() != 0)
{
Log::error("NetworkConsole", "Could not initialize enet.");
return;
}
Log::info("NetworkConsole", "Host initialized.");
// listen keyboard console input
m_thread_keyboard = new pthread_t;
pthread_create(m_thread_keyboard, NULL, mainLoop, this);

View File

@ -60,13 +60,28 @@ STKHost::STKHost()
pthread_mutex_init(&m_exit_mutex, NULL);
Network::openLog();
// Start with initialising ENet
// ============================
if (enet_initialize() != 0)
{
Log::error("NetworkConsole", "Could not initialize enet.");
return;
}
Log::info("NetworkConsole", "Host initialized.");
Network::openLog(); // Open packet log file
ProtocolManager::getInstance<ProtocolManager>();
// Optional: start the network console
m_network_console = new NetworkConsole();
m_network_console->run();
if (m_is_server)
{
NetworkConsole *sc = new NetworkConsole();
sc->run();
// The server control flow starts with the ServerLobbyRoomProtocol.
// This will in turn spawn more protocols:
// GetPublicAddress: Use STUN to discover the public ip address
// and port number for this host.
setupServer(STKHost::HOST_ANY, 7321, 16, 2, 0, 0);
startListening();
ProtocolManager::getInstance()->requestStart(new ServerLobbyRoomProtocol());

View File

@ -36,6 +36,7 @@
#include <pthread.h>
class GameSetup;
class NetworkConsole;
class STKPeer;
/** \class STKHost
@ -74,6 +75,9 @@ private:
/** ENet host interfacing sockets. */
Network* m_network;
/** Network console */
NetworkConsole *m_network_console;
/** The list of peers connected to this instance. */
std::vector<STKPeer*> m_peers;