MCPcopy Create free account
hub / github.com/JACoders/OpenJK / CL_WritePacket

Function CL_WritePacket

codemp/client/cl_input.cpp:1494–1609  ·  view source on GitHub ↗

=================== CL_WritePacket Create and send the command packet to the server Including both the reliable commands and the usercmds During normal gameplay, a client packet will contain something like: 4 sequence number 2 qport 4 serverid 4 acknowledged sequence number 4 clc.serverCommandSequence 1 clc_move or clc_moveNoDelta 1 command count

Source from the content-addressed store, hash-verified

1492===================
1493*/
1494void CL_WritePacket( void ) {
1495 msg_t buf;
1496 byte data[MAX_MSGLEN];
1497 int i, j;
1498 usercmd_t *cmd, *oldcmd;
1499 usercmd_t nullcmd;
1500 int packetNum;
1501 int oldPacketNum;
1502 int count, key;
1503
1504 // don't send anything if playing back a demo
1505 if ( clc.demoplaying || cls.state == CA_CINEMATIC ) {
1506 return;
1507 }
1508
1509 Com_Memset( &nullcmd, 0, sizeof(nullcmd) );
1510 oldcmd = &nullcmd;
1511
1512 MSG_Init( &buf, data, sizeof(data) );
1513
1514 MSG_Bitstream( &buf );
1515 // write the current serverId so the server
1516 // can tell if this is from the current gameState
1517 MSG_WriteLong( &buf, cl.serverId );
1518
1519 // write the last message we received, which can
1520 // be used for delta compression, and is also used
1521 // to tell if we dropped a gamestate
1522 MSG_WriteLong( &buf, clc.serverMessageSequence );
1523
1524 // write the last reliable message we received
1525 MSG_WriteLong( &buf, clc.serverCommandSequence );
1526
1527 // write any unacknowledged clientCommands
1528 for ( i = clc.reliableAcknowledge + 1 ; i <= clc.reliableSequence ; i++ ) {
1529 MSG_WriteByte( &buf, clc_clientCommand );
1530 MSG_WriteLong( &buf, i );
1531 MSG_WriteString( &buf, clc.reliableCommands[ i & (MAX_RELIABLE_COMMANDS-1) ] );
1532 }
1533
1534 // we want to send all the usercmds that were generated in the last
1535 // few packet, so even if a couple packets are dropped in a row,
1536 // all the cmds will make it to the server
1537 if ( cl_packetdup->integer < 0 ) {
1538 Cvar_Set( "cl_packetdup", "0" );
1539 } else if ( cl_packetdup->integer > 5 ) {
1540 Cvar_Set( "cl_packetdup", "5" );
1541 }
1542 oldPacketNum = (clc.netchan.outgoingSequence - 1 - cl_packetdup->integer) & PACKET_MASK;
1543 count = cl.cmdNumber - cl.outPackets[ oldPacketNum ].p_cmdNumber;
1544 if ( count > MAX_PACKET_USERCMDS ) {
1545 count = MAX_PACKET_USERCMDS;
1546 Com_Printf("MAX_PACKET_USERCMDS\n");
1547 }
1548 if ( count >= 1 ) {
1549 if ( cl_showSend->integer ) {
1550 Com_Printf( "(%i)", count );
1551 }

Callers 4

CL_ParseDownloadFunction · 0.70
CL_SendCmdFunction · 0.70
CL_DisconnectFunction · 0.70
CL_DownloadsCompleteFunction · 0.70

Calls 11

MSG_BitstreamFunction · 0.85
Com_HashKeyFunction · 0.85
MSG_WriteDeltaUsercmdKeyFunction · 0.85
CL_Netchan_TransmitFunction · 0.85
MSG_InitFunction · 0.50
MSG_WriteLongFunction · 0.50
MSG_WriteByteFunction · 0.50
MSG_WriteStringFunction · 0.50
Cvar_SetFunction · 0.50
Com_PrintfFunction · 0.50

Tested by

no test coverage detected