From 69a88e1641928fac2931912e4b7049665e5024fd Mon Sep 17 00:00:00 2001 From: Japa Mala Illo Date: Sat, 25 Nov 2017 11:34:02 +0530 Subject: [PATCH] Use json for server config. --- dfhack-config/remote-server.cfg | 2 -- library/RemoteServer.cpp | 38 +++++++++++++++++++++------------ library/xml | 2 +- scripts | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) delete mode 100644 dfhack-config/remote-server.cfg diff --git a/dfhack-config/remote-server.cfg b/dfhack-config/remote-server.cfg deleted file mode 100644 index 877f06179..000000000 --- a/dfhack-config/remote-server.cfg +++ /dev/null @@ -1,2 +0,0 @@ -#change this to true to allow remote RPC connections from other devices. -allow-remote-connections=false \ No newline at end of file diff --git a/library/RemoteServer.cpp b/library/RemoteServer.cpp index 9cd017993..64be8221c 100644 --- a/library/RemoteServer.cpp +++ b/library/RemoteServer.cpp @@ -63,6 +63,8 @@ using namespace DFHack; #include "tinythread.h" using namespace tthread; +#include "jsoncpp.h" + using dfproto::CoreTextNotification; using dfproto::CoreTextFragment; using google::protobuf::MessageLite; @@ -379,23 +381,31 @@ bool ServerMain::listen(int port) socket->Initialize(); - bool allow_remote = false; - std::string filename("dfhack-config/remote-server.cfg"); + std::string filename("dfhack-config/remote-server.json"); + + Json::Value configJson; - std::ifstream configFile(filename); - if (configFile.is_open()) + std::ifstream inFile(filename, std::ios_base::in); + if (inFile.is_open()) { - std::string line; - while (std::getline(configFile, line)) - { - if (line.compare(0, 1, "#") == 0) - continue; - if (line.compare(0, 24, "allow-remote-connections") == 0) - { - allow_remote = (line.compare(25, std::string::npos, "true") == 0); - } - } + inFile >> configJson; + inFile.close(); } + + bool allow_remote = configJson.get("allow_remote", "false").asBool(); + port = configJson.get("port", port).asInt(); + + configJson["allow_remote"] = allow_remote; + configJson["port"] = port; + + std::ofstream outFile(filename, std::ios_base::trunc); + + if (outFile.is_open()) + { + outFile << configJson; + outFile.close(); + } + if (allow_remote) { if (!socket->Listen(NULL, port)) diff --git a/library/xml b/library/xml index 860a9041a..3b5214bca 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 860a9041a75305609643d465123a4b598140dd7f +Subproject commit 3b5214bcad3349bdf3418a1dba71dbeea4a723d1 diff --git a/scripts b/scripts index 09cf8dde9..3baa24fec 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 09cf8dde929e0478a869fa09ec329a27c9631113 +Subproject commit 3baa24fec93461218b5b658de94884ebff0a0b23