Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

handshake now waits for ip list sync

File size: 5.4 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
[9350]50  proxy1Handler = registerVarId( new SynchronizeableIP( &localState.proxy1, &remoteState.proxy1, "proxy server 1", PERMISSION_ALL ) );
51  proxy2Handler = registerVarId( new SynchronizeableIP( &localState.proxy2, &remoteState.proxy2, "proxy server 2", PERMISSION_ALL ) );
[8362]52
[9347]53  // init the local state
[7954]54  localState.completed = 0;
55  localState.error = 0;
56  localState.errorString = "";
57  localState.hostId = clientId;
58  localState.networkManagerId = networkGameManagerId;
59  this->localState.messageManagerId = messageManagerId;
60  localState.orxId = _ORXONOX_ID;
61  localState.version = _ORXONOX_VERSION;
[9347]62  localState.nodeType = nodeType;
[7954]63  localState.canDel = 0;
[9347]64  localState.redirectProxy = 0;
65  localState.proxy1 = IP(0, 0);
66  localState.proxy2 = IP (0, 0);
[8362]67
[9347]68
69  // init the remote state
[7954]70  remoteState.completed = 0;
71  remoteState.error = 0;
72  remoteState.errorString = "";
73  remoteState.hostId = -1;
74  remoteState.networkManagerId = -1;
75  remoteState.messageManagerId = -1;
76  remoteState.orxId = 0;
77  remoteState.version = 0;
[9347]78  remoteState.nodeType = NET_CLIENT;
[7954]79  remoteState.canDel = 0;
[9347]80  remoteState.redirectProxy = 0;
81  remoteState.proxy1 = IP(0, 0);
82  remoteState.proxy2 = IP(0, 0);
[6053]83
[9350]84
85  this->proxyAddressesSynched = 0;
86
87
[9347]88  // activate the synchronization process
[6695]89  this->setSynchronized(true);
[7954]90  PRINTF(0)("Handshake created clientId = %d\n", clientId);
[6043]91}
92
[9347]93
[7954]94/**
95 * handler for changes in synced vars
96 * @param id id's which have changed
97 */
98void Handshake::varChangeHandler( std::list< int > & id )
[6043]99{
[7954]100  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
[6043]101  {
[9347]102    // orxonox id handler
103    if ( *it == this->orxId_handler )
[6043]104    {
[7954]105      if ( remoteState.orxId != _ORXONOX_ID )
106      {
107        localState.error = 1;
108        localState.completed = 1;
109        localState.errorString = "Seems not to be orxonox!";
110        continue;
111      }
[6043]112    }
[8362]113
[9347]114    // orxonox version handler
115    if ( *it == this->version_handler )
[6043]116    {
[7954]117      if ( remoteState.version != _ORXONOX_VERSION )
118      {
119        localState.error = 2;
120        localState.completed = 1;
121        localState.errorString = "Versions of server and client do not match!";
122        continue;
123      }
[9347]124    }
[6043]125
[9347]126    // node type handler: for each node type there is a specific action to be taken
127    if ( *it == this->nodeTypeHandler)
128    {
129      if ( remoteState.nodeType == NET_MASTER_SERVER )
130      {
131        continue;
132      }
133      else if( remoteState.nodeType == NET_PROXY_SERVER_ACTIVE)
134      {
135        continue;
136      }
137      else if( remoteState.nodeType == NET_CLIENT)
138      {
139        continue;
140      }
[6043]141    }
[8362]142
[9347]143    // cancel
[7954]144    if ( *it == candel_id )
[6043]145    {
[7954]146      PRINTF(0)("handshake finished candel changed\n");
[6090]147    }
[8362]148
[9350]149    // the first proxy server synched
150    if( *it == this->proxy1Handler)
151    {
152      this->proxyAddressesSynched++;
153    }
154
155    // the last proxy server synched
156    if( *it == this->proxy2Handler)
157    {
158      this->proxyAddressesSynched++;
159    }
160
[6043]161  }
[8362]162
[9347]163  // handshake completed
164  if ( remoteState.orxId == _ORXONOX_ID &&
[9350]165       remoteState.version == _ORXONOX_VERSION &&
166       this->proxyAddressesSynched  == 2)
[9347]167  {
[7954]168    localState.completed = 1;
[9347]169  }
[6043]170}
171
Note: See TracBrowser for help on using the repository browser.