summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-30 00:40:28 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-30 00:40:28 (GMT)
commit259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec (patch)
treef0fe2c14499345121371bba0ecc3fe21d17e0953 /src/client
parentfe329e9127ebcb8c89c505c4c120e175810d280c (diff)
downloadpowder-259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec.zip
powder-259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec.tar.gz
ASCII for key events, save and Textarea (no caret, yet)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Client.cpp55
-rw-r--r--src/client/Client.h1
2 files changed, 55 insertions, 1 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 9b8b9c2..75b78c5 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -51,6 +51,60 @@ User Client::GetAuthUser()
return authUser;
}
+RequestStatus Client::UploadSave(Save * save)
+{
+ lastError = "";
+ int dataStatus;
+ char * data;
+ int dataLength = 0;
+ std::stringstream userIDStream;
+ userIDStream << authUser.ID;
+ if(authUser.ID)
+ {
+ char * postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL };
+ char * postDatas[] = { (char *)(save->name.c_str()), (char *)(save->Description.c_str()), (char *)(save->GetData()), (char *)(save->Published?"Public":"Private") };
+ int postLengths[] = { save->name.length(), save->Description.length(), save->GetDataLength(), save->Published?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);
+ }
+ else
+ {
+ lastError = "Not authenticated";
+ return RequestFailure;
+ }
+ if(data && dataStatus == 200)
+ {
+ if(strncmp((const char *)data, "OK", 2)!=0)
+ {
+ free(data);
+ lastError = std::string((const char *)data);
+ return RequestFailure;
+ }
+ else
+ {
+ int tempID;
+ std::stringstream saveIDStream((char *)(data+3));
+ saveIDStream >> tempID;
+ if(!tempID)
+ {
+ lastError = "Server did not return Save ID";
+ return RequestFailure;
+ }
+ else
+ {
+ save->id = tempID;
+ }
+ }
+ free(data);
+ return RequestOkay;
+ }
+ else if(data)
+ {
+ free(data);
+ }
+ return RequestFailure;
+}
+
RequestStatus Client::ExecVote(int saveID, int direction)
{
lastError = "";
@@ -83,7 +137,6 @@ RequestStatus Client::ExecVote(int saveID, int direction)
lastError = "Not authenticated";
return RequestFailure;
}
- std::cout << data << std::endl;
if(data && dataStatus == 200)
{
if(strncmp((const char *)data, "OK", 2)!=0)
diff --git a/src/client/Client.h b/src/client/Client.h
index 89c4e64..0587d79 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -38,6 +38,7 @@ public:
~Client();
RequestStatus ExecVote(int saveID, int direction);
+ RequestStatus UploadSave(Save * save);
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
LoginStatus Login(string username, string password, User & user);