Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: merged the network branche back to trunk.

File size: 3.8 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:
12   main-programmer: christoph
13   co-programmer:
14*/
15
16
17/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
18   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
19*/
20#define DEBUG_MODULE_NETWORK
21
22#include "handshake.h"
23
[6753]24#include <cassert>
25
[7954]26Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId )
[6695]27  : Synchronizeable()
[6043]28{
29  /* set the class id for the base object */
30  this->setClassID(CL_HANDSHAKE, "Handshake");
31
[6053]32  this->setIsServer(server);
[7954]33 
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  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
44 
45  localState.completed = 0;
46  localState.error = 0;
47  localState.errorString = "";
48  localState.hostId = clientId;
49  localState.networkManagerId = networkGameManagerId;
50  this->localState.messageManagerId = messageManagerId;
51  localState.orxId = _ORXONOX_ID;
52  localState.version = _ORXONOX_VERSION;
53  localState.canDel = 0;
54 
55  remoteState.completed = 0;
56  remoteState.error = 0;
57  remoteState.errorString = "";
58  remoteState.hostId = -1;
59  remoteState.networkManagerId = -1;
60  remoteState.messageManagerId = -1;
61  remoteState.orxId = 0;
62  remoteState.version = 0;
63  remoteState.canDel = 0;
[6053]64
[6695]65  this->setSynchronized(true);
[7954]66  PRINTF(0)("Handshake created clientId = %d\n", clientId);
[6043]67}
68
[7954]69/**
70 * handler for changes in synced vars
71 * @param id id's which have changed
72 */
73void Handshake::varChangeHandler( std::list< int > & id )
[6043]74{
[7954]75  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
[6043]76  {
[7954]77    if ( *it == orxId_handler )
[6043]78    {
[7954]79      if ( remoteState.orxId != _ORXONOX_ID )
80      {
81        localState.error = 1;
82        localState.completed = 1;
83        localState.errorString = "Seems not to be orxonox!";
84        continue;
85      }
[6043]86
87    }
[7954]88     
89    if ( *it == version_handler )
[6043]90    {
[7954]91      if ( remoteState.version != _ORXONOX_VERSION )
92      {
93        localState.error = 2;
94        localState.completed = 1;
95        localState.errorString = "Versions of server and client do not match!";
96        continue;
97      }
[6043]98
99    }
[7954]100   
101    if ( *it == candel_id )
[6043]102    {
[7954]103      PRINTF(0)("handshake finished candel changed\n");
[6090]104    }
[7954]105   
[6043]106  }
[7954]107 
108  if (
109      remoteState.orxId == _ORXONOX_ID &&
110      remoteState.version == _ORXONOX_VERSION
111     )
112    localState.completed = 1;
[6043]113}
114
Note: See TracBrowser for help on using the repository browser.