summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-06-20 12:40:18 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-06-20 12:40:18 (GMT)
commit2be9c925088c16beb144dd9932202416d00ff581 (patch)
tree51f8ccbf2b0b051890c5f5d12fa28a67635c06c2 /src/client
parent9769239af69695e9a7f8cf103a197695ecf691e0 (diff)
downloadpowder-2be9c925088c16beb144dd9932202416d00ff581.zip
powder-2be9c925088c16beb144dd9932202416d00ff581.tar.gz
OpenGL canvas for Windows, Notifications for main Game, Update checker in Client (+ other client triggered events)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Client.cpp86
-rw-r--r--src/client/Client.h12
-rw-r--r--src/client/ClientListener.h22
3 files changed, 119 insertions, 1 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index f31ad08..285a9ad 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -24,8 +24,11 @@
#include "client/SaveInfo.h"
+#include "ClientListener.h"
+
Client::Client():
- authUser(0, "")
+ authUser(0, ""),
+ updateAvailable(false)
{
int i = 0;
std::string proxyString("");
@@ -108,6 +111,87 @@ Client::Client():
stampIDs.push_back(data);
}
stampsLib.close();
+
+ //Begin version check
+ versionCheckRequest = http_async_req_start(NULL, SERVER "/Version.json", NULL, 0, 1);
+}
+
+void Client::Tick()
+{
+ //Check status on version check request
+ if(versionCheckRequest && http_async_req_status(versionCheckRequest))
+ {
+ int status;
+ int dataLength;
+ char * data = http_async_req_stop(versionCheckRequest, &status, &dataLength);
+ versionCheckRequest = NULL;
+
+ notifyUpdateAvailable();
+ if(status != 200)
+ {
+ if(data)
+ free(data);
+ }
+ else
+ {
+ std::istringstream dataStream(data);
+
+ try
+ {
+ json::Object objDocument;
+ json::Reader::Read(objDocument, dataStream);
+
+ json::Object stableVersion = objDocument["Stable"];
+ json::Object betaVersion = objDocument["Beta"];
+
+ json::Number stableMajor = stableVersion["Major"];
+ json::Number stableMinor = stableVersion["Minor"];
+ json::Number stableBuild = stableVersion["Build"];
+
+ json::Number betaMajor = betaVersion["Major"];
+ json::Number betaMinor = betaVersion["Minor"];
+ json::Number betaBuild = betaVersion["Build"];
+
+#ifdef BETA
+ if( (betaMajor.Value()>SAVE_VERSION || (betaMinor.Value()>MINOR_VERSION && betaMajor.Value()==SAVE_VERSION) || betaBuild.Value()>BUILD_NUM) ||
+ (stableMajor.Value()>SAVE_VERSION || (stableMinor.Value()>MINOR_VERSION && stableMajor.Value()==SAVE_VERSION) || stableBuild.Value()>BUILD_NUM))
+ {
+ updateAvailable = true;
+ }
+#else
+ if(stableMajor.Value()>SAVE_VERSION || (stableMinor.Value()>MINOR_VERSION && stableMajor.Value()==SAVE_VERSION) || stableBuild.Value()>BUILD_NUM)
+ {
+ updateAvailable = true;
+ }
+#endif
+
+ if(updateAvailable)
+ {
+ notifyUpdateAvailable();
+ }
+ }
+ catch (json::Exception &e)
+ {
+ //Do nothing
+ }
+
+ if(data)
+ free(data);
+ }
+ }
+}
+
+void Client::notifyUpdateAvailable()
+{
+ for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator)
+ {
+ (*iterator)->NotifyUpdateAvailable(this);
+ }
+}
+
+void Client::AddListener(ClientListener * listener)
+{
+ listeners.push_back(listener);
}
Client::~Client()
diff --git a/src/client/Client.h b/src/client/Client.h
index 6c1baa5..6cdedd4 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -27,8 +27,13 @@ enum RequestStatus {
RequestOkay, RequestFailure
};
+class ClientListener;
class Client: public Singleton<Client> {
private:
+ void * versionCheckRequest;
+ bool updateAvailable;
+
+
std::string lastError;
list<string> stampIDs;
@@ -46,13 +51,19 @@ private:
int activeThumbRequestCompleteTimes[IMGCONNS];
std::string activeThumbRequestIDs[IMGCONNS];
void updateStamps();
+
+ void notifyUpdateAvailable();
public:
+ vector<ClientListener*> listeners;
+
//Config file handle
json::Object configDocument;
Client();
~Client();
+ void AddListener(ClientListener * listener);
+
RequestStatus ExecVote(int saveID, int direction);
RequestStatus UploadSave(SaveInfo * save);
@@ -82,6 +93,7 @@ public:
std::string GetLastError() {
return lastError;
}
+ void Tick();
};
#endif // CLIENT_H
diff --git a/src/client/ClientListener.h b/src/client/ClientListener.h
new file mode 100644
index 0000000..308721c
--- /dev/null
+++ b/src/client/ClientListener.h
@@ -0,0 +1,22 @@
+/*
+ * ClientListener.h
+ *
+ * Created on: Jun 19, 2012
+ * Author: Simon
+ */
+
+#ifndef CLIENTLISTENER_H_
+#define CLIENTLISTENER_H_
+
+class Client;
+class ClientListener
+{
+public:
+ ClientListener() {}
+ virtual ~ClientListener() {}
+
+ virtual void NotifyUpdateAvailable(Client * sender) {}
+};
+
+
+#endif /* CLIENTLISTENER_H_ */