Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

reimplemented NetworkStream

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