/*! * @file network_stream.h * implementation of a network pipe */ #ifndef _NETWORK_STREAM #define _NETWORK_STREAM #include #include #include "data_stream.h" #include "network_protocol.h" #include "server_socket.h" #include "handshake.h" class Synchronizeable; class NetworkSocket; class ServerSocket; class ConnectionMonitor; class NetworkProtocol; class NetworkGameManager; typedef std::list SynchronizeableList; typedef std::vector NetworkSocketVector; typedef std::vector HandshakeVector; class NetworkStream : public DataStream { public: NetworkStream(); NetworkStream(IPaddress& address); NetworkStream(unsigned int port); ~NetworkStream(); void init(); void createNetworkGameManager(); void startHandshake(); void connectSynchronizeable(Synchronizeable& sync); void disconnectSynchronizeable(Synchronizeable& sync); inline bool isServer() const { return (this->type == NET_SERVER)? true:false; } inline bool isActive() const { return this->bActive; } inline int getMaxConnections(){ return maxConnections; } void setMaxConnections( int n ); virtual void processData(); inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); } inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); } int getSyncCount(); inline bool isUserIdActive( int userID ) { if (userID>=networkSockets.size()) return false; else return networkSockets[userID]!=NULL; } void debug(); private: void updateConnectionList(); private: NetworkProtocol* networkProtocol; ConnectionMonitor* connectionMonitor; SynchronizeableList synchronizeables; NetworkSocketVector networkSockets; HandshakeVector handshakes; ServerSocket* serverSocket; int type; Header packetHeader; bool bActive; std::list freeSocketSlots; int myHostId; int maxConnections; NetworkGameManager* networkGameManager; }; #endif /* _NETWORK_STREAM */