Changeset 6190 in orxonox.OLD for branches/network/src/lib
- Timestamp:
- Dec 20, 2005, 2:51:37 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/handshake.cc
r6139 r6190 37 37 } 38 38 39 void Handshake::writeBytes( const byte * data, int length 39 void Handshake::writeBytes( const byte * data, int length, int sender) 40 40 { 41 41 PRINTF(5)("Handshake::writeBytes states = %d %d %d %d (%d)\n", hasState( HS_RECVD_INIT ), hasState( HS_RECVD_VER ), hasState( HS_RECVD_HID ), hasState( HS_COMPLETED ), state); -
branches/network/src/lib/network/handshake.h
r6139 r6190 42 42 inline void doReject(){ setState(HS_DO_REJECT); } 43 43 44 virtual void writeBytes(const byte* data, int length );44 virtual void writeBytes(const byte* data, int length, int sender); 45 45 virtual int readBytes(byte* data, int maxLength, int * reciever); 46 46 virtual void writeDebug() const; -
branches/network/src/lib/network/network_game_manager.cc
r6139 r6190 20 20 #define DEBUG_MODULE_NETWORK 21 21 22 #include "factory.h" 23 #include "network_stream.h" 24 22 25 /* include your own header */ 23 26 #include "network_game_manager.h" … … 41 44 NetworkGameManager::~NetworkGameManager() 42 45 { 43 } 44 45 46 void NetworkGameManager::writeBytes(const byte* data, int length) 46 for ( int i = 0; i<inBuffer.size(); i++) 47 { 48 if ( inBuffer[i].buffer ) 49 delete inBuffer[i].buffer; 50 if ( outBuffer[i].buffer ) 51 delete outBuffer[i].buffer; 52 } 53 } 54 55 56 void NetworkGameManager::writeBytes(const byte* data, int length, int sender) 47 57 { 48 58 } … … 121 131 bool NetworkGameManager::canCreateEntity(int classID) 122 132 { 123 } 133 return true; 134 } 135 136 /*! 137 * Sends the Entities to the new connected client 138 * @param userID: The ID of the user 139 */ 140 void NetworkGameManager::sendEntityList( int userID ) 141 { 142 } 143 144 /** 145 * Creates a buffer for user n 146 * @param n The ID of the user 147 */ 148 void NetworkGameManager::resizeBufferVector( int n ) 149 { 150 for ( int i = inBuffer.size(); i<=n; i++) 151 { 152 clientBuffer inBuf; 153 clientBuffer outBuf; 154 155 inBuf.length = 0; 156 outBuf.length = 0; 157 158 inBuf.maxLength = 5*1014; 159 outBuf.maxLength = 5*1024; 160 161 inBuf.buffer = new byte[5*1014]; 162 outBuf.buffer = new byte[5*1014]; 163 164 inBuffer.push_back(inBuf); 165 outBuffer.push_back(outBuf); 166 } 167 } 168 169 /** 170 * Creates the entity on this host 171 * @param classID: ClassID of the entity to create 172 * @param uniqueID: Unique ID to assign to the synchronizeable 173 * @param owner: owner of this synchronizealbe 174 */ 175 void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner ) 176 { 177 BaseObject * b = Factory::fabricate( classID ); 178 179 if ( b->isA(CL_SYNCHRONIZEABLE) ) 180 { 181 Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); 182 s->setUniqueID( uniqueID ); 183 s->setOwner( owner ); 184 this->networkStream->connectSynchronizeable( *s ); 185 } 186 else 187 { 188 PRINTF(1)("Class with ID %d is not a synchronizeable!", (int)classID); 189 delete b; 190 } 191 } 192 193 /** 194 * Removes a entity on this host 195 * @param uniqueID: unique ID assigned with the entity to remove 196 */ 197 void NetworkGameManager::doRemoveEntity( int uniqueID ) 198 { 199 SynchronizeableList::const_iterator it,e; 200 it = this->networkStream->getSyncBegin(); 201 e = this->networkStream->getSyncEnd(); 202 203 while ( it != e ) 204 { 205 if ( (*it)->getUniqueID() == uniqueID ) 206 { 207 delete *it; 208 break; 209 } 210 } 211 } 212 213 /** 214 * Tell the synchronizeable that a user's synchronizeable is out of sync 215 * @param uniqueID: unique ID assigned with the entity which is out of sync 216 * @param userID: user ID who's synchronizeable is out of sync 217 */ 218 void NetworkGameManager::doRequestSync( int uniqueID, int userID ) 219 { 220 SynchronizeableList::const_iterator it,e; 221 it = this->networkStream->getSyncBegin(); 222 e = this->networkStream->getSyncEnd(); 223 224 while ( it != e ) 225 { 226 if ( (*it)->getUniqueID() == uniqueID ) 227 { 228 (*it)->requestSync( userID ); 229 break; 230 } 231 } 232 } -
branches/network/src/lib/network/network_game_manager.h
r6139 r6190 18 18 * protocol definition 19 19 * 20 * CREATE_ENTITY: CLASS_ID, UNIQUE_ID, OWNER21 * REMOVE_ENTITY: UNIQUE_ID20 * CREATE_ENTITY: CLASS_ID, UNIQUE_ID, OWNER 21 * REMOVE_ENTITY: UNIQUE_ID 22 22 * 23 * CREATE_ENTITY_LIST: NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER]24 * REMOVE_ENTITY_LIST: NUMBER, [UNIQUE_ID][0..NUMBER]23 * CREATE_ENTITY_LIST: NUMBER, [CLASS_ID, UNIQUE_ID, OWNER][0..NUMBER] 24 * REMOVE_ENTITY_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] 25 25 * 26 * REQUEST_CREATE: CLASS_ID27 * REQUEST_REMOVE: UNIQUE_ID26 * REQUEST_CREATE: CLASS_ID 27 * REQUEST_REMOVE: UNIQUE_ID 28 28 * 29 * REQUEST_SYNC: UNIQUE_ID 30 * REQUEST_SYNC_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] 29 * REQUEST_CREATE_LIST: NUMBER, [CLASS_ID][0..NUMBER] 30 * REQUEST_CREATE_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] 31 * 32 * REQUEST_SYNC: UNIQUE_ID 33 * REQUEST_SYNC_LIST: NUMBER, [UNIQUE_ID][0..NUMBER] 31 34 * 32 35 * 33 36 */ 34 37 38 typedef enum NetworkGameManagerProtocol{ 39 CREATE_ENTITY = 0, 40 REMOVE_ENTITY, 41 REQUEST_CREATE, 42 REQUEST_SYNC 43 }; 35 44 36 37 38 39 40 41 42 45 struct clientBuffer 46 { 47 int length; 48 int maxLength; 49 byte * buffer; 50 }; 43 51 44 52 /*! … … 51 59 ~NetworkGameManager(); 52 60 53 virtual void writeBytes(const byte* data, int length );61 virtual void writeBytes(const byte* data, int length, int sender); 54 62 virtual int readBytes(byte* data, int maxLength, int * reciever); 55 63 virtual void writeDebug() const; … … 57 65 58 66 void createEntity(int classID); 59 void createEntityList(int* classIDList);60 67 void removeEntity(int uniqueID); 61 void removeEntityList(int* uniqueIDList);62 68 63 69 void sync(int uniqueID); 64 void syncList(int* uniqueIDList);65 70 71 void sendEntityList(int userID); 66 72 67 73 private: 68 74 void requestCreateEntity(int classID); 69 75 void executeCreateEntity(int classID); 70 void requestCreateEntityList(int* classIDList);71 void executeCreateEntityList(int* classIDList);72 76 73 77 void requestRemoveEntity(int uniqueID); 74 78 void executeRemoveEntity(int uniqueID); 75 void requestRemoveEntityList(int* uniqueIDList);76 void executeRemoveEntityList(int* uniqueIDList);77 79 78 80 void doCreateEntity(ClassID classID, int uniqueID, int owner); 81 void doRemoveEntity(int uniqueID); 82 void doRequestSync(int uniqueID, int userID); 79 83 80 84 bool canCreateEntity(int classID); 81 85 82 86 void resizeBufferVector(int n); 83 87 84 88 private: 85 byte*inBuffer;86 byte*outBuffer;89 std::vector<clientBuffer> inBuffer; 90 std::vector<clientBuffer> outBuffer; 87 91 }; 88 92 -
branches/network/src/lib/network/network_stream.cc
r6139 r6190 27 27 #include "synchronizeable.h" 28 28 #include "network_manager.h" 29 #include "network_game_manager.h" 29 30 #include "list.h" 30 31 #include "debug.h" … … 77 78 this->handshakes.push_back( NULL ); 78 79 this->bActive = true; 80 this->networkGameManager = new NetworkGameManager(); 81 // setUniqueID( maxCon+2 ) because we need one id for every handshake 82 // and one for handshake to reject client maxCon+1 83 this->networkGameManager->setUniqueID( this->maxConnections+2 ); 84 this->connectSynchronizeable( *(this->networkGameManager) ); 79 85 80 86 this->setMaxConnections( 10 ); … … 88 94 this->bActive = false; 89 95 this->serverSocket = NULL; 96 this->networkGameManager = NULL; 90 97 myHostId = 0; 91 98 } … … 175 182 } 176 183 PRINT(0)("handshake finished\n"); 184 185 this->networkGameManager = new NetworkGameManager(); 186 this->networkGameManager->setUniqueID( handshakes[i]->getNetworkGameManagerId() ); 187 this->connectSynchronizeable( *(this->networkGameManager) ); 188 177 189 delete handshakes[i]; 178 190 handshakes[i] = NULL; 179 //TODO: replace handshake by entitymanager180 191 } 181 192 else … … 199 210 for (SynchronizeableList::iterator it = synchronizeables.begin(); it!=synchronizeables.end(); it++) 200 211 { 201 //TODO: remove items from synchronizeables if they dont exist202 212 if ( (*it)!=NULL && (*it)->getOwner() == myHostId ) 203 213 { … … 214 224 dataLength = networkProtocol->createHeader((byte*)downBuffer, dataLength, DATA_STREAM_BUFFER_SIZE, static_cast<const Synchronizeable&>(*(*it))); 215 225 216 //FIXME: this is a hack, find a better way217 226 Header* header = (Header*)downBuffer; 218 if ( header->synchronizeableID <100)227 if ( header->synchronizeableID < this->maxConnections ) 219 228 header->synchronizeableID = 0; 220 229 … … 284 293 { 285 294 if ( *it && (*it)->getUniqueID()==header.synchronizeableID ) 286 (*it)->writeBytes(upBuffer+sizeof(header), dataLength );295 (*it)->writeBytes(upBuffer+sizeof(header), dataLength, i); 287 296 } 288 297 … … 306 315 freeSocketSlots.pop_back(); 307 316 networkSockets[clientId] = tempNetworkSocket; 308 handshakes[clientId] = new Handshake(true, clientId );317 handshakes[clientId] = new Handshake(true, clientId, this->networkGameManager->getUniqueID()); 309 318 handshakes[clientId]->setUniqueID(clientId); 310 319 } else … … 312 321 clientId = networkSockets.size(); 313 322 networkSockets.push_back(tempNetworkSocket); 314 Handshake* tHs = new Handshake(true, clientId );323 Handshake* tHs = new Handshake(true, clientId, this->networkGameManager->getUniqueID()); 315 324 tHs->setUniqueID(clientId); 316 325 handshakes.push_back(tHs); … … 374 383 } 375 384 this->maxConnections = n; 376 } 377 378 385 this->networkGameManager->setUniqueID( n+2 ); 386 } 387 388 -
branches/network/src/lib/network/network_stream.h
r6139 r6190 20 20 class ConnectionMonitor; 21 21 class NetworkProtocol; 22 class NetworkGameManager; 22 23 23 24 typedef std::list<Synchronizeable*> SynchronizeableList; … … 48 49 virtual void processData(); 49 50 51 inline SynchronizeableList::const_iterator getSyncBegin(){ return synchronizeables.begin(); } 52 inline SynchronizeableList::const_iterator getSyncEnd(){ return synchronizeables.end(); } 53 50 54 private: 51 55 NetworkProtocol* networkProtocol; … … 63 67 int maxConnections; 64 68 69 NetworkGameManager* networkGameManager; 70 65 71 void updateConnectionList(); 66 72 }; -
branches/network/src/lib/network/synchronizeable.cc
r6146 r6190 59 59 * write data to NetworkStream 60 60 */ 61 void Synchronizeable::writeBytes(const byte* data, int length )61 void Synchronizeable::writeBytes(const byte* data, int length, int sender) 62 62 { 63 63 PRINTF(1)("Synchronizeable::writeBytes was called\n"); -
branches/network/src/lib/network/synchronizeable.h
r6139 r6190 30 30 ~Synchronizeable(); 31 31 32 virtual void writeBytes(const byte* data, int length );32 virtual void writeBytes(const byte* data, int length, int sender); 33 33 virtual int readBytes(byte* data, int maxLength, int * reciever); 34 34 virtual void writeDebug() const; … … 60 60 std::list<int> synchronizeRequests; 61 61 62 protected: 62 63 NetworkStream* networkStream; 63 64
Note: See TracChangeset
for help on using the changeset viewer.