Allow specifying server password in dialog
This commit is contained in:
parent
c73536263f
commit
901c5eabec
@ -26,6 +26,10 @@
|
||||
<label proportion="1" text_align="left" I18N="In the networking lobby" text="Game mode:"/>
|
||||
<label proportion="2" text_align="left" id="server_game_mode" text=""/>
|
||||
</div>
|
||||
<div width="100%" height="fit" layout="horizontal-row" >
|
||||
<label id="label_password" text_align="left" proportion="1" text="Password"/>
|
||||
<textbox id="password" proportion="2" height="fit"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<spacer height="20" width="50"/>
|
||||
|
@ -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))
|
||||
|
@ -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; }
|
||||
|
@ -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<Server> 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<Server> a,
|
||||
const std::shared_ptr<Server> 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
|
||||
|
@ -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<TextBoxWidget>("password")->getText();
|
||||
std::string password = StringUtils::xmlEncode(password_w);
|
||||
NetworkConfig::get()->setPassword(StringUtils::wideToUtf8(password_w));
|
||||
std::string password = StringUtils::wideToUtf8(getWidget<TextBoxWidget>
|
||||
("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
|
||||
|
@ -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> 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> server)
|
||||
assert(m_cancel_widget != NULL);
|
||||
m_options_widget->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
|
||||
if (m_server->isPasswordProtected())
|
||||
{
|
||||
m_password = getWidget<TextBoxWidget>("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();
|
||||
|
@ -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 <memory>
|
||||
#include <irrString.h>
|
||||
|
||||
@ -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> server);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user