From 968546b20c6ab477a42df0fd21f95bef30f69600 Mon Sep 17 00:00:00 2001 From: Koncord Date: Wed, 11 Jan 2017 22:58:50 +0800 Subject: [PATCH] Use master server address from config file --- apps/netlauncher/NetController.cpp | 23 +++++------------ apps/netlauncher/NetController.hpp | 4 +-- apps/netlauncher/main.cpp | 35 +++++++++++++++++++++++++- files/tes3mp/tes3mp-client-default.cfg | 3 ++- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/apps/netlauncher/NetController.cpp b/apps/netlauncher/NetController.cpp index 3c457a60e..40f7a2da4 100644 --- a/apps/netlauncher/NetController.cpp +++ b/apps/netlauncher/NetController.cpp @@ -26,10 +26,10 @@ NetController *NetController::get() return mThis; } -void NetController::Create() +void NetController::Create(std::string addr, unsigned short port) { assert(!mThis); - mThis = new NetController; + mThis = new NetController(addr, port); } void NetController::Destroy() @@ -39,7 +39,7 @@ void NetController::Destroy() mThis = nullptr; } -NetController::NetController() : httpNetwork("127.0.0.1", 8080) +NetController::NetController(std::string addr, unsigned short port) : httpNetwork(addr, port) { } @@ -116,30 +116,19 @@ void NetController::downloadInfo(QAbstractItemModel *pModel, QModelIndex index) model->setData(mi, PingRakNetServer(addr[0].toLatin1().data(), addr[1].toUShort())); } - //qDebug() << data; - - if (model->rowCount() != 0) - return; - - /*model->insertRows(0, 6); - model->myData[0] = {"127.0.0.1:25565", 0, 20, 1, "Super Server"}; - model->myData[1] = {"127.0.0.1:25565", 5, 20, 2, "Koncord's server"}; - model->myData[2] = {"server.local:8888", 15, 15, 15, "tes3mp server", "custom mode"}; - model->myData[3] = {"127.0.0.1:25562", 1, 2, 5, "Server"}; - model->myData[4] = {"tes3mp.com:22222", 8, 9, 1000, "Antoher Server", "super duper mod"}; - model->myData[5] = {"localhost:24", 1, 5, 5, "Test Server", "Another mod 0.1"};*/ } -void NetController::updateInfo(QAbstractItemModel *pModel, QModelIndex index) +bool NetController::updateInfo(QAbstractItemModel *pModel, QModelIndex index) { qDebug() << "TODO: \"NetController::updateInfo(QAbstractItemModel *, QModelIndex)\" is not completed"; ServerModel *model = ((ServerModel*)pModel); + bool result; if (index.isValid() && index.row() >= 0) { //ServerData &sd = model->myData[index.row()]; //qDebug() << sd.addr; - downloadInfo(pModel, index); + result = downloadInfo(pModel, index); } else { diff --git a/apps/netlauncher/NetController.hpp b/apps/netlauncher/NetController.hpp index 846ea0986..93ea3f451 100644 --- a/apps/netlauncher/NetController.hpp +++ b/apps/netlauncher/NetController.hpp @@ -16,7 +16,7 @@ class NetController { public: static NetController *get(); - static void Create(); + static void Create(std::string addr, unsigned short port); static void Destroy(); void updateInfo(QAbstractItemModel *pModel, QModelIndex index= QModelIndex()); void updateInfo(); @@ -25,7 +25,7 @@ public: void selectServer(ServerData *pServerData); ServerData *selectedServer(); protected: - NetController(); + NetController(std::string addr, unsigned short port); ~NetController(); private: NetController(const NetController &controller); diff --git a/apps/netlauncher/main.cpp b/apps/netlauncher/main.cpp index 81b5a3270..4caddc666 100644 --- a/apps/netlauncher/main.cpp +++ b/apps/netlauncher/main.cpp @@ -1,13 +1,46 @@ #include +#include +#include #include "Main.hpp" #include "NetController.hpp" +std::string loadSettings (Settings::Manager & settings) +{ + Files::ConfigurationManager mCfgMgr; + // Create the settings manager and load default settings file + const std::string localdefault = (mCfgMgr.getLocalPath() / "tes3mp-client-default.cfg").string(); + const std::string globaldefault = (mCfgMgr.getGlobalPath() / "tes3mp-client-default.cfg").string(); + + // prefer local + if (boost::filesystem::exists(localdefault)) + settings.loadDefault(localdefault); + else if (boost::filesystem::exists(globaldefault)) + settings.loadDefault(globaldefault); + else + throw std::runtime_error ("No default settings file found! Make sure the file \"tes3mp-client-default.cfg\" was properly installed."); + + // load user settings if they exist + const std::string settingspath = (mCfgMgr.getUserConfigPath() / "tes3mp-client.cfg").string(); + if (boost::filesystem::exists(settingspath)) + settings.loadUser(settingspath); + + return settingspath; +} + int main(int argc, char *argv[]) { + Settings::Manager mgr; + Files::ConfigurationManager cfgMgr; + + loadSettings(mgr); + + std::string addr = mgr.getString("address", "Master"); + int port = mgr.getInt("port", "Master"); + // initialize resources, if needed // Q_INIT_RESOURCE(resfile); - NetController::Create(); + NetController::Create(addr, port); atexit(NetController::Destroy); QApplication app(argc, argv); Main d; diff --git a/files/tes3mp/tes3mp-client-default.cfg b/files/tes3mp/tes3mp-client-default.cfg index 98eee813d..7eb47f3f0 100644 --- a/files/tes3mp/tes3mp-client-default.cfg +++ b/files/tes3mp/tes3mp-client-default.cfg @@ -6,7 +6,8 @@ port = 25565 loglevel = 0 [Master] -address = master.tes3mp.com:8080 +address = master.tes3mp.com +port = 8080 [Chat] # Use https://wiki.libsdl.org/SDL_Keycode for rebinding keys