iFun Engine API  1.0.0-b2601
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
matchmaking.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_MATCHMAKING_H_
10 #define INCLUDE_FUNAPI_SERVICE_MATCHMAKING_H_
11 
12 #include <funapi/common/json.h>
15 #include <funapi/time/wall_clock.h>
16 #include <funapi/types.h>
17 
18 
19 namespace fun {
20 
22  public:
23  typedef Uuid MatchId;
24  typedef int64_t Type;
25 
26  struct Player {
27  string id;
28  Json context;
29  Rpc::PeerId location;
30  };
31 
32  struct Match {
33  explicit Match(Type _type);
34  explicit Match(const MatchId &_match_id, Type _type);
35 
36  const MatchId match_id;
37  const Type type;
38 
39  std::vector<Player> players;
40  Json context;
41  };
42 
43  enum MatchResult {
44  kMRSuccess = 0,
45  kMRAlreadyRequested,
46  kMRTimeout,
47  kMRError = 1000
48  };
49 
50  enum CancelResult {
51  kCRSuccess = 0,
52  kCRNoRequest,
53  kCRError = 1000
54  };
55 
56  typedef function<void(const string & /*player_id*/,
57  const Match & /*match*/,
58  MatchResult /*result*/)> MatchCallback;
59 
60  typedef function<void(const string & /*player_id*/,
61  const MatchId & /*match_id*/,
62  const string & /*player_id_joined*/,
63  const string & /*player_id_left*/,
64  const Json & /*match_context*/)> ProgressCallback;
65 
66  typedef function<void(const string & /*player_id*/,
67  CancelResult /*result*/)> CancelCallback;
68 
69 
70  enum TargetServerSelection {
71  kRandom = 0,
72  kMostNumberOfPlayers,
73  kLeastNumberOfPlayers
74  };
75 
77  Rpc::PeerId peer_id;
78  size_t player_count;
79  bool want_more_players;
80  };
81 
82  typedef std::vector<MatchmakingServerInfo> MatchmakingServerInfoVector;
83 
84  static const WallClock::Duration kNullTimeout;
85  static const ProgressCallback kNullProgressCallback;
86 
87  static MatchmakingServerInfoVector GetMatchmakingServerInfo();
88 
89  static void StartMatchmaking(const Type &type, const string &player_id,
90  const Json &player_context, const MatchCallback &match_callback,
91  const TargetServerSelection &target_server = kRandom,
92  const ProgressCallback &progress_callback = kNullProgressCallback,
93  const WallClock::Duration &timeout = kNullTimeout) ASSERT_NO_ROLLBACK;
94 
95  static void StartMatchmaking(const Type &type, const string &player_id,
96  const Json &player_context, const MatchCallback &match_callback,
97  const Rpc::PeerId &target_server,
98  const ProgressCallback &progress_callback = kNullProgressCallback,
99  const WallClock::Duration &timeout = kNullTimeout) ASSERT_NO_ROLLBACK;
100 
101  static void CancelMatchmaking(const Type &type, const string &player_id,
102  const CancelCallback &cancel_callback) ASSERT_NO_ROLLBACK;
103 };
104 
105 
107  public:
108  typedef MatchmakingClient::MatchId MatchId;
109  typedef MatchmakingClient::Type Type;
112  typedef MatchmakingClient::MatchResult MatchResult;
113  typedef MatchmakingClient::CancelResult CancelResult;
114 
115  enum MatchState {
116  kMatchNeedMorePlayer = 0,
117  kMatchComplete
118  };
119 
120  typedef function<bool(const Player & /*player*/,
121  const Match & /*match*/)> MatchChecker;
122 
123  typedef function<MatchState(const Match & /*match*/)> CompletionChecker;
124 
125  typedef function<void(const Player & /*player*/,
126  Match * /*match*/)> JoinCallback;
127 
128  typedef function<void(const Player & /*player*/,
129  Match * /*match*/)> LeaveCallback;
130 
131  static void Start(const MatchChecker &match_checker,
132  const CompletionChecker &completion_checker,
133  const JoinCallback &join_cb, const LeaveCallback &leave_cb);
134 };
135 
136 } // namespace fun
137 
138 #endif // INCLUDE_FUNAPI_SERVICE_MATCHMAKING_H_
Clock roughly representing wall clock.
Definition: wall_clock.h:27
Definition: matchmaking.h:106
Definition: matchmaking.h:21
Definition: json.h:27
Funapi RPC interface.
Definition: rpc.h:27
Definition: matchmaking.h:26
Definition: matchmaking.h:32