Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

redirection flag added, proxy settings as a way to get/save the server settings

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