diff --git a/src/main.cpp b/src/main.cpp index ad90b032b..be54246aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1395,9 +1395,9 @@ int handleCmdLine(bool has_server_config, bool has_parent_process) SocketAddress ipv4_addr = server_addr; if (server_addr.isIPv6()) ipv4_addr.setIP(0); - auto server = std::make_shared(0, - StringUtils::utf8ToWide(addr), 0, 0, 0, 0, ipv4_addr, - !server_password.empty(), false); + auto server = std::make_shared( + StringUtils::utf8ToWide(addr), ipv4_addr, + !server_password.empty()); if (server_addr.isIPv6()) { server->setIPV6Address(server_addr); diff --git a/src/network/protocols/connect_to_server.cpp b/src/network/protocols/connect_to_server.cpp index 4708a68f7..2fdeff3ed 100644 --- a/src/network/protocols/connect_to_server.cpp +++ b/src/network/protocols/connect_to_server.cpp @@ -357,6 +357,7 @@ void ConnectToServer::update(int ticks) if (STKHost::get()->getPeerCount() > 0 && STKHost::get()->getServerPeerForClient()->isConnected()) { + m_server->saveServer(); // Let main thread create ClientLobby for better // synchronization with GUI NetworkConfig::get()->clearActivePlayersForClient(); diff --git a/src/network/server.cpp b/src/network/server.cpp index 0be30aa46..72420280c 100644 --- a/src/network/server.cpp +++ b/src/network/server.cpp @@ -23,6 +23,7 @@ #include "online/profile_manager.hpp" #include "network/network_config.hpp" #include "network/socket_address.hpp" +#include "states_screens/online/online_screen.hpp" #include "tracks/track_manager.hpp" #include "utils/constants.hpp" #include "utils/string_utils.hpp" @@ -197,6 +198,11 @@ Server::Server(unsigned server_id, const core::stringw &name, int max_players, m_current_track = current_track; } // server(server_id, ...) +// ---------------------------------------------------------------------------- +Server::~Server() +{ +} // ~Server + // ---------------------------------------------------------------------------- Track* Server::getCurrentTrack() const { @@ -231,3 +237,9 @@ void Server::setAddress(const SocketAddress& addr) { m_address.reset(new SocketAddress(addr)); } // setAddress + +// ---------------------------------------------------------------------------- +void UserDefinedServer::saveServer() const +{ + OnlineScreen::getInstance()->setEnteredServerName(m_name); +} // saveServer diff --git a/src/network/server.hpp b/src/network/server.hpp index dc5aa0e5a..231448e42 100644 --- a/src/network/server.hpp +++ b/src/network/server.hpp @@ -117,6 +117,8 @@ public: bool password_protected, bool game_started, const std::string& current_track = ""); // ------------------------------------------------------------------------ + virtual ~Server(); + // ------------------------------------------------------------------------ /** Returns IPv4 address and port of this server. */ const SocketAddress& getAddress() const { return *m_address.get(); } // ------------------------------------------------------------------------ @@ -195,5 +197,18 @@ public: return NULL; return m_ipv6_address.get(); } + // ------------------------------------------------------------------------ + virtual void saveServer() const {} }; // Server + +class UserDefinedServer : public Server +{ +public: + UserDefinedServer(const core::stringw& name, const SocketAddress& ipv4, + bool password_protected = false) + : Server(0, name, 0, 0, 0, 0, ipv4, password_protected, false) {} + // ------------------------------------------------------------------------ + virtual void saveServer() const; +}; // UserDefinedServer + #endif // HEADER_SERVER_HPP diff --git a/src/states_screens/online/online_screen.cpp b/src/states_screens/online/online_screen.cpp index 6bab2333e..5e3692b2c 100644 --- a/src/states_screens/online/online_screen.cpp +++ b/src/states_screens/online/online_screen.cpp @@ -247,7 +247,6 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, SocketAddress server_addr(addr_u); if (server_addr.getIP() == 0 && !server_addr.isIPv6()) { - m_entered_server_address = L""; core::stringw err = _("Invalid server address: %s.", addr_w); lw->setText(err, true); @@ -256,21 +255,19 @@ void OnlineScreen::eventCallback(Widget* widget, const std::string& name, SocketAddress ipv4_addr = server_addr; if (server_addr.isIPv6()) ipv4_addr.setIP(0); - auto server = std::make_shared(0, addr_w, 0, 0, 0, 0, - ipv4_addr, false, false); + auto server = + std::make_shared(addr_w, ipv4_addr); if (server_addr.isIPv6()) { server->setIPV6Address(server_addr); server->setIPV6Connection(true); } m_entered_server = server; - m_entered_server_address = - StringUtils::utf8ToWide(server_addr.toString()); return true; }); - if (!m_entered_server_address.empty()) + if (!m_entered_server_name.empty()) { - gtfd->getTextField()->setText(m_entered_server_address); + gtfd->getTextField()->setText(m_entered_server_name); } } } // eventCallback diff --git a/src/states_screens/online/online_screen.hpp b/src/states_screens/online/online_screen.hpp index bf1c4635e..90b8c4122 100644 --- a/src/states_screens/online/online_screen.hpp +++ b/src/states_screens/online/online_screen.hpp @@ -51,7 +51,8 @@ private: std::shared_ptr m_entered_server; - core::stringw m_entered_server_address; + /** Save the previous successfully connected server name. */ + core::stringw m_entered_server_name; OnlineScreen(); @@ -75,6 +76,8 @@ public: /** \brief implement callback from parent class GUIEngine::Screen */ virtual bool onEscapePressed() OVERRIDE; + void setEnteredServerName(const core::stringw& name) + { m_entered_server_name = name; } }; #endif