Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/network_stream.h @ 9346

Last change on this file since 9346 was 9246, checked in by patrick, 18 years ago

some network comments

File size: 3.4 KB
RevLine 
[5566]1/*!
2 * @file network_stream.h
3 *  implementation of a network pipe
4 */
[5587]5
[5566]6#ifndef _NETWORK_STREAM
7#define _NETWORK_STREAM
8
[6139]9#include <vector>
10#include <list>
[7954]11#include <map>
[6139]12
[5582]13#include "data_stream.h"
[6139]14#include "server_socket.h"
15#include "handshake.h"
[7954]16#include "connection_monitor.h"
17#include "udp_server_socket.h"
[5566]18
[5647]19class Synchronizeable;
20class NetworkSocket;
[6139]21class ServerSocket;
[6341]22class NetworkGameManager;
[5589]23
[9246]24//!< this structure contains informations about the network node
[7954]25class PeerInfo
26{
27  public:
28    PeerInfo() { clear(); }
29    void clear() { userId = 0; isServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }
[9246]30
31
32  public:
[7954]33    int                 userId;
34    bool                isServer;
35    NetworkSocket *     socket;
36    Handshake *         handshake;
37    ConnectionMonitor * connectionMonitor;
38    int                 lastAckedState;
39    int                 lastRecvedState;
40};
41
[6139]42typedef std::list<Synchronizeable*>  SynchronizeableList;
[7954]43typedef std::map<int,PeerInfo>       PeerList;
[5809]44
45
[5649]46class NetworkStream : public DataStream
[5566]47{
48
[5996]49  public:
50    NetworkStream();
[7954]51    NetworkStream( std::string host, int port);
52    NetworkStream( int port );
[5804]53
[6981]54    virtual ~NetworkStream();
[5996]55    void init();
[5804]56
[6695]57    void createNetworkGameManager();
58    void startHandshake();
59
[5996]60    void connectSynchronizeable(Synchronizeable& sync);
[6139]61    void disconnectSynchronizeable(Synchronizeable& sync);
[5566]62
[5996]63    inline bool isServer() const { return (this->type == NET_SERVER)? true:false; }
64    inline bool isActive() const { return this->bActive; }
65
[7954]66    inline int getMaxConnections(){ return MAX_CONNECTIONS; }
[6139]67
[5996]68    virtual void processData();
69
[6341]70    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
71    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
[6695]72    int getSyncCount();
[6341]73
[7954]74    inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }
75    inline bool isUserServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isServer; }
[6634]76
[6695]77    void debug();
[9246]78
[7954]79    inline PeerInfo & getPeerInfo( int userId ) { return peers[userId]; }
[6695]80
81
[5996]82  private:
[6695]83    void updateConnectionList();
[7954]84    void handleHandshakes();
[8068]85    void handleUpstream( int tick );
[9246]86    void handleDownstream(int tick );
[7954]87    void handleNewClient( int userId );
88    void cleanUpOldSyncList();
[9246]89
[8623]90    void writeToNewDict( byte * data, int length, bool upstream );
[6139]91
92
[6695]93  private:
94    SynchronizeableList        synchronizeables;
[7954]95    PeerList                   peers;
[6695]96    ServerSocket*              serverSocket;
97    int                        type;
98    bool                       bActive;
99    std::list<int>             freeSocketSlots;
[6341]100
[6695]101    int                        myHostId;
[9246]102
[7954]103    int                        currentState;                //!< current state id
[6695]104
105    NetworkGameManager*        networkGameManager;
[7954]106
107    std::map<int,int>          oldSynchronizeables;         //!< used to save recently deleted sync ids to not recreate them
[9246]108
[7954]109    byte                       buf[UDP_PACKET_SIZE];        //!< used by handleUp/Downstream
110    byte                       compBuf[UDP_PACKET_SIZE];    //!< used by handleUp/Downstream
111
112    int                        remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict
[8623]113
114    int dictServer;
115    int dictClient;
[5587]116};
[5566]117#endif /* _NETWORK_STREAM */
Note: See TracBrowser for help on using the repository browser.