mirror of
https://github.com/zhenyan121/SporeBG-Conid.git
synced 2026-04-10 06:14:08 +08:00
feat: add JSON support for serverPort and hostPort
This commit is contained in:
@@ -19,7 +19,8 @@
|
||||
},
|
||||
"network": {
|
||||
"server_ip": "127.0.0.1",
|
||||
"port": 12345,
|
||||
"server_port": 12345,
|
||||
"host_port": 12345,
|
||||
"max_players": 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ void NetworkManager::startServer() {
|
||||
if (!m_gameServer) {
|
||||
std::cerr << "gameServer is not esist\n";
|
||||
}
|
||||
m_gameServer->startServer(m_config.network.port);
|
||||
m_gameServer->startServer(m_config.network.hostPort);
|
||||
|
||||
std::cout << "start server success\n";
|
||||
//m_ioContext.run();
|
||||
@@ -93,10 +93,10 @@ void NetworkManager::startClient() {
|
||||
}
|
||||
);
|
||||
if (m_netType == NetType::HOST) {
|
||||
m_client->connect("127.0.0.1", m_config.network.port, true);
|
||||
m_client->connect("127.0.0.1", m_config.network.hostPort, true);
|
||||
}
|
||||
if (m_netType == NetType::CLIENT) {
|
||||
m_client->connect(m_config.network.serverIP, m_config.network.port, false);
|
||||
m_client->connect(m_config.network.serverIP, m_config.network.serverPort, false);
|
||||
//m_ioContext.run();
|
||||
}
|
||||
std::cout << "start client success\n";
|
||||
|
||||
@@ -81,7 +81,8 @@ struct Viewport {
|
||||
};
|
||||
|
||||
struct NetworkConfig {
|
||||
int port = 12345;
|
||||
int serverPort = 12345;
|
||||
int hostPort = 12345;
|
||||
int maxPlayers = 2;
|
||||
std::string serverIP = "127.0.0.1";
|
||||
};
|
||||
|
||||
@@ -37,7 +37,8 @@ static void loadNetwork(const json& j, NetworkConfig& network) {
|
||||
std::cout << "Unkonw key " << key << "\n";
|
||||
}
|
||||
};
|
||||
get("port", network.port);
|
||||
get("server_port", network.serverPort);
|
||||
get("host_port", network.hostPort);
|
||||
get("max_players", network.maxPlayers);
|
||||
get("server_ip", network.serverIP);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user