Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

more handshake bugs from me :D

File size: 5.8 KB
Line 
1/*!
2 * @file network_stream.h
3 *  implementation of a network pipe. This node handles the handshake of two network nodes and exchanges informationas
4 * vial to the connection setup.
5 *
6 * the local node only writes in the localState variable. the remoteState variable will be written from the remote network node
7 * so don't write into it!
8 */
9
10#ifndef _HANDSHAKE
11#define _HANDSHAKE
12
13#include "base_object.h"
14#include "ip.h"
15#include "synchronizeable.h"
16
17//!< a struct to save the handshakes to
18struct HandshakeState
19{
20  int           orxId;                         //!< orxonox id
21  int           version;                       //!< network protocol version
22
23  int           networkManagerId;              //!< unique id of the network manager
24  int           messageManagerId;              //!< unique id of the message manager
25  int           hostId;                        //!< host id
26  int           nodeType;                      //!< type of the network node
27
28  int           completed;                     //!< true if completed
29  int           canDel;                        //!< true if marked for deletion
30
31  int           error;                         //!< error number
32
33  std::string   errorString;                   //!< error string
34
35  //additional data
36  std::string   preferedNickName;              //!< prefered nick name
37
38  int           redirectProxy;                 //!< true if the client should reconnect to a proxy server (either 1 or 2 )
39  IP            proxy1;                        //!< ip address of the first proxy (0.0.0.0 of not available)
40  IP            proxy2;                        //!< ip address of the second proxy (0.0.0.0 of not available)
41};
42
43
44//!< the handshake itself with some interface functions
45class Handshake : public Synchronizeable
46{
47
48  public:
49    Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
50
51
52    /* functions indicating states of the handshake */
53    /** @returns true if the handshake is completed */
54    inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; }
55    /** @returns true if no error has occured until now */
56    inline bool ok(){ return localState.error == 0 && remoteState.error == 0; }
57    /** stops the handshake and reject the other side with @param reason: string describing the reason */
58    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
59    /** @returns true if the handshake is finished and the instances can be deleted */
60    inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
61    /** @returns true if the local state can be removed*/
62    inline bool allowDel(){ return localState.canDel == 1; }
63    /** marks the handshake to be deleted */
64    inline void del(){ localState.canDel = 1; }
65
66
67    /* the actual informations exchanged in the handshake */
68    /** @returns the host id of the remote host */
69    inline int  getHostId(){ return remoteState.hostId; }
70    /** @returns the unique id of the network game manager*/
71    inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; }
72    /** @returns the unique id of the message manager */
73    inline int  getMessageManagerId(){ return remoteState.messageManagerId; }
74    /** @returns the node type of the remote host */
75    inline int getRemoteNodeType() { return this->remoteState.nodeType; }
76
77    /** sets @param nick the prefereded nick name */
78    inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
79    /** @returns the prefered nick name */
80    inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }
81
82    /** @returns if true the local client should reconnect to a proxy server from the proxy server list */
83    inline bool redirect() { return this->remoteState.redirectProxy;}
84    /** @param flag: indicating if the client should be redirected */
85    inline void setRedirect(bool flag) { this->localState.redirectProxy = flag; }
86
87    /** @param address: the address of the proxy server 1 if any */
88    inline void setProxy1Address(IP address) { this->localState.proxy1 = address; }
89    /** @returns the address of the proxy server 1 if any */
90    inline IP getProxy1Address() { return this->remoteState.proxy1; }
91    /** @param address: the address of the proxy server 2 if any */
92    inline void setProxy2Address(IP address) { this->localState.proxy2 = address; }
93    /** @returns the address of the proxy server 2 if any */
94    inline IP getProxy2Address() { return this->remoteState.proxy2; }
95
96
97    /* variable handler function */
98    virtual void varChangeHandler( std::list<int> & id );
99
100
101  private:
102    HandshakeState     localState;                            //!< the local handshake state
103    HandshakeState     remoteState;                           //!< the remote handshake state
104
105    int                orxId_handler;                         //!< orxonox id handler
106    int                version_handler;                       //!< orxonox version id handler
107    int                netManId_handler;                      //!< network manager handler
108    int                msgManId_handler;                      //!< message manager handler
109    int                hostId_handler;                        //!< host id handler
110    int                nodeTypeHandler;                       //!< node type handler
111
112    int                completed_handler;                     //!< handshake completion handler
113    int                error_handler;                         //!< handshake error handler
114    int                errorString_handler;                   //!< handshake error string handler
115    int                candel_id;                             //!< handshake deletion handler
116    int                nodeType;                              //!, the type of the network node
117
118};
119
120
121#endif
Note: See TracBrowser for help on using the repository browser.