MCPcopy Create free account
hub / github.com/DFHack/dfhack / GetDefaultPort

Method GetDefaultPort

library/RemoteClient.cpp:133–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131}
132
133int 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
169bool RemoteClient::connect(int port)
170{

Callers

nothing calls this directly

Calls 2

whatMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected