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

100 lines
2.5 KiB
C
Raw Normal View History

#ifndef CLIENT_H
#define CLIENT_H
#include <queue>
#include <vector>
#include <list>
#include <fstream>
2012-01-19 11:59:00 -06:00
#include "Config.h"
#include "HTTP.h"
#include "preview/Comment.h"
#include "search/Thumbnail.h"
#include "client/SaveInfo.h"
#include "client/SaveFile.h"
#include "Singleton.h"
2012-01-25 11:21:55 -06:00
#include "User.h"
#include "cajun/reader.h"
#include "cajun/writer.h"
#include "cajun/elements.h"
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 ClientListener;
2012-01-28 13:56:13 -06:00
class Client: public Singleton<Client> {
private:
void * versionCheckRequest;
bool updateAvailable;
std::string lastError;
2012-01-28 13:56:13 -06:00
list<string> stampIDs;
int 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 updateStamps();
void notifyUpdateAvailable();
public:
vector<ClientListener*> listeners;
//Config file handle
json::Object configDocument;
Client();
~Client();
2012-01-28 13:56:13 -06:00
void AddListener(ClientListener * listener);
2012-01-28 13:56:13 -06:00
RequestStatus ExecVote(int saveID, int direction);
RequestStatus UploadSave(SaveInfo * save);
2012-01-28 13:56:13 -06:00
SaveFile * GetStamp(string stampID);
void DeleteStamp(string stampID);
string AddStamp(GameSave * saveData);
vector<string> GetStamps(int start, int count);
int GetStampsCount();
SaveFile * GetFirstStamp();
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
2012-01-25 11:21:55 -06:00
LoginStatus Login(string username, string password, User & user);
void ClearThumbnailRequests();
std::vector<SaveInfo*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
std::vector<SaveComment*> * GetComments(int saveID, int start, int count);
Thumbnail * GetPreview(int saveID, int saveDate);
Thumbnail * GetThumbnail(int saveID, int saveDate);
SaveInfo * GetSave(int saveID, int saveDate);
RequestStatus DeleteSave(int saveID);
RequestStatus ReportSave(int saveID, std::string message);
RequestStatus UnpublishSave(int saveID);
RequestStatus FavouriteSave(int saveID, bool favourite);
2012-01-28 13:56:13 -06:00
void SetAuthUser(User user);
User GetAuthUser();
std::vector<string> * RemoveTag(int saveID, string tag); //TODO RequestStatus
std::vector<string> * AddTag(int saveID, string tag);
2012-01-28 13:56:13 -06:00
std::string GetLastError() {
return lastError;
}
void Tick();
};
#endif // CLIENT_H