Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the network branche back here
merged with command:
svn merge -r8230:HEAD https://svn.orxonox.net/orxonox/branches/network .
conflicts resolved in favour of the network branche (conflicts were in network)

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