Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

variable alterations

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
[7954]12#define _ORXONOX_ID 0xF91337A0
[6043]13
[7954]14#define _ORXONOX_VERSION 1
[6043]15
[7954]16struct HandshakeState {
17  int orxId;
18  int version;
[9258]19
[7954]20  int networkManagerId;
21  int messageManagerId;
22  int hostId;
[9258]23
[7954]24  int completed;
25  int canDel;
[9258]26
[7954]27  int error;
[9258]28
[7954]29  std::string errorString;
[9258]30
[9235]31  //additional data
32  std::string preferedNickName;
[6043]33};
34
35class Handshake : public Synchronizeable
36{
[9258]37
[6043]38  public:
[7954]39    Handshake( bool server, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
[9258]40
41
[9259]42    /* functions indicating states of the handshake */
[9258]43    /** @returns true if the handshake is completed */
44    inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; }
45    /** @returns true if no error has occured until now */
46    inline bool ok(){ return localState.error == 0 && remoteState.error == 0; }
47    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
48    /** @returns true if the handshake is finished and the instances can be deleted */
49    inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
50    /** @returns true if the local state can be removed*/
51    inline bool allowDel(){ return localState.canDel == 1; }
52    /** marks the handshake to be deleted */
53    inline void del(){ localState.canDel = 1; }
54
[9259]55    /* the actual informations exchanged in the handshake */
56    /** @returns the host id of the remote host */
57    inline int  getHostId(){ return remoteState.hostId; }
58    /** @returns the unique id of the network game manager*/
59    inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; }
60    /** @returns the unique id of the message manager */
61    inline int  getMessageManagerId(){ return remoteState.messageManagerId; }
62    /** stops the handshake and reject the other side with @param reason: string describing the reason */
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
[6043]82
[9260]83    int                completed_handler;                     //!< handshake completion handler
84    int                error_handler;                         //!< handshake error handler
85    int                errorString_handler;                   //!< handshake error string handler
86    int                candel_id;                             //!< handshake deletion handler
87
[6043]88};
89
90
91#endif
Note: See TracBrowser for help on using the repository browser.