From 480ef0a468b3d7e80f610e657ce7014a51553aca Mon Sep 17 00:00:00 2001 From: mittorn Date: Tue, 29 Jan 2019 19:01:21 +0700 Subject: [PATCH] legacymode: add netsplit support (incoming only) --- engine/client/cl_main.c | 34 +++++++++++++++++++++++++++++++++- engine/client/cl_parse.c | 5 +++++ engine/common/net_chan.c | 2 +- engine/common/net_ws.c | 5 ++++- engine/common/net_ws.h | 4 ++++ 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index 29952b99..e1d86ee8 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -1015,6 +1015,13 @@ void CL_SendConnectPacket( void ) if( cls.legacymode ) { + // set related userinfo keys + if( cl_dlmax->value >= 40000 || cl_dlmax->value < 100 ) + Cvar_FullSet( "cl_maxpacket", "1400", FCVAR_USERINFO ); + else + Cvar_FullSet( "cl_maxpacket", cl_dlmax->string, FCVAR_USERINFO ); + Cvar_FullSet( "cl_maxpayload", "1000", FCVAR_USERINFO ); + /// TODO: add input devices list //Info_SetValueForKey( protinfo, "d", va( "%d", input_devices ), sizeof( protinfo ) ); Info_SetValueForKey( protinfo, "v", XASH_VERSION, sizeof( protinfo ) ); @@ -1023,12 +1030,15 @@ void CL_SendConnectPacket( void ) Info_SetValueForKey( protinfo, "a", Q_buildarch(), sizeof( protinfo ) ); Info_SetValueForKey( protinfo, "i", ID_GetMD5(), sizeof( protinfo ) ); - Netchan_OutOfBandPrint( NS_CLIENT, adr, "connect %i %i %i \"%s\" 0 \"%s\"\n", + Netchan_OutOfBandPrint( NS_CLIENT, adr, "connect %i %i %i \"%s\" 2 \"%s\"\n", PROTOCOL_LEGACY_VERSION, Q_atoi( qport ), cls.challenge, cls.userinfo, protinfo ); Con_Printf( "Trying to connect by legacy protocol\n" ); } else { + // remove useless userinfo keys + Cvar_FullSet( "cl_maxpacket", "0", 0 ); + Cvar_FullSet( "cl_maxpayload", "1000", 0 ); Info_SetValueForKey( protinfo, "uuid", key, sizeof( protinfo )); Info_SetValueForKey( protinfo, "qport", qport, sizeof( protinfo )); Netchan_OutOfBandPrint( NS_CLIENT, adr, "connect %i %i \"%s\" \"%s\"\n", PROTOCOL_VERSION, cls.challenge, protinfo, cls.userinfo ); @@ -1365,6 +1375,19 @@ void CL_Reconnect( qboolean setup_netchan ) if( setup_netchan ) { Netchan_Setup( NS_CLIENT, &cls.netchan, net_from, Cvar_VariableInteger( "net_qport" ), NULL, CL_GetFragmentSize ); + + if( cls.legacymode ) + { + unsigned int extensions = Q_atoi( Cmd_Argv( 1 ) ); + + if( extensions & NET_EXT_SPLIT ) + { + // only enable incoming split for legacy mode + cls.netchan.split = true; + Con_Reportf( "^2NET_EXT_SPLIT enabled^7 (packet sizes is %d/%d)\n", (int)cl_dlmax->value, 65536 ); + } + } + } else { @@ -2036,6 +2059,11 @@ void CL_ReadNetMessage( void ) while( CL_GetMessage( net_message_buffer, &curSize )) { + if( cls.legacymode && *((int *)&net_message_buffer) == 0xFFFFFFFE ) + // Will rewrite existing packet by merged + if( !NetSplit_GetLong( &cls.netchan.netsplit, &net_from, net_message_buffer, &curSize ) ) + continue; + MSG_Init( &net_message, "ServerData", net_message_buffer, curSize ); // check for connectionless packet (0xffffffff) first @@ -2653,6 +2681,10 @@ void CL_InitLocal( void ) Cvar_Get( "team", "", FCVAR_USERINFO, "player team" ); Cvar_Get( "skin", "", FCVAR_USERINFO, "player skin" ); + // legacy mode cvars (need this to add it to userinfo) + Cvar_Get( "cl_maxpacket", "0", 0, "legacy server compatibility" ); + Cvar_Get( "cl_maxpayload", "1000", 0, "legacy server compatibility" ); + cl_showfps = Cvar_Get( "cl_showfps", "1", FCVAR_ARCHIVE, "show client fps" ); cl_nosmooth = Cvar_Get( "cl_nosmooth", "0", FCVAR_ARCHIVE, "disable smooth up stair climbing and interpolate position in multiplayer" ); cl_smoothtime = Cvar_Get( "cl_smoothtime", "0", FCVAR_ARCHIVE, "time to smooth up" ); diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 737e9457..db23748d 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -3107,3 +3107,8 @@ void CL_LegacyUpdateInfo( void ) MSG_BeginClientCmd( &cls.netchan.message, clc_legacy_userinfo ); MSG_WriteString( &cls.netchan.message, cls.userinfo ); } + +qboolean CL_LegacyMode( void ) +{ + return cls.legacymode; +} diff --git a/engine/common/net_chan.c b/engine/common/net_chan.c index cabb0b1a..b2db3dbf 100644 --- a/engine/common/net_chan.c +++ b/engine/common/net_chan.c @@ -189,7 +189,7 @@ qboolean NetSplit_GetLong( netsplit_t *ns, netadr_t *from, byte *data, size_t *l *length = len; // Con_Reportf( S_NOTE "NetSplit_GetLong: packet from %s, id %d received %d length %d\n", NET_AdrToString( *from ), (int)packet->id, (int)p->received, (int)packet->length ); - memcpy( data, p->data, len ); + memcpy( data, p->data, len ); return true; } else diff --git a/engine/common/net_ws.c b/engine/common/net_ws.c index beeaa59e..08e03261 100644 --- a/engine/common/net_ws.c +++ b/engine/common/net_ws.c @@ -1218,7 +1218,10 @@ qboolean NET_QueuePacket( netsrc_t sock, netadr_t *from, byte *data, size_t *len // Transfer data memcpy( data, buf, ret ); *length = ret; - +#ifndef XASH_DEDICATED + if( CL_LegacyMode() ) + return NET_LagPacket( true, sock, from, length, data ); +#endif // check for split message if( *(int *)data == NET_HEADER_SPLITPACKET ) { diff --git a/engine/common/net_ws.h b/engine/common/net_ws.h index c946dd3f..c8f45d6f 100644 --- a/engine/common/net_ws.h +++ b/engine/common/net_ws.h @@ -63,4 +63,8 @@ qboolean NET_BufferToBufferDecompress( char *dest, uint *destLen, char *source, void NET_SendPacket( netsrc_t sock, size_t length, const void *data, netadr_t to ); void NET_ClearLagData( qboolean bClient, qboolean bServer ); +#ifndef XASH_DEDICATED +qboolean CL_LegacyMode( void ); +#endif + #endif//NET_WS_H