Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged network back to trunk

File size: 5.7 KB
Line 
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:
12   main-programmer: Christoph Renner (rennerc@ee.ethz.ch)
13   co-programmer: Patirck Boenzli (boenzlip@orxonox.ethz.ch)
14*/
15
16
17#define DEBUG_MODULE_NETWORK
18
19#include "handshake.h"
20
21#include <cassert>
22#include "debug.h"
23
24#include "synchronizeable_var/synchronizeable_classid_list.h"
25
26std::map< std::string, int >* Handshake::classIdList = NULL;
27
28ObjectListDefinition(Handshake);
29
30
31 Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId )
32  : Synchronizeable()
33{
34  /* set the class id for the base object */
35  this->registerObject(this, Handshake::_objectList);
36
37  if ( !Handshake::classIdList )
38  {
39    //TODO who else?
40    if ( SharedNetworkData::getInstance()->isMasterServer() )
41    {
42      Handshake::classIdList = ObjectListBase::createStrToId();
43    }
44    else
45    {
46      Handshake::classIdList = new std::map< std::string, int >();
47    }
48  }
49
50  // register all variable handlers
51  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
52  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
53  netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) );
54  msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) );
55  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) );
56  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) );
57  error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) );
58  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
59
60  this->nodeTypeHandler = registerVarId( new SynchronizeableInt( &localState.nodeType, &remoteState.nodeType, "nodeType", PERMISSION_ALL ) );
61
62  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
63
64  registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
65  // now synchronize only two of the available proxy server addresses
66  registerVar( new SynchronizeableIP( &this->proxy1, &this->proxy1, "proxy server 1", PERMISSION_MASTER_SERVER ) );
67  registerVar( new SynchronizeableIP( &this->proxy2, &this->proxy2, "proxy server 2", PERMISSION_MASTER_SERVER ) );
68  registerVar( new SynchronizeableInt( &this->redirectProxy, &this->redirectProxy, "proxy server redirection flag", PERMISSION_MASTER_SERVER ) );
69 
70  registerVar( new SynchronizeableClassIDList( Handshake::classIdList, Handshake::classIdList, "classId List", PERMISSION_MASTER_SERVER ) );
71
72
73  // init the local state
74  localState.completed = 0;
75  localState.error = 0;
76  localState.errorString = "";
77  localState.hostId = clientId;
78  localState.networkManagerId = networkGameManagerId;
79  this->localState.messageManagerId = messageManagerId;
80  localState.orxId = _ORXONOX_ID;
81  localState.version = _ORXONOX_VERSION;
82  localState.nodeType = nodeType;
83  localState.canDel = 0;
84
85
86  // init the remote state
87  remoteState.completed = 0;
88  remoteState.error = 0;
89  remoteState.errorString = "";
90  remoteState.hostId = NET_ID_UNASSIGNED;
91  remoteState.networkManagerId = -1;
92  remoteState.messageManagerId = -1;
93  remoteState.orxId = 0;
94  remoteState.version = 0;
95  remoteState.nodeType = NET_UNASSIGNED;
96  remoteState.canDel = 0;
97
98
99  this->proxy1 = IP(0, 0);
100  this->proxy2 = IP(0, 0);
101  this->redirectProxy = 0;
102
103
104  // activate the synchronization process
105  this->setSynchronized(true);
106  PRINTF(0)("Handshake created clientId = %d\n", clientId);
107}
108
109
110/**
111 * handler for changes in synced vars
112 * @param id id's which have changed
113 */
114void Handshake::varChangeHandler( std::list< int > & id )
115{
116  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
117  {
118    // orxonox id handler
119    if ( *it == this->orxId_handler )
120    {
121      if ( remoteState.orxId != _ORXONOX_ID )
122      {
123        localState.error = 1;
124        localState.completed = 1;
125        localState.errorString = "Seems not to be orxonox!";
126        continue;
127      }
128    }
129
130    // orxonox version handler
131    if ( *it == this->version_handler )
132    {
133      if ( remoteState.version != _ORXONOX_VERSION )
134      {
135        localState.error = 2;
136        localState.completed = 1;
137        localState.errorString = "Versions of server and client do not match!";
138        continue;
139      }
140    }
141
142    // node type handler: for each node type there is a specific action to be taken
143    if ( *it == this->nodeTypeHandler)
144    {
145      if ( remoteState.nodeType == NET_MASTER_SERVER )
146      {
147        continue;
148      }
149      else if( remoteState.nodeType == NET_PROXY_SERVER_ACTIVE)
150      {
151        continue;
152      }
153      else if( remoteState.nodeType == NET_CLIENT)
154      {
155        continue;
156      }
157    }
158
159    // cancel
160    if ( *it == candel_id )
161    {
162      PRINTF(0)("handshake finished candel changed\n");
163    }
164  }
165
166  // handshake completed
167  if ( remoteState.orxId == _ORXONOX_ID &&
168       remoteState.version == _ORXONOX_VERSION )
169  {
170    localState.completed = 1;
171  }
172}
173
Note: See TracBrowser for help on using the repository browser.