Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9268 was 9268, checked in by patrick, 19 years ago

extending handshake for node type exchange

File size: 4.0 KB
Line 
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
13struct 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
33class Handshake : public Synchronizeable
34{
35
36  public:
37    Handshake( bool server, 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    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
46    /** @returns true if the handshake is finished and the instances can be deleted */
47    inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
48    /** @returns true if the local state can be removed*/
49    inline bool allowDel(){ return localState.canDel == 1; }
50    /** marks the handshake to be deleted */
51    inline void del(){ localState.canDel = 1; }
52
53    /* the actual informations exchanged in the handshake */
54    /** @returns the host id of the remote host */
55    inline int  getHostId(){ return remoteState.hostId; }
56    /** @returns the unique id of the network game manager*/
57    inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; }
58    /** @returns the unique id of the message manager */
59    inline int  getMessageManagerId(){ return remoteState.messageManagerId; }
60    /** stops the handshake and reject the other side with @param reason: string describing the reason */
61
62    /** sets @param nick the prefereded nick name */
63    inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
64    /** @returns the prefered nick name */
65    inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }
66
67    /* variable handler function */
68    virtual void varChangeHandler( std::list<int> & id );
69
70
71  private:
72    HandshakeState     localState;                            //!< the local handshake state
73    HandshakeState     remoteState;                           //!< the remote handshake state
74
75    int                orxId_handler;                         //!< orxonox id handler
76    int                version_handler;                       //!< orxonox version id handler
77    int                netManId_handler;                      //!< network manager handler
78    int                msgManId_handler;                      //!< message manager handler
79    int                hostId_handler;                        //!< host id handler
80    int                nodeTypeHandler;                       //!< node type handler
81
82    int                completed_handler;                     //!< handshake completion handler
83    int                error_handler;                         //!< handshake error handler
84    int                errorString_handler;                   //!< handshake error string handler
85    int                candel_id;                             //!< handshake deletion handler
86    int                nodeType;                              //!, the type of the network node
87
88};
89
90
91#endif
Note: See TracBrowser for help on using the repository browser.