use jsoncpp for ParseServerReturn and startup check
This commit is contained in:
parent
5c1cc0c0fb
commit
df1a2243fd
@ -684,23 +684,20 @@ RequestStatus Client::ParseServerReturn(char *result, int status, bool json)
|
|||||||
if (json)
|
if (json)
|
||||||
{
|
{
|
||||||
std::istringstream datastream(result);
|
std::istringstream datastream(result);
|
||||||
json::Object root;
|
Json::Value root;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
json::Reader::Read(root, datastream);
|
datastream >> root;
|
||||||
// assume everything is fine if an empty [] is returned
|
// assume everything is fine if an empty [] is returned
|
||||||
if (root.Size() == 0)
|
if (root.size() == 0)
|
||||||
{
|
{
|
||||||
return RequestOkay;
|
return RequestOkay;
|
||||||
}
|
}
|
||||||
json::Number status = root["Status"];
|
int status = root.get("Status", 1).asInt();
|
||||||
if (status != 1)
|
if (status != 1)
|
||||||
{
|
{
|
||||||
json::String error = root["Error"];
|
lastError = root.get("Error", "Unspecified Error").asString();
|
||||||
lastError = std::string(error);
|
|
||||||
if (lastError == "")
|
|
||||||
lastError = "Unspecified Error";
|
|
||||||
return RequestFailure;
|
return RequestFailure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -765,27 +762,26 @@ bool Client::CheckUpdate(void *updateRequest, bool checkSession)
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
json::Object objDocument;
|
Json::Value objDocument;
|
||||||
json::Reader::Read(objDocument, dataStream);
|
dataStream >> objDocument;
|
||||||
|
|
||||||
//Check session
|
//Check session
|
||||||
if (checkSession)
|
if (checkSession)
|
||||||
{
|
{
|
||||||
json::Boolean sessionStatus = objDocument["Session"];
|
if (!objDocument["Session"].asBool())
|
||||||
if(!sessionStatus.Value())
|
|
||||||
{
|
{
|
||||||
SetAuthUser(User(0, ""));
|
SetAuthUser(User(0, ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Notifications from server
|
//Notifications from server
|
||||||
json::Array notificationsArray = objDocument["Notifications"];
|
Json::Value notificationsArray = objDocument["Notifications"];
|
||||||
for(size_t j = 0; j < notificationsArray.Size(); j++)
|
for(size_t j = 0; j < notificationsArray.size(); j++)
|
||||||
{
|
{
|
||||||
json::String notificationLink = notificationsArray[j]["Link"];
|
std::string notificationLink = notificationsArray[j]["Link"].asString();
|
||||||
json::String notificationText = notificationsArray[j]["Text"];
|
std::string notificationText = notificationsArray[j]["Text"].asString();
|
||||||
|
|
||||||
std::pair<std::string, std::string> item = std::pair<std::string, std::string>(notificationText.Value(), notificationLink.Value());
|
std::pair<std::string, std::string> item = std::pair<std::string, std::string>(notificationText, notificationLink);
|
||||||
AddServerNotification(item);
|
AddServerNotification(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,50 +789,49 @@ bool Client::CheckUpdate(void *updateRequest, bool checkSession)
|
|||||||
//MOTD
|
//MOTD
|
||||||
if (!usingAltUpdateServer || !checkSession)
|
if (!usingAltUpdateServer || !checkSession)
|
||||||
{
|
{
|
||||||
json::String messageOfTheDay = objDocument["MessageOfTheDay"];
|
this->messageOfTheDay = objDocument["MessageOfTheDay"].asString();
|
||||||
this->messageOfTheDay = messageOfTheDay.Value();
|
|
||||||
notifyMessageOfTheDay();
|
notifyMessageOfTheDay();
|
||||||
|
|
||||||
#ifndef IGNORE_UPDATES
|
#ifndef IGNORE_UPDATES
|
||||||
//Check for updates
|
//Check for updates
|
||||||
json::Object versions = objDocument["Updates"];
|
Json::Value versions = objDocument["Updates"];
|
||||||
#if !defined(BETA) && !defined(SNAPSHOT)
|
#if !defined(BETA) && !defined(SNAPSHOT)
|
||||||
json::Object stableVersion = versions["Stable"];
|
Json::Value stableVersion = versions["Stable"];
|
||||||
json::Number stableMajor = stableVersion["Major"];
|
int stableMajor = stableVersion["Major"].asInt();
|
||||||
json::Number stableMinor = stableVersion["Minor"];
|
int stableMinor = stableVersion["Minor"].asInt();
|
||||||
json::Number stableBuild = stableVersion["Build"];
|
int stableBuild = stableVersion["Build"].asInt();
|
||||||
json::String stableFile = stableVersion["File"];
|
std::string stableFile = stableVersion["File"].asString();
|
||||||
json::String stableChangelog = stableVersion["Changelog"];
|
std::string stableChangelog = stableVersion["Changelog"].asString();
|
||||||
if (stableMajor.Value()>SAVE_VERSION || (stableMinor.Value()>MINOR_VERSION && stableMajor.Value()==SAVE_VERSION) || stableBuild.Value()>BUILD_NUM)
|
if (stableMajor > SAVE_VERSION || (stableMinor > MINOR_VERSION && stableMajor == SAVE_VERSION) || stableBuild > BUILD_NUM)
|
||||||
{
|
{
|
||||||
updateAvailable = true;
|
updateAvailable = true;
|
||||||
updateInfo = UpdateInfo(stableMajor.Value(), stableMinor.Value(), stableBuild.Value(), stableFile.Value(), stableChangelog.Value(), UpdateInfo::Stable);
|
updateInfo = UpdateInfo(stableMajor, stableMinor, stableBuild, stableFile, stableChangelog, UpdateInfo::Stable);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef BETA
|
#ifdef BETA
|
||||||
json::Object betaVersion = versions["Beta"];
|
Json::Value betaVersion = versions["Beta"];
|
||||||
json::Number betaMajor = betaVersion["Major"];
|
int betaMajor = betaVersion["Major"].asInt();
|
||||||
json::Number betaMinor = betaVersion["Minor"];
|
int betaMinor = betaVersion["Minor"].asInt();
|
||||||
json::Number betaBuild = betaVersion["Build"];
|
int betaBuild = betaVersion["Build"].asInt();
|
||||||
json::String betaFile = betaVersion["File"];
|
std::string betaFile = betaVersion["File"].asString();
|
||||||
json::String betaChangelog = betaVersion["Changelog"];
|
std::string betaChangelog = betaVersion["Changelog"].asString();
|
||||||
if (betaMajor.Value()>SAVE_VERSION || (betaMinor.Value()>MINOR_VERSION && betaMajor.Value()==SAVE_VERSION) || betaBuild.Value()>BUILD_NUM)
|
if (betaMajor > SAVE_VERSION || (betaMinor > MINOR_VERSION && betaMajor == SAVE_VERSION) || betaBuild > BUILD_NUM)
|
||||||
{
|
{
|
||||||
updateAvailable = true;
|
updateAvailable = true;
|
||||||
updateInfo = UpdateInfo(betaMajor.Value(), betaMinor.Value(), betaBuild.Value(), betaFile.Value(), betaChangelog.Value(), UpdateInfo::Beta);
|
updateInfo = UpdateInfo(betaMajor, betaMinor, betaBuild, betaFile, betaChangelog, UpdateInfo::Beta);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SNAPSHOT
|
#ifdef SNAPSHOT
|
||||||
json::Object snapshotVersion = versions["Snapshot"];
|
Json::Value snapshotVersion = versions["Snapshot"];
|
||||||
json::Number snapshotSnapshot = snapshotVersion["Snapshot"];
|
int snapshotSnapshot = snapshotVersion["Snapshot"].asInt();
|
||||||
json::String snapshotFile = snapshotVersion["File"];
|
std::string snapshotFile = snapshotVersion["File"].asString();
|
||||||
json::String snapshotChangelog = snapshotVersion["Changelog"];
|
std::string snapshotChangelog = snapshotVersion["Changelog"].asString();
|
||||||
if (snapshotSnapshot.Value() > SNAPSHOT_ID)
|
if (snapshotSnapshot > SNAPSHOT_ID)
|
||||||
{
|
{
|
||||||
updateAvailable = true;
|
updateAvailable = true;
|
||||||
updateInfo = UpdateInfo(snapshotSnapshot.Value(), snapshotFile.Value(), snapshotChangelog.Value(), UpdateInfo::Snapshot);
|
updateInfo = UpdateInfo(snapshotSnapshot, snapshotFile, snapshotChangelog, UpdateInfo::Snapshot);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -847,7 +842,7 @@ bool Client::CheckUpdate(void *updateRequest, bool checkSession)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (json::Exception &e)
|
catch (std::exception & e)
|
||||||
{
|
{
|
||||||
//Do nothing
|
//Do nothing
|
||||||
}
|
}
|
||||||
@ -2022,7 +2017,7 @@ Json::Value Client::GetPref(Json::Value root, std::string prop, Json::Value defa
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int dot = prop.find_last_of('.');
|
int dot = prop.find('.');
|
||||||
if (dot == prop.npos)
|
if (dot == prop.npos)
|
||||||
return root.get(prop, defaultValue);
|
return root.get(prop, defaultValue);
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user