diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-21 21:49:06 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-21 21:49:06 (GMT) |
| commit | 81a34222d1797f112a65c30f9ef7db07562ffdf1 (patch) | |
| tree | 4a7500b25f58cf13a4744ea75ae855c0495d5613 /src/client/Client.cpp | |
| parent | b4564f212a17539604e9fa63d649e157f8888eb1 (diff) | |
| download | powder-81a34222d1797f112a65c30f9ef7db07562ffdf1.zip powder-81a34222d1797f112a65c30f9ef7db07562ffdf1.tar.gz | |
POST requests for APIRequest, allow saving user details from within the game, Asynchronous HTTP POST
Diffstat (limited to 'src/client/Client.cpp')
| -rw-r--r-- | src/client/Client.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index dcd4903..ef457b9 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -3,6 +3,7 @@ #include <sstream> #include <string> #include <vector> +#include <map> #include <iomanip> #include <time.h> #include <stdio.h> @@ -1181,6 +1182,40 @@ std::vector<unsigned char> Client::GetSaveData(int saveID, int saveDate) return saveData; } +RequestBroker::Request * Client::SaveUserInfoAsync(UserInfo info) +{ + class StatusParser: public APIResultParser + { + virtual void * ProcessResponse(unsigned char * data, int dataLength) + { + try + { + std::istringstream dataStream((char*)data); + json::Object objDocument; + json::Reader::Read(objDocument, dataStream); + json::Number tempStatus = objDocument["Status"]; + + bool returnValue = tempStatus.Value() == 1; + + return (void*)(returnValue ? 1 : 0); + } + catch (json::Exception &e) + { + return 0; + } + } + virtual void Cleanup(void * objectPtr) + { + //delete (UserInfo*)objectPtr; + } + virtual ~StatusParser() { } + }; + std::map<std::string, std::string> postData; + postData.insert(std::pair<std::string, std::string>("Location", info.Location)); + postData.insert(std::pair<std::string, std::string>("Biography", info.Biography)); + return new APIRequest("http://" SERVER "/Profile.json", postData, new StatusParser()); +} + RequestBroker::Request * Client::GetUserInfoAsync(std::string username) { class UserInfoParser: public APIResultParser @@ -1197,13 +1232,15 @@ RequestBroker::Request * Client::GetUserInfoAsync(std::string username) json::Number userIDTemp = tempUser["ID"]; json::String usernameTemp = tempUser["Username"]; json::String bioTemp = tempUser["Biography"]; - //json::Number ageTemp = tempUser["Age"]; + json::String locationTemp = tempUser["Location"]; + json::Number ageTemp = tempUser["Age"]; return new UserInfo( userIDTemp.Value(), - 0,//ageTemp.Value(), + ageTemp.Value(), usernameTemp.Value(), - bioTemp.Value()); + bioTemp.Value(), + locationTemp.Value()); } catch (json::Exception &e) { |
