iFun Engine API  1.0.0-b3776
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*/)> ProgressCallback;
64 
65  typedef function<void(const string & /*player_id*/,
66  const Match & /*match*/,
67  const string & /*player_id_joined*/,
68  const string & /*player_id_left*/)> ProgressCallback2;
69 
70  typedef function<void(const string & /*player_id*/,
71  CancelResult /*result*/)> CancelCallback;
72 
73 
74  enum TargetServerSelection {
75  kRandom = 0,
76  kMostNumberOfPlayers,
77  kLeastNumberOfPlayers
78  };
79 
81  Rpc::PeerId peer_id;
82  size_t player_count;
83  bool want_more_players;
84  };
85 
86  typedef std::vector<MatchmakingServerInfo> MatchmakingServerInfoVector;
87 
88  static const WallClock::Duration kNullTimeout;
89  static const ProgressCallback kNullProgressCallback;
90  static const ProgressCallback2 kNullProgressCallback2;
91 
92  static MatchmakingServerInfoVector GetMatchmakingServerInfo();
93 
94  static void StartMatchmaking(const Type &type, const string &player_id,
95  const Json &player_context, const MatchCallback &match_callback,
96  const TargetServerSelection &target_server = kRandom,
97  const ProgressCallback &progress_callback = kNullProgressCallback,
98  const WallClock::Duration &timeout = kNullTimeout) ASSERT_NO_ROLLBACK;
99 
100  static void StartMatchmaking(const Type &type, const string &player_id,
101  const Json &player_context, const MatchCallback &match_callback,
102  const Rpc::PeerId &target_server,
103  const ProgressCallback &progress_callback = kNullProgressCallback,
104  const WallClock::Duration &timeout = kNullTimeout) ASSERT_NO_ROLLBACK;
105 
106  static void StartMatchmaking2(const Type &type, const string &player_id,
107  const Json &player_context, const MatchCallback &match_callback,
108  const TargetServerSelection &target_server = kRandom,
109  const ProgressCallback2 &progress_callback2 = kNullProgressCallback2,
110  const WallClock::Duration &timeout = kNullTimeout) ASSERT_NO_ROLLBACK;
111 
112  static void StartMatchmaking2(const Type &type, const string &player_id,
113  const Json &player_context, const MatchCallback &match_callback,
114  const Rpc::PeerId &target_server,
115  const ProgressCallback2 &progress_callback2 = kNullProgressCallback2,
116  const WallClock::Duration &timeout = kNullTimeout) ASSERT_NO_ROLLBACK;
117 
118  static void CancelMatchmaking(const Type &type, const string &player_id,
119  const CancelCallback &cancel_callback) ASSERT_NO_ROLLBACK;
120 
121  static void UpdateMatchPlayerContext(const Type &type,
122  const string &player_id, const Json &new_context) ASSERT_NO_ROLLBACK;
123 };
124 
125 
127  public:
128  typedef MatchmakingClient::MatchId MatchId;
129  typedef MatchmakingClient::Type Type;
132  typedef MatchmakingClient::MatchResult MatchResult;
133  typedef MatchmakingClient::CancelResult CancelResult;
134 
135  enum MatchState {
136  kMatchNeedMorePlayer = 0,
137  kMatchComplete
138  };
139 
140  typedef function<bool(const Player & /*player*/,
141  const Match & /*match*/)> MatchChecker;
142 
143  typedef function<MatchState(const Match & /*match*/)> CompletionChecker;
144 
145  typedef function<void(const Player & /*player*/,
146  Match * /*match*/)> JoinCallback;
147 
148  typedef function<void(const Player & /*player*/,
149  Match * /*match*/)> LeaveCallback;
150 
151  static void Start(const MatchChecker &match_checker,
152  const CompletionChecker &completion_checker,
153  const JoinCallback &join_cb, const LeaveCallback &leave_cb);
154 };
155 
156 } // namespace fun
157 
158 #endif // INCLUDE_FUNAPI_SERVICE_MATCHMAKING_H_
Clock roughly representing wall clock.
Definition: wall_clock.h:27
Definition: matchmaking.h:126
Definition: matchmaking.h:21
Definition: json.h:27
Funapi RPC interface.
Definition: rpc.h:27
Definition: matchmaking.h:26
Definition: matchmaking.h:32