| [6043] | 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 | |
|---|
| [9295] | 13 | struct HandshakeState |
|---|
| 14 | { |
|---|
| 15 | int orxId; //!< orxonox id |
|---|
| 16 | int version; //!< network protocol version |
|---|
| [9258] | 17 | |
|---|
| [9295] | 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 |
|---|
| [9258] | 22 | |
|---|
| [9295] | 23 | int completed; //!< true if completed |
|---|
| 24 | int canDel; //!< true if marked for deletion |
|---|
| [9258] | 25 | |
|---|
| [9295] | 26 | int error; //!< error number |
|---|
| [9258] | 27 | |
|---|
| [9295] | 28 | std::string errorString; //!< error string |
|---|
| [9258] | 29 | |
|---|
| [9235] | 30 | //additional data |
|---|
| [9295] | 31 | std::string preferedNickName; //!< prefered nick name |
|---|
| 32 | |
|---|
| 33 | int freeSlots; //!< true if there are still free slots on this server |
|---|
| 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) |
|---|
| [6043] | 36 | }; |
|---|
| 37 | |
|---|
| 38 | class Handshake : public Synchronizeable |
|---|
| 39 | { |
|---|
| [9258] | 40 | |
|---|
| [6043] | 41 | public: |
|---|
| [9270] | 42 | Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 ); |
|---|
| [9258] | 43 | |
|---|
| 44 | |
|---|
| [9259] | 45 | /* functions indicating states of the handshake */ |
|---|
| [9258] | 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; } |
|---|
| [9269] | 50 | /** stops the handshake and reject the other side with @param reason: string describing the reason */ |
|---|
| [9258] | 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 | |
|---|
| [9295] | 59 | |
|---|
| [9259] | 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; } |
|---|
| [9269] | 67 | /** @returns the node type of the remote host */ |
|---|
| 68 | inline int getRemoteNodeType() { return this->remoteState.nodeType; } |
|---|
| [9259] | 69 | |
|---|
| [9258] | 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 */ |
|---|
| [9235] | 73 | inline std::string getPreferedNickName(){ return remoteState.preferedNickName; } |
|---|
| [9258] | 74 | |
|---|
| [9295] | 75 | /** @param address: the address of the proxy server 1 if any */ |
|---|
| 76 | inline void setProxy1Address(IPaddress address) { this->localState.proxy1 = address; } |
|---|
| 77 | /** @returns the address of the proxy server 1 if any */ |
|---|
| 78 | inline IPaddress getProxy1Address() { return this->localState.proxy1; } |
|---|
| 79 | /** @param address: the address of the proxy server 2 if any */ |
|---|
| 80 | inline void setProxy2Address(IPaddress address) { this->localState.proxy2 = address; } |
|---|
| 81 | /** @returns the address of the proxy server 2 if any */ |
|---|
| 82 | inline IPaddress getProxy2Address() { return this->localState.proxy2; } |
|---|
| 83 | |
|---|
| 84 | |
|---|
| [9259] | 85 | /* variable handler function */ |
|---|
| [7954] | 86 | virtual void varChangeHandler( std::list<int> & id ); |
|---|
| [6043] | 87 | |
|---|
| [9259] | 88 | |
|---|
| [6043] | 89 | private: |
|---|
| [9259] | 90 | HandshakeState localState; //!< the local handshake state |
|---|
| 91 | HandshakeState remoteState; //!< the remote handshake state |
|---|
| [9258] | 92 | |
|---|
| [9260] | 93 | int orxId_handler; //!< orxonox id handler |
|---|
| 94 | int version_handler; //!< orxonox version id handler |
|---|
| [9259] | 95 | int netManId_handler; //!< network manager handler |
|---|
| 96 | int msgManId_handler; //!< message manager handler |
|---|
| [9260] | 97 | int hostId_handler; //!< host id handler |
|---|
| [9268] | 98 | int nodeTypeHandler; //!< node type handler |
|---|
| [6043] | 99 | |
|---|
| [9260] | 100 | int completed_handler; //!< handshake completion handler |
|---|
| 101 | int error_handler; //!< handshake error handler |
|---|
| 102 | int errorString_handler; //!< handshake error string handler |
|---|
| 103 | int candel_id; //!< handshake deletion handler |
|---|
| [9268] | 104 | int nodeType; //!, the type of the network node |
|---|
| [9260] | 105 | |
|---|
| [6043] | 106 | }; |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | #endif |
|---|