| 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 |  | 
|---|
| 13 | struct HandshakeState { | 
|---|
| 14 |   int orxId;                         //!< orxonox id | 
|---|
| 15 |   int version;                       //!< network protocol version | 
|---|
| 16 |  | 
|---|
| 17 |   int networkManagerId;              //!< unique id of the network manager | 
|---|
| 18 |   int messageManagerId;              //!< unique id of the message manager | 
|---|
| 19 |   int hostId;                        //!< host id | 
|---|
| 20 |   int nodeType;                      //!< type of the network node | 
|---|
| 21 |  | 
|---|
| 22 |   int completed;                     //!< true if completed | 
|---|
| 23 |   int canDel;                        //!< true if marked for deletion | 
|---|
| 24 |  | 
|---|
| 25 |   int error;                         //!< error number | 
|---|
| 26 |  | 
|---|
| 27 |   std::string errorString;           //!< error string | 
|---|
| 28 |  | 
|---|
| 29 |   //additional data | 
|---|
| 30 |   std::string preferedNickName;      //!< prefered nick name | 
|---|
| 31 | }; | 
|---|
| 32 |  | 
|---|
| 33 | class Handshake : public Synchronizeable | 
|---|
| 34 | { | 
|---|
| 35 |  | 
|---|
| 36 |   public: | 
|---|
| 37 |     Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 ); | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 |     /* functions indicating states of the handshake */ | 
|---|
| 41 |     /** @returns true if the handshake is completed */ | 
|---|
| 42 |     inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; } | 
|---|
| 43 |     /** @returns true if no error has occured until now */ | 
|---|
| 44 |     inline bool ok(){ return localState.error == 0 && remoteState.error == 0; } | 
|---|
| 45 |     /** stops the handshake and reject the other side with @param reason: string describing the reason */ | 
|---|
| 46 |     inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } | 
|---|
| 47 |     /** @returns true if the handshake is finished and the instances can be deleted */ | 
|---|
| 48 |     inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; } | 
|---|
| 49 |     /** @returns true if the local state can be removed*/ | 
|---|
| 50 |     inline bool allowDel(){ return localState.canDel == 1; } | 
|---|
| 51 |     /** marks the handshake to be deleted */ | 
|---|
| 52 |     inline void del(){ localState.canDel = 1; } | 
|---|
| 53 |  | 
|---|
| 54 |     /* the actual informations exchanged in the handshake */ | 
|---|
| 55 |     /** @returns the host id of the remote host */ | 
|---|
| 56 |     inline int  getHostId(){ return remoteState.hostId; } | 
|---|
| 57 |     /** @returns the unique id of the network game manager*/ | 
|---|
| 58 |     inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; } | 
|---|
| 59 |     /** @returns the unique id of the message manager */ | 
|---|
| 60 |     inline int  getMessageManagerId(){ return remoteState.messageManagerId; } | 
|---|
| 61 |     /** @returns the node type of the remote host */ | 
|---|
| 62 |     inline int getRemoteNodeType() { return this->remoteState.nodeType; } | 
|---|
| 63 |  | 
|---|
| 64 |     /** sets @param nick the prefereded nick name */ | 
|---|
| 65 |     inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; } | 
|---|
| 66 |     /** @returns the prefered nick name */ | 
|---|
| 67 |     inline std::string getPreferedNickName(){ return remoteState.preferedNickName; } | 
|---|
| 68 |  | 
|---|
| 69 |     /* variable handler function */ | 
|---|
| 70 |     virtual void varChangeHandler( std::list<int> & id ); | 
|---|
| 71 |  | 
|---|
| 72 |  | 
|---|
| 73 |   private: | 
|---|
| 74 |     HandshakeState     localState;                            //!< the local handshake state | 
|---|
| 75 |     HandshakeState     remoteState;                           //!< the remote handshake state | 
|---|
| 76 |  | 
|---|
| 77 |     int                orxId_handler;                         //!< orxonox id handler | 
|---|
| 78 |     int                version_handler;                       //!< orxonox version id handler | 
|---|
| 79 |     int                netManId_handler;                      //!< network manager handler | 
|---|
| 80 |     int                msgManId_handler;                      //!< message manager handler | 
|---|
| 81 |     int                hostId_handler;                        //!< host id handler | 
|---|
| 82 |     int                nodeTypeHandler;                       //!< node type handler | 
|---|
| 83 |  | 
|---|
| 84 |     int                completed_handler;                     //!< handshake completion handler | 
|---|
| 85 |     int                error_handler;                         //!< handshake error handler | 
|---|
| 86 |     int                errorString_handler;                   //!< handshake error string handler | 
|---|
| 87 |     int                candel_id;                             //!< handshake deletion handler | 
|---|
| 88 |     int                nodeType;                              //!, the type of the network node | 
|---|
| 89 |  | 
|---|
| 90 | }; | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 | #endif | 
|---|