From ea9c31a8f7381a92f6bf998b6e012c1535ba94d3 Mon Sep 17 00:00:00 2001 From: Koncord Date: Mon, 20 Feb 2017 22:02:52 +0800 Subject: [PATCH] [Client] Add password to client params and to config file --- apps/openmw/mwmp/Main.cpp | 18 ++++++++++++++---- apps/openmw/mwmp/Main.hpp | 1 + apps/openmw/mwmp/Networking.cpp | 1 - files/tes3mp/tes3mp-client-default.cfg | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index cb9bd4563..9d0de523c 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -25,6 +25,7 @@ #include "../mwmechanics/spellcasting.hpp" #include #include +#include #include "Networking.hpp" #include "LocalPlayer.hpp" @@ -37,6 +38,7 @@ using namespace std; Main *Main::pMain = 0; std::string Main::addr = ""; +std::string Main::passw = TES3MP_DEFAULT_PASSW; std::string loadSettings (Settings::Manager & settings) { @@ -85,13 +87,17 @@ Main::~Main() 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)"); + desc->add_options() + ("connect", bpo::value()->default_value(""), + "connect to server (e.g. --connect=127.0.0.1:25565)") + ("password", bpo::value()->default_value(TES3MP_DEFAULT_PASSW), + "сonnect to a secured server. (e.g. --password=AnyPassword"); } void Main::configure(const boost::program_options::variables_map &variables) { Main::addr = variables["connect"].as(); + Main::passw = variables["password"].as(); } static Settings::CategorySettingValueMap saveUserSettings; @@ -130,15 +136,19 @@ bool Main::init(std::vector &content) { pMain->server = mgr.getString("server", "General"); pMain->port = (unsigned short) mgr.getInt("port", "General"); + + passw = mgr.getString("password", "General"); + if (passw.empty()) + passw = TES3MP_DEFAULT_PASSW; } else { size_t delim_pos = addr.find(':'); pMain->server = addr.substr(0, delim_pos); pMain->port = atoi(addr.substr(delim_pos + 1).c_str()); - } - + get().mLocalPlayer->passw = passw; + pMain->mNetworking->connect(pMain->server, pMain->port); RestoreMgr(mgr); return pMain->mNetworking->isConnected(); diff --git a/apps/openmw/mwmp/Main.hpp b/apps/openmw/mwmp/Main.hpp index bc4635f00..673de61e8 100644 --- a/apps/openmw/mwmp/Main.hpp +++ b/apps/openmw/mwmp/Main.hpp @@ -34,6 +34,7 @@ namespace mwmp private: static std::string addr; + static std::string passw; Main (const Main&); ///< not implemented Main& operator= (const Main&); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 9fdeb8565..d7af76a0e 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -189,7 +189,6 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) { case ID_HANDSHAKE: { - getLocalPlayer()->passw = "SuperPassword"; myPacket->Send(getLocalPlayer(), serverAddr); break; } diff --git a/files/tes3mp/tes3mp-client-default.cfg b/files/tes3mp/tes3mp-client-default.cfg index 079f54148..ed7c4498b 100644 --- a/files/tes3mp/tes3mp-client-default.cfg +++ b/files/tes3mp/tes3mp-client-default.cfg @@ -1,6 +1,7 @@ [General] server = mp.tes3mp.com port = 25565 +password = # 0 - Verbose (spam), 1 - Info, 2 - Warnings, 3 - Errors, 4 - Only fatal errors loglevel = 0