Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

starting to extend the handshake to synchronize proxy server addresses

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