Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

added some debug output

File size: 4.4 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 "network_log.h"
25
26#include <cassert>
27
28Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId )
29  : Synchronizeable()
30{
31  /* set the class id for the base object */
32  this->setClassID(CL_HANDSHAKE, "Handshake");
33
34  this->setIsServer(server);
35 
36  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
37  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
38  netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) );
39  msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) );
40  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) );
41  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) );
42  error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) );
43  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", 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 
54  remoteState.completed = 0;
55  remoteState.error = 0;
56  remoteState.errorString = "";
57  remoteState.hostId = -1;
58  remoteState.networkManagerId = -1;
59  remoteState.messageManagerId = -1;
60  remoteState.orxId = 0;
61  remoteState.version = 0;
62
63  this->setSynchronized(true);
64  PRINTF(0)("Handshake created clientId = %d\n", clientId);
65}
66
67/**
68 * handler for changes in synced vars
69 * @param id id's which have changed
70 */
71void Handshake::varChangeHandler( std::list< int > & id )
72{
73  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
74  {
75    if ( *it == orxId_handler )
76    {
77      if ( remoteState.orxId != _ORXONOX_ID )
78      {
79        localState.error = 1;
80        localState.completed = 1;
81        localState.errorString = "Seems not to be orxonox!";
82        return;
83      }
84      else
85        if ( remoteState.version -= _ORXONOX_VERSION )
86          localState.completed = 1;
87    }
88     
89    if ( *it == version_handler )
90    {
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        return;
97      }
98      else
99        if ( remoteState.orxId == _ORXONOX_ID )
100          localState.completed = 1;
101    }
102   
103  }
104 
105  PRINTF(0)("=======================BEGIN=============================");
106  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
107  { 
108    if ( *it == netManId_handler )
109      PRINTF(0)("netManId_handler\n");
110    if ( *it == msgManId_handler )
111      PRINTF(0)("msgManId_handler\n");
112    if ( *it == hostId_handler )
113      PRINTF(0)("hostId_handler\n");
114    if ( *it == completed_handler )
115      PRINTF(0)("completed_handler\n");
116    if ( *it == error_handler )
117      PRINTF(0)("error_handler\n");
118    if ( *it == errorString_handler )
119      PRINTF(0)("errorString_handler\n");
120    if ( *it == orxId_handler )
121      PRINTF(0)("orxId_handler\n");
122    if ( *it == version_handler )
123      PRINTF(0)("version_handler\n");
124  }
125  PRINTF(0)("=========================================================");
126}
127
Note: See TracBrowser for help on using the repository browser.