- Timestamp:
- Dec 21, 2005, 3:00:35 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/network_game_manager.cc
r6230 r6231 229 229 void NetworkGameManager::requestCreateEntity(ClassID classID) 230 230 { 231 byte* bp; 232 byte b = REQUEST_CREATE; 233 bp = Converter::intToByteArray( classID ); 234 235 if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) ) 236 { 237 PRINTF(1)("Could not write to clientBuffer\n"); 238 return; 239 } 240 241 if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) ) 242 { 243 PRINTF(1)("Could not write to clientBuffer\n"); 244 delete bp; 245 return; 246 } 247 delete bp; 231 if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_CREATE ) ) 232 return; 233 if ( !writeToClientBuffer( allOutBuffer, (int)classID ) ) 234 return; 248 235 } 249 236 … … 254 241 void NetworkGameManager::requestRemoveEntity(int uniqueID) 255 242 { 256 byte* bp; 257 byte b = REQUEST_REMOVE; 258 bp = Converter::intToByteArray( uniqueID ); 259 260 if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) ) 261 { 262 PRINTF(1)("Could not write to clientBuffer\n"); 263 return; 264 } 265 266 if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) ) 267 { 268 PRINTF(1)("Could not write to clientBuffer\n"); 269 delete bp; 270 return; 271 } 272 delete bp; 243 if ( !writeToClientBuffer( allOutBuffer, (byte)REQUEST_REMOVE ) ) 244 return; 245 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 246 return; 273 247 } 274 248 … … 280 254 void NetworkGameManager::executeCreateEntity(ClassID classID, int uniqueID, int owner) 281 255 { 282 byte* bp; 283 byte b = CREATE_ENTITY; 284 285 if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) ) 286 { 287 PRINTF(1)("Could not write to clientBuffer\n"); 288 return; 289 } 290 291 bp = Converter::intToByteArray( uniqueID ); 292 if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) ) 293 { 294 PRINTF(1)("Could not write to clientBuffer\n"); 295 delete bp; 296 return; 297 } 298 delete bp; 299 300 bp = Converter::intToByteArray( uniqueID ); 301 if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) ) 302 { 303 PRINTF(1)("Could not write to clientBuffer\n"); 304 delete bp; 305 return; 306 } 307 delete bp; 308 309 bp = Converter::intToByteArray( owner ); 310 if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) ) 311 { 312 PRINTF(1)("Could not write to clientBuffer\n"); 313 delete bp; 314 return; 315 } 316 delete bp; 256 if ( !writeToClientBuffer( allOutBuffer, (byte)CREATE_ENTITY ) ) 257 return; 258 if ( !writeToClientBuffer( allOutBuffer, (int)classID ) ) 259 return; 260 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 261 return; 262 if ( !writeToClientBuffer( allOutBuffer, owner ) ) 263 return; 317 264 318 265 doCreateEntity( classID, uniqueID, owner ); … … 326 273 void NetworkGameManager::executeRemoveEntity(int uniqueID) 327 274 { 328 byte* bp; 329 byte b = REMOVE_ENTITY; 330 331 if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) ) 332 { 333 PRINTF(1)("Could not write to clientBuffer\n"); 334 return; 335 } 336 337 bp = Converter::intToByteArray( uniqueID ); 338 if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) ) 339 { 340 PRINTF(1)("Could not write to clientBuffer\n"); 341 delete bp; 342 return; 343 } 344 delete bp; 275 if ( !writeToClientBuffer( allOutBuffer, (byte)REMOVE_ENTITY ) ) 276 return; 277 if ( !writeToClientBuffer( allOutBuffer, uniqueID ) ) 278 return; 345 279 346 280 doRemoveEntity(uniqueID); … … 373 307 e = this->networkStream->getSyncEnd(); 374 308 375 byte b = CREATE_ENTITY_LIST; 376 byte* ib; 377 378 if ( !writeToClientBuffer( outBuffer[userID], &b, 1 ) ) 379 { 380 PRINTF(1)("Could not write to clientBuffer\n"); 381 return; 382 } 383 384 ib = Converter::intToByteArray( networkStream->getSyncCount() ); 385 if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) ) 386 { 387 PRINTF(1)("Could not write to clientBuffer\n"); 388 delete ib; 389 return; 390 } 391 delete ib; 309 if ( !writeToClientBuffer( outBuffer[userID], (byte)CREATE_ENTITY_LIST ) ) 310 return; 311 312 if ( !writeToClientBuffer( outBuffer[userID], networkStream->getSyncCount() ) ) 313 return; 392 314 393 315 while ( it != e ) 394 316 { 395 ib = Converter::intToByteArray( (*it)->getClassID() ); 396 if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) ) 397 { 398 PRINTF(1)("Could not write to clientBuffer\n"); 399 delete ib; 317 if ( !writeToClientBuffer( outBuffer[userID], (*it)->getClassID() ) ) 400 318 return; 401 } 402 delete ib; 403 404 ib = Converter::intToByteArray( (*it)->getUniqueID() ); 405 if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) ) 406 { 407 PRINTF(1)("Could not write to clientBuffer\n"); 408 delete ib; 319 320 if ( !writeToClientBuffer( outBuffer[userID], (*it)->getUniqueID() ) ) 409 321 return; 410 } 411 delete ib; 412 413 ib = Converter::intToByteArray( (*it)->getOwner() ); 414 if ( !writeToClientBuffer( outBuffer[userID], ib, INTSIZE ) ) 415 { 416 PRINTF(1)("Could not write to clientBuffer\n"); 417 delete ib; 322 323 if ( !writeToClientBuffer( outBuffer[userID], (*it)->getOwner() ) ) 418 324 return; 419 }420 delete ib;421 325 422 326 it++; … … 574 478 return; 575 479 576 byte* bp;577 byte b = YOU_ARE_ENTITY;578 579 480 if ( userID != 0 ) 580 481 { 581 if ( !writeToClientBuffer( allOutBuffer, &b, 1 ) ) 582 { 583 PRINTF(1)("Could not write to clientBuffer\n"); 482 if ( !writeToClientBuffer( outBuffer[userID], (byte)YOU_ARE_ENTITY ) ) 584 483 return; 585 } 586 587 bp = Converter::intToByteArray( uniqueID ); 588 if ( !writeToClientBuffer( allOutBuffer, bp, INTSIZE ) ) 589 { 590 PRINTF(1)("Could not write to clientBuffer\n"); 591 delete bp; 484 485 if ( !writeToClientBuffer( outBuffer[userID], uniqueID ) ) 592 486 return; 593 }594 delete bp;595 487 } 596 488 else … … 607 499 return false; 608 500 } 609 int classID = Converter::byteArrayToInt( data );610 i += INTSIZE;501 int classID; 502 i += Converter::byteArrayToInt( data, &classID ); 611 503 612 504 createEntity( (ClassID)classID ); … … 622 514 return false; 623 515 } 624 int uniqueID = Converter::byteArrayToInt( data );625 i += INTSIZE;516 int uniqueID; 517 i += Converter::byteArrayToInt( data, &uniqueID ); 626 518 627 519 removeEntity( uniqueID ); … … 637 529 return false; 638 530 } 639 int classID = Converter::byteArrayToInt( data );640 i += INTSIZE;531 int classID; 532 i += Converter::byteArrayToInt( data, &classID ); 641 533 642 534 if ( INTSIZE > length-i ) … … 645 537 return false; 646 538 } 647 int uniqueID = Converter::byteArrayToInt( data );648 i += INTSIZE;539 int uniqueID; 540 i += Converter::byteArrayToInt( data, &uniqueID ); 649 541 650 542 if ( INTSIZE > length-i ) … … 653 545 return false; 654 546 } 655 int owner = Converter::byteArrayToInt( data );656 i += INTSIZE;547 int owner; 548 i += Converter::byteArrayToInt( data, &owner ); 657 549 658 550 doCreateEntity( (ClassID)classID, uniqueID, owner ); … … 668 560 return false; 669 561 } 670 int uniqueID = Converter::byteArrayToInt( data );671 i += INTSIZE;562 int uniqueID; 563 i += Converter::byteArrayToInt( data, &uniqueID ); 672 564 673 565 doRemoveEntity( uniqueID ); … … 683 575 return false; 684 576 } 685 int n = Converter::byteArrayToInt( data );686 i += INTSIZE;577 int n; 578 i += Converter::byteArrayToInt( data, &n ); 687 579 688 580 int classID, uniqueID, owner; … … 696 588 return false; 697 589 } 698 classID = Converter::byteArrayToInt( data ); 699 i += INTSIZE; 590 i += Converter::byteArrayToInt( data, &classID ); 700 591 701 592 if ( INTSIZE > length-i ) … … 704 595 return false; 705 596 } 706 uniqueID = Converter::byteArrayToInt( data ); 707 i += INTSIZE; 597 i += Converter::byteArrayToInt( data, &uniqueID ); 708 598 709 599 if ( INTSIZE > length-i ) … … 712 602 return false; 713 603 } 714 owner = Converter::byteArrayToInt( data ); 715 i += INTSIZE; 604 i += Converter::byteArrayToInt( data, &owner ); 716 605 717 606 doCreateEntity( (ClassID)classID, uniqueID, owner ); … … 728 617 return false; 729 618 } 730 int n = Converter::byteArrayToInt( data );731 i += INTSIZE;619 int n; 620 i += Converter::byteArrayToInt( data, &n ); 732 621 733 622 int uniqueID; … … 741 630 return false; 742 631 } 743 uniqueID = Converter::byteArrayToInt( data ); 744 i += INTSIZE; 632 i += Converter::byteArrayToInt( data, &uniqueID ); 745 633 746 634 doRemoveEntity( uniqueID ); … … 757 645 return false; 758 646 } 759 int uniqueID = Converter::byteArrayToInt( data ); 760 i += INTSIZE; 647 648 int uniqueID; 649 i += Converter::byteArrayToInt( data, &uniqueID ); 761 650 762 651 doYouAre( uniqueID ); … … 772 661 return false; 773 662 } 774 int uniqueID = Converter::byteArrayToInt( data );775 i += INTSIZE;663 int uniqueID; 664 i += Converter::byteArrayToInt( data, &uniqueID ); 776 665 777 666 doRequestSync( uniqueID, sender ); … … 780 669 } 781 670 671 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, byte b ) 672 { 673 if ( cb.maxLength-cb.length < 1 ) 674 { 675 PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 byte\n"); 676 return false; 677 } 678 679 cb.buffer[cb.length++] = b; 680 681 return true; 682 } 683 684 bool NetworkGameManager::writeToClientBuffer( clientBuffer & cb, int i ) 685 { 686 int n = Converter::intToByteArray( i, cb.buffer, cb.maxLength-cb.length ); 687 cb.length += n; 688 689 if ( n <= 0 ) 690 { 691 PRINTF(1)("Cannot write to clientBuffer! Not enough space for 1 int\n"); 692 return false; 693 } 694 695 return true; 696 } 697 -
branches/network/src/lib/network/network_game_manager.h
r6230 r6231 97 97 98 98 inline bool writeToClientBuffer( clientBuffer &cb, byte*data, int length ); 99 inline bool writeToClientBuffer( clientBuffer &cb, byte b ); 100 inline bool writeToClientBuffer( clientBuffer &cb, int i ); 99 101 inline bool readFromClientBuffer( clientBuffer &cb, byte*data, int length ); 100 102
Note: See TracChangeset
for help on using the changeset viewer.