Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

removed old proxy synchronization mech

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