diff --git a/data/gui/online/server_info_dialog.stkgui b/data/gui/online/server_info_dialog.stkgui
index aa98b72e0..eb53f5fc6 100644
--- a/data/gui/online/server_info_dialog.stkgui
+++ b/data/gui/online/server_info_dialog.stkgui
@@ -26,6 +26,10 @@
+
+
+
+
diff --git a/src/main.cpp b/src/main.cpp
index 1c3f17533..ba6767533 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1045,11 +1045,11 @@ int handleCmdLine()
if(CommandLine::has("--network-console"))
STKHost::m_enable_console = true;
- core::stringw server_password;
+ std::string server_password;
if (CommandLine::has("--server-password", &s))
{
- server_password = StringUtils::xmlDecode(s);
- NetworkConfig::get()->setPassword(StringUtils::wideToUtf8(server_password));
+ server_password = s;
+ NetworkConfig::get()->setPassword(server_password);
}
if (CommandLine::has("--server-id-file", &s))
diff --git a/src/network/network_config.hpp b/src/network/network_config.hpp
index b71c0be00..710375aae 100644
--- a/src/network/network_config.hpp
+++ b/src/network/network_config.hpp
@@ -164,7 +164,11 @@ public:
void setIsWAN() { m_network_type = NETWORK_WAN; }
// ------------------------------------------------------------------------
/** Set that this is not a networked game. */
- void unsetNetworking() { m_network_type = NETWORK_NONE; }
+ void unsetNetworking()
+ {
+ m_network_type = NETWORK_NONE;
+ m_password = "";
+ }
// ------------------------------------------------------------------------
/** Sets the maximum number of players for this server. */
void setMaxPlayers(int n) { m_max_players = n; }
diff --git a/src/network/protocols/connect_to_server.cpp b/src/network/protocols/connect_to_server.cpp
index d5da2f262..0c0b193fc 100644
--- a/src/network/protocols/connect_to_server.cpp
+++ b/src/network/protocols/connect_to_server.cpp
@@ -78,17 +78,26 @@ void ConnectToServer::asynchronousUpdate()
StkTime::sleep(1);
while (!ServersManager::get()->listUpdated())
StkTime::sleep(1);
- if (!ServersManager::get()->getServers().empty())
+ auto servers = ServersManager::get()->getServers();
+ ServersManager::get()->cleanUpServers();
+
+ // Remove password protected servers
+ servers.erase(std::remove_if(servers.begin(), servers.end(), []
+ (const std::shared_ptr a)->bool
+ {
+ return a->isPasswordProtected();
+ }), servers.end());
+
+ if (!servers.empty())
{
// For quick play we choose the server with the least player
- ServersManager::get()->sortServers([]
+ std::sort(servers.begin(), servers.end(), []
(const std::shared_ptr a,
const std::shared_ptr b)->bool
{
return a->getCurrentPlayers() < b->getCurrentPlayers();
});
- m_server = ServersManager::get()->getServers()[0];
- ServersManager::get()->cleanUpServers();
+ m_server = servers[0];
}
else
{
@@ -99,6 +108,7 @@ void ConnectToServer::asynchronousUpdate()
m_state = EXITING;
return;
}
+ servers.clear();
}
STKHost::get()->setPublicAddress();
// Set to DONE will stop STKHost is not connected
diff --git a/src/states_screens/create_server_screen.cpp b/src/states_screens/create_server_screen.cpp
index a824902a8..f8119b475 100644
--- a/src/states_screens/create_server_screen.cpp
+++ b/src/states_screens/create_server_screen.cpp
@@ -164,18 +164,31 @@ void CreateServerScreen::createServer()
if (name.size() < 4 || name.size() > 30)
{
+ //I18N: In the create server screen
m_info_widget->setText(
_("Name has to be between 4 and 30 characters long!"), false);
SFXManager::get()->quickSound("anvil");
return;
}
- assert(max_players > 1 &&
- max_players <= UserConfigParams::m_server_max_players.getDefaultValue());
+ assert(max_players > 1 && max_players <=
+ UserConfigParams::m_server_max_players.getDefaultValue());
UserConfigParams::m_server_max_players = max_players;
- core::stringw password_w = getWidget("password")->getText();
- std::string password = StringUtils::xmlEncode(password_w);
- NetworkConfig::get()->setPassword(StringUtils::wideToUtf8(password_w));
+ std::string password = StringUtils::wideToUtf8(getWidget
+ ("password")->getText());
+ if ((!password.empty() != 0 &&
+ password.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
+ "QRSTUVWXYZ01234567890_") != std::string::npos) ||
+ password.size() > 255)
+ {
+ //I18N: In the create server screen
+ m_info_widget->setText(
+ _("Incorrect characters in password!"), false);
+ SFXManager::get()->quickSound("anvil");
+ return;
+ }
+
+ NetworkConfig::get()->setPassword(password);
if (!password.empty())
password = std::string(" --server-password=") + password;
@@ -186,7 +199,7 @@ void CreateServerScreen::createServer()
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_w.empty());
+ race_manager->getMajorMode()), server_address, !password.empty());
#undef USE_GRAPHICS_SERVER
#ifdef USE_GRAPHICS_SERVER
diff --git a/src/states_screens/dialogs/server_info_dialog.cpp b/src/states_screens/dialogs/server_info_dialog.cpp
index 7597c3fbe..779606aee 100644
--- a/src/states_screens/dialogs/server_info_dialog.cpp
+++ b/src/states_screens/dialogs/server_info_dialog.cpp
@@ -18,8 +18,13 @@
#include "states_screens/dialogs/server_info_dialog.hpp"
#include "guiengine/engine.hpp"
+#include "guiengine/widgets/icon_button_widget.hpp"
+#include "guiengine/widgets/label_widget.hpp"
+#include "guiengine/widgets/ribbon_widget.hpp"
+#include "guiengine/widgets/text_box_widget.hpp"
#include "network/server.hpp"
#include "network/stk_host.hpp"
+#include "network/network_config.hpp"
#include "states_screens/networking_lobby.hpp"
#include "states_screens/state_manager.hpp"
#include "utils/string_utils.hpp"
@@ -39,7 +44,7 @@ using namespace Online;
* server (i.e. while it is being created).
*/
ServerInfoDialog::ServerInfoDialog(std::shared_ptr server)
- : ModalDialog(0.8f,0.8f), m_server(server)
+ : ModalDialog(0.8f,0.8f), m_server(server), m_password(NULL)
{
Log::info("ServerInfoDialog", "Server id is %d, Host id is %d",
server->getServerId(), server->getHostId());
@@ -67,10 +72,21 @@ ServerInfoDialog::ServerInfoDialog(std::shared_ptr server)
assert(m_cancel_widget != NULL);
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
+ if (m_server->isPasswordProtected())
+ {
+ m_password = getWidget("password");
+ m_password->setPasswordBox(true, L'*');
+ assert(m_password != NULL);
+ }
+ else
+ {
+ getWidget("label_password")->setVisible(false);
+ getWidget("password")->setVisible(false);
+ }
+
} // ServerInfoDialog
// -----------------------------------------------------------------------------
-
ServerInfoDialog::~ServerInfoDialog()
{
} // ~ServerInfoDialog
@@ -78,6 +94,16 @@ ServerInfoDialog::~ServerInfoDialog()
// -----------------------------------------------------------------------------
void ServerInfoDialog::requestJoin()
{
+ if (m_server->isPasswordProtected())
+ {
+ assert(m_password != NULL);
+ NetworkConfig::get()->setPassword(
+ StringUtils::wideToUtf8(m_password->getText()));
+ }
+ else
+ {
+ NetworkConfig::get()->setPassword("");
+ }
STKHost::create(m_server);
NetworkingLobby::getInstance()->setJoinedServer(m_server);
ModalDialog::dismiss();
diff --git a/src/states_screens/dialogs/server_info_dialog.hpp b/src/states_screens/dialogs/server_info_dialog.hpp
index 5c89ababa..38b08b985 100644
--- a/src/states_screens/dialogs/server_info_dialog.hpp
+++ b/src/states_screens/dialogs/server_info_dialog.hpp
@@ -20,11 +20,16 @@
#define HEADER_SERVER_INFO_DIALOG_HPP
#include "guiengine/modaldialog.hpp"
-#include "guiengine/widgets/icon_button_widget.hpp"
-#include "guiengine/widgets/ribbon_widget.hpp"
-#include "guiengine/widgets/label_widget.hpp"
#include "utils/types.hpp"
+namespace GUIEngine
+{
+ class LabelWidget;
+ class RibbonWidget;
+ class IconButtonWidget;
+ class TextBoxWidget;
+}
+
#include
#include
@@ -49,6 +54,8 @@ private:
/** The cancel button. */
GUIEngine::IconButtonWidget *m_cancel_widget;
+ /** Specify server password if needed. */
+ GUIEngine::TextBoxWidget* m_password;
public:
ServerInfoDialog(std::shared_ptr server);
diff --git a/src/states_screens/online_profile_servers.cpp b/src/states_screens/online_profile_servers.cpp
index ba055ee4c..5847c9a9e 100644
--- a/src/states_screens/online_profile_servers.cpp
+++ b/src/states_screens/online_profile_servers.cpp
@@ -110,6 +110,7 @@ void OnlineProfileServers::eventCallback(Widget* widget, const std::string& name
// ----------------------------------------------------------------------------
void OnlineProfileServers::doQuickPlay()
{
+ NetworkConfig::get()->setPassword("");
STKHost::create();
NetworkingLobby::getInstance()->setJoinedServer(nullptr);
NetworkingLobby::getInstance()->push();