diff --git a/resources/DefaultConfig.ini b/resources/DefaultConfig.ini index 6c6d4808..3ab402ad 100644 --- a/resources/DefaultConfig.ini +++ b/resources/DefaultConfig.ini @@ -10,7 +10,10 @@ VSYNC=false Width=1280 Height=720 FOV=45 + [Networking] StartNetwork=false +IsServer=false +Name=Bob Address=127.0.0.1 Port=13 \ No newline at end of file diff --git a/resources/DefaultInput.ini b/resources/DefaultInput.ini index 9246de59..95ebbc22 100644 --- a/resources/DefaultInput.ini +++ b/resources/DefaultInput.ini @@ -19,4 +19,6 @@ F1=ToggleEditor 2=EditorToolRotate 3=EditorToolScale X=EditorToggleTransformSpace -C=ConnectToServer \ No newline at end of file +C=ConnectToServer +N=SwitchToServer +M=SwitchToClient \ No newline at end of file diff --git a/src/Engine/Network/Client.cpp b/src/Engine/Network/Client.cpp index 8efd97ce..5c7e9c8f 100644 --- a/src/Engine/Network/Client.cpp +++ b/src/Engine/Network/Client.cpp @@ -10,6 +10,7 @@ Client::Client(ConfigFile* config) : m_Socket(m_IOService) int port = config->Get("Networking.Port", 13); m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string(address), port); // Set up network stream + m_PlayerName = config->Get("Networking.Name", "Raptorcopter"); m_NextSnapshot.InputForward = ""; m_NextSnapshot.InputRight = ""; } @@ -29,12 +30,11 @@ void Client::Start(World* world, EventBroker* eventBroker) m_EInputCommand = decltype(m_EInputCommand)(std::bind(&Client::OnInputCommand, this, std::placeholders::_1)); m_EventBroker->Subscribe(m_EInputCommand); - LOG_INFO("Please enter your name: "); - std::cin >> m_PlayerName; - while (m_PlayerName.size() > 7) { - LOG_INFO("Please enter your name (No longer than 7 characters):"); - std::cin >> m_PlayerName; - } + + //while (m_PlayerName.size() > 7) { + // LOG_INFO("Please enter your name (No longer than 7 characters):"); + // std::cin >> m_PlayerName; + //} m_Socket.connect(m_ReceiverEndpoint); LOG_INFO("I am client. BIP BOP"); } diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp index e3f710cb..a02e2c62 100644 --- a/src/Game/Game.cpp +++ b/src/Game/Game.cpp @@ -96,7 +96,6 @@ void Game::Tick() m_ClientOrServer->Update(); } - // Iterate through systems and update world! m_SystemPipeline->Update(m_World, dt); debugTick(dt); @@ -123,6 +122,16 @@ bool Game::debugOnInputCommand(const Events::InputCommand& e) ResourceManager::Load(mapToLoad)->PopulateWorld(m_World); } } + if (e.Command == "SwitchToServer" && e.Value > 0) { + m_ClientOrServer = new Server(); + LOG_INFO("Switching to server"); + m_ClientOrServer->Start(m_World, m_EventBroker); + } + if (e.Command == "SwitchToClient" && e.Value > 0) { + m_ClientOrServer = new Client(m_Config); + m_ClientOrServer->Start(m_World, m_EventBroker); + LOG_INFO("Switching to client"); + } return false; } @@ -139,14 +148,12 @@ void Game::debugTick(double dt) void Game::networkFunction() { - std::string inputMessage; - LOG_INFO("Start client or server? (c/s)"); - std::cin >> inputMessage; - if (inputMessage == "c" || inputMessage == "C") { + bool isServer = m_Config->Get("Networking.IsServer", false); + if (!isServer) { m_IsClientOrServer = true; m_ClientOrServer = new Client(m_Config); } - if (inputMessage == "s" || inputMessage == "S") { + if (isServer) { m_IsClientOrServer = true; m_ClientOrServer = new Server(); } @@ -155,6 +162,6 @@ void Game::networkFunction() // ~Game() is not called if the game is exited by closing console windows // When server or client is done set it to false. //m_IsClientOrServer = false; - // Destroy it! (with fire) + // Destroy it //delete m_ClientOrServer; } \ No newline at end of file