Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9406 in orxonox.OLD for trunk/src/lib/network/network_stream.h


Ignore:
Timestamp:
Jul 24, 2006, 11:09:47 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/network_stream.h

    r9246 r9406  
    1414#include "server_socket.h"
    1515#include "handshake.h"
    16 #include "connection_monitor.h"
     16#include "monitor/connection_monitor.h"
    1717#include "udp_server_socket.h"
     18#include "peer_info.h"
     19
     20#include "shared_network_data.h"
    1821
    1922class Synchronizeable;
     
    2124class ServerSocket;
    2225class NetworkGameManager;
     26class NetworkMonitor;
    2327
    24 //!< this structure contains informations about the network node
    25 class PeerInfo
    26 {
    27   public:
    28     PeerInfo() { clear(); }
    29     void clear() { userId = 0; isServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }
    30 
    31 
    32   public:
    33     int                 userId;
    34     bool                isServer;
    35     NetworkSocket *     socket;
    36     Handshake *         handshake;
    37     ConnectionMonitor * connectionMonitor;
    38     int                 lastAckedState;
    39     int                 lastRecvedState;
    40 };
    4128
    4229typedef std::list<Synchronizeable*>  SynchronizeableList;
     
    4936  public:
    5037    NetworkStream();
    51     NetworkStream( std::string host, int port);
    52     NetworkStream( int port );
     38    NetworkStream(int nodeType);
     39    virtual ~NetworkStream();
    5340
    54     virtual ~NetworkStream();
    5541    void init();
     42
     43    void connectToMasterServer(std::string host, int port);
     44    void connectToProxyServer(std::string host, int port);
     45    void createServer(int port);
    5646
    5747    void createNetworkGameManager();
    5848    void startHandshake();
    5949
     50    /* synchronizeable interface */
    6051    void connectSynchronizeable(Synchronizeable& sync);
    6152    void disconnectSynchronizeable(Synchronizeable& sync);
    6253
    63     inline bool isServer() const { return (this->type == NET_SERVER)? true:false; }
    64     inline bool isActive() const { return this->bActive; }
     54    inline int getMaxConnections(){ return SharedNetworkData::getInstance()->getMaxPlayer(); }
    6555
    66     inline int getMaxConnections(){ return MAX_CONNECTIONS; }
     56    /* functions for the peerInfo information retreival */
     57    inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }
     58    inline bool isUserMasterServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isMasterServer(); }
     59    inline bool isUserProxyServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServer(); }
     60    inline bool isUserClient( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isClient(); }
    6761
     62    /* peering interface */
     63    inline PeerInfo & getPeerInfo( int userId ) { return peers[userId]; }
     64    inline PeerInfo* getPeerInfo() { return this->pInfo; }
     65    inline PeerList getPeerInfoList() { return this->peers; }
     66
     67    /* data processing*/
    6868    virtual void processData();
     69
     70    /* debugging */
     71    void debug();
     72
     73
     74  private:
    6975
    7076    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
    7177    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
     78    void cleanUpOldSyncList();
    7279    int getSyncCount();
    7380
    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; }
    76 
    77     void debug();
    78 
    79     inline PeerInfo & getPeerInfo( int userId ) { return peers[userId]; }
    80 
    81 
    82   private:
    8381    void updateConnectionList();
     82    /* handle processes */
    8483    void handleHandshakes();
    8584    void handleUpstream( int tick );
    8685    void handleDownstream(int tick );
     86
     87    /* handle events*/
    8788    void handleNewClient( int userId );
    88     void cleanUpOldSyncList();
     89    void handleReconnect( int userId );
    8990
    9091    void writeToNewDict( byte * data, int length, bool upstream );
     
    9293
    9394  private:
    94     SynchronizeableList        synchronizeables;
    95     PeerList                   peers;
    96     ServerSocket*              serverSocket;
    97     int                        type;
    98     bool                       bActive;
    99     std::list<int>             freeSocketSlots;
     95    PeerList                   peers;                       //!< list of the network node informations
    10096
    101     int                        myHostId;
     97    PeerInfo*                  pInfo;                       //!< the info about the local peer node (not in the PeerList)
    10298
     99    std::list<int>             freeSocketSlots;             //!< list of free sockets (to ensure not to resycle sockets)
    103100    int                        currentState;                //!< current state id
    104101
    105     NetworkGameManager*        networkGameManager;
     102    NetworkMonitor*            networkMonitor;              //!< the network monitor
     103    NetworkGameManager*        networkGameManager;          //!< reference to the network game manager
     104    ServerSocket*              serverSocket;                //!< the listening socket of the server
    106105
    107106    std::map<int,int>          oldSynchronizeables;         //!< used to save recently deleted sync ids to not recreate them
     107    SynchronizeableList        synchronizeables;            //!< list of the synchronizeables
    108108
    109109    byte                       buf[UDP_PACKET_SIZE];        //!< used by handleUp/Downstream
    110110    byte                       compBuf[UDP_PACKET_SIZE];    //!< used by handleUp/Downstream
    111 
    112111    int                        remainingBytesToWriteToDict; //!< if > 0 NetworkStream will write packets to DATA/dicts/newdict
    113112
    114     int dictServer;
    115     int dictClient;
     113    int                        dictServer;                  //!< the zip dict for the server
     114    int                        dictClient;                  //!< the zip dict for the client
    116115};
    117116#endif /* _NETWORK_STREAM */
Note: See TracChangeset for help on using the changeset viewer.