Use STKHost to determine graphics-client-server
This commit is contained in:
parent
6536a311b3
commit
cd5cb5ef6d
16
src/main.cpp
16
src/main.cpp
@ -540,8 +540,8 @@ void cmdLineHelp()
|
|||||||
" and the music.\n"
|
" and the music.\n"
|
||||||
" -t, --track=NAME Start track NAME.\n"
|
" -t, --track=NAME Start track NAME.\n"
|
||||||
" --gp=NAME Start the specified Grand Prix.\n"
|
" --gp=NAME Start the specified Grand Prix.\n"
|
||||||
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved "
|
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved\n"
|
||||||
"in config.xml under additional_gp_directory. Use "
|
"in config.xml under additional_gp_directory. Use\n"
|
||||||
"--add-gp-dir=\"\" to unset.\n"
|
"--add-gp-dir=\"\" to unset.\n"
|
||||||
" --stk-config=FILE use ./data/FILE instead of "
|
" --stk-config=FILE use ./data/FILE instead of "
|
||||||
"./data/stk_config.xml\n"
|
"./data/stk_config.xml\n"
|
||||||
@ -567,7 +567,7 @@ void cmdLineHelp()
|
|||||||
" --no-graphics Do not display the actual race.\n"
|
" --no-graphics Do not display the actual race.\n"
|
||||||
" --demo-mode=t Enables demo mode after t seconds of idle time in "
|
" --demo-mode=t Enables demo mode after t seconds of idle time in "
|
||||||
"main menu.\n"
|
"main menu.\n"
|
||||||
" --demo-tracks=t1,t2 List of tracks to be used in demo mode. No"
|
" --demo-tracks=t1,t2 List of tracks to be used in demo mode. No\n"
|
||||||
" spaces are allowed in the track names.\n"
|
" spaces are allowed in the track names.\n"
|
||||||
" --demo-laps=n Number of laps to use in a demo.\n"
|
" --demo-laps=n Number of laps to use in a demo.\n"
|
||||||
" --demo-karts=n Number of karts to use in a demo.\n"
|
" --demo-karts=n Number of karts to use in a demo.\n"
|
||||||
@ -578,6 +578,7 @@ void cmdLineHelp()
|
|||||||
// " --test-ai=n Use the test-ai for every n-th AI kart.\n"
|
// " --test-ai=n Use the test-ai for every n-th AI kart.\n"
|
||||||
// " (so n=1 means all Ais will be the test ai)\n"
|
// " (so n=1 means all Ais will be the test ai)\n"
|
||||||
// "
|
// "
|
||||||
|
" --network-console Enable network console.\n"
|
||||||
" --wan-server=name Start a Wan server (not a playing client).\n"
|
" --wan-server=name Start a Wan server (not a playing client).\n"
|
||||||
" --public-server Allow direct connection to the server (without stk server)\n"
|
" --public-server Allow direct connection to the server (without stk server)\n"
|
||||||
" --lan-server=name Start a LAN server (not a playing client).\n"
|
" --lan-server=name Start a LAN server (not a playing client).\n"
|
||||||
@ -586,11 +587,10 @@ void cmdLineHelp()
|
|||||||
" --login=s Automatically log in (set the login).\n"
|
" --login=s Automatically log in (set the login).\n"
|
||||||
" --password=s Automatically log in (set the password).\n"
|
" --password=s Automatically log in (set the password).\n"
|
||||||
" --port=n Port number to use.\n"
|
" --port=n Port number to use.\n"
|
||||||
" --my-address=1.1.1.1:1 Own IP address (can replace stun protocol)\n"
|
|
||||||
" --disable-lan Disable LAN detection (connect using WAN).\n"
|
" --disable-lan Disable LAN detection (connect using WAN).\n"
|
||||||
" --auto-connect Automatically connect to fist server and start race\n"
|
" --auto-connect Automatically connect to fist server and start race\n"
|
||||||
" --max-players=n Maximum number of clients (server only).\n"
|
" --max-players=n Maximum number of clients (server only).\n"
|
||||||
" --no-console Does not write messages in the console but to\n"
|
" --no-console-log Does not write messages in the console but to\n"
|
||||||
" stdout.log.\n"
|
" stdout.log.\n"
|
||||||
" -h, --help Show this help.\n"
|
" -h, --help Show this help.\n"
|
||||||
" --log=N Set the verbosity to a value between\n"
|
" --log=N Set the verbosity to a value between\n"
|
||||||
@ -675,7 +675,7 @@ int handleCmdLineOutputModifier()
|
|||||||
Log::disableColor();
|
Log::disableColor();
|
||||||
Log::verbose("main", "Colours disabled.");
|
Log::verbose("main", "Colours disabled.");
|
||||||
}
|
}
|
||||||
if(CommandLine::has("--no-console"))
|
if(CommandLine::has("--no-console-log"))
|
||||||
Log::toggleConsoleLog(false);
|
Log::toggleConsoleLog(false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -1032,7 +1032,7 @@ int handleCmdLine()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Networking command lines
|
// Networking command lines
|
||||||
if(CommandLine::has("--start-console"))
|
if(CommandLine::has("--network-console"))
|
||||||
STKHost::m_enable_console = true;
|
STKHost::m_enable_console = true;
|
||||||
|
|
||||||
if (CommandLine::has("--server-password", &s))
|
if (CommandLine::has("--server-password", &s))
|
||||||
@ -1066,7 +1066,7 @@ int handleCmdLine()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
NetworkConfig::get()->setIsWAN();
|
NetworkConfig::get()->setIsWAN();
|
||||||
NetworkConfig::get()->setClientServer(true);
|
NetworkConfig::get()->setDirectConnect(true);
|
||||||
}
|
}
|
||||||
NetworkConfig::get()->setIsServer(false);
|
NetworkConfig::get()->setIsServer(false);
|
||||||
Log::info("main", "Try to connect to server '%s'.",
|
Log::info("main", "Try to connect to server '%s'.",
|
||||||
|
@ -39,9 +39,8 @@ NetworkConfig::NetworkConfig()
|
|||||||
m_auto_connect = false;
|
m_auto_connect = false;
|
||||||
m_is_server = false;
|
m_is_server = false;
|
||||||
m_is_public_server = false;
|
m_is_public_server = false;
|
||||||
m_client_server = false;
|
|
||||||
m_max_players = 4;
|
m_max_players = 4;
|
||||||
m_is_registered = false;
|
m_direct_connect = false;
|
||||||
m_server_name = "";
|
m_server_name = "";
|
||||||
m_password = "";
|
m_password = "";
|
||||||
m_server_discovery_port = 2757;
|
m_server_discovery_port = 2757;
|
||||||
|
@ -68,19 +68,14 @@ private:
|
|||||||
/** Maximum number of players on the server. */
|
/** Maximum number of players on the server. */
|
||||||
int m_max_players;
|
int m_max_players;
|
||||||
|
|
||||||
/** If this is a server, it indicates if this server is registered
|
/** True if STK was started with connect-now argument, so it use direct
|
||||||
* with the stk server. */
|
* request-connection without using the addon server. */
|
||||||
bool m_is_registered;
|
bool m_direct_connect;
|
||||||
|
|
||||||
/** True if a client should connect to the first server it finds and
|
/** True if a client should connect to the first server it finds and
|
||||||
* immediately start a race. */
|
* immediately start a race. */
|
||||||
bool m_auto_connect;
|
bool m_auto_connect;
|
||||||
|
|
||||||
/** True if this is a client and server in graphics mode made by server
|
|
||||||
* creation screen. This is also used by connect-now to bypass stk
|
|
||||||
* server in wan game. */
|
|
||||||
bool m_client_server;
|
|
||||||
|
|
||||||
/** If this is a server, the server name. */
|
/** If this is a server, the server name. */
|
||||||
irr::core::stringw m_server_name;
|
irr::core::stringw m_server_name;
|
||||||
|
|
||||||
@ -173,10 +168,6 @@ public:
|
|||||||
/** Returns if this instance is a client. */
|
/** Returns if this instance is a client. */
|
||||||
bool isClient() const { return !m_is_server; }
|
bool isClient() const { return !m_is_server; }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void setClientServer(bool val) { m_client_server = val; }
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
bool isClientServer() const { return m_client_server; }
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
/** Sets the name of this server. */
|
/** Sets the name of this server. */
|
||||||
void setServerName(const irr::core::stringw &name)
|
void setServerName(const irr::core::stringw &name)
|
||||||
{
|
{
|
||||||
@ -202,6 +193,11 @@ public:
|
|||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the game mode id and if grandprix from server database id. */
|
/** Returns the game mode id and if grandprix from server database id. */
|
||||||
std::pair<RaceManager::MinorRaceModeType, bool> getLocalGameMode(unsigned);
|
std::pair<RaceManager::MinorRaceModeType, bool> getLocalGameMode(unsigned);
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
void setDirectConnect(bool val) { m_direct_connect = val; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
bool isDirectConnect() const { return m_direct_connect; }
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
|
||||||
}; // class NetworkConfig
|
}; // class NetworkConfig
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ void ConnectToServer::setup()
|
|||||||
// In case of LAN or client-server we already have the server's
|
// In case of LAN or client-server we already have the server's
|
||||||
// and our ip address, so we can immediately start requesting a connection.
|
// and our ip address, so we can immediately start requesting a connection.
|
||||||
m_state = (NetworkConfig::get()->isLAN() ||
|
m_state = (NetworkConfig::get()->isLAN() ||
|
||||||
NetworkConfig::get()->isClientServer()) ?
|
STKHost::get()->isClientServer()) ?
|
||||||
GOT_SERVER_ADDRESS : SET_PUBLIC_ADDRESS;
|
GOT_SERVER_ADDRESS : SET_PUBLIC_ADDRESS;
|
||||||
} // setup
|
} // setup
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ void ConnectToServer::asynchronousUpdate()
|
|||||||
m_server_address.getIP() ==
|
m_server_address.getIP() ==
|
||||||
STKHost::get()->getPublicAddress().getIP()) ||
|
STKHost::get()->getPublicAddress().getIP()) ||
|
||||||
(NetworkConfig::get()->isLAN() ||
|
(NetworkConfig::get()->isLAN() ||
|
||||||
NetworkConfig::get()->isClientServer()))
|
STKHost::get()->isClientServer()))
|
||||||
{
|
{
|
||||||
// We're in the same lan (same public ip address).
|
// We're in the same lan (same public ip address).
|
||||||
// The state will change to CONNECTING
|
// The state will change to CONNECTING
|
||||||
@ -197,7 +197,7 @@ void ConnectToServer::asynchronousUpdate()
|
|||||||
Log::info("ConnectToServer", "Connected");
|
Log::info("ConnectToServer", "Connected");
|
||||||
// LAN networking does not use the stk server tables.
|
// LAN networking does not use the stk server tables.
|
||||||
if (NetworkConfig::get()->isWAN() &&
|
if (NetworkConfig::get()->isWAN() &&
|
||||||
!NetworkConfig::get()->isClientServer())
|
!STKHost::get()->isClientServer())
|
||||||
{
|
{
|
||||||
auto hide_address = std::make_shared<HidePublicAddress>();
|
auto hide_address = std::make_shared<HidePublicAddress>();
|
||||||
hide_address->requestStart();
|
hide_address->requestStart();
|
||||||
@ -212,8 +212,6 @@ void ConnectToServer::asynchronousUpdate()
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We don't need this flag anymore after connect to server
|
|
||||||
NetworkConfig::get()->setClientServer(false);
|
|
||||||
m_state = DONE;
|
m_state = DONE;
|
||||||
break;
|
break;
|
||||||
case DONE:
|
case DONE:
|
||||||
|
@ -76,9 +76,10 @@ void RequestConnection::asynchronousUpdate()
|
|||||||
case NONE:
|
case NONE:
|
||||||
{
|
{
|
||||||
if (NetworkConfig::get()->isLAN() ||
|
if (NetworkConfig::get()->isLAN() ||
|
||||||
NetworkConfig::get()->isClientServer())
|
NetworkConfig::get()->isDirectConnect() ||
|
||||||
|
STKHost::get()->isClientServer())
|
||||||
{
|
{
|
||||||
if (NetworkConfig::get()->isClientServer())
|
if (STKHost::get()->isClientServer())
|
||||||
{
|
{
|
||||||
// Allow 10 seconds for the separate process to fully
|
// Allow 10 seconds for the separate process to fully
|
||||||
// start-up
|
// start-up
|
||||||
@ -88,6 +89,7 @@ void RequestConnection::asynchronousUpdate()
|
|||||||
ServersManager::get()->getServerByID(m_server_id);
|
ServersManager::get()->getServerByID(m_server_id);
|
||||||
BareNetworkString message(std::string("connection-request"));
|
BareNetworkString message(std::string("connection-request"));
|
||||||
STKHost::get()->sendRawPacket(message, server->getAddress());
|
STKHost::get()->sendRawPacket(message, server->getAddress());
|
||||||
|
NetworkConfig::get()->setDirectConnect(false);
|
||||||
m_state = DONE;
|
m_state = DONE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -841,7 +841,8 @@ void STKHost::handleDirectSocketRequest(Network* lan_network)
|
|||||||
{
|
{
|
||||||
// In case of a LAN connection, we only allow connections from
|
// In case of a LAN connection, we only allow connections from
|
||||||
// a LAN address (192.168*, ..., and 127.*).
|
// a LAN address (192.168*, ..., and 127.*).
|
||||||
if (!sender.isLAN() && !sender.isPublicAddressLAN())
|
if (!sender.isLAN() && !sender.isPublicAddressLAN() &&
|
||||||
|
!NetworkConfig::get()->isPublicServer())
|
||||||
{
|
{
|
||||||
Log::error("STKHost", "Client trying to connect from '%s'",
|
Log::error("STKHost", "Client trying to connect from '%s'",
|
||||||
sender.toString().c_str());
|
sender.toString().c_str());
|
||||||
|
@ -201,57 +201,61 @@ public:
|
|||||||
void setErrorMessage(const irr::core::stringw &message);
|
void setErrorMessage(const irr::core::stringw &message);
|
||||||
bool isAuthorisedToControl() const;
|
bool isAuthorisedToControl() const;
|
||||||
|
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the last error (or "" if no error has happened). */
|
/** Returns the last error (or "" if no error has happened). */
|
||||||
const irr::core::stringw& getErrorMessage() const
|
const irr::core::stringw& getErrorMessage() const
|
||||||
{ return m_error_message; }
|
{ return m_error_message; }
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns true if a shutdown of the network infrastructure was
|
/** Returns true if a shutdown of the network infrastructure was
|
||||||
* requested. */
|
* requested. */
|
||||||
bool requestedShutdown() const { return m_shutdown.load(); }
|
bool requestedShutdown() const { return m_shutdown.load(); }
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the current game setup. */
|
/** Returns the current game setup. */
|
||||||
GameSetup* getGameSetup() { return m_game_setup; }
|
GameSetup* getGameSetup() { return m_game_setup; }
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
int receiveRawPacket(char *buffer, int buffer_len,
|
int receiveRawPacket(char *buffer, int buffer_len,
|
||||||
TransportAddress* sender, int max_tries = -1)
|
TransportAddress* sender, int max_tries = -1)
|
||||||
{
|
{
|
||||||
return m_network->receiveRawPacket(buffer, buffer_len, sender,
|
return m_network->receiveRawPacket(buffer, buffer_len, sender,
|
||||||
max_tries);
|
max_tries);
|
||||||
} // receiveRawPacket
|
} // receiveRawPacket
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
// --------------------------------------------------------------------
|
|
||||||
void sendRawPacket(const BareNetworkString &buffer,
|
void sendRawPacket(const BareNetworkString &buffer,
|
||||||
const TransportAddress& dst)
|
const TransportAddress& dst)
|
||||||
{
|
{
|
||||||
m_network->sendRawPacket(buffer, dst);
|
m_network->sendRawPacket(buffer, dst);
|
||||||
} // sendRawPacket
|
} // sendRawPacket
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns a const reference to the list of peers. */
|
/** Returns a const reference to the list of peers. */
|
||||||
const std::vector<STKPeer*> &getPeers() { return m_peers; }
|
const std::vector<STKPeer*> &getPeers() { return m_peers; }
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the next (unique) host id. */
|
/** Returns the next (unique) host id. */
|
||||||
unsigned int getNextHostId() const
|
unsigned int getNextHostId() const
|
||||||
{
|
{
|
||||||
assert(m_next_unique_host_id >= 0);
|
assert(m_next_unique_host_id >= 0);
|
||||||
return m_next_unique_host_id;
|
return m_next_unique_host_id;
|
||||||
}
|
}
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the number of currently connected peers. */
|
/** Returns the number of currently connected peers. */
|
||||||
unsigned int getPeerCount() { return (int)m_peers.size(); }
|
unsigned int getPeerCount() { return (int)m_peers.size(); }
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Sets the global host id of this host. */
|
/** Sets the global host id of this host. */
|
||||||
void setMyHostId(uint8_t my_host_id) { m_host_id = my_host_id; }
|
void setMyHostId(uint8_t my_host_id) { m_host_id = my_host_id; }
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Returns the host id of this host. */
|
/** Returns the host id of this host. */
|
||||||
uint8_t getMyHostId() const { return m_host_id; }
|
uint8_t getMyHostId() const { return m_host_id; }
|
||||||
// --------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
/** Sends a message from a client to the server. */
|
/** Sends a message from a client to the server. */
|
||||||
void sendToServer(NetworkString *data, bool reliable = true)
|
void sendToServer(NetworkString *data, bool reliable = true)
|
||||||
{
|
{
|
||||||
assert(NetworkConfig::get()->isClient());
|
assert(NetworkConfig::get()->isClient());
|
||||||
m_peers[0]->sendPacket(data, reliable);
|
m_peers[0]->sendPacket(data, reliable);
|
||||||
} // sendToServer
|
} // sendToServer
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
/** True if this is a client and server in graphics mode made by server
|
||||||
|
* creation screen. */
|
||||||
|
bool isClientServer() const { return m_separate_process != NULL; }
|
||||||
|
|
||||||
}; // class STKHost
|
}; // class STKHost
|
||||||
|
|
||||||
#endif // STK_HOST_HPP
|
#endif // STK_HOST_HPP
|
||||||
|
@ -213,11 +213,11 @@ void CreateServerScreen::createServer()
|
|||||||
|
|
||||||
NetworkConfig::get()->setIsServer(false);
|
NetworkConfig::get()->setIsServer(false);
|
||||||
std::string server_string = NetworkConfig::get()->isWAN() ?
|
std::string server_string = NetworkConfig::get()->isWAN() ?
|
||||||
"--wan-server=" : "--lan-server=";
|
"--public-server --wan-server=" : "--lan-server=";
|
||||||
server_string += StringUtils::xmlEncode(name);
|
server_string += StringUtils::xmlEncode(name);
|
||||||
char option[1024];
|
char option[1024];
|
||||||
sprintf(option, " --no-graphics --type=%d --difficulty=%d "
|
sprintf(option, " --no-graphics --type=%d --difficulty=%d "
|
||||||
"--max-players=%d --start-console --public-server "
|
"--max-players=%d --network-console --no-console-log "
|
||||||
"--stdout=server.log",
|
"--stdout=server.log",
|
||||||
gamemode_widget->getSelection(PLAYER_ID_GAME_MASTER),
|
gamemode_widget->getSelection(PLAYER_ID_GAME_MASTER),
|
||||||
difficulty_widget->getSelection(PLAYER_ID_GAME_MASTER),
|
difficulty_widget->getSelection(PLAYER_ID_GAME_MASTER),
|
||||||
@ -226,7 +226,6 @@ void CreateServerScreen::createServer()
|
|||||||
new SeparateProcess(SeparateProcess::getCurrentExecutableLocation(),
|
new SeparateProcess(SeparateProcess::getCurrentExecutableLocation(),
|
||||||
server_string + option + password, "quit");
|
server_string + option + password, "quit");
|
||||||
|
|
||||||
NetworkConfig::get()->setClientServer(true);
|
|
||||||
ServersManager::get()->cleanUpServers();
|
ServersManager::get()->cleanUpServers();
|
||||||
TransportAddress address(0x7f000001,
|
TransportAddress address(0x7f000001,
|
||||||
NetworkConfig::get()->getServerDiscoveryPort());
|
NetworkConfig::get()->getServerDiscoveryPort());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user