diff --git a/server/config.cpp b/server/config.cpp index 316b9f5a..f89d2ba0 100644 --- a/server/config.cpp +++ b/server/config.cpp @@ -31,6 +31,22 @@ Config::Config() mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); filename_ = dir + "settings.json"; cerr << filename_ << "\n"; + + ifstream ifs(filename_, std::ifstream::in); + if (ifs.good()) + { + json j; + ifs >> j; + json jClient = j["Client"]; + for (json::iterator it = jClient.begin(); it != jClient.end(); ++it) + { + ClientInfoPtr client = make_shared(); + client->fromJson(*it); + clients.push_back(client); + std::cout << "Client:\n" << std::setw(4) << client->toJson() << '\n'; + } + } + // fs::create_directory(filename_.parent_path()); } diff --git a/server/config.h b/server/config.h index df556c5e..59b96268 100644 --- a/server/config.h +++ b/server/config.h @@ -68,7 +68,7 @@ struct Volume struct ClientInfo { - ClientInfo(const std::string& _macAddress = "") : macAddress(_macAddress), volume(100), connected(false) + ClientInfo(const std::string& _macAddress = "") : macAddress(_macAddress), volume(100), connected(false), latency(0) { lastSeen.tv_sec = 0; lastSeen.tv_usec = 0; @@ -85,6 +85,7 @@ struct ClientInfo lastSeen.tv_sec = jGet(j["lastSeen"], "sec", 0); lastSeen.tv_usec = jGet(j["lastSeen"], "usec", 0); connected = jGet(j, "connected", true); + latency = jGet(j, "latency", 0); } json toJson() @@ -94,22 +95,15 @@ struct ClientInfo j["IP"] = ipAddress; j["host"] = hostName; j["version"] = version; - j["name"] = getName(); + j["name"] = name; j["volume"] = volume.toJson(); j["lastSeen"]["sec"] = lastSeen.tv_sec; j["lastSeen"]["usec"] = lastSeen.tv_usec; j["connected"] = connected; + j["latency"] = latency; return j; } - std::string getName() - { - if (name.empty()) - return hostName; - else - return name; - } - std::string macAddress; std::string ipAddress; std::string hostName; @@ -119,6 +113,7 @@ struct ClientInfo bool muted; timeval lastSeen; bool connected; + int32_t latency; }; typedef std::shared_ptr ClientInfoPtr;