2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-26 03:39:16 +01:00

engine: common: faster and simpler Netchan_OutOfBand

This commit is contained in:
Alibek Omarov 2024-08-08 04:37:16 +03:00
parent 9be061735f
commit f0b4c42c68

View File

@ -457,22 +457,21 @@ Netchan_OutOfBand
Sends an out-of-band datagram Sends an out-of-band datagram
================ ================
*/ */
void Netchan_OutOfBand( int net_socket, netadr_t adr, int length, byte *data ) void Netchan_OutOfBand( int net_socket, netadr_t adr, int len, byte *data )
{ {
byte send_buf[MAX_PRINT_MSG]; byte buf[MAX_PRINT_MSG + 4] = { 0xff, 0xff, 0xff, 0xff };
sizebuf_t send;
if( CL_IsPlaybackDemo( )) if( CL_IsPlaybackDemo( ))
return; return;
// write the packet header if( len > sizeof( buf ) - 4 )
MSG_Init( &send, "SequencePacket", send_buf, sizeof( send_buf )); {
Host_Error( "%s: overflow!\n", __func__ );
return;
}
MSG_WriteLong( &send, NET_HEADER_OUTOFBANDPACKET ); // -1 sequence means out of band memcpy( &buf[4], data, len );
MSG_WriteBytes( &send, data, length ); NET_SendPacket( net_socket, len + 4, buf, adr );
// send the datagram
NET_SendPacket( net_socket, MSG_GetNumBytesWritten( &send ), MSG_GetData( &send ), adr );
} }
/* /*
@ -482,16 +481,26 @@ Netchan_OutOfBandPrint
Sends a text message in an out-of-band datagram Sends a text message in an out-of-band datagram
================ ================
*/ */
void Netchan_OutOfBandPrint( int net_socket, netadr_t adr, const char *format, ... ) void Netchan_OutOfBandPrint( int net_socket, netadr_t adr, const char *fmt, ... )
{ {
char string[MAX_PRINT_MSG]; va_list va;
va_list argptr; byte buf[MAX_PRINT_MSG + 4] = { 0xff, 0xff, 0xff, 0xff };
int len;
va_start( argptr, format ); if( CL_IsPlaybackDemo( ))
Q_vsnprintf( string, sizeof( string ) - 1, format, argptr ); return;
va_end( argptr );
Netchan_OutOfBand( net_socket, adr, Q_strlen( string ), (byte *)string ); va_start( va, fmt );
len = Q_vsnprintf( &buf[4], sizeof( buf ) - 4, fmt, va );
va_end( va );
if( len < 0 )
{
Host_Error( "%s: snprintf overflow!\n", __func__ );
return;
}
NET_SendPacket( net_socket, len + 4, buf, adr );
} }
/* /*