|
1 #ifndef NETWORK_SESSION_HH |
|
2 #define NETWORK_SESSION_HH |
|
3 |
|
4 #include "NetworkTCP.hh" |
|
5 #include "NetworkUDP.hh" |
|
6 |
|
7 #include <map> |
|
8 |
|
9 /* |
|
10 * Should be set to some 8-char magic value to identify the application |
|
11 */ |
|
12 typedef char[8] NetworkSessionMagic; |
|
13 |
|
14 /* |
|
15 * Used to separate packets, ID zero is reserved for NetworkSession use |
|
16 */ |
|
17 typedef uint16_t NetworkChannelID; |
|
18 |
|
19 class NetworkSession { |
|
20 private: |
|
21 NetworkSessionMagic magic; |
|
22 NetworkTCPServer *tcp_srv; |
|
23 NetworkUDP *udp_srv, *udp_client; |
|
24 |
|
25 CL_SlotContainer slots; |
|
26 |
|
27 std::map<NetworkAddress, NetworkNode*> nodes; |
|
28 |
|
29 public: |
|
30 NetworkSession (NetworkSessionMagic magic); |
|
31 |
|
32 void listen (const NetworkAddress &addr); |
|
33 NetworkNode* connect (const NetworkAddress &addr); |
|
34 |
|
35 private: |
|
36 void on_tcp_client (const NetworkTCPTransport *client); |
|
37 void on_disconnect (NetworkNode *node); |
|
38 |
|
39 public: |
|
40 void send_all (NetworkChannelID channel_id, const NetworkPacket &pkt, bool reliable = true); |
|
41 void send_all_except (NetworkChannelID channel_id, const NetworkPacket &pkt, const NetworkNode *node, bool reliable = true); |
|
42 |
|
43 CL_Signal_v1<NetworkNode*> sig_node_connected; |
|
44 CL_Signal_v1<NetworkNode*> sig_node_disconnected; |
|
45 }; |
|
46 |
|
47 #endif /* NETWORK_SESSION_HH */ |