MCPcopy Create free account
hub / github.com/dhewm/dhewm3 / SendMessage

Method SendMessage

neo/framework/async/MsgChannel.cpp:472–528  ·  view source on GitHub ↗

=============== idMsgChannel::SendMessage Sends a message to a connection, fragmenting if necessary A 0 length will still generate a packet. ================ */

Source from the content-addressed store, hash-verified

470================
471*/
472int 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

Callers 7

SendEmptyToClientMethod · 0.45
SendPingToClientMethod · 0.45
SendGameInitToClientMethod · 0.45
SendSnapshotToClientMethod · 0.45
SendEmptyToServerMethod · 0.45
SendUsercmdsToServerMethod · 0.45

Calls 11

GetTotalSizeMethod · 0.80
BeginWritingMethod · 0.80
ErrorMethod · 0.45
GetSizeMethod · 0.45
PrintfMethod · 0.45
InitMethod · 0.45
WriteShortMethod · 0.45
WriteIntMethod · 0.45
SendPacketMethod · 0.45
GetDataMethod · 0.45
GetBoolMethod · 0.45

Tested by

no test coverage detected