src/Network/Session.hh
author saiam
Mon, 08 Dec 2008 00:05:45 +0000
changeset 273 eeb699e1d908
parent 203 3ec7ab40755f
child 286 2a8f20a53ff2
permissions -rw-r--r--
Made forceq to contain time again.
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     1
#ifndef NETWORK_SESSION_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     2
#define NETWORK_SESSION_HH
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     3
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     4
#include <map>
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     5
#include <stdint.h>
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     6
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     7
// forward-declare
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     8
class NetworkSession;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     9
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    10
/*
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    11
 * Used to separate packets, ID zero is reserved for NetworkSession use
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    12
 */
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    13
typedef uint16_t NetworkChannelID;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    14
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 202
diff changeset
    15
/*
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 202
diff changeset
    16
 * Size of a packet header
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 202
diff changeset
    17
 */
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 202
diff changeset
    18
const size_t NETWORK_SESSION_HEADER_SIZE = sizeof(uint16_t);
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 202
diff changeset
    19
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    20
#include "TCP.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    21
#include "UDP.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
    22
#include "Node.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    23
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    24
class NetworkSession {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    25
    friend class NetworkNode;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    26
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    27
    private:
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    28
        uint64_t magic;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    29
        NetworkTCPServer *tcp_srv;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    30
        NetworkUDP *udp_srv, *udp_client;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    31
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    32
        CL_SlotContainer slots;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    33
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    34
        std::map<NetworkAddress, NetworkNode*> nodes;
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    35
        std::map<NetworkChannelID, CL_Signal_v2<NetworkPacketInput&, NetworkNode *> > _map_sig_chan_message;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    36
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    37
    public:
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    38
        NetworkSession (uint64_t magic);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    39
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    40
        void listen (const NetworkAddress &addr);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    41
        NetworkNode* connect (const NetworkAddress &addr);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    42
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    43
    protected:
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    44
        virtual NetworkNode *build_node (NetworkTCPTransport *tcp, NetworkUDP *udp, const NetworkAddress &addr, enum NetworkNodeType type);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    45
        
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    46
        void handle_disconnect (NetworkNode *node);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    47
        void handle_message (NetworkPacketInput &pkt, NetworkNode *node);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    48
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    49
    private:
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    50
        void on_tcp_client (NetworkTCPTransport *client);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    51
        void on_udp_packet (NetworkPacketInput &pkt, const NetworkAddress &addr);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    52
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    53
        CL_Signal_v1<NetworkNode*> _sig_node_connected;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    54
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    55
    public:
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    56
        void send_all (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, bool reliable = true);
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    57
        void send_all_except (NetworkChannelID channel_id, const NetworkPacketBuffer &pkt, const NetworkNode *node, bool reliable = true);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    58
202
b3f5d766391e support sending of raw packets
terom
parents: 200
diff changeset
    59
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    60
        CL_Signal_v1<NetworkNode*>& sig_node_connected (void) { return _sig_node_connected; }
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 186
diff changeset
    61
        CL_Signal_v2<NetworkPacketInput&, NetworkNode *>& sig_chan_message (NetworkChannelID cid) { return _map_sig_chan_message[cid]; }
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    62
};
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    63
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    64
#endif /* NETWORK_SESSION_HH */