Started to add password support for a controlling a server.

This commit is contained in:
hiker 2016-02-10 13:32:39 +11:00
parent cebf395939
commit bfced53aaf
4 changed files with 20 additions and 1 deletions

View File

@ -533,6 +533,7 @@ void cmdLineHelp()
// " n=2: recorded key strokes\n"
" --server=name Start a server (not a playing client).\n"
" --lan-server=name Start a LAN server (not a playing client).\n"
" --server-password= Sets a password for a server (both client&server).\n"
" --login=s Automatically log in (set the login).\n"
" --password=s Automatically log in (set the password).\n"
" --port=n Port number to use.\n"
@ -792,6 +793,10 @@ int handleCmdLine()
STKHost::create();
Log::info("main", "Creating a LAN server '%s'.", s.c_str());
}
if (CommandLine::has("--server-password", &s))
{
NetworkConfig::get()->setPassword(s);
}
if(CommandLine::has("--max-players", &n))
UserConfigParams::m_server_max_players=n;

View File

@ -39,6 +39,7 @@ NetworkConfig::NetworkConfig()
m_max_players = 4;
m_is_registered = false;
m_server_name = "";
m_password = "";
m_private_port = 0;
m_my_address.lock();
m_my_address.getData().clear();

View File

@ -42,6 +42,9 @@ private:
/** True if this host is a server, false otherwise. */
bool m_is_server;
/** The password for a server (or to authenticate to a server). */
std::string m_password;
/** This is either this computer's public IP address, or the LAN
* address in case of a LAN game. With lock since it can
* be updated from a separate thread. */
@ -83,6 +86,16 @@ public:
// ------------------------------------------------------------------------
void setMyAddress(const TransportAddress& addr);
// ------------------------------------------------------------------------
/** Sets the password for a server. */
void setPassword(const std::string &password) { m_password = password; }
// ------------------------------------------------------------------------
/** Returns if the specified password is the correct password for this
* server. */
bool checkPassword(const std::string &password)
{
return m_password == password;
}
// ------------------------------------------------------------------------
/** Return if a network setting is happening. A network setting is active
* if a host (server or client) exists. */

View File

@ -166,7 +166,7 @@ void ServerLobbyRoomProtocol::update()
//-----------------------------------------------------------------------------
/** Callback when the GetPublicAddress terminates. It will unpause this
* protocol, which triggers the next state of the finite state machine.
* protocol, which triggers the next state of the finite state machine.
*/
void ServerLobbyRoomProtocol::callback(Protocol *protocol)
{