Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

redirection flag added, proxy settings as a way to get/save the server settings

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