Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/handshake.cc @ 9360

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

network ip synchronization work

File size: 5.9 KB
RevLine 
[6043]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
[9347]12   main-programmer: Christoph Renner (rennerc@ee.ethz.ch)
13   co-programmer: Patirck Boenzli (boenzlip@orxonox.ethz.ch)
[6043]14*/
15
16
17#define DEBUG_MODULE_NETWORK
18
19#include "handshake.h"
20
[6753]21#include <cassert>
[8362]22#include "debug.h"
[6753]23
[9347]24
25
26
27
28 Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId )
[6695]29  : Synchronizeable()
[6043]30{
31  /* set the class id for the base object */
32  this->setClassID(CL_HANDSHAKE, "Handshake");
33
[9347]34  // register all variable handlers
[7954]35  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
36  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
37  netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) );
38  msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) );
39  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) );
40  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) );
41  error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) );
42  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
[8362]43
[9347]44  this->nodeTypeHandler = registerVarId( new SynchronizeableInt( &localState.nodeType, &remoteState.nodeType, "nodeType", PERMISSION_ALL ) );
45
[7954]46  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
[9347]47
[9235]48  registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
[9347]49  // now synchronize only two of the available proxy server addresses
[9360]50//   registerVar( new SynchronizeableIP( &this->proxy1, &this->proxy1, "proxy server 1", PERMISSION_ALL ) );
51//   registerVar( new SynchronizeableIP( &this->proxy2, &this->proxy2, "proxy server 2", PERMISSION_ALL ) );
52  registerVar( new SynchronizeableInt( this->proxy1.hostRef(), this->proxy1.hostRef(), "proxy server 1", PERMISSION_ALL));
53  registerVar( new SynchronizeableInt( this->proxy1.portRef(), this->proxy1.portRef(), "proxy server 1", PERMISSION_ALL));
54  registerVar( new SynchronizeableInt( this->proxy2.hostRef(), this->proxy2.hostRef(), "proxy server 2", PERMISSION_ALL));
55  registerVar( new SynchronizeableInt( this->proxy2.portRef(), this->proxy2.portRef(), "proxy server 2", PERMISSION_ALL));
[8362]56
[9347]57  // init the local state
[7954]58  localState.completed = 0;
59  localState.error = 0;
60  localState.errorString = "";
61  localState.hostId = clientId;
62  localState.networkManagerId = networkGameManagerId;
63  this->localState.messageManagerId = messageManagerId;
64  localState.orxId = _ORXONOX_ID;
65  localState.version = _ORXONOX_VERSION;
[9347]66  localState.nodeType = nodeType;
[7954]67  localState.canDel = 0;
[8362]68
[9347]69
70  // init the remote state
[7954]71  remoteState.completed = 0;
72  remoteState.error = 0;
73  remoteState.errorString = "";
74  remoteState.hostId = -1;
75  remoteState.networkManagerId = -1;
76  remoteState.messageManagerId = -1;
77  remoteState.orxId = 0;
78  remoteState.version = 0;
[9347]79  remoteState.nodeType = NET_CLIENT;
[7954]80  remoteState.canDel = 0;
[6053]81
[9350]82
[9360]83  this->proxyAddressesSynched = 2;
84  this->proxy1 = IP(0, 0);
85  this->proxy2 = IP(0, 0);
86  this->redirectProxy = 0;
[9350]87
88
[9347]89  // activate the synchronization process
[6695]90  this->setSynchronized(true);
[7954]91  PRINTF(0)("Handshake created clientId = %d\n", clientId);
[6043]92}
93
[9347]94
[7954]95/**
96 * handler for changes in synced vars
97 * @param id id's which have changed
98 */
99void Handshake::varChangeHandler( std::list< int > & id )
[6043]100{
[7954]101  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
[6043]102  {
[9347]103    // orxonox id handler
104    if ( *it == this->orxId_handler )
[6043]105    {
[7954]106      if ( remoteState.orxId != _ORXONOX_ID )
107      {
108        localState.error = 1;
109        localState.completed = 1;
110        localState.errorString = "Seems not to be orxonox!";
111        continue;
112      }
[6043]113    }
[8362]114
[9347]115    // orxonox version handler
116    if ( *it == this->version_handler )
[6043]117    {
[7954]118      if ( remoteState.version != _ORXONOX_VERSION )
119      {
120        localState.error = 2;
121        localState.completed = 1;
122        localState.errorString = "Versions of server and client do not match!";
123        continue;
124      }
[9347]125    }
[6043]126
[9347]127    // node type handler: for each node type there is a specific action to be taken
128    if ( *it == this->nodeTypeHandler)
129    {
130      if ( remoteState.nodeType == NET_MASTER_SERVER )
131      {
132        continue;
133      }
134      else if( remoteState.nodeType == NET_PROXY_SERVER_ACTIVE)
135      {
136        continue;
137      }
138      else if( remoteState.nodeType == NET_CLIENT)
139      {
140        continue;
141      }
[6043]142    }
[8362]143
[9347]144    // cancel
[7954]145    if ( *it == candel_id )
[6043]146    {
[7954]147      PRINTF(0)("handshake finished candel changed\n");
[6090]148    }
[8362]149
[9350]150    // the first proxy server synched
151    if( *it == this->proxy1Handler)
152    {
153      this->proxyAddressesSynched++;
[9360]154      PRINTF(0)("got proxy1: %i, %i\n", this->proxy1.host(), this->proxy1.port());
[9350]155    }
156
157    // the last proxy server synched
158    if( *it == this->proxy2Handler)
159    {
160      this->proxyAddressesSynched++;
[9360]161      PRINTF(0)("got proxy2: %i, %i\n", this->proxy2.host(), this->proxy2.port());
[9350]162    }
163
[6043]164  }
[8362]165
[9347]166  // handshake completed
167  if ( remoteState.orxId == _ORXONOX_ID &&
[9350]168       remoteState.version == _ORXONOX_VERSION &&
169       this->proxyAddressesSynched  == 2)
[9347]170  {
[7954]171    localState.completed = 1;
[9347]172  }
[6043]173}
174
Note: See TracBrowser for help on using the repository browser.