iFun Engine API  1.0.0-b6053
Great Technology for Great Games
multicast_server.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_MULTICAST_SERVER_H_
10 #define INCLUDE_FUNAPI_SERVICE_MULTICAST_SERVER_H_
11 
12 #include <boost/unordered_map.hpp>
13 #include <funapi/common/json.h>
14 #include <funapi/types.h>
15 
16 
17 namespace fun {
18 
19 typedef Uuid SessionId;
20 class Session;
21 
22 
23 class FUNAPI_DLL_VISIBILITY MulticastServer {
24  public:
25  typedef function<
26  bool(const string & /*channel*/,
27  const string & /*sender*/,
28  const Ptr<Session> & /*session*/,
29  Json * /*message*/)> JsonMessageChecker;
30  typedef function<
31  bool(const string & /*channel*/,
32  const string & /*sender*/,
33  const Ptr<Session> & /*session*/,
34  const Ptr<FunMessage> & /*message*/)> ProtobufMessageChecker;
35 
36  typedef function<
37  void(const string & /*channel*/,
38  const string & /*sender*/,
39  const SessionId & /*session_id*/,
40  const Json & /*message*/)> JsonMessageHook;
41  typedef function<
42  void(const string & /*channel*/,
43  const string & /*sender*/,
44  const SessionId & /*session_id*/,
45  const Ptr<const FunMessage> & /*message*/)> ProtobufMessageHook;
46 
47  static void InstallJsonMessageChecker(
48  const JsonMessageChecker &json_message_checker);
49 
50  static void InstallProtobufMessageChecker(
51  const ProtobufMessageChecker &protobuf_message_checker);
52 
53  static void InstallJsonMessageHook(const JsonMessageHook &hook);
54 
55  static void InstallProtobufMessageHook(const ProtobufMessageHook &hook);
56 };
57 
58 
59 typedef boost::unordered_map<string /*channel*/,
60  string /*token*/> MulticastChannelTokenMap;
61 
63  MulticastChannelInfo(const string &name_in, size_t member_count_in) {
64  name = name_in;
65  member_count = member_count_in;
66  }
67 
68  string name;
69  size_t member_count;
70 };
71 
72 typedef std::vector<MulticastChannelInfo> MulticastChannelInfoVector;
73 
74 // Creates a server-side multicast channel.
75 // This function must be called on both the game server and the multicast server.
76 FUNAPI_DLL_VISIBILITY
77 void CreateMulticastChannel(const string &channel, const string &token);
78 
79 // Gets a server-side multicast channel.
80 FUNAPI_DLL_VISIBILITY
81 bool GetMulticastChannel(const string &channel, string *out_token);
82 
83 // Gets the server-side multicast channels.
84 FUNAPI_DLL_VISIBILITY
85 size_t GetMulticastChannelTokenMap(MulticastChannelTokenMap *out);
86 
87 // Disallows to create a client-side multicast channel.
88 FUNAPI_DLL_VISIBILITY
89 void DisallowToCreateClientsideMulticastChannel();
90 
91 FUNAPI_DLL_VISIBILITY
92 void GetGlobalMulticastChannels(MulticastChannelInfoVector *out);
93 
94 } // namespace fun
95 
96 #endif // INCLUDE_FUNAPI_SERVICE_MULTICAST_SERVER_H_
Definition: multicast_server.h:62
Definition: json.h:18
boost::uuids::uuid Uuid
UUID type used throughout Funapi.
Definition: types.h:56
Definition: json.h:27
Definition: multicast_server.h:23