From bb1eb0b48a650afa42cd1f4aab9f9f95dc071bd6 Mon Sep 17 00:00:00 2001 From: Japa Date: Tue, 3 Oct 2017 19:48:37 +0530 Subject: [PATCH] Use a config file to enable outside connections. --- dfhack-config/remote-server.cfg | 2 ++ library/RemoteServer.cpp | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 dfhack-config/remote-server.cfg diff --git a/dfhack-config/remote-server.cfg b/dfhack-config/remote-server.cfg new file mode 100644 index 000000000..877f06179 --- /dev/null +++ b/dfhack-config/remote-server.cfg @@ -0,0 +1,2 @@ +#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 f27bb36ee..4a4787006 100644 --- a/library/RemoteServer.cpp +++ b/library/RemoteServer.cpp @@ -379,8 +379,33 @@ bool ServerMain::listen(int port) socket->Initialize(); - if (!socket->Listen(NULL, port)) - return false; + bool allow_remote = false; + std::string filename("dfhack-config/remote-server.cfg"); + + 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) + { + allow_remote = (line.compare(25, std::string::npos, "true") == 0); + } + } + } + if (allow_remote) + { + if (!socket->Listen(NULL, port)) + return false; + } + else + { + if (!socket->Listen("127.0.0.1", port)) + return false; + } thread = new tthread::thread(threadFn, this); thread->detach();