Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7681 was 7681, checked in by rennerc, 19 years ago

finished and tested MessageManager

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  this->localState.hostId = clientId;
34  this->localState.networkManagerId = networkGameManagerId;
35  this->localState.messageManagerId = messageManagerId;
36 
37  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
38  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
39  netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) );
40  netManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "networkManagerId", PERMISSION_ALL ) );
41  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) );
42  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) );
43  error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) );
44  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
45 
46  localState.completed = false;
47  localState.error = 0;
48  localState.errorString = "";
49  localState.hostId = clientId;
50  localState.networkManagerId = networkGameManagerId;
51  localState.orxId = _ORXONOX_ID;
52  localState.version = _ORXONOX_VERSION;
53 
54  remoteState.completed = false;
55  remoteState.error = 0;
56  remoteState.errorString = "";
57  remoteState.hostId = -1;
58  remoteState.networkManagerId = -1;
59  remoteState.orxId = 0;
60  remoteState.version = 0;
61
62  this->setSynchronized(true);
63  PRINTF(0)("Handshake created clientId = %d\n", clientId);
64}
65
66/**
67 * handler for changes in synced vars
68 * @param id id's which have changed
69 */
70void Handshake::varChangeHandler( std::list< int > & id )
71{
72  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
73  {
74    if ( *it == orxId_handler )
75    {
76      if ( remoteState.orxId != _ORXONOX_ID )
77      {
78        localState.error = 1;
79        localState.completed = true;
80        localState.errorString = "Seems not to be orxonox!";
81        return;
82      }
83      else
84        localState.completed = true;
85    }
86     
87    if ( *it == version_handler )
88    {
89      if ( remoteState.version != _ORXONOX_VERSION )
90      {
91        localState.error = 2;
92        localState.completed = true;
93        localState.errorString = "Versions of server and client do not match!";
94        return;
95      }
96      else
97        localState.completed = true;
98    }
99   
100  }
101}
102
Note: See TracBrowser for help on using the repository browser.