Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/handshake.cc @ 9653

Last change on this file since 9653 was 9494, checked in by bensch, 18 years ago

merged the proxy back

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:
[9406]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
[9406]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
[8362]34
[9406]35  // register all variable handlers
[7954]36  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
37  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
38  netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) );
39  msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) );
40  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) );
41  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) );
42  error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) );
43  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
[8362]44
[9406]45  this->nodeTypeHandler = registerVarId( new SynchronizeableInt( &localState.nodeType, &remoteState.nodeType, "nodeType", PERMISSION_ALL ) );
46
[7954]47  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
[9406]48
[9235]49  registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
[9406]50  // now synchronize only two of the available proxy server addresses
51  registerVar( new SynchronizeableIP( &this->proxy1, &this->proxy1, "proxy server 1", PERMISSION_MASTER_SERVER ) );
52  registerVar( new SynchronizeableIP( &this->proxy2, &this->proxy2, "proxy server 2", PERMISSION_MASTER_SERVER ) );
53  registerVar( new SynchronizeableInt( &this->redirectProxy, &this->redirectProxy, "proxy server redirection flag", PERMISSION_MASTER_SERVER ) );
[8362]54
[9406]55
56  // init the local state
[7954]57  localState.completed = 0;
58  localState.error = 0;
59  localState.errorString = "";
60  localState.hostId = clientId;
61  localState.networkManagerId = networkGameManagerId;
62  this->localState.messageManagerId = messageManagerId;
63  localState.orxId = _ORXONOX_ID;
64  localState.version = _ORXONOX_VERSION;
[9406]65  localState.nodeType = nodeType;
[7954]66  localState.canDel = 0;
[8362]67
[9406]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;
[9494]78  remoteState.nodeType = NET_UNASSIGNED;
[7954]79  remoteState.canDel = 0;
[6053]80
[9406]81
82  this->proxy1 = IP(0, 0);
83  this->proxy2 = IP(0, 0);
84  this->redirectProxy = 0;
85
86
87  // activate the synchronization process
[6695]88  this->setSynchronized(true);
[7954]89  PRINTF(0)("Handshake created clientId = %d\n", clientId);
[6043]90}
91
[9406]92
[7954]93/**
94 * handler for changes in synced vars
95 * @param id id's which have changed
96 */
97void Handshake::varChangeHandler( std::list< int > & id )
[6043]98{
[7954]99  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
[6043]100  {
[9406]101    // orxonox id handler
102    if ( *it == this->orxId_handler )
[6043]103    {
[7954]104      if ( remoteState.orxId != _ORXONOX_ID )
105      {
106        localState.error = 1;
107        localState.completed = 1;
108        localState.errorString = "Seems not to be orxonox!";
109        continue;
110      }
[6043]111    }
[8362]112
[9406]113    // orxonox version handler
114    if ( *it == this->version_handler )
[6043]115    {
[7954]116      if ( remoteState.version != _ORXONOX_VERSION )
117      {
118        localState.error = 2;
119        localState.completed = 1;
120        localState.errorString = "Versions of server and client do not match!";
121        continue;
122      }
[9406]123    }
[6043]124
[9406]125    // node type handler: for each node type there is a specific action to be taken
126    if ( *it == this->nodeTypeHandler)
127    {
128      if ( remoteState.nodeType == NET_MASTER_SERVER )
129      {
130        continue;
131      }
132      else if( remoteState.nodeType == NET_PROXY_SERVER_ACTIVE)
133      {
134        continue;
135      }
136      else if( remoteState.nodeType == NET_CLIENT)
137      {
138        continue;
139      }
[6043]140    }
[8362]141
[9406]142    // cancel
[7954]143    if ( *it == candel_id )
[6043]144    {
[7954]145      PRINTF(0)("handshake finished candel changed\n");
[6090]146    }
[6043]147  }
[8362]148
[9406]149  // handshake completed
150  if ( remoteState.orxId == _ORXONOX_ID &&
151       remoteState.version == _ORXONOX_VERSION )
152  {
[7954]153    localState.completed = 1;
[9406]154  }
[6043]155}
156
Note: See TracBrowser for help on using the repository browser.