Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9347 in orxonox.OLD for branches/proxy/src/lib/network/handshake.h


Ignore:
Timestamp:
Jul 20, 2006, 11:43:27 AM (18 years ago)
Author:
bensch
Message:

orxonox/proxy: merged the proxy.old back again, and it seems to work.

Merged with command
svn merge -r9247:HEAD https://svn.orxonox.net/orxonox/branches/proxy.old .

no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/proxy/src/lib/network/handshake.h

    r9235 r9347  
    11/*!
    22 * @file network_stream.h
    3  *  implementation of a network pipe
     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!
    48 */
    59
     
    812
    913#include "base_object.h"
     14#include "ip.h"
    1015#include "synchronizeable.h"
    1116
    12 #define _ORXONOX_ID 0xF91337A0
     17//!< a struct to save the handshakes to
     18struct HandshakeState
     19{
     20  int           orxId;                         //!< orxonox id
     21  int           version;                       //!< network protocol version
    1322
    14 #define _ORXONOX_VERSION 1
     23  int           networkManagerId;              //!< unique id of the network manager
     24  int           messageManagerId;              //!< unique id of the message manager
     25  int           hostId;                        //!< host id
     26  int           nodeType;                      //!< type of the network node
    1527
    16 struct HandshakeState {
    17   int orxId;
    18   int version;
    19  
    20   int networkManagerId;
    21   int messageManagerId;
    22   int hostId;
    23  
    24   int completed;
    25   int canDel;
    26  
    27   int error;
    28  
    29   std::string errorString;
    30  
     28  int           completed;                     //!< true if completed
     29  int           canDel;                        //!< true if marked for deletion
     30
     31  int           error;                         //!< error number
     32
     33  std::string   errorString;                   //!< error string
     34
    3135  //additional data
    32   std::string preferedNickName;
     36  std::string   preferedNickName;              //!< prefered nick name
     37
     38  int           redirectProxy;                 //!< true if the client should reconnect to a proxy server (either 1 or 2 )
     39  IP            proxy1;                        //!< ip address of the first proxy (0.0.0.0 of not available)
     40  IP            proxy2;                        //!< ip address of the second proxy (0.0.0.0 of not available)
    3341};
    3442
     43
     44//!< the handshake itself with some interface functions
    3545class Handshake : public Synchronizeable
    3646{
     47
    3748  public:
    38     Handshake( bool server, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
    39     inline bool       completed(){ return localState.completed != 0 && remoteState.completed != 0; }
    40     inline bool       ok(){ return localState.error == 0 && remoteState.error == 0; }
    41     inline int        getHostId(){ return remoteState.hostId; }
    42     inline int        getNetworkGameManagerId(){ return remoteState.networkManagerId; }
    43     inline int        getMessageManagerId(){ return remoteState.messageManagerId; }
    44     inline void       doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
    45     inline bool       canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
    46     inline bool       allowDel(){ return localState.canDel == 1; }
    47     inline void       del(){ localState.canDel = 1; }
    48    
    49     inline void       setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
     49    Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 );
     50
     51
     52    /* functions indicating states of the handshake */
     53    /** @returns true if the handshake is completed */
     54    inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; }
     55    /** @returns true if no error has occured until now */
     56    inline bool ok(){ return localState.error == 0 && remoteState.error == 0; }
     57    /** stops the handshake and reject the other side with @param reason: string describing the reason */
     58    inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; }
     59    /** @returns true if the handshake is finished and the instances can be deleted */
     60    inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; }
     61    /** @returns true if the local state can be removed*/
     62    inline bool allowDel(){ return localState.canDel == 1; }
     63    /** marks the handshake to be deleted */
     64    inline void del(){ localState.canDel = 1; }
     65
     66
     67    /* the actual informations exchanged in the handshake */
     68    /** @returns the host id of the remote host */
     69    inline int  getHostId(){ return remoteState.hostId; }
     70    /** @returns the unique id of the network game manager*/
     71    inline int  getNetworkGameManagerId(){ return remoteState.networkManagerId; }
     72    /** @returns the unique id of the message manager */
     73    inline int  getMessageManagerId(){ return remoteState.messageManagerId; }
     74    /** @returns the node type of the remote host */
     75    inline int getRemoteNodeType() { return this->remoteState.nodeType; }
     76
     77    /** sets @param nick the prefereded nick name */
     78    inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; }
     79    /** @returns the prefered nick name */
    5080    inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }
    51    
     81
     82    /** @returns if true the local client should reconnect to a proxy server from the proxy server list */
     83    inline bool redirect() { return this->remoteState.redirectProxy;}
     84    /** @param flag: indicating if the client should be redirected */
     85    inline void setRedirect(bool flag) { this->localState.redirectProxy = flag; }
     86
     87    /** @param address: the address of the proxy server 1 if any */
     88    inline void setProxy1Address(IP address) { this->localState.proxy1 = address; }
     89    /** @returns the address of the proxy server 1 if any */
     90    inline IP getProxy1Address() { return this->remoteState.proxy1; }
     91    /** @param address: the address of the proxy server 2 if any */
     92    inline void setProxy2Address(IP address) { this->localState.proxy2 = address; }
     93    /** @returns the address of the proxy server 2 if any */
     94    inline IP getProxy2Address() { return this->remoteState.proxy2; }
     95
     96
     97    /* variable handler function */
    5298    virtual void varChangeHandler( std::list<int> & id );
    5399
     100
    54101  private:
    55     HandshakeState localState;
    56     HandshakeState remoteState;
    57    
    58     int netManId_handler;
    59     int msgManId_handler;
    60     int hostId_handler;
    61     int completed_handler;
    62     int error_handler;
    63     int errorString_handler;
    64     int orxId_handler;
    65     int version_handler;
    66     int candel_id;
     102    HandshakeState     localState;                            //!< the local handshake state
     103    HandshakeState     remoteState;                           //!< the remote handshake state
     104
     105    int                orxId_handler;                         //!< orxonox id handler
     106    int                version_handler;                       //!< orxonox version id handler
     107    int                netManId_handler;                      //!< network manager handler
     108    int                msgManId_handler;                      //!< message manager handler
     109    int                hostId_handler;                        //!< host id handler
     110    int                nodeTypeHandler;                       //!< node type handler
     111
     112    int                completed_handler;                     //!< handshake completion handler
     113    int                error_handler;                         //!< handshake error handler
     114    int                errorString_handler;                   //!< handshake error string handler
     115    int                candel_id;                             //!< handshake deletion handler
     116    int                nodeType;                              //!, the type of the network node
    67117
    68118};
Note: See TracChangeset for help on using the changeset viewer.