summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-12 14:15:47 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-12 14:15:47 (GMT)
commit5d3d1d4916cf6d126b54c8bbfb9ba67e27a2e789 (patch)
treec25f80f42de7d771011f5809bb34ea58d6f50938 /src/client
parent08b4e5553aa10df74c4fdb0ba519fb700fa8100b (diff)
downloadpowder-5d3d1d4916cf6d126b54c8bbfb9ba67e27a2e789.zip
powder-5d3d1d4916cf6d126b54c8bbfb9ba67e27a2e789.tar.gz
Message of the day and user session check on startup
Diffstat (limited to 'src/client')
-rw-r--r--src/client/Client.cpp48
-rw-r--r--src/client/Client.h6
-rw-r--r--src/client/ClientListener.h1
3 files changed, 51 insertions, 4 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index c546813..9908e69 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -24,6 +24,7 @@
#endif
#include "Config.h"
+#include "Format.h"
#include "Client.h"
#include "MD5.h"
#include "graphics/Graphics.h"
@@ -129,7 +130,12 @@ void Client::Initialise(std::string proxyString)
stampsLib.close();
//Begin version check
- versionCheckRequest = http_async_req_start(NULL, SERVER "/Download/Version.json", NULL, 0, 1);
+ versionCheckRequest = http_async_req_start(NULL, SERVER "/Startup.json", NULL, 0, 1);
+
+ if(authUser.ID)
+ {
+ http_auth_headers(versionCheckRequest, (char *)format::NumberToString<int>(authUser.ID).c_str(), NULL, (char *)authUser.SessionID.c_str());
+ }
}
bool Client::DoInstallation()
@@ -485,6 +491,17 @@ std::vector<unsigned char> Client::ReadFile(std::string filename)
}
}
+void Client::SetMessageOfTheDay(std::string message)
+{
+ messageOfTheDay = message;
+ notifyMessageOfTheDay();
+}
+
+std::string Client::GetMessageOfTheDay()
+{
+ return messageOfTheDay;
+}
+
void Client::Tick()
{
//Check thumbnail queue
@@ -512,9 +529,24 @@ void Client::Tick()
json::Object objDocument;
json::Reader::Read(objDocument, dataStream);
- json::Object stableVersion = objDocument["Stable"];
- json::Object betaVersion = objDocument["Beta"];
- json::Object snapshotVersion = objDocument["Snapshot"];
+ //Check session
+ json::Boolean sessionStatus = objDocument["Session"];
+ if(!sessionStatus.Value())
+ {
+ authUser = User(0, "");
+ }
+
+ //MOTD
+ json::String messageOfTheDay = objDocument["MessageOfTheDay"];
+ this->messageOfTheDay = messageOfTheDay.Value();
+ notifyMessageOfTheDay();
+
+ //Check for updates
+ json::Object versions = objDocument["Updates"];
+
+ json::Object stableVersion = versions["Stable"];
+ json::Object betaVersion = versions["Beta"];
+ json::Object snapshotVersion = versions["Snapshot"];
json::Number stableMajor = stableVersion["Major"];
json::Number stableMinor = stableVersion["Minor"];
@@ -580,6 +612,14 @@ void Client::notifyUpdateAvailable()
}
}
+void Client::notifyMessageOfTheDay()
+{
+ for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator)
+ {
+ (*iterator)->NotifyMessageOfTheDay(this);
+ }
+}
+
void Client::notifyAuthUserChanged()
{
for (std::vector<ClientListener*>::iterator iterator = listeners.begin(), end = listeners.end(); iterator != end; ++iterator)
diff --git a/src/client/Client.h b/src/client/Client.h
index 8812496..31f1fa1 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -46,6 +46,8 @@ class ThumbnailListener;
class ClientListener;
class Client: public Singleton<Client> {
private:
+ std::string messageOfTheDay;
+
void * versionCheckRequest;
bool updateAvailable;
UpdateInfo updateInfo;
@@ -71,6 +73,7 @@ private:
static vector<std::string> explodePropertyString(std::string property);
void notifyUpdateAvailable();
void notifyAuthUserChanged();
+ void notifyMessageOfTheDay();
//Config file handle
json::Object configDocument;
@@ -90,6 +93,9 @@ public:
std::vector<unsigned char> ReadFile(std::string filename);
+ void SetMessageOfTheDay(std::string message);
+ std::string GetMessageOfTheDay();
+
void Initialise(std::string proxyString);
void SetProxy(std::string proxy);
diff --git a/src/client/ClientListener.h b/src/client/ClientListener.h
index 4fc2d89..07e784c 100644
--- a/src/client/ClientListener.h
+++ b/src/client/ClientListener.h
@@ -17,6 +17,7 @@ public:
virtual void NotifyUpdateAvailable(Client * sender) {}
virtual void NotifyAuthUserChanged(Client * sender) {}
+ virtual void NotifyMessageOfTheDay(Client * sender) {}
};