Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

work of the day in one commit:D

  • switched whole network framework to ip sturcture
  • extended ip structrue a little bit
  • reimplemented the disconnection/reconnection algorithm
  • synchronizeable ip bug discovered and solved
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:
[9263]12   main-programmer: Christoph Renner (rennerc@ee.ethz.ch)
[9327]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
[9263]24
25
26
27
[9300]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
[9261]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
[9268]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 ) );
[9261]47
[9235]48  registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
[9300]49  // now synchronize only two of the available proxy server addresses
[9295]50  registerVar( new SynchronizeableIP( &localState.proxy1, &remoteState.proxy1, "proxy server 1", PERMISSION_ALL ) );
[9296]51  registerVar( new SynchronizeableIP( &localState.proxy2, &remoteState.proxy1, "proxy server 2", PERMISSION_ALL ) );
[8362]52
[9261]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;
[9270]62  localState.nodeType = nodeType;
[7954]63  localState.canDel = 0;
[9296]64  localState.redirectProxy = 0;
[9334]65  localState.proxy1 = IP(0, 0);
66  localState.proxy2 = IP (0, 0);
[8362]67
[9300]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;
[9269]78  remoteState.nodeType = NET_CLIENT;
[7954]79  remoteState.canDel = 0;
[9296]80  remoteState.redirectProxy = 0;
[9334]81  remoteState.proxy1 = IP(0, 0);
82  remoteState.proxy2 = IP(0, 0);
[6053]83
[9261]84  // activate the synchronization process
[6695]85  this->setSynchronized(true);
[7954]86  PRINTF(0)("Handshake created clientId = %d\n", clientId);
[6043]87}
88
[9296]89
[7954]90/**
91 * handler for changes in synced vars
92 * @param id id's which have changed
93 */
94void Handshake::varChangeHandler( std::list< int > & id )
[6043]95{
[7954]96  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
[6043]97  {
[9262]98    // orxonox id handler
[9269]99    if ( *it == this->orxId_handler )
[6043]100    {
[7954]101      if ( remoteState.orxId != _ORXONOX_ID )
102      {
103        localState.error = 1;
104        localState.completed = 1;
105        localState.errorString = "Seems not to be orxonox!";
106        continue;
107      }
[6043]108    }
[8362]109
[9262]110    // orxonox version handler
[9269]111    if ( *it == this->version_handler )
[6043]112    {
[7954]113      if ( remoteState.version != _ORXONOX_VERSION )
114      {
115        localState.error = 2;
116        localState.completed = 1;
117        localState.errorString = "Versions of server and client do not match!";
118        continue;
119      }
[9269]120    }
[6043]121
[9269]122    // node type handler: for each node type there is a specific action to be taken
123    if ( *it == this->nodeTypeHandler)
124    {
125      if ( remoteState.nodeType == NET_MASTER_SERVER )
126      {
127        continue;
128      }
[9303]129      else if( remoteState.nodeType == NET_PROXY_SERVER_ACTIVE)
[9269]130      {
131        continue;
132      }
133      else if( remoteState.nodeType == NET_CLIENT)
134      {
135        continue;
136      }
[6043]137    }
[8362]138
[9262]139    // cancel
[7954]140    if ( *it == candel_id )
[6043]141    {
[7954]142      PRINTF(0)("handshake finished candel changed\n");
[6090]143    }
[8362]144
[6043]145  }
[8362]146
[9262]147  // handshake completed
148  if ( remoteState.orxId == _ORXONOX_ID &&
149       remoteState.version == _ORXONOX_VERSION )
150  {
[7954]151    localState.completed = 1;
[9262]152  }
[6043]153}
154
Note: See TracBrowser for help on using the repository browser.