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();