Emergency 20 Dokumentation  4.2.0
HighscoreManager.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 //[ Includes ]
11 //[-------------------------------------------------------]
13 
16 #include <qsf/time/DateTime.h>
17 
18 #include <boost/container/flat_set.hpp>
19 
20 #include <map>
21 
22 
23 //[-------------------------------------------------------]
24 //[ Namespace ]
25 //[-------------------------------------------------------]
26 namespace em5
27 {
28 
29 
30  //[-------------------------------------------------------]
31  //[ Global definitions ]
32  //[-------------------------------------------------------]
34  {
37  std::string name;
38 
39  inline HighscoreEntry() :
40  score(qsf::getUninitialized<uint32>())
41  {
42  // Nothing to do in here
43  }
44 
45  inline HighscoreEntry(uint32 score, const qsf::DateTime& date, const std::string& name) :
46  score(score),
47  date(date),
48  name(name)
49  {
50  // Nothing to do in here
51  }
52 
53  inline bool operator<(const HighscoreEntry& rhs) const
54  {
55  return (score < rhs.score || (score == rhs.score && (date < rhs.date || (date == rhs.date && name < rhs.name))));
56  }
57  };
58 
60  {
63  std::string token;
64  };
65 
67  {
68  std::string token;
69  };
70 
72  {
79  std::vector<HighscoreOnlinePageEntry> entries;
80  };
81 
82 
83  //[-------------------------------------------------------]
84  //[ Classes ]
85  //[-------------------------------------------------------]
91  {
92 
93 
94  //[-------------------------------------------------------]
95  //[ Public definitions ]
96  //[-------------------------------------------------------]
97  public:
98  // The ordering is the same as in MapIdentifier
99  enum Map
100  {
101  MAP_UNKNOWN = -1,
102  MAP_MUNICH = 0,
103  MAP_HAMBURG = 1,
104  MAP_BERLIN = 2,
105  MAP_COLOGNE = 3,
106  };
107 
108 
109  //[-------------------------------------------------------]
110  //[ Public static methods ]
111  //[-------------------------------------------------------]
112  public:
113  static std::string getMainEventRankingId(Map map, uint32 mainEventNumber);
114  static std::string getFreeplayEndlessRankingId(Map map);
115  static std::string getFreeplayChallengeRankingId(Map map);
116  static std::string getMultiplayerRankingId(Map map, em5::multiplayer::GameMode gameMode, uint32 numberOfPlayers, uint32 duration);
117 
118 
119  //[-------------------------------------------------------]
120  //[ Public methods ]
121  //[-------------------------------------------------------]
122  public:
128 
133  virtual ~HighscoreManager();
134 
135  //[-------------------------------------------------------]
136  //[ Local highscores ]
137  //[-------------------------------------------------------]
138  uint32 submitLocalHighscore(const std::string& rankingId, const std::string& name, uint32 score);
139  const boost::container::flat_set<HighscoreEntry>& getLocalHighscores(const std::string& rankingId);
140 
141  //[-------------------------------------------------------]
142  //[ Online highscores ]
143  //[-------------------------------------------------------]
144  /*
145  * @return
146  * Rank
147  */
148  uint32 submitOnlineHighscore(const std::string& rankingId, const std::string& name, uint32 score, const std::string& group = "");
149 
150  bool getOnlineHighscorePage(const std::string& rankingId, uint32 pageIndex, HighscoreOnlinePage& output);
151 
152  bool getOnlineHighscoreSingleUserEntry(const std::string& rankingId, const std::string& name, HighscoreOnlineEntry& output);
153 
154 
155  //[-------------------------------------------------------]
156  //[ Private methods ]
157  //[-------------------------------------------------------]
158  private:
159  boost::container::flat_set<HighscoreEntry>& getLocalHighscoreSet(const std::string& rankingId);
160  bool saveLocalHighscore(const std::string& rankingId, const boost::container::flat_set<HighscoreEntry>& entries);
161  bool loadLocalHighscore(const std::string& rankingId, boost::container::flat_set<HighscoreEntry>& entries);
162  void serialize(qsf::BinarySerializer& serializer, boost::container::flat_set<HighscoreEntry>& entries);
163 
164  // Older version support
165  void loadLocalHighscoreVersion1(const std::string& rankingId, boost::container::flat_set<HighscoreEntry>& entries);
166 
167 
168  //[-------------------------------------------------------]
169  //[ Private data ]
170  //[-------------------------------------------------------]
171  private:
172  std::map<uint32, boost::container::flat_set<HighscoreEntry>> mLocalHighscores;
173 
174 
175  };
176 
177 
178 //[-------------------------------------------------------]
179 //[ Namespace ]
180 //[-------------------------------------------------------]
181 } // em5
uint32 rank
Definition: HighscoreManager.h:62
Definition: ActionPriority.h:13
Data type for encapsulating date time information (in UTC)
Definition: DateTime.h:37
Map
Definition: HighscoreManager.h:99
uint32 to
Definition: HighscoreManager.h:78
unsigned int uint32
Definition: PlatformTypes.h:181
#define EM5_API_EXPORT
Definition: Export.h:28
Definition: HighscoreManager.h:59
std::vector< HighscoreOnlinePageEntry > entries
Definition: HighscoreManager.h:79
uint32 lastPage
Definition: HighscoreManager.h:76
uint32 total
Definition: HighscoreManager.h:73
void serialize(BinarySerializer &serializer, BitFlagSet< STORAGE, ENUM > &bitFlagSet)
Definition: BitFlagSet.h:359
Abstract manager interface.
Definition: Manager.h:40
GameMode
< Connected to CAMP
Definition: MatchmakingTypes.h:41
Definition: PickupPersonByParamedicAction.h:21
Definition: HighscoreManager.h:66
std::string name
Definition: HighscoreManager.h:37
bool operator<(const HighscoreEntry &rhs) const
Definition: HighscoreManager.h:53
T getUninitialized()
Definition: GetUninitialized.h:38
std::string token
Definition: HighscoreManager.h:68
Definition: HighscoreManager.h:71
Definition: HighscoreManager.h:33
uint32 score
Definition: HighscoreManager.h:35
uint32 from
Definition: HighscoreManager.h:77
uint32 currentPage
Definition: HighscoreManager.h:75
HighscoreEntry(uint32 score, const qsf::DateTime &date, const std::string &name)
Definition: HighscoreManager.h:45
uint32 perPage
Definition: HighscoreManager.h:74
HighscoreEntry()
Definition: HighscoreManager.h:39
Binary serializer class.
Definition: BinarySerializer.h:35
EMERGENCY 5 highscore manager class.
Definition: HighscoreManager.h:90
uint32 id
Definition: HighscoreManager.h:61
std::string token
Definition: HighscoreManager.h:63
qsf::DateTime date
Definition: HighscoreManager.h:36