MCPcopy Create free account
hub / github.com/PlayFab/gsdk / decodeHeartbeatResponse

Method decodeHeartbeatResponse

cpp/cppsdk/gsdk.cpp:315–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313 }
314
315 void GSDKInternal::decodeHeartbeatResponse(const std::string& responseJson)
316 {
317 Json::CharReaderBuilder jsonReaderFactory;
318 std::unique_ptr<Json::CharReader> jsonReader(jsonReaderFactory.newCharReader());
319 Json::Value heartbeatResponse;
320 JSONCPP_STRING jsonParseErrors;
321 bool parsedSuccessfully = jsonReader->parse(responseJson.c_str(), responseJson.c_str() + responseJson.length(), &heartbeatResponse, &jsonParseErrors);
322
323 if (!parsedSuccessfully) {
324 GSDK::logMessage("Failed to parse heartbeat");
325 GSDK::logMessage(jsonParseErrors);
326 GSDK::logMessage("Message: " + responseJson);
327 return;
328 }
329
330 try {
331 if (heartbeatResponse.isMember("sessionConfig"))
332 {
333 std::lock_guard<std::mutex> lock(m_configMutex);
334 Json::Value sessionConfig = heartbeatResponse["sessionConfig"];
335 for (Json::ValueIterator i = sessionConfig.begin(); i != sessionConfig.end(); ++i)
336 {
337 if ((*i).isString())
338 {
339 m_configSettings[i.key().asCString()] = (*i).asCString();
340 }
341 }
342
343 // Update initial players only if this is the first time populating it.
344 if (m_initialPlayers.empty() && sessionConfig.isMember("initialPlayers"))
345 {
346 Json::Value players = sessionConfig["initialPlayers"];
347
348 for (Json::ArrayIndex i = 0; i < players.size(); ++i)
349 {
350 m_initialPlayers.push_back(players[i].asCString());
351 }
352 }
353
354 if (sessionConfig.isMember("metadata"))
355 {
356 Json::Value sessionMetadata = sessionConfig["metadata"];
357 for (Json::ValueIterator i = sessionMetadata.begin(); i != sessionMetadata.end(); ++i)
358 {
359 if ((*i).isString())
360 {
361 m_configSettings[i.key().asCString()] = (*i).asCString();
362 }
363 }
364 }
365 }
366
367 if (heartbeatResponse.isMember("nextScheduledMaintenanceUtc"))
368 {
369 tm nextMaintenance = parseDate(heartbeatResponse["nextScheduledMaintenanceUtc"].asCString());
370 time_t nextMaintenanceTime = cGSDKUtils::tm2timet_utc(&nextMaintenance);
371 time_t cachedMaintenanceTime = cGSDKUtils::tm2timet_utc(&m_cachedScheduledMaintenance);
372 double diff = difftime(nextMaintenanceTime, cachedMaintenanceTime);

Callers 1

TEST_METHODFunction · 0.80

Calls 15

newCharReaderMethod · 0.80
lengthMethod · 0.80
isMemberMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
isStringMethod · 0.80
asCStringMethod · 0.80
keyMethod · 0.80
emptyMethod · 0.80
sizeMethod · 0.80
asStringMethod · 0.80
asIntMethod · 0.80

Tested by 1

TEST_METHODFunction · 0.64