2012-01-19 07:44:59 -06:00
|
|
|
#ifndef CLIENT_H
|
|
|
|
#define CLIENT_H
|
|
|
|
|
|
|
|
#include <queue>
|
2012-01-19 14:10:05 -06:00
|
|
|
#include <vector>
|
2012-06-10 13:52:24 -05:00
|
|
|
#include <list>
|
2012-01-19 14:10:05 -06:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
#include "common/String.h"
|
2012-01-19 11:59:00 -06:00
|
|
|
#include "Config.h"
|
2016-03-27 10:41:36 -05:00
|
|
|
#include "common/Singleton.h"
|
2012-08-12 16:32:57 -05:00
|
|
|
|
2012-01-25 11:21:55 -06:00
|
|
|
#include "User.h"
|
2013-03-21 16:49:06 -05:00
|
|
|
#include "UserInfo.h"
|
2012-01-19 07:44:59 -06:00
|
|
|
|
2016-01-25 00:09:07 -06:00
|
|
|
#include "json/json.h"
|
2012-01-31 12:49:14 -06:00
|
|
|
|
2013-03-16 12:45:18 -05:00
|
|
|
#include "requestbroker/RequestBroker.h"
|
|
|
|
|
2012-08-12 16:32:57 -05:00
|
|
|
class Thumbnail;
|
|
|
|
class SaveInfo;
|
|
|
|
class SaveFile;
|
|
|
|
class SaveComment;
|
|
|
|
class GameSave;
|
2013-03-10 13:08:34 -05:00
|
|
|
class VideoBuffer;
|
2012-08-12 16:32:57 -05:00
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
enum LoginStatus {
|
2012-01-24 18:57:39 -06:00
|
|
|
LoginOkay, LoginError
|
2012-01-24 14:19:19 -06:00
|
|
|
};
|
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
enum RequestStatus {
|
|
|
|
RequestOkay, RequestFailure
|
|
|
|
};
|
|
|
|
|
2012-06-22 13:04:38 -05:00
|
|
|
class UpdateInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum BuildType { Stable, Beta, Snapshot };
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString File;
|
|
|
|
String Changelog;
|
2012-06-22 13:04:38 -05:00
|
|
|
int Major;
|
|
|
|
int Minor;
|
|
|
|
int Build;
|
2012-07-22 12:51:05 -05:00
|
|
|
int Time;
|
2012-06-22 13:04:38 -05:00
|
|
|
BuildType Type;
|
2015-09-26 10:47:51 -05:00
|
|
|
UpdateInfo() : File(""), Changelog(""), Major(0), Minor(0), Build(0), Time(0), Type(Stable) {}
|
2018-04-30 13:13:24 -05:00
|
|
|
UpdateInfo(int major, int minor, int build, ByteString file, String changelog, BuildType type) : File(file), Changelog(changelog), Major(major), Minor(minor), Build(build), Time(0), Type(type) {}
|
|
|
|
UpdateInfo(int time, ByteString file, String changelog, BuildType type) : File(file), Changelog(changelog), Major(0), Minor(0), Build(0), Time(time), Type(type) {}
|
2012-06-22 13:04:38 -05:00
|
|
|
};
|
|
|
|
|
2013-03-12 16:17:19 -05:00
|
|
|
class RequestListener;
|
2012-06-20 07:40:18 -05:00
|
|
|
class ClientListener;
|
2012-01-28 13:56:13 -06:00
|
|
|
class Client: public Singleton<Client> {
|
2012-01-19 07:44:59 -06:00
|
|
|
private:
|
2018-04-30 13:13:24 -05:00
|
|
|
String messageOfTheDay;
|
|
|
|
std::vector<std::pair<String, ByteString> > serverNotifications;
|
2012-08-12 09:15:47 -05:00
|
|
|
|
2012-06-20 07:40:18 -05:00
|
|
|
void * versionCheckRequest;
|
2015-09-26 10:47:51 -05:00
|
|
|
void * alternateVersionCheckRequest;
|
|
|
|
bool usingAltUpdateServer;
|
2012-06-20 07:40:18 -05:00
|
|
|
bool updateAvailable;
|
2012-06-22 13:04:38 -05:00
|
|
|
UpdateInfo updateInfo;
|
2012-06-20 07:40:18 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
String lastError;
|
2015-05-14 22:22:20 -05:00
|
|
|
bool firstRun;
|
2012-01-28 13:56:13 -06:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
std::list<ByteString> stampIDs;
|
2015-01-16 16:26:04 -06:00
|
|
|
unsigned lastStampTime;
|
2012-04-02 11:01:28 -05:00
|
|
|
int lastStampName;
|
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
//Auth session
|
|
|
|
User authUser;
|
|
|
|
|
|
|
|
//Thumbnail retreival
|
2012-01-19 07:44:59 -06:00
|
|
|
int thumbnailCacheNextID;
|
2012-01-19 11:59:00 -06:00
|
|
|
Thumbnail * thumbnailCache[THUMB_CACHE_SIZE];
|
|
|
|
void * activeThumbRequests[IMGCONNS];
|
|
|
|
int activeThumbRequestTimes[IMGCONNS];
|
|
|
|
int activeThumbRequestCompleteTimes[IMGCONNS];
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString activeThumbRequestIDs[IMGCONNS];
|
2012-06-20 07:40:18 -05:00
|
|
|
void notifyUpdateAvailable();
|
2012-07-17 13:14:05 -05:00
|
|
|
void notifyAuthUserChanged();
|
2012-08-12 09:15:47 -05:00
|
|
|
void notifyMessageOfTheDay();
|
2018-04-30 13:13:24 -05:00
|
|
|
void notifyNewNotification(std::pair<String, ByteString> notification);
|
2012-06-20 07:40:18 -05:00
|
|
|
|
2016-01-25 00:09:07 -06:00
|
|
|
// internal preferences handling
|
|
|
|
Json::Value preferences;
|
2018-04-30 13:13:24 -05:00
|
|
|
Json::Value GetPref(Json::Value root, ByteString prop, Json::Value defaultValue = Json::nullValue);
|
|
|
|
Json::Value SetPrefHelper(Json::Value root, ByteString prop, Json::Value value);
|
2017-07-12 23:19:35 -05:00
|
|
|
|
|
|
|
// Save stealing info
|
|
|
|
Json::Value authors;
|
|
|
|
|
2012-06-21 19:04:55 -05:00
|
|
|
public:
|
2012-07-31 13:49:08 -05:00
|
|
|
|
2012-08-12 16:32:57 -05:00
|
|
|
std::vector<ClientListener*> listeners;
|
2012-01-31 12:49:14 -06:00
|
|
|
|
2017-07-12 23:19:35 -05:00
|
|
|
// Save stealing info
|
|
|
|
void MergeStampAuthorInfo(Json::Value linksToAdd);
|
|
|
|
void MergeAuthorInfo(Json::Value linksToAdd);
|
|
|
|
void OverwriteAuthorInfo(Json::Value overwrite) { authors = overwrite; }
|
2017-07-15 15:21:16 -05:00
|
|
|
Json::Value GetAuthorInfo() { return authors; }
|
2017-07-12 23:19:35 -05:00
|
|
|
void SaveAuthorInfo(Json::Value *saveInto);
|
|
|
|
void ClearAuthorInfo() { authors.clear(); }
|
|
|
|
bool IsAuthorsEmpty() { return authors.size() == 0; }
|
|
|
|
|
2012-06-22 13:04:38 -05:00
|
|
|
UpdateInfo GetUpdateInfo();
|
|
|
|
|
2012-01-19 07:44:59 -06:00
|
|
|
Client();
|
|
|
|
~Client();
|
2012-01-28 13:56:13 -06:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
std::vector<ByteString> DirectorySearch(ByteString directory, ByteString search, std::vector<ByteString> extensions);
|
|
|
|
std::vector<ByteString> DirectorySearch(ByteString directory, ByteString search, ByteString extension);
|
2012-07-27 14:06:17 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString FileOpenDialogue();
|
2013-03-21 16:49:06 -05:00
|
|
|
//std::string FileSaveDialogue();
|
|
|
|
|
2012-08-10 09:41:39 -05:00
|
|
|
bool DoInstallation();
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
std::vector<unsigned char> ReadFile(ByteString filename);
|
2012-07-27 14:06:17 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
void AddServerNotification(std::pair<String, ByteString> notification);
|
|
|
|
std::vector<std::pair<String, ByteString> > GetServerNotifications();
|
2012-12-09 06:05:27 -06:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
void SetMessageOfTheDay(String message);
|
|
|
|
String GetMessageOfTheDay();
|
2012-08-12 09:15:47 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
void Initialise(ByteString proxyString);
|
|
|
|
void SetProxy(ByteString proxy);
|
2015-05-14 22:22:20 -05:00
|
|
|
bool IsFirstRun();
|
2012-08-08 12:34:37 -05:00
|
|
|
|
2012-10-19 18:17:15 -05:00
|
|
|
int MakeDirectory(const char * dirname);
|
2018-04-30 13:13:24 -05:00
|
|
|
bool WriteFile(std::vector<unsigned char> fileData, ByteString filename);
|
|
|
|
bool WriteFile(std::vector<char> fileData, ByteString filename);
|
|
|
|
bool FileExists(ByteString filename);
|
2012-08-01 16:29:22 -05:00
|
|
|
|
2012-06-20 07:40:18 -05:00
|
|
|
void AddListener(ClientListener * listener);
|
2012-07-17 13:14:05 -05:00
|
|
|
void RemoveListener(ClientListener * listener);
|
2012-06-20 07:40:18 -05:00
|
|
|
|
2012-01-28 13:56:13 -06:00
|
|
|
RequestStatus ExecVote(int saveID, int direction);
|
2012-08-01 16:29:22 -05:00
|
|
|
RequestStatus UploadSave(SaveInfo & save);
|
2012-01-28 13:56:13 -06:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
SaveFile * GetStamp(ByteString stampID);
|
|
|
|
void DeleteStamp(ByteString stampID);
|
|
|
|
ByteString AddStamp(GameSave * saveData);
|
|
|
|
std::vector<ByteString> GetStamps(int start, int count);
|
2012-10-05 09:46:42 -05:00
|
|
|
void RescanStamps();
|
2012-06-10 13:52:24 -05:00
|
|
|
int GetStampsCount();
|
|
|
|
SaveFile * GetFirstStamp();
|
2018-04-30 13:13:24 -05:00
|
|
|
void MoveStampToFront(ByteString stampID);
|
2014-11-11 22:48:36 -06:00
|
|
|
void updateStamps();
|
2012-04-02 11:01:28 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
RequestStatus AddComment(int saveID, String comment);
|
2012-07-18 07:07:33 -05:00
|
|
|
|
2013-03-16 12:45:18 -05:00
|
|
|
//Retrieves a "UserInfo" object
|
2018-04-30 13:13:24 -05:00
|
|
|
RequestBroker::Request * GetUserInfoAsync(ByteString username);
|
2013-03-21 16:49:06 -05:00
|
|
|
RequestBroker::Request * SaveUserInfoAsync(UserInfo info);
|
2013-03-10 13:08:34 -05:00
|
|
|
|
2013-07-27 06:38:52 -05:00
|
|
|
RequestBroker::Request * GetSaveDataAsync(int saveID, int saveDate);
|
2012-01-25 19:13:33 -06:00
|
|
|
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
2012-08-08 15:32:10 -05:00
|
|
|
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);
|
2013-07-27 06:38:52 -05:00
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
LoginStatus Login(ByteString username, ByteString password, User & user);
|
2012-01-19 07:44:59 -06:00
|
|
|
void ClearThumbnailRequests();
|
2018-04-30 13:13:24 -05:00
|
|
|
std::vector<SaveInfo*> * SearchSaves(int start, int count, String query, ByteString sort, ByteString category, int & resultCount);
|
|
|
|
std::vector<std::pair<ByteString, int> > * GetTags(int start, int count, String query, int & resultCount);
|
2013-07-28 04:30:01 -05:00
|
|
|
|
|
|
|
RequestBroker::Request * GetCommentsAsync(int saveID, int start, int count);
|
|
|
|
|
2012-06-07 08:23:26 -05:00
|
|
|
SaveInfo * GetSave(int saveID, int saveDate);
|
2013-07-28 04:30:01 -05:00
|
|
|
RequestBroker::Request * GetSaveAsync(int saveID, int saveDate);
|
|
|
|
|
2012-04-06 18:45:24 -05:00
|
|
|
RequestStatus DeleteSave(int saveID);
|
2018-04-30 13:13:24 -05:00
|
|
|
RequestStatus ReportSave(int saveID, String message);
|
2012-04-14 13:00:24 -05:00
|
|
|
RequestStatus UnpublishSave(int saveID);
|
2015-01-10 17:18:28 -06:00
|
|
|
RequestStatus PublishSave(int saveID);
|
2012-04-14 13:00:24 -05:00
|
|
|
RequestStatus FavouriteSave(int saveID, bool favourite);
|
2012-01-28 13:56:13 -06:00
|
|
|
void SetAuthUser(User user);
|
|
|
|
User GetAuthUser();
|
2018-04-30 13:13:24 -05:00
|
|
|
std::list<ByteString> * RemoveTag(int saveID, ByteString tag); //TODO RequestStatus
|
|
|
|
std::list<ByteString> * AddTag(int saveID, ByteString tag);
|
|
|
|
String GetLastError() {
|
2012-01-28 13:56:13 -06:00
|
|
|
return lastError;
|
|
|
|
}
|
2015-08-29 12:14:17 -05:00
|
|
|
RequestStatus ParseServerReturn(char *result, int status, bool json);
|
2012-06-20 07:40:18 -05:00
|
|
|
void Tick();
|
2015-09-26 10:47:51 -05:00
|
|
|
bool CheckUpdate(void *updateRequest, bool checkSession);
|
2012-06-21 19:04:55 -05:00
|
|
|
void Shutdown();
|
|
|
|
|
2016-01-25 00:09:07 -06:00
|
|
|
// preferences functions
|
2012-08-18 06:44:07 -05:00
|
|
|
void WritePrefs();
|
|
|
|
|
2018-04-30 13:13:24 -05:00
|
|
|
ByteString GetPrefByteString(ByteString prop, ByteString defaultValue);
|
|
|
|
String GetPrefString(ByteString prop, String defaultValue);
|
|
|
|
double GetPrefNumber(ByteString prop, double defaultValue);
|
|
|
|
int GetPrefInteger(ByteString prop, int defaultValue);
|
|
|
|
unsigned int GetPrefUInteger(ByteString prop, unsigned int defaultValue);
|
|
|
|
bool GetPrefBool(ByteString prop, bool defaultValue);
|
|
|
|
std::vector<ByteString> GetPrefByteStringArray(ByteString prop);
|
|
|
|
std::vector<String> GetPrefStringArray(ByteString prop);
|
|
|
|
std::vector<double> GetPrefNumberArray(ByteString prop);
|
|
|
|
std::vector<int> GetPrefIntegerArray(ByteString prop);
|
|
|
|
std::vector<unsigned int> GetPrefUIntegerArray(ByteString prop);
|
|
|
|
std::vector<bool> GetPrefBoolArray(ByteString prop);
|
|
|
|
|
|
|
|
void SetPref(ByteString prop, Json::Value value);
|
|
|
|
void SetPref(ByteString property, std::vector<Json::Value> value);
|
|
|
|
void SetPrefUnicode(ByteString prop, String value);
|
2012-01-19 07:44:59 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CLIENT_H
|