Emergency 20 Dokumentation  4.2.0
AccountManager.h
Go to the documentation of this file.
1 // Copyright (C) 2012-2018 Promotion Software GmbH
2 
3 
4 //[-------------------------------------------------------]
5 //[ Header guard ]
6 //[-------------------------------------------------------]
7 #pragma once
8 
9 
10 //[-------------------------------------------------------]
11 //[ Includes ]
12 //[-------------------------------------------------------]
14 
16 #include <qsf/forward/BoostPTree.h>
17 #include <qsf/job/JobProxy.h>
20 
21 #include <boost/signals2.hpp>
22 
23 #include <queue>
24 
25 
26 //[-------------------------------------------------------]
27 //[ Forward declarations ]
28 //[-------------------------------------------------------]
29 namespace qsf
30 {
31  class NamedIdentifier;
32 }
33 namespace em5
34 {
35  class Achievement;
36  class HighscoreManager;
37 }
38 
39 
40 //[-------------------------------------------------------]
41 //[ Namespace ]
42 //[-------------------------------------------------------]
43 namespace em5
44 {
45 
46 
47  //[-------------------------------------------------------]
48  //[ Classes ]
49  //[-------------------------------------------------------]
51  {
52  public:
53  std::string screenName;
54  std::string title;
59  bool firstLogin;
60 
61  inline OnlineAccountData() :
62  ep(qsf::getUninitialized<uint32>()),
63  totalScore(qsf::getUninitialized<uint32>()),
64  lastTitleScore(qsf::getUninitialized<uint32>()),
65  nextTitleScore(qsf::getUninitialized<uint32>()),
66  firstLogin(false)
67  {
68  // Nothing to do here
69  }
70 
71  const Achievement* getCurrentTitleAchievement() const;
72  };
73 
79  {
80 
81 
82  //[-------------------------------------------------------]
83  //[ Friend classes ]
84  //[-------------------------------------------------------]
85  friend PlayerProgress;
86  friend HighscoreManager;
87 
88 
89  //[-------------------------------------------------------]
90  //[ Public Boost signals ]
91  //[-------------------------------------------------------]
92  public:
93  boost::signals2::signal<void (const std::string&, const std::string&, std::string&, qsf::StringQueryParameters&)> LogInStringQueryParameters;
94  boost::signals2::signal<void (boost::property_tree::wptree&)> LogInResponsePTree;
95  boost::signals2::signal<void (std::string&, qsf::StringQueryParameters&)> LogOutStringQueryParameters;
96  boost::signals2::signal<void (std::string&, qsf::StringQueryParameters&)> QueryNewsEntryStringQueryParameters;
97  boost::signals2::signal<void (std::string&, qsf::StringQueryParameters&)> CloudListStringQueryParameters;
98  boost::signals2::signal<void (std::string&, qsf::MultipartFormPostData&)> CloudStoreMultipartFormPostData;
99  boost::signals2::signal<void (const std::string&, std::string&, qsf::MultipartFormPostData&)> CloudDeleteMultipartFormPostData;
100  boost::signals2::signal<void (const std::string&, std::string&, qsf::MultipartFormPostData&)> CloudLoadMultipartFormPostData;
101  boost::signals2::signal<void (boost::property_tree::ptree&)> CloudResponsePTree;
102 
103 
104  //[-------------------------------------------------------]
105  //[ Public definitions ]
106  //[-------------------------------------------------------]
107  public:
108  typedef std::vector<qsf::CookieComponents> SessionCookies;
109 
110  struct NewsEntry
111  {
113  std::string url;
114  std::string title;
115  std::string sub;
116  std::string text;
117  std::string date;
118  };
119 
121  {
123  parseAndDeleteDownloadedJsonFile(false)
124  {
125  // Nothing to do in here
126  }
127 
128  std::string absoluteFilename;
129  std::string url;
130  std::shared_ptr<qsf::MultipartFormPostData> postData;
131  boost::function<bool(const boost::property_tree::ptree&)> resultCallback;
133  };
134 
135 
136  //[-------------------------------------------------------]
137  //[ Public static methods ]
138  //[-------------------------------------------------------]
139  public:
140  static std::string getAccountDirectoryPath(const std::string& screenName);
141  static std::string getAccountTempJsonPath();
142 
143 
144  //[-------------------------------------------------------]
145  //[ Public methods ]
146  //[-------------------------------------------------------]
147  public:
152  AccountManager();
153 
158  virtual ~AccountManager();
159 
160  const std::string& getServerAddress() const;
161  void setServerAddress(const std::string& serverAddress);
162  void setSharedSecret(const std::string& sharedSecret); // No getter method for security reasons
163  const std::string& getCloudSyncDirectoryAndSlug() const;
164  const std::string& getGameSlug() const;
165  void setGameSlug(const std::string& gameSlug);
166  const std::string& getSlug() const;
167  void setCloudSyncDirectoryAndSlug(const std::string& directory, const std::string& slug);
168 
169  bool isLoggedIn() const;
170  void setCloudSyncPaused(bool paused);
171  const SessionCookies& getSessionCookies() const;
172  const OnlineAccountData& getOnlineAccountData() const;
173  std::string getAccountDirectoryPath() const;
174  bool save();
175  bool getConnectionError() const;
176 
177  //[-------------------------------------------------------]
178  //[ Lifecycle ]
179  //[-------------------------------------------------------]
180  bool startup();
181  void shutdown();
182 
183  //[-------------------------------------------------------]
184  //[ Server interactions ]
185  //[-------------------------------------------------------]
186  bool logIn(const std::string& loginName, const std::string& password, bool passwordAlreadyHashed = false);
187  void logOut();
188  bool setTitle(const qsf::NamedIdentifier& title);
189  bool queryNewsEntry(NewsEntry& entry);
190 
191  //[-------------------------------------------------------]
192  //[ Server interactions ]
193  //[-------------------------------------------------------]
195  void triggerCloudSync(bool forceBlockingAutosaveDownload = false);
196 
198  void tryTriggerCloudSync(bool forceBlockingAutosaveDownload = false);
199 
201  bool isCloudSyncActive() const;
202 
204  bool isCloudSyncLocalCopyOutdated() const;
205 
206 
207  //[-------------------------------------------------------]
208  //[ Protected methods ]
209  //[-------------------------------------------------------]
210  protected:
211  bool notifyAchievementProgress(const Achievement& achievement);
212  bool unlockMedal(const qsf::NamedIdentifier& medal, PlayerProgress::MedalType medalType);
213  bool setTotalScore(uint32 score);
214  uint32 submitHighscore(const std::string& ranking, const std::string& name, uint32 score, const std::string& group);
215 
216 
217  //[-------------------------------------------------------]
218  //[ Private methods ]
219  //[-------------------------------------------------------]
220  private:
221  std::string generateVerifyStringHash(const std::string& value) const;
222 
223  void queueHttpPostDownload(const std::string& url, const std::string& absoluteTargetFileName, std::shared_ptr<qsf::MultipartFormPostData> postData, boost::function<bool(const boost::property_tree::ptree&)> resultCallback = 0);
224  bool executeHttpPostDownload(const std::string& url, const std::string& absoluteTargetFileName, std::shared_ptr<qsf::MultipartFormPostData> postData, boost::function<bool(const boost::property_tree::ptree&)> resultCallback = 0);
225 
226  void queueHttpPostQuery(const std::string& url, std::shared_ptr<qsf::MultipartFormPostData> postData, boost::function<bool(const boost::property_tree::ptree&)> resultCallback = 0);
227  void queueHttpPostQuery(const std::string& url, const qsf::StringQueryParameters& postParameters, boost::function<bool(const boost::property_tree::ptree&)> resultCallback = 0);
228  bool executeHttpPostQuery(const std::string& url, std::shared_ptr<qsf::MultipartFormPostData> postData, boost::function<bool(const boost::property_tree::ptree&)> resultCallback = 0);
229  bool executeHttpPostQuery(const std::string& url, const qsf::StringQueryParameters& postParameters, boost::function<bool(const boost::property_tree::ptree&)> resultCallback = 0);
230 
231  void updateJob(const qsf::JobArguments& jobArguments);
232  void updateAchievementUpload(const qsf::JobArguments& jobArguments);
233  void updateCloudSynchronisationWindow();
234 
235  void onHttpPostQueryFinished();
236  void onHttpPostQueryFailed();
237 
238  bool handlePostQueryResponse();
239 
240  bool onSetTotalScoreHttpResponse(const boost::property_tree::ptree& resultPtree);
241  bool onSetAchievementProgressHttpResponse(const boost::property_tree::ptree& resultPtree);
242  bool onSetHighscoreHttpResponse(const boost::property_tree::ptree& resultPtree, uint32& rank);
243 
244  bool onCloudListFilesHttpResponse(const boost::property_tree::ptree& resultPtree);
245  bool onCloudLoadFileHttpResponse(const boost::property_tree::ptree& resultPtree, const std::string& absoluteFilename, std::time_t modificationDate);
246  bool onCloudDeleteFileHttpResponse(const boost::property_tree::ptree& resultPtree);
247  bool onCloudStoreFileHttpResponse(const boost::property_tree::ptree& resultPtree, const std::string& absoluteFilename, std::time_t localTimestamp);
248 
249  void updateCloudSyncStateFile();
250 
251  void onAchievementUpdated(const qsf::MessageParameters& parameters);
252  void onPlayerMedalUnlocked(const qsf::MessageParameters& parameters);
253  void onPlayerTotalScoreChanged(const qsf::MessageParameters& parameters);
254 
255 
256  //[-------------------------------------------------------]
257  //[ Private data ]
258  //[-------------------------------------------------------]
259  private:
260  std::string mServerAddress;
261  bool mIsLoggedIn;
262  bool mConnectionError;
263  OnlineAccountData mOnlineAccountData;
264  SessionCookies mSessionCookies;
265  bool mCloudSyncPaused;
266 
267  qsf::MessageProxy mAchievementMessageProxy;
268  qsf::MessageProxy mPlayerMedalMessageProxy;
269  qsf::MessageProxy mPlayerTotalScoreMessageProxy;
270 
271  qsf::JobProxy mJobProxy;
272  qsf::JobProxy mAchievementUploadJobProxy;
273 
274  std::queue<ProgressHttpPostQueryData> mHttpPostQueue;
275  qsf::HttpDownload* mCurrentProgressHttpPost;
276  boost::container::flat_set<const Achievement*> mAchievementsToUpload;
277 
278  bool mIsCloudSyncRescanQueued;
279  uint32 mNumberOfCloudSyncDownloadsQueued;
280  uint32 mNumberOfCloudSyncUploadsAndDeletesQueued;
281 
282 
283  };
284 
285 
286 //[-------------------------------------------------------]
287 //[ Namespace ]
288 //[-------------------------------------------------------]
289 } // em5
uint32 ep
Definition: AccountManager.h:55
Definition: ActionPriority.h:13
EMERGENCY 5 specialized achievement class.
Definition: Achievement.h:32
Job proxy class.
Definition: JobProxy.h:51
std::vector< qsf::CookieComponents > SessionCookies
Definition: AccountManager.h:108
Message parameters class.
Definition: MessageParameters.h:34
std::shared_ptr< qsf::MultipartFormPostData > postData
Definition: AccountManager.h:130
unsigned int uint32
Definition: PlatformTypes.h:181
uint32 nextTitleScore
Definition: AccountManager.h:58
uint32 lastTitleScore
Definition: AccountManager.h:57
#define EM5_API_EXPORT
Definition: Export.h:28
boost::signals2::signal< void(const std::string &, std::string &, qsf::MultipartFormPostData &)> CloudDeleteMultipartFormPostData
This Boost signal is emitted just before the string parameters are used for cloud delete...
Definition: AccountManager.h:99
boost::signals2::signal< void(std::string &, qsf::MultipartFormPostData &)> CloudStoreMultipartFormPostData
This Boost signal is emitted just before the string parameters are used for cloud store...
Definition: AccountManager.h:98
std::string title
Definition: AccountManager.h:54
boost::signals2::signal< void(boost::property_tree::wptree &)> LogInResponsePTree
This Boost signal is emitted after log-in response, can e.g. be used to transform the response to mak...
Definition: AccountManager.h:94
Message listener proxy class.
Definition: MessageProxy.h:47
boost::signals2::signal< void(const std::string &, const std::string &, std::string &, qsf::StringQueryParameters &)> LogInStringQueryParameters
This Boost signal is emitted just before the string parameters are used for log-in, log-in name as first parameter, password as second parameter, login URL as third parameter and current string query parameters as fourth parameter.
Definition: AccountManager.h:93
ProgressHttpPostQueryData()
Definition: AccountManager.h:122
std::string text
Definition: AccountManager.h:116
bool parseAndDeleteDownloadedJsonFile
Definition: AccountManager.h:132
EMERGENCY 5 player progress class.
Definition: PlayerProgress.h:57
boost::signals2::signal< void(const std::string &, std::string &, qsf::MultipartFormPostData &)> CloudLoadMultipartFormPostData
This Boost signal is emitted just before the string parameters are used for cloud load...
Definition: AccountManager.h:100
Definition: AccountManager.h:110
Job arguments class: holds data to be passed to the called job method by the job manager.
Definition: JobArguments.h:40
bool firstLogin
Definition: AccountManager.h:59
Abstract manager interface.
Definition: Manager.h:40
Definition: PickupPersonByParamedicAction.h:21
Definition: AccountManager.h:120
uint32 newsId
Definition: AccountManager.h:112
uint32 totalScore
Definition: AccountManager.h:56
std::string url
Definition: AccountManager.h:129
Definition: AccountManager.h:50
T getUninitialized()
Definition: GetUninitialized.h:38
std::string url
Definition: AccountManager.h:113
std::string date
Definition: AccountManager.h:117
Definition: DensityCalculator.h:29
HTTP download class.
Definition: HttpDownload.h:120
std::string sub
Definition: AccountManager.h:115
boost::signals2::signal< void(boost::property_tree::ptree &)> CloudResponsePTree
This Boost signal is emitted just before the cloud ptree response is processed, can e...
Definition: AccountManager.h:101
boost::signals2::signal< void(std::string &, qsf::StringQueryParameters &)> LogOutStringQueryParameters
This Boost signal is emitted just before the string parameters are used for log-out, log-out URL as first parameter and current string query parameters as second parameter.
Definition: AccountManager.h:95
Class combining strings with their hashes.
Definition: NamedIdentifier.h:34
EMERGENCY 5 network manager class.
Definition: AccountManager.h:78
boost::signals2::signal< void(std::string &, qsf::StringQueryParameters &)> CloudListStringQueryParameters
This Boost signal is emitted just before the string parameters are used for cloud list...
Definition: AccountManager.h:97
boost::container::flat_map< std::string, std::string > StringQueryParameters
Definition: HttpDownload.h:38
OnlineAccountData()
Definition: AccountManager.h:61
boost::function< bool(const boost::property_tree::ptree &)> resultCallback
Definition: AccountManager.h:131
std::string absoluteFilename
Definition: AccountManager.h:128
EMERGENCY 5 highscore manager class.
Definition: HighscoreManager.h:90
boost::signals2::signal< void(std::string &, qsf::StringQueryParameters &)> QueryNewsEntryStringQueryParameters
This Boost signal is emitted just before the string parameters are used for query news entry...
Definition: AccountManager.h:96
MedalType
Definition: PlayerProgress.h:84
std::string screenName
Definition: AccountManager.h:53
std::string title
Definition: AccountManager.h:114