Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/handshake.h @ 10432

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

merged network back to trunk

File size: 6.4 KB
RevLine 
[6043]1/*!
2 * @file network_stream.h
[9406]3 *  implementation of a network pipe. This node handles the handshake of two network nodes and exchanges informationas
4 * vial to the connection setup.
5 *
6 * the local node only writes in the localState variable. the remoteState variable will be written from the remote network node
7 * so don't write into it!
[6043]8 */
9
10#ifndef _HANDSHAKE
11#define _HANDSHAKE
12
13#include "base_object.h"
[9406]14#include "ip.h"
[6043]15#include "synchronizeable.h"
[9406]16#include "shared_network_data.h"
[6043]17
[9406]18//!< a struct to save the handshakes to
19struct HandshakeState
20{
21  int           orxId;                         //!< orxonox id
22  int           version;                       //!< network protocol version
[6043]23
[9406]24  int           networkManagerId;              //!< unique id of the network manager
25  int           messageManagerId;              //!< unique id of the message manager
26  int           hostId;                        //!< host id
27  int           nodeType;                      //!< type of the network node
[6043]28
[9406]29  int           completed;                     //!< true if completed
30  int           canDel;                        //!< true if marked for deletion
31
32  int           error;                         //!< error number
33
34  std::string   errorString;                   //!< error string
35
[9235]36  //additional data
[9406]37  std::string   preferedNickName;              //!< prefered nick name
[6043]38};
39
[9406]40
41//!< the handshake itself with some interface functions
[6043]42class Handshake : public Synchronizeable
43{
[9869]44  ObjectListDeclaration(Handshake);
[6043]45  public:
[9406]46    Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
47
48
49    /* functions indicating states of the handshake */
50    /** @returns true if the handshake is completed */
[9494]51    inline bool completed() const { return localState.completed != 0 && remoteState.completed != 0; }
[9406]52    /** @returns true if no error has occured until now */
[9494]53    inline bool ok() const { return localState.error == 0 && remoteState.error == 0; }
[9406]54    /** stops the handshake and reject the other side with @param reason: string describing the reason */
55    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
56    /** @returns true if the handshake is finished and the instances can be deleted */
[9494]57    inline bool canDel() const { return localState.canDel == 1 && remoteState.canDel == 1; }
[9406]58    /** @returns true if the local state can be removed*/
[9494]59    inline bool allowDel() const { return localState.canDel == 1; }
[9406]60    /** marks the handshake to be deleted */
[9494]61    inline void del() { localState.canDel = 1; }
[9406]62
63
64    /* the actual informations exchanged in the handshake */
65    /** @returns the host id of the remote host */
[9494]66    inline int  getHostId() const { return remoteState.hostId; }
[9406]67    /** @returns the unique id of the network game manager*/
[9494]68    inline int  getNetworkGameManagerId() const { return remoteState.networkManagerId; }
[9406]69    /** @returns the unique id of the message manager */
[9494]70    inline int  getMessageManagerId() const { return remoteState.messageManagerId; }
[9406]71    /** @returns the node type of the remote host */
[9494]72    inline int getRemoteNodeType() const { return this->remoteState.nodeType; }
[9406]73
74    /** sets @param nick the prefereded nick name */
75    inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
76    /** @returns the prefered nick name */
[9494]77    inline const std::string& getPreferedNickName() const { return remoteState.preferedNickName; }
[9406]78
79    /** @returns if true the local client should reconnect to a proxy server from the proxy server list */
[9494]80    inline bool redirect() const  { return this->redirectProxy; }
[9406]81    /** @param flag: indicating if the client should be redirected */
82    inline void setRedirect(bool flag) { if( SharedNetworkData::getInstance()->isClient()) return; this->redirectProxy = (int)flag; }
83
84    /** @param address: the address of the proxy server 1 if any */
85    inline void setProxy1Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy1 = address; }
86    /** @returns the address of the proxy server 1 if any */
[9494]87    inline IP getProxy1Address() const { return this->proxy1; }
[9406]88    /** @param address: the address of the proxy server 2 if any */
89    inline void setProxy2Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy2 = address; }
90    /** @returns the address of the proxy server 2 if any */
[9494]91    inline IP getProxy2Address() const { return this->proxy2; }
[9406]92
93
94    /* variable handler function */
[7954]95    virtual void varChangeHandler( std::list<int> & id );
[6043]96
[9406]97
[6043]98  private:
[9406]99    HandshakeState     localState;                            //!< the local handshake state
100    HandshakeState     remoteState;                           //!< the remote handshake state
[6043]101
[9406]102    int                orxId_handler;                         //!< orxonox id handler
103    int                version_handler;                       //!< orxonox version id handler
104    int                netManId_handler;                      //!< network manager handler
105    int                msgManId_handler;                      //!< message manager handler
106    int                hostId_handler;                        //!< host id handler
107    int                nodeTypeHandler;                       //!< node type handler
108    int                proxy1Handler;                         //!< handler for the proxy
109    int                proxy2Handler;                         //!< handler for the proxy
110
111    int                completed_handler;                     //!< handshake completion handler
112    int                error_handler;                         //!< handshake error handler
113    int                errorString_handler;                   //!< handshake error string handler
114    int                candel_id;                             //!< handshake deletion handler
[10114]115    int                nodeType;                              //!< the type of the network node
[9406]116
117    int                redirectProxy;                         //!< true if the client should reconnect to a proxy server
118    IP                 proxy1;                               //!< ip address of the first proxy (0.0.0.0 of not available)
119    IP                 proxy2;                               //!< ip address of the second proxy (0.0.0.0 of not available)
[10114]120   
121    static std::map< std::string, int >* classIdList;
122  public:
123    std::map< std::string, int >* getClassIdList(){ return classIdList; }
[6043]124};
125
126
127#endif
Note: See TracBrowser for help on using the repository browser.