[6067] | 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: Benjamin Wuest |
---|
| 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 | |
---|
[6341] | 22 | #include "factory.h" |
---|
| 23 | #include "network_stream.h" |
---|
| 24 | #include "converter.h" |
---|
| 25 | |
---|
[6424] | 26 | #include "p_node.h" |
---|
[6498] | 27 | #include "state.h" |
---|
| 28 | #include "game_world.h" |
---|
| 29 | #include "world_entity.h" |
---|
| 30 | #include "playable.h" |
---|
| 31 | #include "player.h" |
---|
[6917] | 32 | #include "shared_network_data.h" |
---|
[6424] | 33 | |
---|
[6737] | 34 | #include "class_list.h" |
---|
[6424] | 35 | |
---|
[6067] | 36 | /* include your own header */ |
---|
[6116] | 37 | #include "network_game_manager.h" |
---|
[6067] | 38 | |
---|
| 39 | |
---|
| 40 | /* using namespace std is default, this needs to be here */ |
---|
| 41 | using namespace std; |
---|
| 42 | |
---|
[6341] | 43 | NetworkGameManager* NetworkGameManager::singletonRef = NULL; |
---|
| 44 | |
---|
[6067] | 45 | /*! |
---|
| 46 | * Standard constructor |
---|
| 47 | */ |
---|
[6116] | 48 | NetworkGameManager::NetworkGameManager() |
---|
[6695] | 49 | : Synchronizeable() |
---|
[6067] | 50 | { |
---|
[6341] | 51 | PRINTF(0)("START\n"); |
---|
| 52 | |
---|
[6067] | 53 | /* set the class id for the base object */ |
---|
[6341] | 54 | this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager"); |
---|
| 55 | |
---|
| 56 | hasRequestedWorld = false; |
---|
[6695] | 57 | this->setSynchronized(true); |
---|
[6067] | 58 | } |
---|
| 59 | |
---|
| 60 | /*! |
---|
| 61 | * Standard destructor |
---|
| 62 | */ |
---|
[6116] | 63 | NetworkGameManager::~NetworkGameManager() |
---|
[6067] | 64 | { |
---|
[6341] | 65 | for ( int i = 0; i<outBuffer.size(); i++) |
---|
| 66 | { |
---|
| 67 | if ( outBuffer[i].buffer ) |
---|
| 68 | delete outBuffer[i].buffer; |
---|
| 69 | } |
---|
| 70 | |
---|
[6067] | 71 | } |
---|
| 72 | |
---|
| 73 | |
---|
[6341] | 74 | int NetworkGameManager::writeBytes(const byte* data, int length, int sender) |
---|
[6067] | 75 | { |
---|
[6341] | 76 | int i = 0; |
---|
| 77 | byte b; |
---|
| 78 | |
---|
| 79 | while ( i<length ) |
---|
| 80 | { |
---|
| 81 | b = data[i++]; |
---|
| 82 | |
---|
[6695] | 83 | /**************** Commands only processed by servers ****************/ |
---|
[6341] | 84 | if ( isServer() ) |
---|
| 85 | { |
---|
[6695] | 86 | if ( b == NET_REQUEST_CREATE ) |
---|
[6341] | 87 | { |
---|
| 88 | if ( !handleRequestCreate( i, data, length, sender ) ) |
---|
| 89 | return i; |
---|
| 90 | continue; |
---|
| 91 | } |
---|
[6695] | 92 | else if ( b == NET_REQUEST_REMOVE ) |
---|
[6341] | 93 | { |
---|
| 94 | if ( !handleRequestRemove( i, data, length, sender ) ) |
---|
| 95 | return i; |
---|
| 96 | continue; |
---|
| 97 | } |
---|
[6695] | 98 | else if ( b == NET_REQUEST_PNODE_PATH ) |
---|
| 99 | { |
---|
| 100 | if ( !handleRequestPNodePath( i, data, length, sender ) ) |
---|
| 101 | return i; |
---|
| 102 | continue; |
---|
| 103 | } |
---|
[6341] | 104 | } |
---|
| 105 | else |
---|
| 106 | { |
---|
[6695] | 107 | /**************** Commands only processed by clients ****************/ |
---|
| 108 | if ( b == NET_CREATE_ENTITY ) |
---|
[6341] | 109 | { |
---|
[6634] | 110 | PRINTF(0)("CREATE_ENTITY\n"); |
---|
[6341] | 111 | if ( !handleCreateEntity( i, data, length, sender ) ) |
---|
| 112 | return i; |
---|
| 113 | continue; |
---|
| 114 | } |
---|
[6695] | 115 | else if ( b == NET_REMOVE_ENTITY ) |
---|
[6341] | 116 | { |
---|
| 117 | if ( !handleRemoveEntity( i, data, length, sender ) ) |
---|
| 118 | return i; |
---|
| 119 | continue; |
---|
| 120 | } |
---|
[6695] | 121 | else if ( b == NET_CREATE_ENTITY_LIST ) |
---|
[6341] | 122 | { |
---|
| 123 | if ( !handleCreateEntityList( i, data, length, sender ) ) |
---|
| 124 | return i; |
---|
| 125 | continue; |
---|
| 126 | } |
---|
[6695] | 127 | else if ( b == NET_REMOVE_ENTITY_LIST ) |
---|
[6341] | 128 | { |
---|
| 129 | if ( !handleRemoveEntityList( i, data, length, sender ) ) |
---|
| 130 | return i; |
---|
| 131 | continue; |
---|
| 132 | } |
---|
[6695] | 133 | else if ( b == NET_YOU_ARE_ENTITY ) |
---|
[6341] | 134 | { |
---|
| 135 | if ( !handleYouAreEntity( i, data, length, sender ) ) |
---|
| 136 | return i; |
---|
| 137 | continue; |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
[6695] | 141 | /**************** Commands processed by servers and clients ****************/ |
---|
| 142 | if ( b == NET_REQUEST_ENTITY_LIST ) |
---|
[6341] | 143 | { |
---|
[6634] | 144 | sendEntityList( sender ); |
---|
[6341] | 145 | continue; |
---|
| 146 | } |
---|
[6695] | 147 | else if ( b == NET_REQUEST_SYNC ) |
---|
[6341] | 148 | { |
---|
[6634] | 149 | if ( !handleRequestSync( i, data, length, sender ) ) |
---|
| 150 | return i; |
---|
[6341] | 151 | continue; |
---|
| 152 | } |
---|
| 153 | |
---|
[6695] | 154 | |
---|
| 155 | PRINTF(1)("Network is asynchronous: couldn't decode the command sent by %i\n", sender); |
---|
| 156 | PRINTF(1)("Probably this is because the network protocol has different \n"); |
---|
| 157 | PRINTF(1)("versions or there occured an error in the sending algorithm\n"); |
---|
[6341] | 158 | PRINTF(1)("Data is not in the right format! i=%d\n", i); |
---|
| 159 | return i; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | return i; |
---|
[6067] | 163 | } |
---|
| 164 | |
---|
[6116] | 165 | int NetworkGameManager::readBytes(byte* data, int maxLength, int * reciever) |
---|
[6067] | 166 | { |
---|
[6341] | 167 | if ( !isServer() && !hasRequestedWorld ) |
---|
| 168 | { |
---|
[6815] | 169 | assert( maxLength >= 1 ); |
---|
| 170 | data[0] = NET_REQUEST_ENTITY_LIST; |
---|
[6341] | 171 | hasRequestedWorld = true; |
---|
[6815] | 172 | return 1; |
---|
[6341] | 173 | } |
---|
[6498] | 174 | |
---|
[6341] | 175 | for ( int i = 0; i<outBuffer.size(); i++ ) |
---|
| 176 | { |
---|
| 177 | *reciever = i; |
---|
| 178 | if ( outBuffer[i].length>0 ) |
---|
| 179 | { |
---|
| 180 | int nbytes = outBuffer[i].length; |
---|
| 181 | outBuffer[i].length = 0; |
---|
| 182 | |
---|
| 183 | if ( nbytes > maxLength ) |
---|
| 184 | { |
---|
| 185 | PRINTF(1)("OutBuffer.length (%d) > (%d) networkStreamBuffer.maxLength\n", nbytes, maxLength); |
---|
| 186 | return 0; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | memcpy(data, outBuffer[i].buffer, nbytes); |
---|
| 190 | return nbytes; |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | |
---|
[6634] | 194 | return 0; |
---|
[6067] | 195 | } |
---|
| 196 | |
---|
[6116] | 197 | void NetworkGameManager::writeDebug() const |
---|
[6067] | 198 | { |
---|
| 199 | } |
---|
| 200 | |
---|
[6116] | 201 | void NetworkGameManager::readDebug() const |
---|
[6067] | 202 | { |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | /*! |
---|
| 207 | * Checks whether this is connected to a server or a client |
---|
[6341] | 208 | * and afterwards creates the needed entity |
---|
[6067] | 209 | * @param classID: The ID of the class of which an entity should be created |
---|
| 210 | */ |
---|
[6498] | 211 | int NetworkGameManager::createEntity( ClassID classID, int owner ) |
---|
[6067] | 212 | { |
---|
[6695] | 213 | if ( this->isServer()) |
---|
[6341] | 214 | { |
---|
[6695] | 215 | if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) |
---|
[6341] | 216 | { |
---|
| 217 | PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); |
---|
[6498] | 218 | return -1; |
---|
[6341] | 219 | } |
---|
[6695] | 220 | return this->executeCreateEntity( classID, SharedNetworkData::getInstance()->getNewUniqueID(), owner ); |
---|
[6341] | 221 | } |
---|
| 222 | else |
---|
| 223 | { |
---|
| 224 | this->requestCreateEntity( classID ); |
---|
[6498] | 225 | return -1; |
---|
[6341] | 226 | } |
---|
[6067] | 227 | } |
---|
| 228 | |
---|
[6341] | 229 | |
---|
[6067] | 230 | /*! |
---|
| 231 | * Checks whether this is connected to a server or a client |
---|
[6341] | 232 | * and afterwards creates the needed entity |
---|
| 233 | * @param classID: The ID of the class of which an entity should be created |
---|
| 234 | */ |
---|
[6424] | 235 | BaseObject* NetworkGameManager::createEntity(const TiXmlElement* element) |
---|
[6341] | 236 | { |
---|
| 237 | if ( this->isServer() ) |
---|
| 238 | { |
---|
[6695] | 239 | if ( SharedNetworkData::getInstance()->getNewUniqueID() < 0 ) |
---|
[6341] | 240 | { |
---|
| 241 | PRINTF(1)("Cannot create entity! There are no more uniqueIDs left!\n"); |
---|
| 242 | return NULL; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | BaseObject * b = Factory::fabricate( element ); |
---|
| 246 | |
---|
| 247 | if ( !b ) |
---|
| 248 | { |
---|
[6424] | 249 | PRINTF(1)("Could not fabricate Object with className %s\n", element->Value() ); |
---|
[6341] | 250 | return NULL; |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | if ( b->isA(CL_SYNCHRONIZEABLE) ) |
---|
| 255 | { |
---|
| 256 | Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); |
---|
[6695] | 257 | s->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() ); |
---|
[6341] | 258 | s->setOwner( 0 ); |
---|
[6695] | 259 | // all entities created via this function are added automaticaly to the synchronizeable list |
---|
| 260 | s->setSynchronized(true); |
---|
[6341] | 261 | return b; |
---|
| 262 | } |
---|
| 263 | else |
---|
| 264 | { |
---|
| 265 | PRINTF(1)("Class %s is not a synchronizeable!\n", b->getClassName() ); |
---|
| 266 | delete b; |
---|
| 267 | } |
---|
[6498] | 268 | |
---|
[6341] | 269 | } |
---|
| 270 | else |
---|
[6695] | 271 | |
---|
[6341] | 272 | { |
---|
| 273 | PRINTF(1)("This node is not a server and cannot create id %x\n", element->Value()); |
---|
| 274 | } |
---|
| 275 | return NULL; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | /*! |
---|
| 280 | * Checks whether this is connected to a server or a client |
---|
[6067] | 281 | * and afterwards removes the specified entity |
---|
| 282 | * @param uniqueID: The ID of the entity object which should be removed |
---|
| 283 | */ |
---|
[6116] | 284 | void NetworkGameManager::removeEntity(int uniqueID) |
---|
[6067] | 285 | { |
---|
[6341] | 286 | if ( this->isServer() ) |
---|
| 287 | { |
---|
| 288 | this->executeRemoveEntity( uniqueID ); |
---|
| 289 | } |
---|
| 290 | else |
---|
| 291 | { |
---|
| 292 | this->requestRemoveEntity( uniqueID ); |
---|
| 293 | } |
---|
[6067] | 294 | } |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | |
---|
| 298 | /*! |
---|
| 299 | * Creates the needed entity on the server if possible |
---|
| 300 | * @param classID: The ID of the class of which an entity should be created |
---|
| 301 | */ |
---|
[6341] | 302 | void NetworkGameManager::requestCreateEntity(ClassID classID) |
---|
[6067] | 303 | { |
---|
[6634] | 304 | for ( int i = 0; i<outBuffer.size(); i++) |
---|
| 305 | { |
---|
| 306 | if ( !this->networkStream->isUserIdActive( i ) ) |
---|
| 307 | continue; |
---|
| 308 | |
---|
[6695] | 309 | if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_CREATE ) ) |
---|
[6634] | 310 | return; |
---|
| 311 | if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) |
---|
| 312 | return; |
---|
| 313 | } |
---|
[6067] | 314 | } |
---|
| 315 | |
---|
| 316 | /*! |
---|
| 317 | * Removes the specified entity on the server |
---|
| 318 | * @param uniqueID: The ID of the entity object which should be removed |
---|
| 319 | */ |
---|
[6116] | 320 | void NetworkGameManager::requestRemoveEntity(int uniqueID) |
---|
[6067] | 321 | { |
---|
[6634] | 322 | for ( int i = 0; i<outBuffer.size(); i++) |
---|
| 323 | { |
---|
| 324 | if ( !this->networkStream->isUserIdActive( i ) ) |
---|
| 325 | continue; |
---|
| 326 | |
---|
[6695] | 327 | if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REQUEST_REMOVE ) ) |
---|
[6634] | 328 | return; |
---|
| 329 | if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) |
---|
| 330 | return; |
---|
| 331 | } |
---|
[6067] | 332 | } |
---|
| 333 | |
---|
| 334 | /*! |
---|
| 335 | * Creates the needed entity if possible |
---|
| 336 | * This function is called if this is a server |
---|
| 337 | * @param classID: The ID of the class of which an entity should be created |
---|
| 338 | */ |
---|
[6498] | 339 | int NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner) |
---|
[6067] | 340 | { |
---|
[6634] | 341 | for ( int i = 0; i<outBuffer.size(); i++) |
---|
| 342 | { |
---|
| 343 | if ( !this->networkStream->isUserIdActive( i ) ) |
---|
| 344 | continue; |
---|
[6341] | 345 | |
---|
[6695] | 346 | if ( !writeToClientBuffer( outBuffer[i], (byte)NET_CREATE_ENTITY ) ) |
---|
[6634] | 347 | return -1; |
---|
| 348 | if ( !writeToClientBuffer( outBuffer[i], (int)classID ) ) |
---|
| 349 | return -1; |
---|
| 350 | if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) |
---|
| 351 | return -1; |
---|
| 352 | if ( !writeToClientBuffer( outBuffer[i], owner ) ) |
---|
| 353 | return -1; |
---|
| 354 | } |
---|
| 355 | |
---|
[6695] | 356 | PRINTF(0)("ExecuteCreateEntity: server side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); |
---|
[6341] | 357 | doCreateEntity( classID, uniqueID, owner ); |
---|
[6498] | 358 | |
---|
| 359 | return uniqueID; |
---|
[6067] | 360 | } |
---|
| 361 | |
---|
| 362 | /*! |
---|
| 363 | * Removes the specified entity |
---|
| 364 | * This function is called if this is a server |
---|
| 365 | * @param uniqueID: The ID of the entity object which should be removed |
---|
| 366 | */ |
---|
[6116] | 367 | void NetworkGameManager::executeRemoveEntity(int uniqueID) |
---|
[6067] | 368 | { |
---|
[6634] | 369 | for ( int i = 0; i<outBuffer.size(); i++) |
---|
| 370 | { |
---|
| 371 | if ( !this->networkStream->isUserIdActive( i ) ) |
---|
| 372 | continue; |
---|
[6341] | 373 | |
---|
[6695] | 374 | if ( !writeToClientBuffer( outBuffer[i], (byte)NET_REMOVE_ENTITY ) ) |
---|
[6634] | 375 | return; |
---|
| 376 | if ( !writeToClientBuffer( outBuffer[i], uniqueID ) ) |
---|
| 377 | return; |
---|
| 378 | } |
---|
| 379 | |
---|
[6341] | 380 | doRemoveEntity(uniqueID); |
---|
[6067] | 381 | } |
---|
| 382 | |
---|
| 383 | /*! |
---|
| 384 | * Checks whether it is possible to create an entity of a given class |
---|
| 385 | * @return: true if the entity can be created, false otherwise |
---|
| 386 | */ |
---|
[6341] | 387 | bool NetworkGameManager::canCreateEntity(ClassID classID) |
---|
[6067] | 388 | { |
---|
[6341] | 389 | return true; |
---|
[6067] | 390 | } |
---|
[6341] | 391 | |
---|
| 392 | /*! |
---|
| 393 | * Sends the Entities to the new connected client |
---|
| 394 | * @param userID: The ID of the user |
---|
| 395 | */ |
---|
| 396 | void NetworkGameManager::sendEntityList( int userID ) |
---|
| 397 | { |
---|
| 398 | if ( !isServer() ) |
---|
| 399 | return; |
---|
| 400 | |
---|
| 401 | if ( userID >= outBuffer.size() ) |
---|
| 402 | resizeBufferVector( userID ); |
---|
| 403 | |
---|
| 404 | SynchronizeableList::const_iterator it, e; |
---|
| 405 | |
---|
| 406 | it = this->networkStream->getSyncBegin(); |
---|
| 407 | e = this->networkStream->getSyncEnd(); |
---|
| 408 | |
---|
[6695] | 409 | // send the packet header |
---|
| 410 | if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_CREATE_ENTITY_LIST ) ) |
---|
[6341] | 411 | return; |
---|
| 412 | |
---|
[6695] | 413 | // send the number of entities: -2 because you must not send network_game_manager and handshake |
---|
[6341] | 414 | if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) ) |
---|
| 415 | return; |
---|
| 416 | |
---|
| 417 | //PRINTF(0)("SendEntityList: n = %d\n", networkStream->getSyncCount()-2 ); |
---|
| 418 | |
---|
[6695] | 419 | // first send the NullParent |
---|
| 420 | if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getLeafClassID()) ) |
---|
| 421 | return; |
---|
| 422 | if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getUniqueID()) ) |
---|
| 423 | return; |
---|
| 424 | if ( !writeToClientBuffer( outBuffer[userID], (int)PNode::getNullParent()->getOwner()) ) |
---|
| 425 | return; |
---|
[6424] | 426 | |
---|
[6695] | 427 | // now send the rest of the entities |
---|
[6341] | 428 | while ( it != e ) |
---|
| 429 | { |
---|
[6695] | 430 | if( (*it)->beSynchronized() && (*it) != PNode::getNullParent()) |
---|
| 431 | { |
---|
| 432 | PRINTF(0)("SENDING ENTITY %s classid: %x, uniqueid %d\n", (*it)->getClassName(), (*it)->getLeafClassID(), (*it)->getUniqueID() ); |
---|
| 433 | if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getLeafClassID()) ) ) |
---|
| 434 | return; |
---|
[6341] | 435 | |
---|
[6695] | 436 | if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getUniqueID()) ) ) |
---|
| 437 | return; |
---|
[6341] | 438 | |
---|
[6695] | 439 | if ( !writeToClientBuffer( outBuffer[userID], (int)((*it)->getOwner()) ) ) |
---|
| 440 | return; |
---|
| 441 | } |
---|
[6498] | 442 | it++; |
---|
| 443 | } |
---|
[6424] | 444 | |
---|
[6498] | 445 | signalNewPlayer( userID ); |
---|
| 446 | } |
---|
[6424] | 447 | |
---|
| 448 | |
---|
| 449 | |
---|
[6498] | 450 | bool NetworkGameManager::signalNewPlayer(int userId) |
---|
| 451 | { |
---|
[6634] | 452 | if ( userId >= outBuffer.size() ) |
---|
| 453 | resizeBufferVector( userId ); |
---|
[6341] | 454 | |
---|
[6498] | 455 | /* create new playable for Player*/ |
---|
| 456 | PRINTF(0)("Request for creation: %i\n", userId); |
---|
| 457 | int uniqueId = this->createEntity(CL_SPACE_SHIP, userId); |
---|
| 458 | PRINTF(0)("Request for creation: userid: %i, uniqueid: %i\n", userId, uniqueId); |
---|
| 459 | this->sendYouAre(uniqueId, userId); |
---|
[6341] | 460 | |
---|
| 461 | } |
---|
| 462 | |
---|
[6498] | 463 | |
---|
[6737] | 464 | |
---|
| 465 | bool NetworkGameManager::signalLeftPlayer(int userID) |
---|
| 466 | { |
---|
| 467 | const std::list<BaseObject*>* playableList = ClassList::getList(CL_PLAYABLE); |
---|
| 468 | std::list<BaseObject*>::const_iterator it = playableList->begin(); |
---|
| 469 | |
---|
| 470 | for(; it != playableList->end(); it++) |
---|
| 471 | { |
---|
| 472 | if( dynamic_cast<Synchronizeable*>(*it)->getOwner() == userID ) |
---|
| 473 | { |
---|
| 474 | PRINTF(0)("remove playable from %i\n", userID); |
---|
| 475 | this->removeEntity(dynamic_cast<Synchronizeable*>(*it)->getUniqueID()); |
---|
| 476 | return true; |
---|
| 477 | } |
---|
| 478 | } |
---|
| 479 | return false; |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | |
---|
[6341] | 483 | /** |
---|
| 484 | * Creates a buffer for user n |
---|
| 485 | * @param n The ID of the user |
---|
| 486 | */ |
---|
| 487 | void NetworkGameManager::resizeBufferVector( int n ) |
---|
| 488 | { |
---|
| 489 | for ( int i = outBuffer.size(); i<=n; i++) |
---|
| 490 | { |
---|
| 491 | clientBuffer outBuf; |
---|
| 492 | |
---|
| 493 | outBuf.length = 0; |
---|
| 494 | |
---|
| 495 | outBuf.maxLength = 5*1024; |
---|
| 496 | |
---|
| 497 | outBuf.buffer = new byte[5*1014]; |
---|
| 498 | |
---|
| 499 | outBuffer.push_back(outBuf); |
---|
| 500 | } |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | /** |
---|
| 504 | * Creates the entity on this host |
---|
| 505 | * @param classID: ClassID of the entity to create |
---|
| 506 | * @param uniqueID: Unique ID to assign to the synchronizeable |
---|
| 507 | * @param owner: owner of this synchronizealbe |
---|
| 508 | */ |
---|
[6424] | 509 | BaseObject* NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner ) |
---|
[6341] | 510 | { |
---|
[6695] | 511 | PRINTF(0)("Creating Entity via Factory: classid: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); |
---|
[6341] | 512 | |
---|
[6695] | 513 | BaseObject * b; |
---|
| 514 | /* These are some small exeptions in creation: Not all objects can/should be created via Factory */ |
---|
| 515 | /* Exception 1: NullParent */ |
---|
| 516 | if( classID == CL_NULL_PARENT) |
---|
| 517 | { |
---|
| 518 | b = (BaseObject*)PNode::getNullParent(); |
---|
| 519 | } |
---|
| 520 | else |
---|
| 521 | b = Factory::fabricate( classID ); |
---|
| 522 | |
---|
[6341] | 523 | if ( !b ) |
---|
| 524 | { |
---|
| 525 | PRINTF(1)("Could not fabricate Object with classID %x\n", classID); |
---|
[6424] | 526 | return NULL; |
---|
[6341] | 527 | } |
---|
| 528 | |
---|
| 529 | if ( b->isA(CL_SYNCHRONIZEABLE) ) |
---|
| 530 | { |
---|
| 531 | Synchronizeable * s = dynamic_cast<Synchronizeable*>(b); |
---|
| 532 | s->setUniqueID( uniqueID ); |
---|
| 533 | s->setOwner( owner ); |
---|
[6695] | 534 | s->setSynchronized(true); |
---|
| 535 | //this->networkStream->connectSynchronizeable( *s ); |
---|
[6341] | 536 | if ( !isServer() ) |
---|
| 537 | s->setIsOutOfSync( true ); |
---|
| 538 | PRINTF(0)("Fabricated %s with id %d\n", s->getClassName(), s->getUniqueID()); |
---|
[6498] | 539 | |
---|
| 540 | //HACK: hack to prevent collision |
---|
[6634] | 541 | if ( b->isA(CL_WORLD_ENTITY) && !b->isA(CL_PLAYABLE) ) |
---|
[6498] | 542 | { |
---|
[6917] | 543 | if ( SharedNetworkData::getInstance()->getHostID()!=0 ) |
---|
[6498] | 544 | { |
---|
| 545 | static Vector pos = Vector(1000.0, 1000.0, 1000.0); |
---|
| 546 | PNode *p = dynamic_cast<PNode*>(b); |
---|
[6634] | 547 | p->setAbsCoor(pos); |
---|
[6737] | 548 | p->updateNode(0); |
---|
[6498] | 549 | pos += Vector(1000.0, 1000.0, 1000.0); |
---|
| 550 | } |
---|
| 551 | } |
---|
| 552 | |
---|
[6424] | 553 | return b; |
---|
[6341] | 554 | } |
---|
| 555 | else |
---|
| 556 | { |
---|
| 557 | PRINTF(1)("Class with ID %x is not a synchronizeable!", (int)classID); |
---|
| 558 | delete b; |
---|
| 559 | } |
---|
[6424] | 560 | return NULL; |
---|
[6341] | 561 | } |
---|
| 562 | |
---|
| 563 | /** |
---|
| 564 | * Removes a entity on this host |
---|
| 565 | * @param uniqueID: unique ID assigned with the entity to remove |
---|
| 566 | */ |
---|
| 567 | void NetworkGameManager::doRemoveEntity( int uniqueID ) |
---|
| 568 | { |
---|
| 569 | SynchronizeableList::const_iterator it,e; |
---|
| 570 | it = this->networkStream->getSyncBegin(); |
---|
| 571 | e = this->networkStream->getSyncEnd(); |
---|
| 572 | |
---|
| 573 | while ( it != e ) |
---|
| 574 | { |
---|
| 575 | if ( (*it)->getUniqueID() == uniqueID ) |
---|
| 576 | { |
---|
[6868] | 577 | assert((*it)->isA(CL_WORLD_ENTITY)); |
---|
| 578 | dynamic_cast<WorldEntity*>(*it)->toList(OM_DEAD); |
---|
[6341] | 579 | break; |
---|
| 580 | } |
---|
| 581 | it++; |
---|
| 582 | } |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | /** |
---|
| 586 | * Tell the synchronizeable that a user's synchronizeable is out of sync |
---|
| 587 | * @param uniqueID: unique ID assigned with the entity which is out of sync |
---|
| 588 | * @param userID: user ID who's synchronizeable is out of sync |
---|
| 589 | */ |
---|
| 590 | void NetworkGameManager::doRequestSync( int uniqueID, int userID ) |
---|
| 591 | { |
---|
| 592 | SynchronizeableList::const_iterator it,e; |
---|
| 593 | it = this->networkStream->getSyncBegin(); |
---|
| 594 | e = this->networkStream->getSyncEnd(); |
---|
| 595 | |
---|
| 596 | while ( it != e ) |
---|
| 597 | { |
---|
| 598 | if ( (*it)->getUniqueID() == uniqueID ) |
---|
| 599 | { |
---|
| 600 | (*it)->requestSync( userID ); |
---|
| 601 | break; |
---|
| 602 | } |
---|
| 603 | it++; |
---|
| 604 | } |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | /** |
---|
| 608 | * Copies length bytes to the clientBuffer with error checking |
---|
| 609 | * @param clientBuffer: the clientBuffer to write to |
---|
| 610 | * @param data: buffer to the data |
---|
| 611 | * @param length: length of data |
---|
| 612 | * @return false on error true else |
---|
| 613 | */ |
---|
| 614 | bool NetworkGameManager::writeToClientBuffer( clientBuffer &cb, byte * data, int length ) |
---|
| 615 | { |
---|
| 616 | if ( length > cb.maxLength-cb.length ) |
---|
| 617 | { |
---|
| 618 | PRINTF(1)("No space left in clientBuffer\n"); |
---|
| 619 | return false; |
---|
| 620 | } |
---|
| 621 | |
---|
| 622 | memcpy( cb.buffer+cb.length, data, length ); |
---|
| 623 | return true; |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | /** |
---|
| 627 | * Reads data from clientBuffer with error checking |
---|
| 628 | * @param clientBuffer: the clientBuffer to read from |
---|
| 629 | * @param data: pointer to the buffer |
---|
| 630 | * @param length: |
---|
| 631 | * @return |
---|
| 632 | */ |
---|
| 633 | bool NetworkGameManager::readFromClientBuffer( clientBuffer &cb, byte * data, int length ) |
---|
| 634 | { |
---|
| 635 | if ( cb.length < length ) |
---|
| 636 | { |
---|
| 637 | PRINTF(0)("There is not enough data in clientBuffer\n"); |
---|
| 638 | return 0; |
---|
| 639 | } |
---|
| 640 | |
---|
| 641 | memcpy( data, cb.buffer+cb.length-length, length ); |
---|
| 642 | return true; |
---|
| 643 | } |
---|
| 644 | |
---|
| 645 | /** |
---|
| 646 | * Tells this client that he has to control this entity |
---|
| 647 | * @param uniqueID: the entity's uniqeID |
---|
| 648 | */ |
---|
| 649 | void NetworkGameManager::doYouAre( int uniqueID ) |
---|
| 650 | { |
---|
[6498] | 651 | |
---|
| 652 | SynchronizeableList::const_iterator it = this->networkStream->getSyncBegin(); |
---|
| 653 | |
---|
| 654 | Playable *p = NULL; |
---|
[6634] | 655 | Synchronizeable *s = NULL; |
---|
[6498] | 656 | |
---|
| 657 | for ( ; it !=networkStream->getSyncEnd(); it++ ) |
---|
| 658 | { |
---|
| 659 | if ( (*it)->getUniqueID()==uniqueID ) |
---|
| 660 | { |
---|
[6634] | 661 | if ( (*it)->isA( CL_SYNCHRONIZEABLE ) ) |
---|
| 662 | { |
---|
| 663 | s = dynamic_cast<Synchronizeable*>(*it); |
---|
| 664 | } |
---|
[6498] | 665 | if ( (*it)->isA( CL_PLAYABLE ) ) |
---|
| 666 | { |
---|
| 667 | p = dynamic_cast<Playable*>(*it); |
---|
| 668 | break; |
---|
| 669 | } else |
---|
| 670 | { |
---|
| 671 | PRINTF(1)("UniqueID is not a Playable\n"); |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | Player* player = State::getPlayer(); |
---|
| 677 | assert(p != NULL); |
---|
[6634] | 678 | assert(s != NULL); |
---|
[6498] | 679 | assert(player != NULL); |
---|
| 680 | |
---|
[6634] | 681 | s->setIsOutOfSync( true ); |
---|
| 682 | |
---|
| 683 | PRINTF(0)("uniqueID = %d\n", s->getUniqueID()); |
---|
| 684 | |
---|
[6498] | 685 | player->setControllable(p); |
---|
| 686 | |
---|
| 687 | |
---|
[6341] | 688 | } |
---|
| 689 | |
---|
| 690 | /** |
---|
| 691 | * Tells a remote client that he has to control this entity |
---|
| 692 | * @param uniqueID: the entity's uniqeID |
---|
| 693 | * @param userID: the users ID |
---|
| 694 | */ |
---|
| 695 | void NetworkGameManager::sendYouAre( int uniqueID, int userID ) |
---|
| 696 | { |
---|
| 697 | if ( !isServer() ) |
---|
| 698 | return; |
---|
| 699 | |
---|
| 700 | if ( userID != 0 ) |
---|
| 701 | { |
---|
[6695] | 702 | if ( !writeToClientBuffer( outBuffer[userID], (byte)NET_YOU_ARE_ENTITY ) ) |
---|
[6341] | 703 | return; |
---|
| 704 | |
---|
| 705 | if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) ) |
---|
| 706 | return; |
---|
| 707 | } |
---|
| 708 | else |
---|
| 709 | { |
---|
| 710 | doYouAre(uniqueID); |
---|
| 711 | } |
---|
| 712 | } |
---|
| 713 | |
---|
| 714 | bool NetworkGameManager::handleRequestCreate( int & i, const byte * data, int length, int sender ) |
---|
| 715 | { |
---|
| 716 | if ( INTSIZE > length-i ) |
---|
| 717 | { |
---|
| 718 | PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); |
---|
| 719 | return false; |
---|
| 720 | } |
---|
| 721 | int classID; |
---|
| 722 | i += Converter::byteArrayToInt( &data[i], &classID ); |
---|
| 723 | |
---|
| 724 | createEntity( (ClassID)classID ); |
---|
| 725 | |
---|
| 726 | return true; |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | bool NetworkGameManager::handleRequestRemove( int & i, const byte * data, int length, int sender ) |
---|
| 730 | { |
---|
| 731 | if ( INTSIZE > length-i ) |
---|
| 732 | { |
---|
| 733 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 734 | return false; |
---|
| 735 | } |
---|
| 736 | int uniqueID; |
---|
| 737 | i += Converter::byteArrayToInt( &data[i], &uniqueID ); |
---|
| 738 | |
---|
| 739 | removeEntity( uniqueID ); |
---|
| 740 | |
---|
| 741 | return true; |
---|
| 742 | } |
---|
| 743 | |
---|
| 744 | bool NetworkGameManager::handleCreateEntity( int & i, const byte * data, int length, int sender ) |
---|
| 745 | { |
---|
| 746 | if ( INTSIZE > length-i ) |
---|
| 747 | { |
---|
| 748 | PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); |
---|
| 749 | return false; |
---|
| 750 | } |
---|
| 751 | int classID; |
---|
| 752 | i += Converter::byteArrayToInt( &data[i], &classID ); |
---|
| 753 | |
---|
| 754 | if ( INTSIZE > length-i ) |
---|
| 755 | { |
---|
| 756 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 757 | return false; |
---|
| 758 | } |
---|
| 759 | int uniqueID; |
---|
| 760 | i += Converter::byteArrayToInt( &data[i], &uniqueID ); |
---|
| 761 | |
---|
| 762 | if ( INTSIZE > length-i ) |
---|
| 763 | { |
---|
| 764 | PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n"); |
---|
| 765 | return false; |
---|
| 766 | } |
---|
| 767 | int owner; |
---|
| 768 | i += Converter::byteArrayToInt( &data[i], &owner ); |
---|
| 769 | |
---|
[6695] | 770 | PRINTF(0)("handleCreateEntity: client side: classID: %x, uniqueID: %i, owner: %i\n", classID, uniqueID, owner); |
---|
[6341] | 771 | doCreateEntity( (ClassID)classID, uniqueID, owner ); |
---|
| 772 | |
---|
| 773 | return true; |
---|
| 774 | } |
---|
| 775 | |
---|
| 776 | bool NetworkGameManager::handleRemoveEntity( int & i, const byte * data, int length, int sender ) |
---|
| 777 | { |
---|
| 778 | if ( INTSIZE > length-i ) |
---|
| 779 | { |
---|
| 780 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 781 | return false; |
---|
| 782 | } |
---|
| 783 | int uniqueID; |
---|
| 784 | i += Converter::byteArrayToInt( &data[i], &uniqueID ); |
---|
| 785 | |
---|
| 786 | doRemoveEntity( uniqueID ); |
---|
| 787 | |
---|
| 788 | return true; |
---|
| 789 | } |
---|
| 790 | |
---|
| 791 | bool NetworkGameManager::handleCreateEntityList( int & i, const byte * data, int length, int sender ) |
---|
| 792 | { |
---|
| 793 | if ( INTSIZE > length-i ) |
---|
| 794 | { |
---|
| 795 | PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); |
---|
| 796 | return false; |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | PRINTF(0)("HandleCreateEntityList: data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]); |
---|
| 800 | |
---|
| 801 | int n; |
---|
| 802 | i += Converter::byteArrayToInt( &data[i], &n ); |
---|
| 803 | |
---|
| 804 | |
---|
| 805 | PRINTF(0)("HandleCreateEntityList: n = %d\n", n); |
---|
| 806 | |
---|
| 807 | int classID, uniqueID, owner; |
---|
| 808 | |
---|
| 809 | for ( int j = 0; j<n; j++ ) |
---|
| 810 | { |
---|
| 811 | |
---|
| 812 | if ( INTSIZE > length-i ) |
---|
| 813 | { |
---|
| 814 | PRINTF(1)("Cannot read classID from buffer! Not enough data left!\n"); |
---|
| 815 | return false; |
---|
| 816 | } |
---|
| 817 | i += Converter::byteArrayToInt( &data[i], &classID ); |
---|
| 818 | |
---|
| 819 | if ( INTSIZE > length-i ) |
---|
| 820 | { |
---|
| 821 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 822 | return false; |
---|
| 823 | } |
---|
| 824 | i += Converter::byteArrayToInt( &data[i], &uniqueID ); |
---|
| 825 | |
---|
| 826 | if ( INTSIZE > length-i ) |
---|
| 827 | { |
---|
| 828 | PRINTF(1)("Cannot read owner from buffer! Not enough data left!\n"); |
---|
| 829 | return false; |
---|
| 830 | } |
---|
| 831 | i += Converter::byteArrayToInt( &data[i], &owner ); |
---|
| 832 | |
---|
| 833 | if ( classID != CL_NETWORK_GAME_MANAGER && classID != CL_HANDSHAKE ) |
---|
[6424] | 834 | { |
---|
| 835 | BaseObject* b = doCreateEntity( (ClassID)classID, uniqueID, owner ); |
---|
| 836 | } |
---|
| 837 | |
---|
[6341] | 838 | } |
---|
[6424] | 839 | |
---|
[6341] | 840 | return true; |
---|
| 841 | } |
---|
| 842 | |
---|
| 843 | bool NetworkGameManager::handleRemoveEntityList( int & i, const byte * data, int length, int sender ) |
---|
| 844 | { |
---|
| 845 | if ( INTSIZE > length-i ) |
---|
| 846 | { |
---|
| 847 | PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); |
---|
| 848 | return false; |
---|
| 849 | } |
---|
| 850 | int n; |
---|
| 851 | i += Converter::byteArrayToInt( &data[i], &n ); |
---|
| 852 | |
---|
| 853 | int uniqueID; |
---|
| 854 | |
---|
| 855 | for ( int j = 0; j<n; j++ ) |
---|
| 856 | { |
---|
| 857 | |
---|
| 858 | if ( INTSIZE > length-i ) |
---|
| 859 | { |
---|
| 860 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 861 | return false; |
---|
| 862 | } |
---|
| 863 | i += Converter::byteArrayToInt( &data[i], &uniqueID ); |
---|
| 864 | |
---|
| 865 | doRemoveEntity( uniqueID ); |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | return true; |
---|
| 869 | } |
---|
| 870 | |
---|
| 871 | bool NetworkGameManager::handleYouAreEntity( int & i, const byte * data, int length, int sender ) |
---|
| 872 | { |
---|
| 873 | if ( INTSIZE > length-i ) |
---|
| 874 | { |
---|
| 875 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 876 | return false; |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | int uniqueID; |
---|
| 880 | i += Converter::byteArrayToInt( &data[i], &uniqueID ); |
---|
| 881 | |
---|
| 882 | doYouAre( uniqueID ); |
---|
| 883 | |
---|
| 884 | return true; |
---|
| 885 | } |
---|
| 886 | |
---|
| 887 | bool NetworkGameManager::handleRequestSync( int & i, const byte * data, int length, int sender ) |
---|
| 888 | { |
---|
| 889 | if ( INTSIZE > length-i ) |
---|
| 890 | { |
---|
| 891 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 892 | return false; |
---|
| 893 | } |
---|
| 894 | int uniqueID; |
---|
| 895 | i += Converter::byteArrayToInt( &data[i], &uniqueID ); |
---|
| 896 | |
---|
[6892] | 897 | PRINTF(0)("handleRequestSync %d %d\n", uniqueID, sender); |
---|
[6341] | 898 | doRequestSync( uniqueID, sender ); |
---|
| 899 | |
---|
| 900 | return true; |
---|
| 901 | } |
---|
| 902 | |
---|
[6695] | 903 | |
---|
| 904 | /** |
---|
| 905 | * handles the network signal NET_REQUEST_PNODE_PATH |
---|
| 906 | * @param i byte offset in the buffer |
---|
| 907 | * @param data data array |
---|
| 908 | * @param length length of the data arary |
---|
| 909 | * @param sender the sender id |
---|
| 910 | * @return true if process terminated sucessfully |
---|
| 911 | */ |
---|
| 912 | bool NetworkGameManager::handleRequestPNodePath(int& i, const byte* data, int length, int sender) |
---|
| 913 | { |
---|
| 914 | if( INTSIZE > length-i ) |
---|
| 915 | { |
---|
| 916 | PRINTF(1)("Cannot read n from buffer! Not enough data left!\n"); |
---|
| 917 | return false; |
---|
| 918 | } |
---|
| 919 | PRINTF(0)("HandleRequestPNodePath: data[i..i+3] = %d %d %d %d\n", data[i], data[i+1], data[i+2], data[i+3]); |
---|
| 920 | |
---|
| 921 | int uniqueID1, uniqueID2; |
---|
| 922 | if( INTSIZE > length-i ) |
---|
| 923 | { |
---|
| 924 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 925 | return false; |
---|
| 926 | } |
---|
| 927 | i += Converter::byteArrayToInt( &data[i], &uniqueID1 ); |
---|
| 928 | |
---|
| 929 | if( INTSIZE > length-i ) |
---|
| 930 | { |
---|
| 931 | PRINTF(1)("Cannot read uniqueID from buffer! Not enough data left!\n"); |
---|
| 932 | return false; |
---|
| 933 | } |
---|
| 934 | i += Converter::byteArrayToInt( &data[i], &uniqueID2 ); |
---|
| 935 | |
---|
| 936 | |
---|
| 937 | PRINTF(0)("HandleRequestPNodePath: got a request for path from uid %i to uid %i\n", uniqueID1, uniqueID2); |
---|
| 938 | |
---|
| 939 | return true; |
---|
| 940 | } |
---|
| 941 | |
---|
| 942 | |
---|
[6341] | 943 | bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b ) |
---|
| 944 | { |
---|
| 945 | if ( cb.maxLength-cb.length < 1 ) |
---|
| 946 | { |
---|
| 947 | PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 byte\n"); |
---|
| 948 | return false; |
---|
| 949 | } |
---|
| 950 | |
---|
| 951 | cb.buffer[cb.length++] = b; |
---|
| 952 | |
---|
| 953 | return true; |
---|
| 954 | } |
---|
| 955 | |
---|
| 956 | bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i ) |
---|
| 957 | { |
---|
| 958 | int n = Converter::intToByteArray( i, cb.buffer+cb.length, cb.maxLength-cb.length ); |
---|
| 959 | cb.length += n; |
---|
| 960 | |
---|
| 961 | if ( n <= 0 ) |
---|
| 962 | { |
---|
| 963 | PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 int\n"); |
---|
| 964 | return false; |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | return true; |
---|
| 968 | } |
---|
| 969 | |
---|
| 970 | void NetworkGameManager::sync( int uniqueID, int owner ) |
---|
| 971 | { |
---|
[6634] | 972 | /*if ( owner==this->getHostID() ) |
---|
| 973 | return;*/ |
---|
[6341] | 974 | |
---|
| 975 | if ( !isServer() ) |
---|
| 976 | executeRequestSync( uniqueID, 0 ); |
---|
| 977 | else |
---|
| 978 | executeRequestSync( uniqueID, owner ); |
---|
| 979 | } |
---|
| 980 | |
---|
| 981 | void NetworkGameManager::executeRequestSync( int uniqueID, int user ) |
---|
| 982 | { |
---|
[6892] | 983 | PRINTF(0)("executeRequestSync %d %d\n", uniqueID, user); |
---|
[6341] | 984 | if ( user >= outBuffer.size() ) |
---|
| 985 | resizeBufferVector( user ); |
---|
| 986 | |
---|
[6695] | 987 | if ( !writeToClientBuffer( outBuffer[user], (byte)NET_REQUEST_SYNC ) ) |
---|
[6341] | 988 | return; |
---|
| 989 | if ( !writeToClientBuffer( outBuffer[user], uniqueID ) ) |
---|
| 990 | return; |
---|
| 991 | } |
---|
| 992 | |
---|