From fb2ba6a6e2c61e661c03ab69741f77e0c51493a1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 13 Mar 2023 05:12:46 +0300 Subject: [PATCH] engine: common: net_buffer: add MSG_WriteStringf wrapper --- engine/common/net_buffer.c | 12 ++++++++++++ engine/common/net_buffer.h | 1 + 2 files changed, 13 insertions(+) diff --git a/engine/common/net_buffer.c b/engine/common/net_buffer.c index 567047f2..2ec7b008 100644 --- a/engine/common/net_buffer.c +++ b/engine/common/net_buffer.c @@ -452,6 +452,18 @@ qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr ) return !sb->bOverflow; } +qboolean MSG_WriteStringf( sizebuf_t *sb, const char *format, ... ) +{ + va_list va; + char buf[MAX_VA_STRING]; + + va_start( va, format ); + Q_vsnprintf( buf, sizeof( buf ), format, va ); + va_end( va ); + + return MSG_WriteString( sb, buf ); +} + int MSG_ReadOneBit( sizebuf_t *sb ) { if( !MSG_Overflow( sb, 1 )) diff --git a/engine/common/net_buffer.h b/engine/common/net_buffer.h index 62ded8dc..0be9e25b 100644 --- a/engine/common/net_buffer.h +++ b/engine/common/net_buffer.h @@ -102,6 +102,7 @@ void MSG_WriteVec3Coord( sizebuf_t *sb, const float *fa ); void MSG_WriteVec3Angles( sizebuf_t *sb, const float *fa ); qboolean MSG_WriteBytes( sizebuf_t *sb, const void *pBuf, int nBytes ); // same as MSG_WriteData qboolean MSG_WriteString( sizebuf_t *sb, const char *pStr ); // returns false if it overflows the buffer. +qboolean MSG_WriteStringf( sizebuf_t *sb, const char *format, ... ) _format( 2 ); // helper functions _inline int MSG_GetNumBytesWritten( sizebuf_t *sb ) { return BitByte( sb->iCurBit ); }