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