Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

network node type handshake extension

File size: 4.5 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)
[6043]13*/
14
15
16#define DEBUG_MODULE_NETWORK
17
18#include "handshake.h"
19
[6753]20#include <cassert>
[8362]21#include "debug.h"
[6753]22
[9263]23
24
25
26
[7954]27Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId )
[6695]28  : Synchronizeable()
[6043]29{
30  /* set the class id for the base object */
31  this->setClassID(CL_HANDSHAKE, "Handshake");
32
[6053]33  this->setIsServer(server);
[8362]34
[9261]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
[9268]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 ) );
[9261]48
[9235]49  registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
[8362]50
[9261]51  // init the local state
[7954]52  localState.completed = 0;
53  localState.error = 0;
54  localState.errorString = "";
55  localState.hostId = clientId;
56  localState.networkManagerId = networkGameManagerId;
57  this->localState.messageManagerId = messageManagerId;
58  localState.orxId = _ORXONOX_ID;
59  localState.version = _ORXONOX_VERSION;
[9269]60  localState.nodeType = NET_CLIENT;
[7954]61  localState.canDel = 0;
[8362]62
[7954]63  remoteState.completed = 0;
64  remoteState.error = 0;
65  remoteState.errorString = "";
66  remoteState.hostId = -1;
67  remoteState.networkManagerId = -1;
68  remoteState.messageManagerId = -1;
69  remoteState.orxId = 0;
70  remoteState.version = 0;
[9269]71  remoteState.nodeType = NET_CLIENT;
[7954]72  remoteState.canDel = 0;
[6053]73
[9261]74  // activate the synchronization process
[6695]75  this->setSynchronized(true);
[7954]76  PRINTF(0)("Handshake created clientId = %d\n", clientId);
[6043]77}
78
[7954]79/**
80 * handler for changes in synced vars
81 * @param id id's which have changed
82 */
83void Handshake::varChangeHandler( std::list< int > & id )
[6043]84{
[7954]85  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
[6043]86  {
[9262]87    // orxonox id handler
[9269]88    if ( *it == this->orxId_handler )
[6043]89    {
[7954]90      if ( remoteState.orxId != _ORXONOX_ID )
91      {
92        localState.error = 1;
93        localState.completed = 1;
94        localState.errorString = "Seems not to be orxonox!";
95        continue;
96      }
[6043]97    }
[8362]98
[9262]99    // orxonox version handler
[9269]100    if ( *it == this->version_handler )
[6043]101    {
[7954]102      if ( remoteState.version != _ORXONOX_VERSION )
103      {
104        localState.error = 2;
105        localState.completed = 1;
106        localState.errorString = "Versions of server and client do not match!";
107        continue;
108      }
[9269]109    }
[6043]110
[9269]111    // node type handler: for each node type there is a specific action to be taken
112    if ( *it == this->nodeTypeHandler)
113    {
114      if ( remoteState.nodeType == NET_MASTER_SERVER )
115      {
116        continue;
117      }
118      else if( remoteState.nodeType == NET_PROXY_SERVER)
119      {
120        continue;
121      }
122      else if( remoteState.nodeType == NET_CLIENT)
123      {
124        continue;
125      }
[6043]126    }
[8362]127
[9269]128
[9262]129    // cancel
[7954]130    if ( *it == candel_id )
[6043]131    {
[7954]132      PRINTF(0)("handshake finished candel changed\n");
[6090]133    }
[8362]134
[6043]135  }
[8362]136
[9262]137  // handshake completed
138  if ( remoteState.orxId == _ORXONOX_ID &&
139       remoteState.version == _ORXONOX_VERSION )
140  {
[7954]141    localState.completed = 1;
[9262]142  }
[6043]143}
144
Note: See TracBrowser for help on using the repository browser.