iFun Engine API  1.0.0-b6053
Great Technology for Great Games
leaderboard.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2020 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 
41 struct FUNAPI_DLL_VISIBILITY LeaderboardRange {
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 
59 struct FUNAPI_DLL_VISIBILITY LeaderboardRecord {
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 
84 struct FUNAPI_DLL_VISIBILITY LeaderboardQueryRequest {
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 
128 struct FUNAPI_DLL_VISIBILITY LeaderboardQueryResponse {
130 
131  int64_t total_player_count;
132  LeaderboardRecordVector records;
133 };
134 
135 typedef std::vector<LeaderboardQueryResponse> LeaderboardQueryResponseVector;
136 
137 
138 struct FUNAPI_DLL_VISIBILITY ScoreSubmissionRequest {
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 
179 struct FUNAPI_DLL_VISIBILITY ScoreSubmissionResponse {
181 
182  LeaderboardScoreSubmissionResult result;
183  double new_score;
184  int64_t total_player_count;
185  int64_t rank;
186  double percentage;
187 };
188 
189 
190 struct FUNAPI_DLL_VISIBILITY ScoreDeletionRequest {
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 
202 struct FUNAPI_DLL_VISIBILITY ScoreDeletionResponse {
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 
216 struct FUNAPI_DLL_VISIBILITY LeaderboardResetRequest {
217  explicit LeaderboardResetRequest(const string &leaderboard_id);
218 
219  const string leaderboard_id;
220 };
221 
222 
223 struct FUNAPI_DLL_VISIBILITY LeaderboardResetResponse {
225 
226  bool already_reset;
227  string reset_date_time;
228 };
229 
230 
231 struct FUNAPI_DLL_VISIBILITY LeaderboardResetSchedule {
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 
264 struct FUNAPI_DLL_VISIBILITY LeaderboardResetScheduleStatusQueryRequest {
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 
278 struct FUNAPI_DLL_VISIBILITY LeaderboardResetScheduleStatusQueryResponse {
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 FUNAPI_DLL_VISIBILITY
322 void GetLeaderboard(const LeaderboardQueryRequest &request,
323  const LeaderboardQueryResponseHandler &handler,
324  const string &tag = "");
325 
326 FUNAPI_DLL_VISIBILITY
327 void GetLeaderboard(const LeaderboardQueryRequestVector &requests,
328  const LeaderboardQueryResponseHandler2 &handler,
329  const string &tag = "");
330 
331 FUNAPI_DLL_VISIBILITY
332 bool GetLeaderboardSync(const LeaderboardQueryRequest &request,
333  LeaderboardQueryResponse *response,
334  const string &tag = "");
335 
336 FUNAPI_DLL_VISIBILITY
337 bool GetLeaderboardSync(const LeaderboardQueryRequestVector &requests,
338  LeaderboardQueryResponseVector *responses,
339  const string &tag = "");
340 
341 FUNAPI_DLL_VISIBILITY
342 void SubmitScore(const ScoreSubmissionRequest &request,
343  const ScoreSubmissionResponseHandler &handler,
344  const string &tag = "");
345 
346 FUNAPI_DLL_VISIBILITY
347 bool SubmitScoreSync(const ScoreSubmissionRequest &request,
348  ScoreSubmissionResponse *response,
349  const string &tag = "");
350 
351 FUNAPI_DLL_VISIBILITY
352 void DeleteScore(const ScoreDeletionRequestVector &requests,
353  const ScoreDeletionResponseHandler &handler,
354  const string &tag = "");
355 
356 FUNAPI_DLL_VISIBILITY
357 bool DeleteScoreSync(const ScoreDeletionRequestVector &requests,
358  ScoreDeletionResponseVector *responses,
359  const string &tag = "");
360 
361 FUNAPI_DLL_VISIBILITY
362 void ResetLeaderboard(const LeaderboardResetRequest &request,
363  const LeaderboardResetResponseHandler &handler,
364  const string &tag = "");
365 
366 FUNAPI_DLL_VISIBILITY
367 bool GetLeaderboardResetSchedule(const string &leaderboard_id,
368  const LeaderboardResetSchedule::Period &period,
369  LeaderboardResetSchedule *reset_schedule,
370  const string &tag = "");
371 
372 FUNAPI_DLL_VISIBILITY
373 bool GetLeaderboardResetSchedule(
374  LeaderboardResetScheduleVector *reset_schedules,
375  const string &tag = "");
376 
377 FUNAPI_DLL_VISIBILITY
378 void GetLeaderboardResetScheduleStatusQuery(
380  const LeaderboardResetScheduleStatusQueryResponseHandler &handler,
381  const string &tag = "");
382 
383 FUNAPI_DLL_VISIBILITY
384 bool GetLeaderboardResetScheduleStatusQuerySync(
387  const string &tag = "");
388 
389 } // namespace fun
390 
391 #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: json.h:18
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