Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/resources/src/lib/network/handshake.h @ 8821

Last change on this file since 8821 was 6341, checked in by bensch, 19 years ago

orxonox/trunk: merged the network branche back to the trunk, so we do not get away from each other to fast

File size: 1.7 KB
Line 
1/*!
2 * @file network_stream.h
3 *  implementation of a network pipe
4 */
5
6#ifndef _HANDSHAKE
7#define _HANDSHAKE
8
9#include "base_object.h"
10#include "synchronizeable.h"
11
12#define _INITIAL_DATA "orxonox"
13#define _INITIAL_DATA_LENGTH 7
14
15#define _ORXONOX_VERSION "\x00\x00\x00\x01"
16#define _ORXONOX_VERSION_LENGTH 4
17
18typedef enum HandshakeState {
19  HS_SENT_INIT  = 0x00000001,
20  HS_RECVD_INIT = 0x00000002,
21  HS_SENT_VER   = 0x00000004,
22  HS_RECVD_VER  = 0x00000008,
23  HS_SENT_HID   = 0x00000010,
24  HS_RECVD_HID  = 0x00000020,
25  HS_COMPLETED  = 0x00000040,
26
27  HS_DO_REJECT  = 0x00010000,
28  HS_WAS_REJECT = 0x00020000,
29
30  NUM_STATES
31};
32
33class Handshake : public Synchronizeable
34{
35  public:
36    Handshake(bool server, int clientId = 0, int networkGameManagerId = 0);
37    inline bool       completed(){ return hasState( HS_COMPLETED ); }
38    inline bool       ok(){ return isOk; }
39    inline int        getHostId(){ return newHostId; }
40    inline int        getNetworkGameManagerId(){ return newNetworkGameManagerId; }
41
42    inline void       doReject(){ setState(HS_DO_REJECT); }
43
44    virtual int       writeBytes(const byte* data, int length, int sender);
45    virtual int       readBytes(byte* data, int maxLength, int * reciever);
46    virtual void      writeDebug() const;
47    virtual void      readDebug() const;
48
49  private:
50    int               state;
51    int               clientId;
52    int               networkGameManagerId;
53    int               newHostId;
54    int               newNetworkGameManagerId;
55    bool              isOk;
56
57    inline bool       hasState( int a ){ return (state & a) == a; }
58    inline void       setState( int a ){ state = state | a; }
59    inline void       unsetState( int a ){ state = state & (~a); }
60
61};
62
63
64#endif
Note: See TracBrowser for help on using the repository browser.