iFun Engine API  1.0.0-b2936
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
leaderboard.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2015 iFunFactory Inc. All Rights Reserved.
2 //
3 // This work is confidential and proprietary to iFunFactory Inc. and
4 // must not be used, disclosed, copied, or distributed without the prior
5 // consent of iFunFactory Inc.
6 
9 #ifndef INCLUDE_FUNAPI_SERVICE_LEADERBOARD_H_
10 #define INCLUDE_FUNAPI_SERVICE_LEADERBOARD_H_
11 
12 #include <funapi/player_account.h>
13 #include <funapi/time/wall_clock.h>
14 #include <funapi/types.h>
15 
16 #include <sstream>
17 #include <vector>
18 
19 
20 namespace fun {
21 
22 enum LeaderboardCollection {
23  kSocial = 1,
24  kPublic = 2
25 };
26 
27 
28 enum LeaderboardTimespan {
29  kAllTime = 1,
30 
31  kDaily = 2,
32  kWeekly = 3,
33  kMonthly = 6,
34 
35  kYesterday = 5,
36  kLastWeek = 4,
37  kLastMonth = 7
38 };
39 
40 
42  enum Type {
43  kAll = 1,
44  kFromTop = 2,
45  kNearby = 3
46  };
47 
49  LeaderboardRange(const Type &in_type,
50  const int64_t &in_begin,
51  const int64_t &in_end);
52 
53  Type type;
54  int64_t begin;
55  int64_t end;
56 };
57 
58 
60  LeaderboardRecord(const int64_t &in_rank,
61  const PlayerAccount &in_player_account,
62  const double &in_score,
63  const double &in_percentage);
64 
65  int64_t rank;
66  PlayerAccount player_account;
67  double score;
68  double percentage;
69 };
70 
71 
72 typedef std::vector<LeaderboardRecord> LeaderboardRecordVector;
73 
74 
75 enum LeaderboardScoreSubmissionResult {
76  kNone = 1,
77  kNewRecord = 2,
78  kNewRecordDaily = 3,
79  kNewRecordWeekly = 4,
80  kNewRecordMonthly = 5
81 };
82 
83 
85  enum RankingType {
86  // Update score(do not get ranking)
87  kNone = 0,
88  // 1234 ranking
89  kOrdinal = 1,
90  // 1224 ranking
91  kStdCompetition = 2,
92  // 1223 ranking
93  kDense = 3
94  };
95 
96  // kPublic collection, kFromTop or kAll range
97  LeaderboardQueryRequest(const string &in_leaderboard_id,
98  const LeaderboardTimespan &in_timespan,
99  const LeaderboardRange &in_range,
100  const RankingType &in_ranking_type = kOrdinal);
101  // kPublic collection, kNearby range
102  LeaderboardQueryRequest(const string &in_leaderboard_id,
103  const string &in_service_provider,
104  const string &in_id,
105  const LeaderboardTimespan &in_timespan,
106  const LeaderboardRange &in_range,
107  const RankingType &in_ranking_type = kOrdinal);
108  // kSocial collection, kAll range
109  LeaderboardQueryRequest(const string &in_leaderboard_id,
110  const string &in_service_provider,
111  const string &in_id,
112  const PlayerAccountVector &in_competitors,
113  const LeaderboardTimespan &in_timespan,
114  const RankingType &in_ranking_type = kOrdinal);
115 
116  string leaderboard_id;
117  PlayerAccount player_account;
118  LeaderboardCollection collection;
119  PlayerAccountVector competitors;
120  LeaderboardTimespan timespan;
121  LeaderboardRange range;
122  RankingType ranking_type;
123 };
124 
125 typedef std::vector<LeaderboardQueryRequest> LeaderboardQueryRequestVector;
126 
127 
130 
131  int64_t total_player_count;
132  LeaderboardRecordVector records;
133 };
134 
135 typedef std::vector<LeaderboardQueryResponse> LeaderboardQueryResponseVector;
136 
137 
139  enum Type {
140  // update player score if given score is highest
141  kHighScore = 0,
142 
143  // increase player score
144  kIncrement = 1,
145 
146  // decrease player score
147  kDecrement = 2,
148 
149  // overwrite player score
150  kOverwriting = 3,
151  };
152 
154  const string &in_leaderboard_id,
155  const string &in_service_provider,
156  const string &in_id,
157  const double &in_score,
158  const Type &in_type = kHighScore);
159 
160  // Appending my rank to ScoreSubmissionResponse
162  const string &in_leaderboard_id,
163  const string &in_service_provider,
164  const string &in_id,
165  const double &in_score,
166  const LeaderboardQueryRequest::RankingType &in_ranking_type,
167  const LeaderboardTimespan &in_timespan,
168  const Type &in_type = kHighScore);
169 
170  string leaderboard_id;
171  PlayerAccount player_account;
172  double score;
173  LeaderboardQueryRequest::RankingType ranking_type;
174  LeaderboardTimespan timespan;
175  Type type;
176 };
177 
178 
181 
182  LeaderboardScoreSubmissionResult result;
183  double new_score;
184  int64_t total_player_count;
185  int64_t rank;
186  double percentage;
187 };
188 
189 
191  ScoreDeletionRequest(const string &in_leaderboard_id,
192  const string &in_service_provider,
193  const string &in_id);
194 
195  string leaderboard_id;
196  PlayerAccount player_account;
197 };
198 
199 typedef std::vector<ScoreDeletionRequest> ScoreDeletionRequestVector;
200 
201 
203  enum Result {
204  kNotExist = 0,
205  kDeleted = 1
206  };
207 
209 
210  Result result;
211 };
212 
213 typedef std::vector<ScoreDeletionResponse> ScoreDeletionResponseVector;
214 
215 
217  explicit LeaderboardResetRequest(const string &leaderboard_id);
218 
219  const string leaderboard_id;
220 };
221 
222 
225 
226  bool already_reset;
227  string reset_date_time;
228 };
229 
230 
232  enum Period {
233  kDay = 0,
234  kWeek = 1,
235  kMonth = 2
236  };
237 
239 
240  LeaderboardResetSchedule(const string &leaderboard_id,
241  const Period &period,
242  const int64_t &interval,
243  const WallClock::Value &starts,
244  const WallClock::Value &ends);
245 
246  string leaderboard_id;
247  Period period;
248  int64_t interval;
249  WallClock::Value starts;
250  WallClock::Value ends;
251 
252  WallClock::Value latest_reset_date_time;
253  WallClock::Value upcoming_date_time;
254  WallClock::Duration upcoming_time;
255  WallClock::Value next_date_time;
256  WallClock::Duration next_time;
257  bool expired;
258 };
259 
260 
261 typedef std::vector<LeaderboardResetSchedule> LeaderboardResetScheduleVector;
262 
263 
265  typedef LeaderboardResetSchedule::Period Period;
266 
268  const string &leaderboard_id,
269  Period period,
270  const WallClock::Value &latest_reset_date_time);
271 
272  const string leaderboard_id;
273  const Period period;
274  const string latest_reset_date_time;
275 };
276 
277 
279  enum Result {
280  kOk = 0,
281  kNotExist = 1
282  };
283 
285 
286  Result result;
287  bool is_reset;
288  WallClock::Value reset_date_time;
289 };
290 
291 
292 typedef function<void(const LeaderboardQueryRequest &request,
293  const LeaderboardQueryResponse &response,
294  const bool &error)> LeaderboardQueryResponseHandler;
295 
296 typedef function<void(const LeaderboardQueryRequestVector &requests,
297  const LeaderboardQueryResponseVector &responses,
298  const bool &error)> LeaderboardQueryResponseHandler2;
299 
300 
301 typedef function<void(const ScoreSubmissionRequest &request,
302  const ScoreSubmissionResponse &response,
303  const bool &error)> ScoreSubmissionResponseHandler;
304 
305 
306 typedef function<void(const ScoreDeletionRequestVector &requests,
307  const ScoreDeletionResponseVector &responses,
308  const bool &error)> ScoreDeletionResponseHandler;
309 
310 
311 typedef function<void(const LeaderboardResetRequest &request,
312  const LeaderboardResetResponse &response,
313  const bool &error)> LeaderboardResetResponseHandler;
314 
315 typedef function<
316  void(const LeaderboardResetScheduleStatusQueryRequest &request,
318  const bool &error)> LeaderboardResetScheduleStatusQueryResponseHandler;
319 
320 
321 void GetLeaderboard(const LeaderboardQueryRequest &request,
322  const LeaderboardQueryResponseHandler &handler,
323  const string &tag = "");
324 
325 void GetLeaderboard(const LeaderboardQueryRequestVector &requests,
326  const LeaderboardQueryResponseHandler2 &handler,
327  const string &tag = "");
328 
329 bool GetLeaderboardSync(const LeaderboardQueryRequest &request,
330  LeaderboardQueryResponse *response,
331  const string &tag = "");
332 
333 bool GetLeaderboardSync(const LeaderboardQueryRequestVector &requests,
334  LeaderboardQueryResponseVector *responses,
335  const string &tag = "");
336 
337 
338 void SubmitScore(const ScoreSubmissionRequest &request,
339  const ScoreSubmissionResponseHandler &handler,
340  const string &tag = "");
341 bool SubmitScoreSync(const ScoreSubmissionRequest &request,
342  ScoreSubmissionResponse *response,
343  const string &tag = "");
344 
345 
346 void DeleteScore(const ScoreDeletionRequestVector &requests,
347  const ScoreDeletionResponseHandler &handler,
348  const string &tag = "");
349 
350 bool DeleteScoreSync(const ScoreDeletionRequestVector &requests,
351  ScoreDeletionResponseVector *responses,
352  const string &tag = "");
353 
354 
355 void ResetLeaderboard(const LeaderboardResetRequest &request,
356  const LeaderboardResetResponseHandler &handler,
357  const string &tag = "");
358 
359 
360 bool GetLeaderboardResetSchedule(const string &leaderboard_id,
361  const LeaderboardResetSchedule::Period &period,
362  LeaderboardResetSchedule *reset_schedule,
363  const string &tag = "");
364 
365 bool GetLeaderboardResetSchedule(
366  LeaderboardResetScheduleVector *reset_schedules,
367  const string &tag = "");
368 
369 
370 void GetLeaderboardResetScheduleStatusQuery(
372  const LeaderboardResetScheduleStatusQueryResponseHandler &handler,
373  const string &tag = "");
374 
375 bool GetLeaderboardResetScheduleStatusQuerySync(
378  const string &tag = "");
379 
380 } // namespace fun
381 
382 #endif // INCLUDE_FUNAPI_SERVICE_LEADERBOARD_H_
Definition: leaderboard.h:41
Definition: leaderboard.h:84
Definition: leaderboard.h:179
Account Id.
Definition: player_account.h:20
Definition: leaderboard.h:223
Definition: leaderboard.h:202
Definition: leaderboard.h:216
Definition: leaderboard.h:59
Definition: leaderboard.h:138
Definition: leaderboard.h:231
Definition: leaderboard.h:128
Definition: leaderboard.h:190