Add UserDefinedServer class to allow saving the server name easier
This commit is contained in:
parent
54e09dbbf3
commit
99a5675abe
@ -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<Server>(0,
|
||||
StringUtils::utf8ToWide(addr), 0, 0, 0, 0, ipv4_addr,
|
||||
!server_password.empty(), false);
|
||||
auto server = std::make_shared<UserDefinedServer>(
|
||||
StringUtils::utf8ToWide(addr), ipv4_addr,
|
||||
!server_password.empty());
|
||||
if (server_addr.isIPv6())
|
||||
{
|
||||
server->setIPV6Address(server_addr);
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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<Server>(0, addr_w, 0, 0, 0, 0,
|
||||
ipv4_addr, false, false);
|
||||
auto server =
|
||||
std::make_shared<UserDefinedServer>(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
|
||||
|
@ -51,7 +51,8 @@ private:
|
||||
|
||||
std::shared_ptr<Server> 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
|
||||
|
Loading…
Reference in New Issue
Block a user