| 131 | } |
| 132 | |
| 133 | int RemoteClient::GetDefaultPort() |
| 134 | { |
| 135 | int port = DEFAULT_PORT; |
| 136 | |
| 137 | const char *port_env = getenv("DFHACK_PORT"); |
| 138 | if (port_env) |
| 139 | { |
| 140 | int port_val = atoi(port_env); |
| 141 | if (port_val > 0) |
| 142 | port = port_val; |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | for (const char *filename : {"dfhack-config/remote-server.json", "../dfhack-config/remote-server.json"}) |
| 147 | { |
| 148 | std::ifstream in_file(filename, std::ios_base::in); |
| 149 | if (in_file) |
| 150 | { |
| 151 | Json::Value config; |
| 152 | try { |
| 153 | in_file >> config; |
| 154 | } catch (const std::exception & e) { |
| 155 | std::cerr << "Error reading remote server config file: " << filename << ": " << e.what() << std::endl; |
| 156 | } |
| 157 | in_file.close(); |
| 158 | if (config.isMember("port")) { |
| 159 | port = config["port"].asInt(); |
| 160 | break; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | return port; |
| 167 | } |
| 168 | |
| 169 | bool RemoteClient::connect(int port) |
| 170 | { |