=============== idMsgChannel::SendMessage Sends a message to a connection, fragmenting if necessary A 0 length will still generate a packet. ================ */
| 470 | ================ |
| 471 | */ |
| 472 | int idMsgChannel::SendMessage( idPort &port, const int time, const idBitMsg &msg ) { |
| 473 | int totalLength; |
| 474 | |
| 475 | if ( remoteAddress.type == NA_BAD ) { |
| 476 | return -1; |
| 477 | } |
| 478 | |
| 479 | if ( unsentFragments ) { |
| 480 | common->Error( "idMsgChannel::SendMessage: called with unsent fragments left" ); |
| 481 | return -1; |
| 482 | } |
| 483 | |
| 484 | totalLength = 4 + reliableSend.GetTotalSize() + 4 + msg.GetSize(); |
| 485 | |
| 486 | if ( totalLength > MAX_MESSAGE_SIZE ) { |
| 487 | common->Printf( "idMsgChannel::SendMessage: message too large, length = %i\n", totalLength ); |
| 488 | return -1; |
| 489 | } |
| 490 | |
| 491 | unsentMsg.Init( unsentBuffer, sizeof( unsentBuffer ) ); |
| 492 | unsentMsg.BeginWriting(); |
| 493 | |
| 494 | // fragment large messages |
| 495 | if ( totalLength >= FRAGMENT_SIZE ) { |
| 496 | unsentFragments = true; |
| 497 | unsentFragmentStart = 0; |
| 498 | |
| 499 | // write out the message data |
| 500 | WriteMessageData( unsentMsg, msg ); |
| 501 | |
| 502 | // send the first fragment now |
| 503 | SendNextFragment( port, time ); |
| 504 | |
| 505 | return outgoingSequence; |
| 506 | } |
| 507 | |
| 508 | // write the header |
| 509 | unsentMsg.WriteShort( id ); |
| 510 | unsentMsg.WriteInt( outgoingSequence ); |
| 511 | |
| 512 | // write out the message data |
| 513 | WriteMessageData( unsentMsg, msg ); |
| 514 | |
| 515 | // send the packet |
| 516 | port.SendPacket( remoteAddress, unsentMsg.GetData(), unsentMsg.GetSize() ); |
| 517 | |
| 518 | // update rate control variables |
| 519 | UpdateOutgoingRate( time, unsentMsg.GetSize() ); |
| 520 | |
| 521 | if ( net_channelShowPackets.GetBool() ) { |
| 522 | common->Printf( "%d send %4i : s = %i ack = %i\n", id, unsentMsg.GetSize(), outgoingSequence - 1, incomingSequence ); |
| 523 | } |
| 524 | |
| 525 | outgoingSequence++; |
| 526 | |
| 527 | return ( outgoingSequence - 1 ); |
| 528 | } |
| 529 |
no test coverage detected