diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 9761649ed..67212e7d7 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -13,6 +13,7 @@ #include #include #include +#include "mwmp/Main.hpp" #if defined(_WIN32) // For OutputDebugString @@ -156,6 +157,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat ("activate-dist", bpo::value ()->default_value (-1), "activation distance override"); + mwmp::Main::OptionsDesc(&desc); + bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) .options(desc).allow_unregistered().run(); @@ -253,6 +256,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.setActivationDistanceOverride (variables["activate-dist"].as()); engine.enableFontExport(variables["export-fonts"].as()); + mwmp::Main::Configure(&variables); + return true; } diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index ad2a5f684..0df96ed2d 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "DedicatedPlayer.hpp" #include "LocalPlayer.hpp" @@ -32,6 +33,7 @@ using namespace mwmp; using namespace std; Main *Main::pMain = 0; +std::string Main::addr = ""; std::string loadSettings (Settings::Manager & settings) { @@ -77,6 +79,18 @@ Main::~Main() Players::CleanUp(); } +void Main::OptionsDesc(boost::program_options::options_description *desc) +{ + namespace bpo = boost::program_options; + desc->add_options()("connect", bpo::value()->default_value(""), + "connect to server (e.g. --connect=127.0.0.1:25565)"); +} + +void Main::Configure(const boost::program_options::variables_map &variables) +{ + Main::addr = variables["connect"].as(); +} + void Main::Create() { assert(!pMain); @@ -93,8 +107,18 @@ void Main::Create() int logLevel = mgr.getInt("loglevel", "General"); Log::SetLevel(logLevel); - pMain->server = mgr.getString("server", "General"); - pMain->port = (unsigned short)mgr.getInt("port", "General"); + if(addr.empty()) + { + pMain->server = mgr.getString("server", "General"); + pMain->port = (unsigned short) mgr.getInt("port", "General"); + } + else + { + size_t delim_pos = addr.find(':'); + pMain->server = addr.substr(0, delim_pos); + pMain->port = atoi(addr.substr(delim_pos + 1).c_str()); + + } pMain->mGUIController->setupChat(mgr); diff --git a/apps/openmw/mwmp/Main.hpp b/apps/openmw/mwmp/Main.hpp index e1753e8dc..48ab2336d 100644 --- a/apps/openmw/mwmp/Main.hpp +++ b/apps/openmw/mwmp/Main.hpp @@ -1,4 +1,5 @@ #include +#include #include "Networking.hpp" #include "LocalPlayer.hpp" #include "GUIController.hpp" @@ -11,6 +12,8 @@ namespace mwmp Main(); ~Main(); + static void OptionsDesc(boost::program_options::options_description *desc); + static void Configure(const boost::program_options::variables_map &variables); static void Create(); static void Destroy(); static const Main &get(); @@ -24,6 +27,7 @@ namespace mwmp void UpdateWorld(float dt) const; private: + static std::string addr; Main (const Main&); ///< not implemented Main& operator= (const Main&);