Support direct connection to LAN server using command line option,
based on Benau's fix_2446 branch.
This commit is contained in:
parent
5fc4531c01
commit
b0294060dc
26
src/main.cpp
26
src/main.cpp
@ -222,6 +222,7 @@
|
||||
#include "replay/replay_play.hpp"
|
||||
#include "replay/replay_recorder.hpp"
|
||||
#include "states_screens/main_menu_screen.hpp"
|
||||
#include "states_screens/networking_lobby.hpp"
|
||||
#include "states_screens/register_screen.hpp"
|
||||
#include "states_screens/state_manager.hpp"
|
||||
#include "states_screens/user_screen.hpp"
|
||||
@ -574,6 +575,7 @@ void cmdLineHelp()
|
||||
" --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"
|
||||
" --connect-now=ip Connect to a server with IP known now (in format x.x.x.x:xxx(port)).\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"
|
||||
@ -978,6 +980,22 @@ int handleCmdLine()
|
||||
// Networking command lines
|
||||
NetworkConfig::get()->
|
||||
setMaxPlayers(UserConfigParams::m_server_max_players);
|
||||
if (CommandLine::has("--connect-now", &s))
|
||||
{
|
||||
TransportAddress ip(s);
|
||||
TransportAddress me(2130706433/*127.0.0.1*/, 2757);
|
||||
NetworkConfig::get()->setIsLAN();
|
||||
NetworkConfig::get()->setIsServer(false);
|
||||
NetworkConfig::get()->setMyAddress(me);
|
||||
Log::info("main", "Try to connect to server '%s'.",
|
||||
ip.toString().c_str() );
|
||||
irr::core::stringw name = StringUtils::utf8ToWide(ip.toString());
|
||||
ServersManager::get()->addServer(new Server(name, /*lan*/true,
|
||||
16, 0, ip));
|
||||
ServersManager::get()->setJoinedServer(0);
|
||||
STKHost::create();
|
||||
}
|
||||
|
||||
if(CommandLine::has("--server", &s))
|
||||
{
|
||||
NetworkConfig::get()->setServerName(core::stringw(s.c_str()));
|
||||
@ -1639,7 +1657,13 @@ int main(int argc, char *argv[] )
|
||||
HardwareStats::reportHardwareStats();
|
||||
}
|
||||
|
||||
if(!UserConfigParams::m_no_start_screen)
|
||||
// This can only be the case if --connect-now was used, which adds
|
||||
// a server to the server list.
|
||||
if (ServersManager::get()->getNumServers()==1)
|
||||
{
|
||||
NetworkingLobby::getInstance()->push();
|
||||
}
|
||||
else if (!UserConfigParams::m_no_start_screen)
|
||||
{
|
||||
// If there is a current player, it was saved in the config file,
|
||||
// so we immediately start the main menu (unless it was requested
|
||||
|
@ -57,6 +57,26 @@ public:
|
||||
m_port = a.port;
|
||||
} // TransportAddress(EnetAddress)
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Construct an IO address from a string in the format x.x.x.x:xxx. */
|
||||
TransportAddress(const std::string& str)
|
||||
{
|
||||
std::string combined = StringUtils::replace(str, ":", ".");
|
||||
std::vector<uint32_t> ip = StringUtils::splitToUInt(combined, '.');
|
||||
m_ip = 0;
|
||||
m_port = 0;
|
||||
if (ip.size() == 5)
|
||||
{
|
||||
m_ip = (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3];
|
||||
m_port = (uint16_t)(ip[4] < 65536 ? ip[4] : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ip = 0;
|
||||
m_port = 0;
|
||||
}
|
||||
} // TransportAddress(string of ip)
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
~TransportAddress() {}
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user