Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/handshake.h @ 9260

Last change on this file since 9260 was 9260, checked in by patrick, 18 years ago

variable alterations

File size: 3.4 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 _ORXONOX_ID 0xF91337A0
13
14#define _ORXONOX_VERSION 1
15
16struct HandshakeState {
17  int orxId;
18  int version;
19
20  int networkManagerId;
21  int messageManagerId;
22  int hostId;
23
24  int completed;
25  int canDel;
26
27  int error;
28
29  std::string errorString;
30
31  //additional data
32  std::string preferedNickName;
33};
34
35class Handshake : public Synchronizeable
36{
37
38  public:
39    Handshake( bool server, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
40
41
42    /* functions indicating states of the handshake */
43    /** @returns true if the handshake is completed */
44    inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; }
45    /** @returns true if no error has occured until now */
46    inline bool ok(){ return localState.error == 0 && remoteState.error == 0; }
47    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
48    /** @returns true if the handshake is finished and the instances can be deleted */
49    inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
50    /** @returns true if the local state can be removed*/
51    inline bool allowDel(){ return localState.canDel == 1; }
52    /** marks the handshake to be deleted */
53    inline void del(){ localState.canDel = 1; }
54
55    /* the actual informations exchanged in the handshake */
56    /** @returns the host id of the remote host */
57    inline int  getHostId(){ return remoteState.hostId; }
58    /** @returns the unique id of the network game manager*/
59    inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; }
60    /** @returns the unique id of the message manager */
61    inline int  getMessageManagerId(){ return remoteState.messageManagerId; }
62    /** stops the handshake and reject the other side with @param reason: string describing the reason */
63
64    /** sets @param nick the prefereded nick name */
65    inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
66    /** @returns the prefered nick name */
67    inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }
68
69    /* variable handler function */
70    virtual void varChangeHandler( std::list<int> & id );
71
72
73  private:
74    HandshakeState     localState;                            //!< the local handshake state
75    HandshakeState     remoteState;                           //!< the remote handshake state
76
77    int                orxId_handler;                         //!< orxonox id handler
78    int                version_handler;                       //!< orxonox version id handler
79    int                netManId_handler;                      //!< network manager handler
80    int                msgManId_handler;                      //!< message manager handler
81    int                hostId_handler;                        //!< host id handler
82
83    int                completed_handler;                     //!< handshake completion handler
84    int                error_handler;                         //!< handshake error handler
85    int                errorString_handler;                   //!< handshake error string handler
86    int                candel_id;                             //!< handshake deletion handler
87
88};
89
90
91#endif
Note: See TracBrowser for help on using the repository browser.