| 1 | /*! | 
|---|
| 2 |  * @file network_stream.h | 
|---|
| 3 |  *  implementation of a network pipe | 
|---|
| 4 |  */ | 
|---|
| 5 |  | 
|---|
| 6 | #ifndef _NETWORK_STREAM | 
|---|
| 7 | #define _NETWORK_STREAM | 
|---|
| 8 |  | 
|---|
| 9 | #include <vector> | 
|---|
| 10 | #include <list> | 
|---|
| 11 |  | 
|---|
| 12 | #include "data_stream.h" | 
|---|
| 13 | #include "network_protocol.h" | 
|---|
| 14 | #include "server_socket.h" | 
|---|
| 15 | #include "handshake.h" | 
|---|
| 16 |  | 
|---|
| 17 | #define MAX_CONNECTIONS 1000 | 
|---|
| 18 |  | 
|---|
| 19 | class Synchronizeable; | 
|---|
| 20 | class NetworkSocket; | 
|---|
| 21 | class ServerSocket; | 
|---|
| 22 | class ConnectionMonitor; | 
|---|
| 23 | class NetworkProtocol; | 
|---|
| 24 | class NetworkGameManager; | 
|---|
| 25 |  | 
|---|
| 26 | typedef std::list<Synchronizeable*>  SynchronizeableList; | 
|---|
| 27 | typedef std::vector<NetworkSocket*>  NetworkSocketVector; | 
|---|
| 28 | typedef std::vector<Handshake*>      HandshakeVector; | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 | class NetworkStream : public DataStream | 
|---|
| 32 | { | 
|---|
| 33 |  | 
|---|
| 34 |   public: | 
|---|
| 35 |     NetworkStream(); | 
|---|
| 36 |     NetworkStream(IPaddress& address); | 
|---|
| 37 |     NetworkStream(unsigned int port); | 
|---|
| 38 |  | 
|---|
| 39 |     ~NetworkStream(); | 
|---|
| 40 |     void init(); | 
|---|
| 41 |  | 
|---|
| 42 |     void connectSynchronizeable(Synchronizeable& sync); | 
|---|
| 43 |     void disconnectSynchronizeable(Synchronizeable& sync); | 
|---|
| 44 |  | 
|---|
| 45 |     inline bool isServer() const { return (this->type == NET_SERVER)? true:false; } | 
|---|
| 46 |     inline bool isActive() const { return this->bActive; } | 
|---|
| 47 |  | 
|---|
| 48 |     inline int getMaxConnections(){ return maxConnections; } | 
|---|
| 49 |     void setMaxConnections( int n ); | 
|---|
| 50 |  | 
|---|
| 51 |     virtual void processData(); | 
|---|
| 52 |  | 
|---|
| 53 |     inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); } | 
|---|
| 54 |     inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); } | 
|---|
| 55 |     inline int getSyncCount(){ return synchronizeables.size(); } | 
|---|
| 56 |  | 
|---|
| 57 |   private: | 
|---|
| 58 |     NetworkProtocol*       networkProtocol; | 
|---|
| 59 |     ConnectionMonitor*     connectionMonitor; | 
|---|
| 60 |     SynchronizeableList    synchronizeables; | 
|---|
| 61 |     NetworkSocketVector    networkSockets; | 
|---|
| 62 |     HandshakeVector        handshakes; | 
|---|
| 63 |     ServerSocket*          serverSocket; | 
|---|
| 64 |     int                    type; | 
|---|
| 65 |     Header                 packetHeader; | 
|---|
| 66 |     bool                   bActive; | 
|---|
| 67 |     std::list<int>         freeSocketSlots; | 
|---|
| 68 |  | 
|---|
| 69 |     int                    myHostId; | 
|---|
| 70 |     int                    maxConnections; | 
|---|
| 71 |  | 
|---|
| 72 |     NetworkGameManager*   networkGameManager; | 
|---|
| 73 |  | 
|---|
| 74 |     void updateConnectionList(); | 
|---|
| 75 | }; | 
|---|
| 76 | #endif /* _NETWORK_STREAM */ | 
|---|