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