Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_stream.h @ 7767

Last change on this file since 7767 was 7767, checked in by rennerc, 18 years ago

hover registers sync vars. started with connection monitor

File size: 2.7 KB
Line 
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#include <map>
12
13#include "data_stream.h"
14#include "server_socket.h"
15#include "handshake.h"
16#include "connection_monitor.h"
17
18class Synchronizeable;
19class NetworkSocket;
20class ServerSocket;
21class NetworkGameManager;
22
23class PeerInfo
24{
25  public:
26    PeerInfo() { clear(); }
27    void clear() { userId = 0; isServer = false; socket = NULL; handshake = NULL; lastAckedState = 0; lastRecvedState = 0; connectionMonitor = NULL; }
28    int                 userId;
29    bool                isServer;
30    NetworkSocket *     socket;
31    Handshake *         handshake;
32    ConnectionMonitor * connectionMonitor;
33    int                 lastAckedState;
34    int                 lastRecvedState;
35};
36
37typedef std::list<Synchronizeable*>  SynchronizeableList;
38typedef std::map<int,PeerInfo>       PeerList;
39
40
41class NetworkStream : public DataStream
42{
43
44  public:
45    NetworkStream();
46    NetworkStream( std::string host, int port);
47    NetworkStream( int port );
48
49    virtual ~NetworkStream();
50    void init();
51
52    void createNetworkGameManager();
53    void startHandshake();
54
55    void connectSynchronizeable(Synchronizeable& sync);
56    void disconnectSynchronizeable(Synchronizeable& sync);
57
58    inline bool isServer() const { return (this->type == NET_SERVER)? true:false; }
59    inline bool isActive() const { return this->bActive; }
60
61    inline int getMaxConnections(){ return MAX_CONNECTIONS; }
62
63    virtual void processData();
64
65    inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); }
66    inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); }
67    int getSyncCount();
68
69    inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); }
70    inline bool isUserServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isServer; }
71
72    void debug();
73   
74    inline PeerInfo & getPeerInfo( int userId ) { return peers[userId]; }
75
76
77  private:
78    void updateConnectionList();
79    void handleHandshakes();
80    void handleUpstream();
81    void handleDownstream(); 
82    void handleNewClient( int userId );
83    void cleanUpOldSyncList();
84
85
86  private:
87    SynchronizeableList        synchronizeables;
88    PeerList                   peers;
89    ServerSocket*              serverSocket;
90    int                        type;
91    bool                       bActive;
92    std::list<int>             freeSocketSlots;
93
94    int                        myHostId;
95   
96    int                        currentState;
97
98    NetworkGameManager*        networkGameManager;
99
100    std::map<int,int>          oldSynchronizeables;
101};
102#endif /* _NETWORK_STREAM */
Note: See TracBrowser for help on using the repository browser.