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"
|
||||
" -t, --track=NAME Start track NAME.\n"
|
||||
" --gp=NAME Start the specified Grand Prix.\n"
|
||||
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved "
|
||||
"in config.xml under additional_gp_directory. Use "
|
||||
" --add-gp-dir=DIR Load Grand Prix files in DIR. Setting will be saved\n"
|
||||
"in config.xml under additional_gp_directory. Use\n"
|
||||
"--add-gp-dir=\"\" to unset.\n"
|
||||
" --stk-config=FILE use ./data/FILE instead of "
|
||||
"./data/stk_config.xml\n"
|
||||
@ -567,7 +567,7 @@ void cmdLineHelp()
|
||||
" --no-graphics Do not display the actual race.\n"
|
||||
" --demo-mode=t Enables demo mode after t seconds of idle time in "
|
||||
"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"
|
||||
" --demo-laps=n Number of laps 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"
|
||||
// " (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"
|
||||
" --public-server Allow direct connection to the server (without stk server)\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"
|
||||
" --password=s Automatically log in (set the password).\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"
|
||||
" --auto-connect Automatically connect to fist server and start race\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"
|
||||
" -h, --help Show this help.\n"
|
||||
" --log=N Set the verbosity to a value between\n"
|
||||
@ -675,7 +675,7 @@ int handleCmdLineOutputModifier()
|
||||
Log::disableColor();
|
||||
Log::verbose("main", "Colours disabled.");
|
||||
}
|
||||
if(CommandLine::has("--no-console"))
|
||||
if(CommandLine::has("--no-console-log"))
|
||||
Log::toggleConsoleLog(false);
|
||||
|
||||
return 0;
|
||||
@ -1032,7 +1032,7 @@ int handleCmdLine()
|
||||
}
|
||||
|
||||
// Networking command lines
|
||||
if(CommandLine::has("--start-console"))
|
||||
if(CommandLine::has("--network-console"))
|
||||
STKHost::m_enable_console = true;
|
||||
|
||||
if (CommandLine::has("--server-password", &s))
|
||||
@ -1066,7 +1066,7 @@ int handleCmdLine()
|
||||
else
|
||||
{
|
||||
NetworkConfig::get()->setIsWAN();
|
||||
NetworkConfig::get()->setClientServer(true);
|
||||
NetworkConfig::get()->setDirectConnect(true);
|
||||
}
|
||||
NetworkConfig::get()->setIsServer(false);
|
||||
Log::info("main", "Try to connect to server '%s'.",
|
||||
|
@ -39,9 +39,8 @@ NetworkConfig::NetworkConfig()
|
||||
m_auto_connect = false;
|
||||
m_is_server = false;
|
||||
m_is_public_server = false;
|
||||
m_client_server = false;
|
||||
m_max_players = 4;
|
||||
m_is_registered = false;
|
||||
m_direct_connect = false;
|
||||
m_server_name = "";
|
||||
m_password = "";
|
||||
m_server_discovery_port = 2757;
|
||||
|
@ -68,19 +68,14 @@ private:
|
||||
/** Maximum number of players on the server. */
|
||||
int m_max_players;
|
||||
|
||||
/** If this is a server, it indicates if this server is registered
|
||||
* with the stk server. */
|
||||
bool m_is_registered;
|
||||
/** True if STK was started with connect-now argument, so it use direct
|
||||
* request-connection without using the addon server. */
|
||||
bool m_direct_connect;
|
||||
|
||||
/** True if a client should connect to the first server it finds and
|
||||
* immediately start a race. */
|
||||
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. */
|
||||
irr::core::stringw m_server_name;
|
||||
|
||||
@ -173,10 +168,6 @@ public:
|
||||
/** Returns if this instance is a client. */
|
||||
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. */
|
||||
void setServerName(const irr::core::stringw &name)
|
||||
{
|
||||
@ -202,6 +193,11 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the game mode id and if grandprix from server database id. */
|
||||
std::pair<RaceManager::MinorRaceModeType, bool> getLocalGameMode(unsigned);
|
||||
// ------------------------------------------------------------------------
|
||||
void setDirectConnect(bool val) { m_direct_connect = val; }
|
||||
// ------------------------------------------------------------------------
|
||||
bool isDirectConnect() const { return m_direct_connect; }
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
}; // class NetworkConfig
|
||||
|
||||
|
@ -78,7 +78,7 @@ void ConnectToServer::setup()
|
||||
// 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.
|
||||
m_state = (NetworkConfig::get()->isLAN() ||
|
||||
NetworkConfig::get()->isClientServer()) ?
|
||||
STKHost::get()->isClientServer()) ?
|
||||
GOT_SERVER_ADDRESS : SET_PUBLIC_ADDRESS;
|
||||
} // setup
|
||||
|
||||
@ -153,7 +153,7 @@ void ConnectToServer::asynchronousUpdate()
|
||||
m_server_address.getIP() ==
|
||||
STKHost::get()->getPublicAddress().getIP()) ||
|
||||
(NetworkConfig::get()->isLAN() ||
|
||||
NetworkConfig::get()->isClientServer()))
|
||||
STKHost::get()->isClientServer()))
|
||||
{
|
||||
// We're in the same lan (same public ip address).
|
||||
// The state will change to CONNECTING
|
||||
@ -197,7 +197,7 @@ void ConnectToServer::asynchronousUpdate()
|
||||
Log::info("ConnectToServer", "Connected");
|
||||
// LAN networking does not use the stk server tables.
|
||||
if (NetworkConfig::get()->isWAN() &&
|
||||
!NetworkConfig::get()->isClientServer())
|
||||
!STKHost::get()->isClientServer())
|
||||
{
|
||||
auto hide_address = std::make_shared<HidePublicAddress>();
|
||||
hide_address->requestStart();
|
||||
@ -212,8 +212,6 @@ void ConnectToServer::asynchronousUpdate()
|
||||
{
|
||||
return;
|
||||
}
|
||||
// We don't need this flag anymore after connect to server
|
||||
NetworkConfig::get()->setClientServer(false);
|
||||
m_state = DONE;
|
||||
break;
|
||||
case DONE:
|
||||
|
@ -76,9 +76,10 @@ void RequestConnection::asynchronousUpdate()
|
||||
case NONE:
|
||||
{
|
||||
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
|
||||
// start-up
|
||||
@ -88,6 +89,7 @@ void RequestConnection::asynchronousUpdate()
|
||||
ServersManager::get()->getServerByID(m_server_id);
|
||||
BareNetworkString message(std::string("connection-request"));
|
||||
STKHost::get()->sendRawPacket(message, server->getAddress());
|
||||
NetworkConfig::get()->setDirectConnect(false);
|
||||
m_state = DONE;
|
||||
}
|
||||
else
|
||||
|
@ -841,7 +841,8 @@ void STKHost::handleDirectSocketRequest(Network* lan_network)
|
||||
{
|
||||
// In case of a LAN connection, we only allow connections from
|
||||
// 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'",
|
||||
sender.toString().c_str());
|
||||
|
@ -201,57 +201,61 @@ public:
|
||||
void setErrorMessage(const irr::core::stringw &message);
|
||||
bool isAuthorisedToControl() const;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the last error (or "" if no error has happened). */
|
||||
const irr::core::stringw& getErrorMessage() const
|
||||
{ return m_error_message; }
|
||||
// --------------------------------------------------------------------
|
||||
{ return m_error_message; }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns true if a shutdown of the network infrastructure was
|
||||
* requested. */
|
||||
bool requestedShutdown() const { return m_shutdown.load(); }
|
||||
// --------------------------------------------------------------------
|
||||
bool requestedShutdown() const { return m_shutdown.load(); }
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the current game setup. */
|
||||
GameSetup* getGameSetup() { return m_game_setup; }
|
||||
// --------------------------------------------------------------------
|
||||
GameSetup* getGameSetup() { return m_game_setup; }
|
||||
// ------------------------------------------------------------------------
|
||||
int receiveRawPacket(char *buffer, int buffer_len,
|
||||
TransportAddress* sender, int max_tries = -1)
|
||||
{
|
||||
return m_network->receiveRawPacket(buffer, buffer_len, sender,
|
||||
max_tries);
|
||||
} // receiveRawPacket
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
void sendRawPacket(const BareNetworkString &buffer,
|
||||
const TransportAddress& dst)
|
||||
{
|
||||
m_network->sendRawPacket(buffer, dst);
|
||||
} // sendRawPacket
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** 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. */
|
||||
unsigned int getNextHostId() const
|
||||
{
|
||||
assert(m_next_unique_host_id >= 0);
|
||||
return m_next_unique_host_id;
|
||||
}
|
||||
// --------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------------
|
||||
/** 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. */
|
||||
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. */
|
||||
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. */
|
||||
void sendToServer(NetworkString *data, bool reliable = true)
|
||||
{
|
||||
assert(NetworkConfig::get()->isClient());
|
||||
m_peers[0]->sendPacket(data, reliable);
|
||||
} // 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
|
||||
|
||||
#endif // STK_HOST_HPP
|
||||
|
@ -213,11 +213,11 @@ void CreateServerScreen::createServer()
|
||||
|
||||
NetworkConfig::get()->setIsServer(false);
|
||||
std::string server_string = NetworkConfig::get()->isWAN() ?
|
||||
"--wan-server=" : "--lan-server=";
|
||||
"--public-server --wan-server=" : "--lan-server=";
|
||||
server_string += StringUtils::xmlEncode(name);
|
||||
char option[1024];
|
||||
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",
|
||||
gamemode_widget->getSelection(PLAYER_ID_GAME_MASTER),
|
||||
difficulty_widget->getSelection(PLAYER_ID_GAME_MASTER),
|
||||
@ -226,7 +226,6 @@ void CreateServerScreen::createServer()
|
||||
new SeparateProcess(SeparateProcess::getCurrentExecutableLocation(),
|
||||
server_string + option + password, "quit");
|
||||
|
||||
NetworkConfig::get()->setClientServer(true);
|
||||
ServersManager::get()->cleanUpServers();
|
||||
TransportAddress address(0x7f000001,
|
||||
NetworkConfig::get()->getServerDiscoveryPort());
|
||||
|
Loading…
x
Reference in New Issue
Block a user