iFun Engine API  1.0.0-b6053
Great Technology for Great Games
account_manager.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_ACCOUNT_MANAGER_H_
10 #define INCLUDE_FUNAPI_SERVICE_ACCOUNT_MANAGER_H_
11 
12 #include <boost/noncopyable.hpp>
14 #include <funapi/network/session.h>
15 #include <funapi/types.h>
16 
17 #include <utility>
18 #include <vector>
19 
20 
21 namespace fun {
22 
23 class FUNAPI_DLL_VISIBILITY AccountManager : private boost::noncopyable {
24  public:
25  typedef function<void(const string & /*account_id*/, bool /*ret*/)> Callback;
26  typedef function<void(const string & /*account_id*/,
27  const Ptr<Session> &/*session*/,
28  bool /*ret*/)> LoginCallback;
29  typedef function<void(const string &/*account_id*/,
30  const Ptr<Session> &/*session*/,
31  bool /*ret*/)> LogoutCallback;
32  typedef function<void(const string &/*account_id*/,
33  const Ptr<Session> &/*session*/)> RemoteLogoutCallback;
34  typedef function<void(const string &/*account_id*/,
35  const Rpc::PeerId &/*peer_id*/)> LocateCallback;
36 
37  // Called after authenticating session as "account_id"
38  typedef function<void (const string & /*account_id*/,
39  const Ptr<Session> & /*session*/,
40  bool /*success*/,
41  const string & /*extra_data*/)> RedirectionCallback;
42  typedef function<void (size_t /*count*/,
43  bool /*success*/)> GlobalAccountsNumberCallback;
44 
45  enum RedirectClientResult {
46  kSuccess = 0,
47  kNoRpcPeer,
48  kNotLoggedIn,
49  kNoTransport,
50  kError = 1000
51  };
52 
53  typedef function<
54  void(const Ptr<Session> &/*session*/,
55  const Rpc::PeerId &/*peer_id*/,
56  const string &/*extra_data*/,
57  RedirectClientResult /*result*/)> RedirectClientCallback;
58 
59  static const Callback kNullCallback;
60 
61  static void RegisterRemoteLogoutHandler(const RemoteLogoutCallback &handler);
62  static void RegisterRedirectionHandler(const RedirectionCallback &handler);
63 
73  static bool CheckAndSetLoggedIn(
74  const string &account_id,
75  const Ptr<Session> &session) ASSERT_NO_ROLLBACK;
76 
85  static void CheckAndSetLoggedInAsync(
86  const string &account_id,
87  const Ptr<Session> &session,
88  const LoginCallback &callback) ASSERT_NO_ROLLBACK;
89 
101  static void CheckAndSetLoggedInAsync(
102  const string &account_id,
103  const Ptr<Session> &session,
104  const size_t &max_retry,
105  const LoginCallback &login_callback,
106  const LogoutCallback &logout_callback) ASSERT_NO_ROLLBACK;
107 
113  static bool SetLoggedOut(const string &account_id) ASSERT_NO_ROLLBACK;
114 
120  static bool SetLoggedOut(const Ptr<Session> &session) ASSERT_NO_ROLLBACK;
121 
126  static void SetLoggedOutAsync(
127  const string &account_id,
128  const LogoutCallback &callback) ASSERT_NO_ROLLBACK;
129 
134  static void SetLoggedOutAsync(
135  const Ptr<Session> &session,
136  const LogoutCallback &callback) ASSERT_NO_ROLLBACK;
137 
143  static bool SetLoggedOutGlobal(const string &account_id) ASSERT_NO_ROLLBACK;
144 
149  static void SetLoggedOutGlobalAsync(
150  const string &account_id,
151  const LogoutCallback &callback) ASSERT_NO_ROLLBACK;
152 
155  static void GetAllLocalAccounts(std::vector<string> *accounts);
156 
159  static void GetAllLocalSessions(std::vector<Ptr<Session> > *sessions);
160 
163  static void GetAllLocalAccountsAndSessions(
164  std::vector<std::pair<string, Ptr<Session> > > *accounts);
165 
168  static size_t GetLocalAccountsNumber();
169 
172  static int64_t GetGlobalAccountsNumber();
173 
174  static void GetGlobalAccountsNumberAsync(
175  const GlobalAccountsNumberCallback& callback);
176 
181  static bool IsLoggedIn(const Ptr<Session> &session);
182 
187  static Rpc::PeerId Locate(const string &account_id) ASSERT_NO_ROLLBACK;
188 
193  static void LocateAsync(
194  const string &account_id,
195  const LocateCallback &callback) ASSERT_NO_ROLLBACK;
196 
200  static Ptr<Session> FindLocalSession(const string &account_id);
201 
206  static string FindLocalAccount(const Ptr<Session> &session);
207 
215  static void SendMessage(
216  const string &msg_type, const Ptr<FunMessage> &msg,
217  const string &account_id, const Encryption &enc = kDefaultEncryption,
218  const TransportProtocol &protocol = kDefaultProtocol,
219  const Callback &cb = kNullCallback) ASSERT_NO_ROLLBACK;
220 
228  static void SendMessage(
229  int32_t msg_type, const Ptr<FunMessage> &msg,
230  const string &account_id, const Encryption &enc = kDefaultEncryption,
231  const TransportProtocol &protocol = kDefaultProtocol,
232  const Callback &cb = kNullCallback) ASSERT_NO_ROLLBACK;
233 
241  static void SendMessage(
242  const ProtobufExtensionIdentifier &msg_type, const Ptr<FunMessage> &msg,
243  const string &account_id, const Encryption &enc = kDefaultEncryption,
244  const TransportProtocol &protocol = kDefaultProtocol,
245  const Callback &cb = kNullCallback) ASSERT_NO_ROLLBACK;
246 
254  static void SendMessage(
255  const string &msg_type, const Json &msg, const string &account_id,
256  const Encryption &enc = kDefaultEncryption,
257  const TransportProtocol &protocol = kDefaultProtocol,
258  const Callback &cb = kNullCallback) ASSERT_NO_ROLLBACK;
259 
267  static bool SendMessageSync(
268  const string &msg_type, const Ptr<FunMessage> &msg,
269  const string &account_id, const Encryption &enc = kDefaultEncryption,
270  const TransportProtocol &protocol = kDefaultProtocol) ASSERT_NO_ROLLBACK;
271 
279  static bool SendMessageSync(
280  int32_t msg_type, const Ptr<FunMessage> &msg,
281  const string &account_id, const Encryption &enc = kDefaultEncryption,
282  const TransportProtocol &protocol = kDefaultProtocol) ASSERT_NO_ROLLBACK;
283 
291  static bool SendMessageSync(
292  const ProtobufExtensionIdentifier &msg_type, const Ptr<FunMessage> &msg,
293  const string &account_id, const Encryption &enc = kDefaultEncryption,
294  const TransportProtocol &protocol = kDefaultProtocol) ASSERT_NO_ROLLBACK;
295 
303  static bool SendMessageSync(
304  const string &msg_type, const Json &msg,
305  const string &account_id, const Encryption &enc = kDefaultEncryption,
306  const TransportProtocol &protocl = kDefaultProtocol) ASSERT_NO_ROLLBACK;
307 
313  static void BroadcastLocally(
314  const string &msg_type, const Ptr<FunMessage> &msg,
315  const Encryption &enc,
316  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
317 
323  static void BroadcastLocally(
324  int32_t msg_type, const Ptr<FunMessage> &msg,
325  const Encryption &enc,
326  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
327 
333  static void BroadcastLocally(
334  const ProtobufExtensionIdentifier &msg_type, const Ptr<FunMessage> &msg,
335  const Encryption &enc,
336  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
337 
343  static void BroadcastLocally(
344  const string &msg_type, const Json &msg,
345  const Encryption &enc,
346  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
347 
355  static void BroadcastGlobally(
356  const string &msg_type, const Ptr<FunMessage> &msg,
357  const Rpc::Tag &server_tag,
358  const Encryption &enc,
359  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
360 
368  static void BroadcastGlobally(
369  int32_t msg_type, const Ptr<FunMessage> &msg,
370  const Rpc::Tag &server_tag,
371  const Encryption &enc,
372  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
373 
381  static void BroadcastGlobally(
382  const ProtobufExtensionIdentifier &msg_type, const Ptr<FunMessage> &msg,
383  const Rpc::Tag &server_tag,
384  const Encryption &enc,
385  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
386 
394  static void BroadcastGlobally(
395  const string &msg_type, const Json &msg,
396  const Rpc::Tag &server_tag,
397  const Encryption &enc,
398  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
399 
407  static void BroadcastGlobally(
408  const string &msg_type, const Ptr<FunMessage> &msg,
409  const Rpc::PeerMap &servers,
410  const Encryption &enc,
411  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
412 
420  static void BroadcastGlobally(
421  int32_t msg_type, const Ptr<FunMessage> &msg,
422  const Rpc::PeerMap &servers,
423  const Encryption &enc,
424  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
425 
433  static void BroadcastGlobally(
434  const ProtobufExtensionIdentifier &msg_type, const Ptr<FunMessage> &msg,
435  const Rpc::PeerMap &servers,
436  const Encryption &enc,
437  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
438 
446  static void BroadcastGlobally(
447  const string &msg_type, const Json &msg,
448  const Rpc::PeerMap &servers,
449  const Encryption &enc,
450  const TransportProtocol &protocol) ASSERT_NO_ROLLBACK;
451 
456  static bool RedirectClient(
457  const Ptr<Session> &session, const Rpc::PeerId &peer_id,
458  const string &extra_data) ASSERT_NO_ROLLBACK;
459 
465  static void RedirectClientAsync(
466  const Ptr<Session> &session, const Rpc::PeerId &peer_id,
467  const string &extra_data,
468  const RedirectClientCallback &callback) ASSERT_NO_ROLLBACK;
469 };
470 
471 
472 FUNAPI_DLL_VISIBILITY
473 std::ostream &operator<<(std::ostream &stream,
474  const AccountManager::RedirectClientResult result);
475 
476 } // namespace fun
477 
478 #endif // INCLUDE_FUNAPI_SERVICE_ACCOUNT_MANAGER_H_
Definition: session.h:624
Definition: account_manager.h:23
Definition: json.h:18
Definition: json.h:27