Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7731 was 7731, checked in by rennerc, 18 years ago

fixed bug

File size: 3.5 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
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
24#include <cassert>
25
26Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId )
27  : Synchronizeable()
28{
29  /* set the class id for the base object */
30  this->setClassID(CL_HANDSHAKE, "Handshake");
31
32  this->setIsServer(server);
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  localState.completed = false;
44  localState.error = 0;
45  localState.errorString = "";
46  localState.hostId = clientId;
47  localState.networkManagerId = networkGameManagerId;
48  this->localState.messageManagerId = messageManagerId;
49  localState.orxId = _ORXONOX_ID;
50  localState.version = _ORXONOX_VERSION;
51 
52  remoteState.completed = false;
53  remoteState.error = 0;
54  remoteState.errorString = "";
55  remoteState.hostId = -1;
56  remoteState.networkManagerId = -1;
57  remoteState.messageManagerId = -1;
58  remoteState.orxId = 0;
59  remoteState.version = 0;
60
61  this->setSynchronized(true);
62  PRINTF(0)("Handshake created clientId = %d\n", clientId);
63}
64
65/**
66 * handler for changes in synced vars
67 * @param id id's which have changed
68 */
69void Handshake::varChangeHandler( std::list< int > & id )
70{
71  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
72  {
73    if ( *it == orxId_handler )
74    {
75      if ( remoteState.orxId != _ORXONOX_ID )
76      {
77        localState.error = 1;
78        localState.completed = true;
79        localState.errorString = "Seems not to be orxonox!";
80        return;
81      }
82      else
83        localState.completed = true;
84    }
85     
86    if ( *it == version_handler )
87    {
88      if ( remoteState.version != _ORXONOX_VERSION )
89      {
90        localState.error = 2;
91        localState.completed = true;
92        localState.errorString = "Versions of server and client do not match!";
93        return;
94      }
95      else
96        localState.completed = true;
97    }
98   
99  }
100}
101
Note: See TracBrowser for help on using the repository browser.