From f65278655724686d772d099664c77d3602f9ce8a Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 30 Sep 2012 15:10:11 -0400 Subject: fix saves getting corrupted when saving, fix error messages not showing (correctly) diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 1490f5f..0353d0e 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -756,11 +756,19 @@ RequestStatus Client::UploadSave(SaveInfo & save) return RequestFailure; } + char *saveName = new char[save.GetName().length() + 1]; + std::strcpy ( saveName, save.GetName().c_str() ); + char *saveDescription = new char[save.GetDescription().length() + 1]; + std::strcpy ( saveDescription, save.GetDescription().c_str() ); + char * postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL }; - char * postDatas[] = { (char *)(save.GetName().c_str()), (char *)(save.GetDescription().c_str()), gameData, (char *)(save.GetPublished()?"Public":"Private") }; + char * postDatas[] = { saveName, saveDescription, gameData, (char *)(save.GetPublished()?"Public":"Private") }; int postLengths[] = { save.GetName().length(), save.GetDescription().length(), gameDataLength, save.GetPublished()?6:7 }; //std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl; data = http_multipart_post("http://" SERVER "/Save.api", postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength); + + delete[] saveDescription; + delete[] saveName; } else { @@ -772,8 +780,8 @@ RequestStatus Client::UploadSave(SaveInfo & save) if(strncmp((const char *)data, "OK", 2)!=0) { if(gameData) free(gameData); - free(data); lastError = std::string((const char *)data); + free(data); return RequestFailure; } else @@ -955,8 +963,8 @@ RequestStatus Client::ExecVote(int saveID, int direction) { if(strncmp((const char *)data, "OK", 2)!=0) { - free(data); lastError = std::string((const char *)data); + free(data); return RequestFailure; } free(data); diff --git a/src/save/ServerSaveActivity.cpp b/src/save/ServerSaveActivity.cpp index a704e85..3bf59df 100644 --- a/src/save/ServerSaveActivity.cpp +++ b/src/save/ServerSaveActivity.cpp @@ -153,7 +153,7 @@ void ServerSaveActivity::NotifyDone(Task * task) Exit(); if(!task->GetSuccess()) { - new ErrorMessage("Error", "Error while saving"); + new ErrorMessage("Error", Client::Ref().GetLastError()); } } -- cgit v0.9.2-21-gd62e