[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: |
---|
[9263] | 12 | main-programmer: Christoph Renner (rennerc@ee.ethz.ch) |
---|
[6043] | 13 | */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #define DEBUG_MODULE_NETWORK |
---|
| 17 | |
---|
| 18 | #include "handshake.h" |
---|
| 19 | |
---|
[6753] | 20 | #include <cassert> |
---|
[8362] | 21 | #include "debug.h" |
---|
[6753] | 22 | |
---|
[9263] | 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | |
---|
[7954] | 27 | Handshake::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 | |
---|
[9261] | 35 | // register all variable handlers |
---|
[7954] | 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 ) ); |
---|
[8362] | 44 | |
---|
[7954] | 45 | candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) ); |
---|
[9261] | 46 | |
---|
[9235] | 47 | registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) ); |
---|
[8362] | 48 | |
---|
[9261] | 49 | // init the local state |
---|
[7954] | 50 | localState.completed = 0; |
---|
| 51 | localState.error = 0; |
---|
| 52 | localState.errorString = ""; |
---|
| 53 | localState.hostId = clientId; |
---|
| 54 | localState.networkManagerId = networkGameManagerId; |
---|
| 55 | this->localState.messageManagerId = messageManagerId; |
---|
| 56 | localState.orxId = _ORXONOX_ID; |
---|
| 57 | localState.version = _ORXONOX_VERSION; |
---|
| 58 | localState.canDel = 0; |
---|
[8362] | 59 | |
---|
[7954] | 60 | remoteState.completed = 0; |
---|
| 61 | remoteState.error = 0; |
---|
| 62 | remoteState.errorString = ""; |
---|
| 63 | remoteState.hostId = -1; |
---|
| 64 | remoteState.networkManagerId = -1; |
---|
| 65 | remoteState.messageManagerId = -1; |
---|
| 66 | remoteState.orxId = 0; |
---|
| 67 | remoteState.version = 0; |
---|
| 68 | remoteState.canDel = 0; |
---|
[6053] | 69 | |
---|
[9261] | 70 | // activate the synchronization process |
---|
[6695] | 71 | this->setSynchronized(true); |
---|
[7954] | 72 | PRINTF(0)("Handshake created clientId = %d\n", clientId); |
---|
[6043] | 73 | } |
---|
| 74 | |
---|
[7954] | 75 | /** |
---|
| 76 | * handler for changes in synced vars |
---|
| 77 | * @param id id's which have changed |
---|
| 78 | */ |
---|
| 79 | void Handshake::varChangeHandler( std::list< int > & id ) |
---|
[6043] | 80 | { |
---|
[7954] | 81 | for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ ) |
---|
[6043] | 82 | { |
---|
[9262] | 83 | // orxonox id handler |
---|
[7954] | 84 | if ( *it == orxId_handler ) |
---|
[6043] | 85 | { |
---|
[7954] | 86 | if ( remoteState.orxId != _ORXONOX_ID ) |
---|
| 87 | { |
---|
| 88 | localState.error = 1; |
---|
| 89 | localState.completed = 1; |
---|
| 90 | localState.errorString = "Seems not to be orxonox!"; |
---|
| 91 | continue; |
---|
| 92 | } |
---|
[6043] | 93 | |
---|
| 94 | } |
---|
[8362] | 95 | |
---|
[9262] | 96 | // orxonox version handler |
---|
[7954] | 97 | if ( *it == version_handler ) |
---|
[6043] | 98 | { |
---|
[7954] | 99 | if ( remoteState.version != _ORXONOX_VERSION ) |
---|
| 100 | { |
---|
| 101 | localState.error = 2; |
---|
| 102 | localState.completed = 1; |
---|
| 103 | localState.errorString = "Versions of server and client do not match!"; |
---|
| 104 | continue; |
---|
| 105 | } |
---|
[6043] | 106 | |
---|
| 107 | } |
---|
[8362] | 108 | |
---|
[9262] | 109 | // cancel |
---|
[7954] | 110 | if ( *it == candel_id ) |
---|
[6043] | 111 | { |
---|
[7954] | 112 | PRINTF(0)("handshake finished candel changed\n"); |
---|
[6090] | 113 | } |
---|
[8362] | 114 | |
---|
[6043] | 115 | } |
---|
[8362] | 116 | |
---|
[9262] | 117 | // handshake completed |
---|
| 118 | if ( remoteState.orxId == _ORXONOX_ID && |
---|
| 119 | remoteState.version == _ORXONOX_VERSION ) |
---|
| 120 | { |
---|
[7954] | 121 | localState.completed = 1; |
---|
[9262] | 122 | } |
---|
[6043] | 123 | } |
---|
| 124 | |
---|