rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
#ifndef NETWORK_NODE_HH
#define NETWORK_NODE_HH
/**
* @file
*
* Remote NetworkSessions
*/
// forward-declare
class NetworkNode;
/**
* Used to differentiate between different kinds of nodes in NetworkSession::build_node
*
* @see NetworkSession::build_node
*/
enum NetworkNodeType {
NETWORK_NODE_SERVER_CLIENT, //<<< A server's client
NETWORK_NODE_CLIENT_SERVER //<<< A client's server
};
#include "TCP.hh"
#include "UDP.hh"
#include "Session.hh"
#include "Target.hh"
/**
* A NetworkNode represents a remote NetworkSession connected to our NetworkSession.
*
* A NetworkNode has a tcp connection, plus an udp socket to us (either NetworkSession's udp_srv or udp_client)
*
* NetworkNode implements the NetworkTarget interface, so you can use send()
*/
class NetworkNode : public NetworkTarget {
private:
/**
* Our local NetworkSession
*/
NetworkSession &session;
/**
* The TCP connection
*/
NetworkTCPTransport *tcp;
/**
* Our NetworkSession's UDP socket that we should use to send UDP packets to this node
*/
NetworkUDP *udp;
/**
* This address that the node connected from using TCP, used to associate received UDP packets with this node
*/
const NetworkAddress address;
CL_SlotContainer slots;
public:
/**
* Construct a new NetworkNode from the given tcp/udp sockets and address
*
* @param session our NetworkSession
* @param tcp this node's TCP socket
* @param udp the UDP socket to use for outgoing packets
* @param address the remote address
*/
NetworkNode (NetworkSession &session, NetworkTCPTransport *tcp, NetworkUDP *udp, const NetworkAddress &address);
private:
/**
* Node should not be copied
*/
NetworkNode (const NetworkNode ©);
~NetworkNode (void);
NetworkNode& operator= (const NetworkNode ©);
/**
* Our TCP socket indicates disconnect, tell NetworkSession and trigger sig_disconnect
*/
void on_disconnect (void);
/**
* Our disconnect signal
*/
CL_Signal_v0 _sig_disconnected;
protected:
/**
* Send the given packet to this node, used by NetworkTarget
*/
virtual void send_pkt (const NetworkPacketBuffer &pkt, bool reliable = true);
public:
/**
* Get this node's remote address (both TCP and UDP).
*
* @return NetworkAddress the remote address
*/
const NetworkAddress& getRemoteAddress (void);
/**
* This node's TCP connection was lost, and the node has been removed from the NetworkSession's nodes list.
*
* Once this completes, the node will be destructed
*/
CL_Signal_v0& sig_disconnected (void) { return _sig_disconnected; }
};
#endif /* NETWORK_NODE_HH */