The-Powder-Toy/src/client/Client.h

209 lines
6.7 KiB
C
Raw Normal View History

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