Add --connect option to client

This commit is contained in:
Koncord 2016-08-24 16:15:34 +08:00
parent fc4d8b82fb
commit 997c62cc52
3 changed files with 35 additions and 2 deletions

View file

@ -13,6 +13,7 @@
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream_buffer.hpp>
#include <boost/filesystem/fstream.hpp>
#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 <int> ()->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<int>());
engine.enableFontExport(variables["export-fonts"].as<bool>());
mwmp::Main::Configure(&variables);
return true;
}

View file

@ -24,6 +24,7 @@
#include <apps/openmw/mwworld/inventorystore.hpp>
#include <apps/openmw/mwmechanics/spellcasting.hpp>
#include <components/openmw-mp/Log.hpp>
#include <cstdlib>
#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<std::string>()->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<string>();
}
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);

View file

@ -1,4 +1,5 @@
#include <apps/openmw/mwworld/ptr.hpp>
#include <boost/program_options.hpp>
#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&);