Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network node type handshake extension

File size: 4.1 KB
RevLine 
[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
[7954]13struct HandshakeState {
[9268]14  int orxId;                         //!< orxonox id
15  int version;                       //!< network protocol version
[9258]16
[9268]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
[9258]21
[9268]22  int completed;                     //!< true if completed
23  int canDel;                        //!< true if marked for deletion
[9258]24
[9268]25  int error;                         //!< error number
[9258]26
[9268]27  std::string errorString;           //!< error string
[9258]28
[9235]29  //additional data
[9268]30  std::string preferedNickName;      //!< prefered nick name
[6043]31};
32
33class Handshake : public Synchronizeable
34{
[9258]35
[6043]36  public:
[7954]37    Handshake( bool server, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
[9258]38
39
[9259]40    /* functions indicating states of the handshake */
[9258]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; }
[9269]45    /** stops the handshake and reject the other side with @param reason: string describing the reason */
[9258]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
[9259]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; }
[9269]61    /** @returns the node type of the remote host */
62    inline int getRemoteNodeType() { return this->remoteState.nodeType; }
[9259]63
[9258]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 */
[9235]67    inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }
[9258]68
[9259]69    /* variable handler function */
[7954]70    virtual void varChangeHandler( std::list<int> & id );
[6043]71
[9259]72
[6043]73  private:
[9259]74    HandshakeState     localState;                            //!< the local handshake state
75    HandshakeState     remoteState;                           //!< the remote handshake state
[9258]76
[9260]77    int                orxId_handler;                         //!< orxonox id handler
78    int                version_handler;                       //!< orxonox version id handler
[9259]79    int                netManId_handler;                      //!< network manager handler
80    int                msgManId_handler;                      //!< message manager handler
[9260]81    int                hostId_handler;                        //!< host id handler
[9268]82    int                nodeTypeHandler;                       //!< node type handler
[6043]83
[9260]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
[9268]88    int                nodeType;                              //!, the type of the network node
[9260]89
[6043]90};
91
92
93#endif
Note: See TracBrowser for help on using the repository browser.