Use json for server config.

develop
Japa Mala Illo 2017-11-25 11:34:02 +05:30
parent 272f51ef4b
commit 69a88e1641
4 changed files with 26 additions and 18 deletions

@ -1,2 +0,0 @@
#change this to true to allow remote RPC connections from other devices.
allow-remote-connections=false

@ -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");
std::ifstream configFile(filename);
if (configFile.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)
Json::Value configJson;
std::ifstream inFile(filename, std::ios_base::in);
if (inFile.is_open())
{
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))

@ -1 +1 @@
Subproject commit 860a9041a75305609643d465123a4b598140dd7f
Subproject commit 3b5214bcad3349bdf3418a1dba71dbeea4a723d1

@ -1 +1 @@
Subproject commit 09cf8dde929e0478a869fa09ec329a27c9631113
Subproject commit 3baa24fec93461218b5b658de94884ebff0a0b23