Now uses config file to determine if client or server should be started.

This commit is contained in:
stiffly
2015-12-18 13:34:21 +01:00
parent a858dab8b6
commit a0255f1b31
4 changed files with 26 additions and 14 deletions
+3
View File
@@ -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
+3 -1
View File
@@ -19,4 +19,6 @@ F1=ToggleEditor
2=EditorToolRotate
3=EditorToolScale
X=EditorToggleTransformSpace
C=ConnectToServer
C=ConnectToServer
N=SwitchToServer
M=SwitchToClient
+6 -6
View File
@@ -10,6 +10,7 @@ Client::Client(ConfigFile* config) : m_Socket(m_IOService)
int port = config->Get<int>("Networking.Port", 13);
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string(address), port);
// Set up network stream
m_PlayerName = config->Get<std::string>("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");
}
+14 -7
View File
@@ -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<EntityXMLFile>(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<bool>("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;
}