Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9562 was 9494, checked in by bensch, 18 years ago

merged the proxy back

File size: 4.8 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"
[9406]16#include "monitor/connection_monitor.h"
[7954]17#include "udp_server_socket.h"
[9406]18#include "peer_info.h"
[5566]19
[9406]20#include "shared_network_data.h"
21
[5647]22class Synchronizeable;
23class NetworkSocket;
[6139]24class ServerSocket;
[6341]25class NetworkGameManager;
[9406]26class NetworkMonitor;
[5589]27
[9246]28
[6139]29typedef std::list<Synchronizeable*>  SynchronizeableList;
[7954]30typedef std::map<int,PeerInfo>       PeerList;
[5809]31
32
[5649]33class NetworkStream : public DataStream
[5566]34{
35
[5996]36  public:
37    NetworkStream();
[9406]38    NetworkStream(int nodeType);
39    virtual ~NetworkStream();
[5804]40
[5996]41    void init();
[5804]42
[9406]43    void connectToMasterServer(std::string host, int port);
[9494]44    void connectToProxyServer(int proxyId, std::string host, int port);
45    void createServer(int clientPort, int proxyPort);
[9406]46
[6695]47    void createNetworkGameManager();
[9494]48    void startHandshake(int userId = NET_ID_MASTER_SERVER);
[6695]49
[9406]50    /* synchronizeable interface */
[5996]51    void connectSynchronizeable(Synchronizeable& sync);
[6139]52    void disconnectSynchronizeable(Synchronizeable& sync);
[5566]53
[9406]54    inline int getMaxConnections(){ return SharedNetworkData::getInstance()->getMaxPlayer(); }
[5996]55
[9406]56    /* functions for the peerInfo information retreival */
[9494]57    /** @returns true if this userId is activated at this client false if not*/
[9406]58    inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }
[9494]59    /** @returns true if this userId is a local client */
60    inline bool isUserLocal( int userID) { return this->isUserIdActive(userID); }
61    /** @returns true if this user is a master server */
[9406]62    inline bool isUserMasterServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isMasterServer(); }
[9494]63    /** @returns true if this user is a proxy server */
64    inline bool isUserProxyServerActive( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServerActive(); }
65    /** @returns true if this user is a client */
[9406]66    inline bool isUserClient( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isClient(); }
[6139]67
[9406]68    /* peering interface */
69    inline PeerInfo & getPeerInfo( int userId ) { return peers[userId]; }
70    inline PeerInfo* getPeerInfo() { return this->pInfo; }
71    inline PeerList getPeerInfoList() { return this->peers; }
72
73    /* data processing*/
[5996]74    virtual void processData();
75
[9406]76    /* debugging */
77    void debug();
78
79
80  private:
81
[6341]82    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
83    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
[9406]84    void cleanUpOldSyncList();
[6695]85    int getSyncCount();
[6341]86
[6695]87    void updateConnectionList();
[9494]88
[9406]89    /* handle processes */
[7954]90    void handleHandshakes();
[8068]91    void handleUpstream( int tick );
[9246]92    void handleDownstream(int tick );
[9406]93
94    /* handle events*/
[7954]95    void handleNewClient( int userId );
[9494]96
97    void handleConnect( int userId);
[9406]98    void handleReconnect( int userId );
[9494]99    void handleDisconnect( int userId );
[9246]100
[8623]101    void writeToNewDict( byte * data, int length, bool upstream );
[6139]102
103
[6695]104  private:
[9406]105    PeerList                   peers;                       //!< list of the network node informations
[6341]106
[9406]107    PeerInfo*                  pInfo;                       //!< the info about the local peer node (not in the PeerList)
[9246]108
[9406]109    std::list<int>             freeSocketSlots;             //!< list of free sockets (to ensure not to resycle sockets)
[7954]110    int                        currentState;                //!< current state id
[6695]111
[9406]112    NetworkMonitor*            networkMonitor;              //!< the network monitor
113    NetworkGameManager*        networkGameManager;          //!< reference to the network game manager
[9494]114    ServerSocket*              clientSocket;                //!< the listening socket of the server
115    ServerSocket*              proxySocket;                 //!< socket for proxy connections
[7954]116
117    std::map<int,int>          oldSynchronizeables;         //!< used to save recently deleted sync ids to not recreate them
[9406]118    SynchronizeableList        synchronizeables;            //!< list of the synchronizeables
[9246]119
[7954]120    byte                       buf[UDP_PACKET_SIZE];        //!< used by handleUp/Downstream
121    byte                       compBuf[UDP_PACKET_SIZE];    //!< used by handleUp/Downstream
122    int                        remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict
[8623]123
[9406]124    int                        dictServer;                  //!< the zip dict for the server
125    int                        dictClient;                  //!< the zip dict for the client
[9494]126
127    bool                       bRedirect;                   //!< true if the master server sent a redirect command
[5587]128};
[5566]129#endif /* _NETWORK_STREAM */
Note: See TracBrowser for help on using the repository browser.