Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

player joins game with last chosen nickname

File size: 3.9 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>
[8362]25#include "debug.h"
[6753]26
[7954]27Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId )
[6695]28  : Synchronizeable()
[6043]29{
30  /* set the class id for the base object */
31  this->setClassID(CL_HANDSHAKE, "Handshake");
32
[6053]33  this->setIsServer(server);
[8362]34
[7954]35  orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) );
36  version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) );
37  netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) );
38  msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) );
39  hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) );
40  completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) );
41  error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) );
42  errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) );
[8362]43
[7954]44  candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) );
[9116]45 
46  registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) );
[8362]47
[7954]48  localState.completed = 0;
49  localState.error = 0;
50  localState.errorString = "";
51  localState.hostId = clientId;
52  localState.networkManagerId = networkGameManagerId;
53  this->localState.messageManagerId = messageManagerId;
54  localState.orxId = _ORXONOX_ID;
55  localState.version = _ORXONOX_VERSION;
56  localState.canDel = 0;
[8362]57
[7954]58  remoteState.completed = 0;
59  remoteState.error = 0;
60  remoteState.errorString = "";
61  remoteState.hostId = -1;
62  remoteState.networkManagerId = -1;
63  remoteState.messageManagerId = -1;
64  remoteState.orxId = 0;
65  remoteState.version = 0;
66  remoteState.canDel = 0;
[6053]67
[6695]68  this->setSynchronized(true);
[7954]69  PRINTF(0)("Handshake created clientId = %d\n", clientId);
[6043]70}
71
[7954]72/**
73 * handler for changes in synced vars
74 * @param id id's which have changed
75 */
76void Handshake::varChangeHandler( std::list< int > & id )
[6043]77{
[7954]78  for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ )
[6043]79  {
[7954]80    if ( *it == orxId_handler )
[6043]81    {
[7954]82      if ( remoteState.orxId != _ORXONOX_ID )
83      {
84        localState.error = 1;
85        localState.completed = 1;
86        localState.errorString = "Seems not to be orxonox!";
87        continue;
88      }
[6043]89
90    }
[8362]91
[7954]92    if ( *it == version_handler )
[6043]93    {
[7954]94      if ( remoteState.version != _ORXONOX_VERSION )
95      {
96        localState.error = 2;
97        localState.completed = 1;
98        localState.errorString = "Versions of server and client do not match!";
99        continue;
100      }
[6043]101
102    }
[8362]103
[7954]104    if ( *it == candel_id )
[6043]105    {
[7954]106      PRINTF(0)("handshake finished candel changed\n");
[6090]107    }
[8362]108
[6043]109  }
[8362]110
[7954]111  if (
112      remoteState.orxId == _ORXONOX_ID &&
113      remoteState.version == _ORXONOX_VERSION
114     )
115    localState.completed = 1;
[6043]116}
117
Note: See TracBrowser for help on using the repository browser.