[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: |
---|
[9406] | 12 | main-programmer: Christoph Renner (rennerc@ee.ethz.ch) |
---|
| 13 | co-programmer: Patirck Boenzli (boenzlip@orxonox.ethz.ch) |
---|
[6043] | 14 | */ |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | #define DEBUG_MODULE_NETWORK |
---|
| 18 | |
---|
| 19 | #include "handshake.h" |
---|
| 20 | |
---|
[6753] | 21 | #include <cassert> |
---|
[8362] | 22 | #include "debug.h" |
---|
[6753] | 23 | |
---|
[10114] | 24 | #include "synchronizeable_var/synchronizeable_classid_list.h" |
---|
[9406] | 25 | |
---|
[10114] | 26 | std::map< std::string, int >* Handshake::classIdList = NULL; |
---|
| 27 | |
---|
[9869] | 28 | ObjectListDefinition(Handshake); |
---|
[9406] | 29 | |
---|
| 30 | |
---|
| 31 | Handshake::Handshake( int nodeType, int clientId, int networkGameManagerId, int messageManagerId ) |
---|
[6695] | 32 | : Synchronizeable() |
---|
[6043] | 33 | { |
---|
| 34 | /* set the class id for the base object */ |
---|
[9869] | 35 | this->registerObject(this, Handshake::_objectList); |
---|
[6043] | 36 | |
---|
[10114] | 37 | if ( !Handshake::classIdList ) |
---|
| 38 | { |
---|
| 39 | //TODO who else? |
---|
| 40 | if ( SharedNetworkData::getInstance()->isMasterServer() ) |
---|
| 41 | { |
---|
| 42 | Handshake::classIdList = ObjectListBase::createStrToId(); |
---|
| 43 | } |
---|
| 44 | else |
---|
| 45 | { |
---|
| 46 | Handshake::classIdList = new std::map< std::string, int >(); |
---|
| 47 | } |
---|
| 48 | } |
---|
[8362] | 49 | |
---|
[9406] | 50 | // register all variable handlers |
---|
[7954] | 51 | orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) ); |
---|
| 52 | version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) ); |
---|
| 53 | netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) ); |
---|
| 54 | msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) ); |
---|
| 55 | hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) ); |
---|
| 56 | completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) ); |
---|
| 57 | error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) ); |
---|
| 58 | errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) ); |
---|
[8362] | 59 | |
---|
[9406] | 60 | this->nodeTypeHandler = registerVarId( new SynchronizeableInt( &localState.nodeType, &remoteState.nodeType, "nodeType", PERMISSION_ALL ) ); |
---|
| 61 | |
---|
[7954] | 62 | candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) ); |
---|
[9406] | 63 | |
---|
[9235] | 64 | registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) ); |
---|
[9406] | 65 | // now synchronize only two of the available proxy server addresses |
---|
| 66 | registerVar( new SynchronizeableIP( &this->proxy1, &this->proxy1, "proxy server 1", PERMISSION_MASTER_SERVER ) ); |
---|
| 67 | registerVar( new SynchronizeableIP( &this->proxy2, &this->proxy2, "proxy server 2", PERMISSION_MASTER_SERVER ) ); |
---|
| 68 | registerVar( new SynchronizeableInt( &this->redirectProxy, &this->redirectProxy, "proxy server redirection flag", PERMISSION_MASTER_SERVER ) ); |
---|
[10114] | 69 | |
---|
| 70 | registerVar( new SynchronizeableClassIDList( Handshake::classIdList, Handshake::classIdList, "classId List", PERMISSION_MASTER_SERVER ) ); |
---|
[8362] | 71 | |
---|
[9406] | 72 | |
---|
| 73 | // init the local state |
---|
[7954] | 74 | localState.completed = 0; |
---|
| 75 | localState.error = 0; |
---|
| 76 | localState.errorString = ""; |
---|
| 77 | localState.hostId = clientId; |
---|
| 78 | localState.networkManagerId = networkGameManagerId; |
---|
| 79 | this->localState.messageManagerId = messageManagerId; |
---|
| 80 | localState.orxId = _ORXONOX_ID; |
---|
| 81 | localState.version = _ORXONOX_VERSION; |
---|
[9406] | 82 | localState.nodeType = nodeType; |
---|
[7954] | 83 | localState.canDel = 0; |
---|
[8362] | 84 | |
---|
[9406] | 85 | |
---|
| 86 | // init the remote state |
---|
[7954] | 87 | remoteState.completed = 0; |
---|
| 88 | remoteState.error = 0; |
---|
| 89 | remoteState.errorString = ""; |
---|
[9656] | 90 | remoteState.hostId = NET_ID_UNASSIGNED; |
---|
[7954] | 91 | remoteState.networkManagerId = -1; |
---|
| 92 | remoteState.messageManagerId = -1; |
---|
| 93 | remoteState.orxId = 0; |
---|
| 94 | remoteState.version = 0; |
---|
[9494] | 95 | remoteState.nodeType = NET_UNASSIGNED; |
---|
[7954] | 96 | remoteState.canDel = 0; |
---|
[6053] | 97 | |
---|
[9406] | 98 | |
---|
| 99 | this->proxy1 = IP(0, 0); |
---|
| 100 | this->proxy2 = IP(0, 0); |
---|
| 101 | this->redirectProxy = 0; |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | // activate the synchronization process |
---|
[6695] | 105 | this->setSynchronized(true); |
---|
[7954] | 106 | PRINTF(0)("Handshake created clientId = %d\n", clientId); |
---|
[6043] | 107 | } |
---|
| 108 | |
---|
[9406] | 109 | |
---|
[7954] | 110 | /** |
---|
| 111 | * handler for changes in synced vars |
---|
| 112 | * @param id id's which have changed |
---|
| 113 | */ |
---|
| 114 | void Handshake::varChangeHandler( std::list< int > & id ) |
---|
[6043] | 115 | { |
---|
[7954] | 116 | for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ ) |
---|
[6043] | 117 | { |
---|
[9406] | 118 | // orxonox id handler |
---|
| 119 | if ( *it == this->orxId_handler ) |
---|
[6043] | 120 | { |
---|
[7954] | 121 | if ( remoteState.orxId != _ORXONOX_ID ) |
---|
| 122 | { |
---|
| 123 | localState.error = 1; |
---|
| 124 | localState.completed = 1; |
---|
| 125 | localState.errorString = "Seems not to be orxonox!"; |
---|
| 126 | continue; |
---|
| 127 | } |
---|
[6043] | 128 | } |
---|
[8362] | 129 | |
---|
[9406] | 130 | // orxonox version handler |
---|
| 131 | if ( *it == this->version_handler ) |
---|
[6043] | 132 | { |
---|
[7954] | 133 | if ( remoteState.version != _ORXONOX_VERSION ) |
---|
| 134 | { |
---|
| 135 | localState.error = 2; |
---|
| 136 | localState.completed = 1; |
---|
| 137 | localState.errorString = "Versions of server and client do not match!"; |
---|
| 138 | continue; |
---|
| 139 | } |
---|
[9406] | 140 | } |
---|
[6043] | 141 | |
---|
[9406] | 142 | // node type handler: for each node type there is a specific action to be taken |
---|
| 143 | if ( *it == this->nodeTypeHandler) |
---|
| 144 | { |
---|
| 145 | if ( remoteState.nodeType == NET_MASTER_SERVER ) |
---|
| 146 | { |
---|
| 147 | continue; |
---|
| 148 | } |
---|
| 149 | else if( remoteState.nodeType == NET_PROXY_SERVER_ACTIVE) |
---|
| 150 | { |
---|
| 151 | continue; |
---|
| 152 | } |
---|
| 153 | else if( remoteState.nodeType == NET_CLIENT) |
---|
| 154 | { |
---|
| 155 | continue; |
---|
| 156 | } |
---|
[6043] | 157 | } |
---|
[8362] | 158 | |
---|
[9406] | 159 | // cancel |
---|
[7954] | 160 | if ( *it == candel_id ) |
---|
[6043] | 161 | { |
---|
[7954] | 162 | PRINTF(0)("handshake finished candel changed\n"); |
---|
[6090] | 163 | } |
---|
[6043] | 164 | } |
---|
[8362] | 165 | |
---|
[9406] | 166 | // handshake completed |
---|
| 167 | if ( remoteState.orxId == _ORXONOX_ID && |
---|
| 168 | remoteState.version == _ORXONOX_VERSION ) |
---|
| 169 | { |
---|
[7954] | 170 | localState.completed = 1; |
---|
[9406] | 171 | } |
---|
[6043] | 172 | } |
---|
| 173 | |
---|