[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 | |
---|
[9270] | 27 | Handshake::Handshake( int nodeType, 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 | |
---|
[9261] | 33 | // register all variable handlers |
---|
[7954] | 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 ) ); |
---|
[8362] | 42 | |
---|
[9268] | 43 | this->nodeTypeHandler = registerVarId( new SynchronizeableInt( &localState.nodeType, &remoteState.nodeType, "nodeType", PERMISSION_ALL ) ); |
---|
| 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; |
---|
[9270] | 58 | localState.nodeType = nodeType; |
---|
[7954] | 59 | localState.canDel = 0; |
---|
[8362] | 60 | |
---|
[7954] | 61 | remoteState.completed = 0; |
---|
| 62 | remoteState.error = 0; |
---|
| 63 | remoteState.errorString = ""; |
---|
| 64 | remoteState.hostId = -1; |
---|
| 65 | remoteState.networkManagerId = -1; |
---|
| 66 | remoteState.messageManagerId = -1; |
---|
| 67 | remoteState.orxId = 0; |
---|
| 68 | remoteState.version = 0; |
---|
[9269] | 69 | remoteState.nodeType = NET_CLIENT; |
---|
[7954] | 70 | remoteState.canDel = 0; |
---|
[6053] | 71 | |
---|
[9261] | 72 | // activate the synchronization process |
---|
[6695] | 73 | this->setSynchronized(true); |
---|
[7954] | 74 | PRINTF(0)("Handshake created clientId = %d\n", clientId); |
---|
[6043] | 75 | } |
---|
| 76 | |
---|
[7954] | 77 | /** |
---|
| 78 | * handler for changes in synced vars |
---|
| 79 | * @param id id's which have changed |
---|
| 80 | */ |
---|
| 81 | void Handshake::varChangeHandler( std::list< int > & id ) |
---|
[6043] | 82 | { |
---|
[7954] | 83 | for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ ) |
---|
[6043] | 84 | { |
---|
[9262] | 85 | // orxonox id handler |
---|
[9269] | 86 | if ( *it == this->orxId_handler ) |
---|
[6043] | 87 | { |
---|
[7954] | 88 | if ( remoteState.orxId != _ORXONOX_ID ) |
---|
| 89 | { |
---|
| 90 | localState.error = 1; |
---|
| 91 | localState.completed = 1; |
---|
| 92 | localState.errorString = "Seems not to be orxonox!"; |
---|
| 93 | continue; |
---|
| 94 | } |
---|
[6043] | 95 | } |
---|
[8362] | 96 | |
---|
[9262] | 97 | // orxonox version handler |
---|
[9269] | 98 | if ( *it == this->version_handler ) |
---|
[6043] | 99 | { |
---|
[7954] | 100 | if ( remoteState.version != _ORXONOX_VERSION ) |
---|
| 101 | { |
---|
| 102 | localState.error = 2; |
---|
| 103 | localState.completed = 1; |
---|
| 104 | localState.errorString = "Versions of server and client do not match!"; |
---|
| 105 | continue; |
---|
| 106 | } |
---|
[9269] | 107 | } |
---|
[6043] | 108 | |
---|
[9269] | 109 | // node type handler: for each node type there is a specific action to be taken |
---|
| 110 | if ( *it == this->nodeTypeHandler) |
---|
| 111 | { |
---|
| 112 | if ( remoteState.nodeType == NET_MASTER_SERVER ) |
---|
| 113 | { |
---|
| 114 | continue; |
---|
| 115 | } |
---|
| 116 | else if( remoteState.nodeType == NET_PROXY_SERVER) |
---|
| 117 | { |
---|
| 118 | continue; |
---|
| 119 | } |
---|
| 120 | else if( remoteState.nodeType == NET_CLIENT) |
---|
| 121 | { |
---|
| 122 | continue; |
---|
| 123 | } |
---|
[6043] | 124 | } |
---|
[8362] | 125 | |
---|
[9269] | 126 | |
---|
[9262] | 127 | // cancel |
---|
[7954] | 128 | if ( *it == candel_id ) |
---|
[6043] | 129 | { |
---|
[7954] | 130 | PRINTF(0)("handshake finished candel changed\n"); |
---|
[6090] | 131 | } |
---|
[8362] | 132 | |
---|
[6043] | 133 | } |
---|
[8362] | 134 | |
---|
[9262] | 135 | // handshake completed |
---|
| 136 | if ( remoteState.orxId == _ORXONOX_ID && |
---|
| 137 | remoteState.version == _ORXONOX_VERSION ) |
---|
| 138 | { |
---|
[7954] | 139 | localState.completed = 1; |
---|
[9262] | 140 | } |
---|
[6043] | 141 | } |
---|
| 142 | |
---|