Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9263 was 9262, checked in by patrick, 19 years ago

starting to extend the handshake to synchronize proxy server addresses

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