From 47a86cc36fb297a2f5c95a8959d5c046eab389d2 Mon Sep 17 00:00:00 2001 From: Benau Date: Sat, 31 Mar 2018 01:19:23 +0800 Subject: [PATCH] Add initial support for GP and soccer info in lobby --- src/main.cpp | 47 ++++++++++-- src/network/game_setup.cpp | 63 +++++++++++++--- src/network/game_setup.hpp | 61 ++++++++++++--- src/network/network_config.cpp | 49 ++++++++---- src/network/network_config.hpp | 23 ++++-- src/network/protocols/client_lobby.cpp | 75 ++++++++++++++++++- src/network/protocols/client_lobby.hpp | 2 +- src/network/protocols/lobby_protocol.cpp | 9 +-- src/network/protocols/server_lobby.cpp | 8 +- src/network/server.cpp | 8 +- src/network/server.hpp | 10 +-- src/network/stk_host.cpp | 12 +-- src/network/stk_host.hpp | 7 +- src/states_screens/create_server_screen.cpp | 23 +++++- .../dialogs/server_info_dialog.cpp | 2 +- src/states_screens/networking_lobby.cpp | 38 ---------- src/states_screens/networking_lobby.hpp | 9 ++- src/states_screens/server_selection.cpp | 5 +- 18 files changed, 322 insertions(+), 129 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ce5f1b3db..68d505ddc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -210,6 +210,8 @@ #include "modes/cutscene_world.hpp" #include "modes/demo_world.hpp" #include "modes/profile_world.hpp" +#include "network/protocols/lobby_protocol.hpp" +#include "network/game_setup.hpp" #include "network/network_config.hpp" #include "network/network_string.hpp" #include "network/rewind_manager.hpp" @@ -1014,7 +1016,6 @@ int handleCmdLine() } } // --type - if (CommandLine::has("--login", &s)) login = s.c_str(); if (CommandLine::has("--password", &s)) @@ -1053,6 +1054,12 @@ int handleCmdLine() NetworkConfig::get()->setPassword(server_password); } + if (CommandLine::has("--motd", &s)) + { + core::stringw motd = StringUtils::xmlDecode(s); + NetworkConfig::get()->setMOTD(motd); + } + if (CommandLine::has("--server-id-file", &s)) { NetworkConfig::get()->setServerIdFile( @@ -1084,13 +1091,12 @@ int handleCmdLine() irr::core::stringw name = StringUtils::utf8ToWide(ip.toString()); auto server = std::make_shared(0, name, NetworkConfig::get()->getMaxPlayers(), 0, - race_manager->getDifficulty(), - NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(), - race_manager->getMajorMode()), ip, !server_password.empty()); + race_manager->getDifficulty(), 0, ip, !server_password.empty()); NetworkingLobby::getInstance()->setJoinedServer(server); STKHost::create(server); } + std::shared_ptr server_lobby; if (CommandLine::has("--wan-server", &s)) { // Try to use saved user token if exists @@ -1115,7 +1121,7 @@ int handleCmdLine() NetworkConfig::get()->setIsServer(true); NetworkConfig::get()->setIsWAN(); NetworkConfig::get()->setIsPublicServer(); - STKHost::create(); + server_lobby = STKHost::create(); Log::info("main", "Creating a WAN server '%s'.", s.c_str()); } } @@ -1124,7 +1130,7 @@ int handleCmdLine() NetworkConfig::get()->setServerName(StringUtils::xmlDecode(s)); NetworkConfig::get()->setIsServer(true); NetworkConfig::get()->setIsLAN(); - STKHost::create(); + server_lobby = STKHost::create(); Log::info("main", "Creating a LAN server '%s'.", s.c_str()); } if (CommandLine::has("--auto-connect")) @@ -1132,6 +1138,34 @@ int handleCmdLine() NetworkConfig::get()->setAutoConnect(true); } + if (CommandLine::has("--extra-server-info", &n)) + { + if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) + { + LobbyProtocol::get()->getGameSetup() + ->setSoccerGoalTarget((bool)n); + NetworkConfig::get()->setServerMode( + race_manager->getMinorMode(), + RaceManager::MAJOR_MODE_SINGLE); + } + else + { + LobbyProtocol::get()->getGameSetup() + ->setGrandPrixTrack(n); + NetworkConfig::get()->setServerMode( + race_manager->getMinorMode(), + RaceManager::MAJOR_MODE_GRAND_PRIX); + } + } + else + { + NetworkConfig::get()->setServerMode( + race_manager->getMinorMode(), RaceManager::MAJOR_MODE_SINGLE); + } + // The extra server info has to be set before server lobby started + if (server_lobby) + server_lobby->requestStart(); + /** Disable detection of LAN connection when connecting via WAN. This is * mostly a debugging feature to force using WAN connection. */ if (CommandLine::has("--disable-lan")) @@ -1902,6 +1936,7 @@ int main(int argc, char *argv[] ) if (STKHost::existHost()) STKHost::get()->shutdown(); + NetworkConfig::destroy(); cleanSuperTuxKart(); #ifdef DEBUG diff --git a/src/network/game_setup.cpp b/src/network/game_setup.cpp index 84327cc71..0f4a38526 100644 --- a/src/network/game_setup.cpp +++ b/src/network/game_setup.cpp @@ -21,20 +21,12 @@ #include "config/player_manager.hpp" #include "karts/abstract_kart.hpp" #include "modes/world.hpp" +#include "network/network_config.hpp" #include "network/network_player_profile.hpp" #include "online/online_profile.hpp" #include "race/race_manager.hpp" #include "utils/log.hpp" -//----------------------------------------------------------------------------- -GameSetup::GameSetup() -{ - m_num_local_players = 0; - m_local_master = 0; - m_laps = 0; - m_reverse = false; -} // GameSetup - //----------------------------------------------------------------------------- /** Update and see if any player disconnects. * \param remove_disconnected_players remove the disconnected players, @@ -61,9 +53,58 @@ void GameSetup::update(bool remove_disconnected_players) //----------------------------------------------------------------------------- void GameSetup::loadWorld() { - assert(!m_track.empty()); + assert(!m_tracks.empty()); // Disable accidentally unlocking of a challenge PlayerManager::getCurrentPlayer()->setCurrentChallenge(""); + race_manager->setTimeTarget(0.0f); race_manager->setReverseTrack(m_reverse); - race_manager->startSingleRace(m_track, m_laps, false/*from_overworld*/); + if (race_manager->getMinorMode() == RaceManager::MINOR_MODE_SOCCER) + { + if (isSoccerGoalTarget()) + race_manager->setMaxGoal(m_laps); + else + race_manager->setTimeTarget((float)m_laps * 60.0f); + } + else + { + race_manager->startSingleRace(m_tracks.back(), m_laps, + false/*from_overworld*/); + } } // loadWorld + +//----------------------------------------------------------------------------- +bool GameSetup::isGrandPrix() const +{ + return m_extra_server_info != -1 && + NetworkConfig::get()->getLocalGameMode().second == + RaceManager::MAJOR_MODE_GRAND_PRIX; +} // isGrandPrix + +//----------------------------------------------------------------------------- +void GameSetup::configClientAcceptConnection(NetworkString* ns) +{ + assert(NetworkConfig::get()->isServer()); + ns->encodeString(NetworkConfig::get()->getServerName()); + ns->addUInt8(race_manager->getDifficulty()) + .addUInt8((uint8_t)NetworkConfig::get()->getMaxPlayers()) + .addUInt8((uint8_t)NetworkConfig::get()->getServerMode()); + if (hasExtraSeverInfo()) + { + if (isGrandPrix()) + { + ns->addUInt8((uint8_t)2).addUInt8((uint8_t)m_tracks.size()) + .addUInt8(getExtraServerInfo()); + } + else + { + // Soccer mode + ns->addUInt8((uint8_t)1).addUInt8(getExtraServerInfo()); + } + } + else + { + // No extra server info + ns->addUInt8((uint8_t)0); + } + ns->encodeString(NetworkConfig::get()->getMOTD()); +} // configClientAcceptConnection diff --git a/src/network/game_setup.hpp b/src/network/game_setup.hpp index 3a81b76e7..f22ccf211 100644 --- a/src/network/game_setup.hpp +++ b/src/network/game_setup.hpp @@ -24,12 +24,14 @@ #include "network/remote_kart_info.hpp" +#include #include #include #include #include class NetworkPlayerProfile; +class NetworkString; // ============================================================================ /*! \class GameSetup @@ -47,19 +49,22 @@ private: /** Stores the number of local players. */ int m_num_local_players; - /** The player id of the local game master, used in - * kart selection screen. */ - uint8_t m_local_master; - - std::string m_track; + std::vector m_tracks; unsigned m_laps; bool m_reverse; + int m_extra_server_info; + public: // ------------------------------------------------------------------------ - GameSetup(); + GameSetup() + { + m_num_local_players = 0; + m_extra_server_info = -1; + reset(); + } // ------------------------------------------------------------------------ ~GameSetup() {} // ------------------------------------------------------------------------ @@ -69,7 +74,7 @@ public: void update(bool remove_disconnected_players); // ------------------------------------------------------------------------ /** Sets the number of local players. */ - void setNumLocalPlayers(int n) { m_num_local_players = n; } + void setNumLocalPlayers(int n) { m_num_local_players = n; } // ------------------------------------------------------------------------ /** Returns the nunber of local players. */ int getNumLocalPlayers() const { return m_num_local_players; } @@ -104,17 +109,51 @@ public: return (unsigned)m_players.size(); } // ------------------------------------------------------------------------ - /** Returns the id of the local master. */ - int getLocalMasterID() const { return m_local_master; } - // ------------------------------------------------------------------------ void setRace(const std::string& track, unsigned laps, bool reverse) { - m_track = track; + m_tracks.push_back(track); m_laps = laps; m_reverse = reverse; } // ------------------------------------------------------------------------ + void reset() + { + m_tracks.clear(); + m_laps = 0; + m_reverse = false; + } + // ------------------------------------------------------------------------ + void setGrandPrixTrack(int tracks_no) { m_extra_server_info = tracks_no; } + // ------------------------------------------------------------------------ + void configClientAcceptConnection(NetworkString* ns); + // ------------------------------------------------------------------------ void loadWorld(); + // ------------------------------------------------------------------------ + bool isGrandPrix() const; + // ------------------------------------------------------------------------ + bool hasExtraSeverInfo() const { return m_extra_server_info != -1; } + // ------------------------------------------------------------------------ + uint8_t getExtraServerInfo() const + { + assert(hasExtraSeverInfo()); + return (uint8_t)m_extra_server_info; + } + // ------------------------------------------------------------------------ + unsigned getTotalGrandPrixTracks() const + { + assert(isGrandPrix()); + return m_extra_server_info; + } + // ------------------------------------------------------------------------ + void setSoccerGoalTarget(bool val) { m_extra_server_info = (int)val; } + // ------------------------------------------------------------------------ + bool isSoccerGoalTarget() const + { + assert(hasExtraSeverInfo()); + return (bool)m_extra_server_info; + } + // ------------------------------------------------------------------------ + const std::vector& getAllTracks() const { return m_tracks; } }; #endif // GAME_SETUP_HPP diff --git a/src/network/network_config.cpp b/src/network/network_config.cpp index aa33cfded..5ee5719c3 100644 --- a/src/network/network_config.cpp +++ b/src/network/network_config.cpp @@ -72,39 +72,38 @@ void NetworkConfig::setIsServer(bool b) } // setIsServer // ---------------------------------------------------------------------------- -unsigned NetworkConfig::getServerGameMode(RaceManager::MinorRaceModeType minor, - RaceManager::MajorRaceModeType major) +void NetworkConfig::setServerMode(RaceManager::MinorRaceModeType minor, + RaceManager::MajorRaceModeType major) { if (major == RaceManager::MAJOR_MODE_GRAND_PRIX) { if (minor == RaceManager::MINOR_MODE_NORMAL_RACE) - return 0; + m_server_mode = 0; else if (minor == RaceManager::MINOR_MODE_TIME_TRIAL) - return 1; + m_server_mode = 1; else if (minor == RaceManager::MINOR_MODE_FOLLOW_LEADER) - return 2; + m_server_mode = 2; } else { if (minor == RaceManager::MINOR_MODE_NORMAL_RACE) - return 3; + m_server_mode = 3; else if (minor == RaceManager::MINOR_MODE_TIME_TRIAL) - return 4; + m_server_mode = 4; else if (minor == RaceManager::MINOR_MODE_FOLLOW_LEADER) - return 5; + m_server_mode = 5; else if (minor == RaceManager::MINOR_MODE_3_STRIKES) - return 6; + m_server_mode = 6; else if (minor == RaceManager::MINOR_MODE_SOCCER) - return 7; + m_server_mode = 7; } - return 0; -} // getServerGameMode +} // setServerMode // ---------------------------------------------------------------------------- std::pair - NetworkConfig::getLocalGameMode(unsigned id) + NetworkConfig::getLocalGameMode() { - switch(id) + switch (m_server_mode) { case 0: return { RaceManager::MINOR_MODE_NORMAL_RACE, @@ -147,3 +146,25 @@ void NetworkConfig::setUserDetails(Online::XMLRequest* r, r->addParameter("userid", m_cur_user_id); r->addParameter("token", m_cur_user_token); } // setUserDetails + +// ---------------------------------------------------------------------------- +core::stringw NetworkConfig::getModeName(unsigned id) +{ + switch(id) + { + case 0: + return _("Normal Race (Grand Prix)"); + case 1: + return _("Time Trial (Grand Prix)"); + case 3: + return _("Normal Race"); + case 4: + return _("Time Trial"); + case 6: + return _("3 Strikes Battle"); + case 7: + return _("Soccer"); + default: + return L""; + } +} // getModeName diff --git a/src/network/network_config.hpp b/src/network/network_config.hpp index bcd97c5f8..d0e36b662 100644 --- a/src/network/network_config.hpp +++ b/src/network/network_config.hpp @@ -86,6 +86,8 @@ private: /** If this is a server, the server name. */ irr::core::stringw m_server_name; + unsigned m_server_mode; + /** Used by wan server. */ uint32_t m_cur_user_id; std::string m_cur_user_token; @@ -96,6 +98,8 @@ private: std::vector > m_network_players; + core::stringw m_motd; + NetworkConfig(); public: @@ -249,13 +253,9 @@ public: * requested. */ bool isAutoConnect() const { return m_auto_connect; } // ------------------------------------------------------------------------ - /** Returns the game mode id for server database. */ - unsigned getServerGameMode(RaceManager::MinorRaceModeType mode, - RaceManager::MajorRaceModeType); - // ------------------------------------------------------------------------ /** Returns the minor and majar game mode from server database id. */ std::pair - getLocalGameMode(unsigned); + getLocalGameMode(); // ------------------------------------------------------------------------ void setCurrentUserId(uint32_t id) { m_cur_user_id = id ; } // ------------------------------------------------------------------------ @@ -270,6 +270,19 @@ public: void setServerIdFile(const std::string& id) { m_server_id_file = id; } // ------------------------------------------------------------------------ const std::string& getServerIdFile() const { return m_server_id_file; } + // ------------------------------------------------------------------------ + void setMOTD(const core::stringw& motd) { m_motd = motd; } + // ------------------------------------------------------------------------ + const core::stringw& getMOTD() const { return m_motd; } + // ------------------------------------------------------------------------ + void setServerMode(RaceManager::MinorRaceModeType mode, + RaceManager::MajorRaceModeType); + // ------------------------------------------------------------------------ + void setServerMode(unsigned mode) { m_server_mode = mode; } + // ------------------------------------------------------------------------ + unsigned getServerMode() const { return m_server_mode; } + // ------------------------------------------------------------------------ + core::stringw getModeName(unsigned id); }; // class NetworkConfig diff --git a/src/network/protocols/client_lobby.cpp b/src/network/protocols/client_lobby.cpp index 600cf7fbc..8dd9ad3c4 100644 --- a/src/network/protocols/client_lobby.cpp +++ b/src/network/protocols/client_lobby.cpp @@ -135,6 +135,7 @@ bool ClientLobby::notifyEvent(Event* event) case LE_EXIT_RESULT: exitResultScreen(event); break; case LE_UPDATE_PLAYER_LIST: updatePlayerList(event); break; case LE_CHAT: handleChat(event); break; + case LE_CONNECTION_ACCEPTED: connectionAccepted(event); break; default: return false; break; @@ -159,7 +160,6 @@ bool ClientLobby::notifyEventAsynchronous(Event* event) case LE_PLAYER_DISCONNECTED : disconnectedPlayer(event); break; case LE_START_RACE: startGame(event); break; case LE_CONNECTION_REFUSED: connectionRefused(event); break; - case LE_CONNECTION_ACCEPTED: connectionAccepted(event); break; case LE_VOTE: displayPlayerVote(event); break; case LE_SERVER_OWNERSHIP: becomingServerOwner(); break; default: break; @@ -419,8 +419,8 @@ void ClientLobby::disconnectedPlayer(Event* event) */ void ClientLobby::connectionAccepted(Event* event) { - // At least 4 byte should remain now - if (!checkDataSize(event, 4)) return; + // At least 10 bytes should remain now + if (!checkDataSize(event, 10)) return; NetworkString &data = event->data(); STKPeer* peer = event->getPeer(); @@ -437,6 +437,73 @@ void ClientLobby::connectionAccepted(Event* event) uint32_t token = data.getToken(); if (!peer->isClientServerTokenSet()) peer->setClientServerToken(token); + // Add server info + core::stringw str, each_line; + uint8_t u_data; + data.decodeStringW(&str); + + //I18N: In the networking lobby + each_line = _("Server name: %s", str); + NetworkingLobby::getInstance()->addMoreServerInfo(each_line); + + u_data = data.getUInt8(); + const core::stringw& difficulty_name = + race_manager->getDifficultyName((RaceManager::Difficulty)u_data); + race_manager->setDifficulty((RaceManager::Difficulty)u_data); + //I18N: In the networking lobby + each_line = _("Difficulty: %s", difficulty_name); + NetworkingLobby::getInstance()->addMoreServerInfo(each_line); + + u_data = data.getUInt8(); + //I18N: In the networking lobby + each_line = _("Max players: %d", (int)u_data); + NetworkingLobby::getInstance()->addMoreServerInfo(each_line); + + u_data = data.getUInt8(); + NetworkConfig::get()->setServerMode(u_data); + auto game_mode = NetworkConfig::get()->getLocalGameMode(); + race_manager->setMinorMode(game_mode.first); + // We may use single mode in network even it's grand prix + //race_manager->setMajorMode(game_mode.second); + + //I18N: In the networking lobby + each_line = _("Game mode: %s", NetworkConfig::get()->getModeName(u_data)); + NetworkingLobby::getInstance()->addMoreServerInfo(each_line); + + uint8_t extra_server_info = data.getUInt8(); + switch (extra_server_info) + { + case 0: + break; + case 1: + { + u_data = data.getUInt8(); + core::stringw tl = _("Time limit"); + core::stringw gl = _("Goals limit"); + core::stringw sgt = u_data == 0 ? tl : gl; + m_game_setup->setSoccerGoalTarget((bool)u_data); + //I18N: In the networking lobby + each_line = _("Soccer game type: %s", sgt); + NetworkingLobby::getInstance()->addMoreServerInfo(each_line); + break; + } + case 2: + { + unsigned cur_gp_track = data.getUInt8(); + unsigned total_gp_track = data.getUInt8(); + m_game_setup->setGrandPrixTrack(total_gp_track); + each_line = _("Grand prix progress: %d / %d", cur_gp_track, + total_gp_track); + NetworkingLobby::getInstance()->addMoreServerInfo(each_line); + break; + } + } + + // MOTD + data.decodeStringW(&str); + if (!str.empty()) + NetworkingLobby::getInstance()->addMoreServerInfo(str); + m_state = CONNECTED; } // connectionAccepted @@ -537,7 +604,7 @@ void ClientLobby::connectionRefused(Event* event) //----------------------------------------------------------------------------- /*! \brief Called when the server broadcasts to start the race to all clients. - * \param event : Event providing the information (no additional information + * \param event : Event providing the information (no additional informati * in this case). */ void ClientLobby::startGame(Event* event) diff --git a/src/network/protocols/client_lobby.hpp b/src/network/protocols/client_lobby.hpp index 06ea1037a..498246436 100644 --- a/src/network/protocols/client_lobby.hpp +++ b/src/network/protocols/client_lobby.hpp @@ -64,7 +64,7 @@ public: virtual void setup() OVERRIDE; virtual void update(int ticks) OVERRIDE; virtual bool waitingForPlayers() const OVERRIDE - { return m_state == LINKED; } + { return m_state == CONNECTED; } virtual void asynchronousUpdate() OVERRIDE {} }; diff --git a/src/network/protocols/lobby_protocol.cpp b/src/network/protocols/lobby_protocol.cpp index faa4f2807..92be34b1a 100644 --- a/src/network/protocols/lobby_protocol.cpp +++ b/src/network/protocols/lobby_protocol.cpp @@ -36,14 +36,13 @@ std::weak_ptr LobbyProtocol::m_lobby; LobbyProtocol::LobbyProtocol(CallbackObject* callback_object) : Protocol(PROTOCOL_LOBBY_ROOM, callback_object) { - m_game_setup = NULL; + m_game_setup = new GameSetup(); } // LobbyProtocol // ---------------------------------------------------------------------------- LobbyProtocol::~LobbyProtocol() { - if (m_game_setup) - delete m_game_setup; + delete m_game_setup; } // ~LobbyProtocol //----------------------------------------------------------------------------- @@ -140,7 +139,5 @@ void LobbyProtocol::configRemoteKart( */ void LobbyProtocol::setup() { - if (m_game_setup) - delete m_game_setup; - m_game_setup = new GameSetup(); + m_game_setup->reset(); } // setupNewGame diff --git a/src/network/protocols/server_lobby.cpp b/src/network/protocols/server_lobby.cpp index 3a9dff7a0..146af0056 100644 --- a/src/network/protocols/server_lobby.cpp +++ b/src/network/protocols/server_lobby.cpp @@ -476,9 +476,7 @@ void ServerLobby::registerServer() request->addParameter("max_players", NetworkConfig::get()->getMaxPlayers()); request->addParameter("difficulty", race_manager->getDifficulty()); - request->addParameter("game_mode", - NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(), - race_manager->getMajorMode())); + request->addParameter("game_mode", NetworkConfig::get()->getServerMode()); request->addParameter("password", (unsigned)(!NetworkConfig::get()->getPassword().empty())); request->addParameter("version", @@ -927,9 +925,11 @@ void ServerLobby::connectionRequested(Event* event) peer->setClientServerToken(token); } // send a message to the one that asked to connect - NetworkString *message_ack = getNetworkString(4); + NetworkString* message_ack = getNetworkString(4); + message_ack->setSynchronous(true); // connection success -- return the host id of peer message_ack->addUInt8(LE_CONNECTION_ACCEPTED).addUInt32(peer->getHostId()); + m_game_setup->configClientAcceptConnection(message_ack); peer->sendPacket(message_ack); delete message_ack; diff --git a/src/network/server.cpp b/src/network/server.cpp index 903226c7e..2139830ef 100644 --- a/src/network/server.cpp +++ b/src/network/server.cpp @@ -39,10 +39,9 @@ Server::Server(const XMLNode& xml) m_current_players = 0; m_max_players = 0; m_distance = 0.0f; + m_server_mode = 0; + xml.get("game_mode", &m_server_mode); unsigned server_data = 0; - xml.get("game_mode", &server_data); - m_minor_mode = NetworkConfig::get()->getLocalGameMode(server_data).first; - m_major_mode = NetworkConfig::get()->getLocalGameMode(server_data).second; xml.get("difficulty", &server_data); m_difficulty = (RaceManager::Difficulty)server_data; @@ -121,8 +120,7 @@ Server::Server(unsigned server_id, const core::stringw &name, int max_players, // In case of LAN server, public and private port are the same. m_private_port = m_address.getPort(); m_difficulty = (RaceManager::Difficulty)difficulty; - m_minor_mode = NetworkConfig::get()->getLocalGameMode(server_mode).first; - m_major_mode = NetworkConfig::get()->getLocalGameMode(server_mode).second; + m_server_mode = server_mode; m_password_protected = password_protected; m_distance = 0.0f; } // server(server_id, ...) diff --git a/src/network/server.hpp b/src/network/server.hpp index a4023708d..25de7ff39 100644 --- a/src/network/server.hpp +++ b/src/network/server.hpp @@ -68,9 +68,7 @@ protected: * connection using the private port with a broadcast is possible. */ uint16_t m_private_port; - RaceManager::MinorRaceModeType m_minor_mode; - - RaceManager::MajorRaceModeType m_major_mode; + unsigned m_server_mode; RaceManager::Difficulty m_difficulty; @@ -115,11 +113,7 @@ public: /** Returns the number of currently connected players. */ const int getCurrentPlayers() const { return m_current_players; } // ------------------------------------------------------------------------ - RaceManager::MinorRaceModeType getRaceMinorMode() const - { return m_minor_mode; } - // ------------------------------------------------------------------------ - RaceManager::MajorRaceModeType getRaceMajorMode() const - { return m_major_mode; } + unsigned getServerMode() const { return m_server_mode; } // ------------------------------------------------------------------------ RaceManager::Difficulty getDifficulty() const { return m_difficulty; } // ------------------------------------------------------------------------ diff --git a/src/network/stk_host.cpp b/src/network/stk_host.cpp index a18259d8e..7a4ec124c 100644 --- a/src/network/stk_host.cpp +++ b/src/network/stk_host.cpp @@ -67,14 +67,15 @@ STKHost *STKHost::m_stk_host = NULL; bool STKHost::m_enable_console = false; -void STKHost::create(std::shared_ptr server, SeparateProcess* p) +std::shared_ptr STKHost::create(std::shared_ptr server, + SeparateProcess* p) { assert(m_stk_host == NULL); + std::shared_ptr lp; if (NetworkConfig::get()->isServer()) { - std::shared_ptr sl = LobbyProtocol::create(); + lp = LobbyProtocol::create(); m_stk_host = new STKHost(NetworkConfig::get()->getServerName()); - sl->requestStart(); } else { @@ -86,6 +87,7 @@ void STKHost::create(std::shared_ptr server, SeparateProcess* p) delete m_stk_host; m_stk_host = NULL; } + return lp; } // create // ============================================================================ @@ -941,9 +943,7 @@ void STKHost::handleDirectSocketRequest(Network* direct_socket, s.addUInt8((uint8_t)sl->getGameSetup()->getPlayerCount()); s.addUInt16(m_private_port); s.addUInt8((uint8_t)race_manager->getDifficulty()); - s.addUInt8((uint8_t) - NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(), - race_manager->getMajorMode())); + s.addUInt8((uint8_t)NetworkConfig::get()->getServerMode()); s.addUInt8(!NetworkConfig::get()->getPassword().empty()); direct_socket->sendRawPacket(s, sender); } // if message is server-requested diff --git a/src/network/stk_host.hpp b/src/network/stk_host.hpp index d437dfaac..81537bc1e 100644 --- a/src/network/stk_host.hpp +++ b/src/network/stk_host.hpp @@ -43,6 +43,7 @@ #include class GameSetup; +class LobbyProtocol; class NetworkPlayerProfile; class Server; class ServerLobby; @@ -154,9 +155,9 @@ public: /** Creates the STKHost. It takes all confifguration parameters from * NetworkConfig. This STKHost can either be a client or a server. */ - static void create(std::shared_ptr server = nullptr, - SeparateProcess* p = NULL); - + static std::shared_ptr + create(std::shared_ptr server = nullptr, + SeparateProcess* p = NULL); // ------------------------------------------------------------------------ /** Returns the instance of STKHost. */ static STKHost *get() diff --git a/src/states_screens/create_server_screen.cpp b/src/states_screens/create_server_screen.cpp index 48ca02931..0ad39e480 100644 --- a/src/states_screens/create_server_screen.cpp +++ b/src/states_screens/create_server_screen.cpp @@ -250,8 +250,7 @@ void CreateServerScreen::createServer() auto server = std::make_shared(0/*server_id*/, name, max_players, /*current_player*/0, (RaceManager::Difficulty) difficulty_widget->getSelection(PLAYER_ID_GAME_MASTER), - NetworkConfig::get()->getServerGameMode(race_manager->getMinorMode(), - race_manager->getMajorMode()), server_address, !password.empty()); + 0, server_address, !password.empty()); #undef USE_GRAPHICS_SERVER #ifdef USE_GRAPHICS_SERVER @@ -276,7 +275,9 @@ void CreateServerScreen::createServer() race_manager->setMinorMode(RaceManager::MINOR_MODE_NORMAL_RACE); race_manager->setReverseTrack(false); - STKHost::create(); + auto sl = STKHost::create(); + assert(sl); + sl->requestStart(); #else NetworkConfig::get()->setIsServer(false); @@ -311,6 +312,22 @@ void CreateServerScreen::createServer() " --server-id-file=" << server_id_file << " --log=1 --no-console-log"; + if (m_more_options_spinner->isVisible()) + { + int esi = m_more_options_spinner->getValue(); + if (gamemode_widget->getSelection(PLAYER_ID_GAME_MASTER) + != 3/*is soccer*/) + { + // Grand prix track count + if (esi > 0) + server_cfg << " --extra-server-info=" << esi; + } + else + { + server_cfg << " --extra-server-info=" << esi; + } + } + SeparateProcess* sp = new SeparateProcess(SeparateProcess::getCurrentExecutableLocation(), server_cfg.str() + password); diff --git a/src/states_screens/dialogs/server_info_dialog.cpp b/src/states_screens/dialogs/server_info_dialog.cpp index fb13a23d8..cd6698468 100644 --- a/src/states_screens/dialogs/server_info_dialog.cpp +++ b/src/states_screens/dialogs/server_info_dialog.cpp @@ -60,7 +60,7 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr server) GUIEngine::LabelWidget *lbldifficulty = getWidget("server_difficulty"); lbldifficulty->setText(difficulty, false); - core::stringw mode = RaceManager::getNameOf(server->getRaceMinorMode()); + core::stringw mode = NetworkConfig::get()->getModeName(server->getServerMode()); GUIEngine::LabelWidget *gamemode = getWidget("server_game_mode"); gamemode->setText(mode, false); diff --git a/src/states_screens/networking_lobby.cpp b/src/states_screens/networking_lobby.cpp index 341f575e0..686387f58 100644 --- a/src/states_screens/networking_lobby.cpp +++ b/src/states_screens/networking_lobby.cpp @@ -152,44 +152,6 @@ void NetworkingLobby::init() } // init -// ---------------------------------------------------------------------------- -void NetworkingLobby::setJoinedServer(std::shared_ptr server) -{ - if (server == m_joined_server) - return; - - m_joined_server = server; - m_server_info.clear(); - - if (!m_joined_server) - return; - core::stringw each_line; - - //I18N: In the networking lobby - each_line = _("Server name: %s", m_joined_server->getName()); - m_server_info.push_back(each_line); - - const core::stringw& difficulty_name = - race_manager->getDifficultyName(m_joined_server->getDifficulty()); - //I18N: In the networking lobby - each_line = _("Difficulty: %s", difficulty_name); - m_server_info.push_back(each_line); - - //I18N: In the networking lobby - each_line = _("Max players: %d", m_joined_server->getMaxPlayers()); - m_server_info.push_back(each_line); - - //I18N: In the networking lobby - core::stringw mode = RaceManager::getNameOf(m_joined_server->getRaceMinorMode()); - each_line = _("Game mode: %s", mode); - - race_manager->setMinorMode(m_joined_server->getRaceMinorMode()); - race_manager->setMajorMode(m_joined_server->getRaceMajorMode()); - race_manager->setDifficulty(m_joined_server->getDifficulty()); - - m_server_info.push_back(each_line); -} // setJoinedServer - // ---------------------------------------------------------------------------- void NetworkingLobby::addMoreServerInfo(core::stringw info) { diff --git a/src/states_screens/networking_lobby.hpp b/src/states_screens/networking_lobby.hpp index 0628679ff..7b45ae582 100644 --- a/src/states_screens/networking_lobby.hpp +++ b/src/states_screens/networking_lobby.hpp @@ -115,7 +115,14 @@ public: void finishAddingPlayers(); void addMoreServerInfo(core::stringw info); - void setJoinedServer(std::shared_ptr server); + void setJoinedServer(std::shared_ptr server) + { + if (server == m_joined_server) + return; + + m_joined_server = server; + m_server_info.clear(); + } void updatePlayers(const std::vector >& p); diff --git a/src/states_screens/server_selection.cpp b/src/states_screens/server_selection.cpp index 81fe90113..4fab27af9 100644 --- a/src/states_screens/server_selection.cpp +++ b/src/states_screens/server_selection.cpp @@ -149,7 +149,7 @@ void ServerSelection::loadList(unsigned sort_case) return c->getDifficulty() > d->getDifficulty(); break; case 3: - return c->getRaceMinorMode() > d->getRaceMinorMode(); + return c->getServerMode() > d->getServerMode(); break; case 4: return c->getServerOwnerName() > d->getServerOwnerName(); @@ -175,7 +175,8 @@ void ServerSelection::loadList(unsigned sort_case) race_manager->getDifficultyName(server->getDifficulty()); row.push_back(GUIEngine::ListWidget::ListCell(difficulty, -1, 1, true)); - core::stringw mode = RaceManager::getNameOf(server->getRaceMinorMode()); + core::stringw mode = + NetworkConfig::get()->getModeName(server->getServerMode()); row.push_back(GUIEngine::ListWidget::ListCell(mode, -1, 2, true)); if (NetworkConfig::get()->isWAN())