From 20baf8e39074313cc3620d99e3cd099d87d933dc Mon Sep 17 00:00:00 2001 From: Knightmare66 Date: Thu, 18 Mar 2021 05:35:26 -0400 Subject: [PATCH] Added handling for "print" command in cl_main.c->CL_ConnectionlessPacket() that changes cl_servertrick and reconnects when a known "wrong version" rejection message is received. Changed wrong protocol rejection messaged in sv_main.c->SVC_DirectConnect() to send KMQuake2 version instead of just version number. --- client/cl_main.c | 27 +++++++++++++++++++++++++++ kmquake2.txt | 2 +- kmquake2_changelog.txt | 2 ++ server/sv_main.c | 3 ++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/client/cl_main.c b/client/cl_main.c index 1887ccd..d4c99cd 100644 --- a/client/cl_main.c +++ b/client/cl_main.c @@ -1569,11 +1569,38 @@ void CL_ConnectionlessPacket (void) Cbuf_AddText ("\n"); return; } + // print command from somewhere if (!strcmp(c, "print")) { + char thisVersionRejMsg[64]; + s = MSG_ReadString (&net_message); Com_Printf ("%s", s); + + // catch wrong version reply from server here + Com_sprintf (thisVersionRejMsg, sizeof(thisVersionRejMsg), "You need KMQuake2 version %4.2f to play on this server.", VERSION); + if ( strstr(s, "Server is version 3.19") || strstr(s, "Server is version 3.2") // stock Q2 3.19 / 3.2x rejection messages + || strstr(s, "You need Quake II 3.19 or higher to play on this server.") // R1Q2 + || strstr(s, "Unsupported protocol version") || strstr(s, "You need Quake 2 version 3.19 or higher.") ) // Q2Pro + { + Cvar_SetInteger ("cl_servertrick", 1); + Com_Printf ("Wrong version reply received from server. Reconnecting as protocol version %i.\n", OLD_PROTOCOL_VERSION); + CL_Reconnect_f (); + } + else if ( strstr(s, thisVersionRejMsg) ) // Same version of KMQ2 + { + Cvar_SetInteger ("cl_servertrick", 0); + Com_Printf ("Wrong version reply received from server. Reconnecting as protocol version %i.\n", PROTOCOL_VERSION); + CL_Reconnect_f (); + } + else if ( strstr(s, "Server is version") ) // don't keep going if unknown version + { + Com_Printf ("Unknown wrong version reply received from server. Disconnecting.\n"); + SCR_EndLoadingPlaque (); + CL_Disconnect (); + } + return; } diff --git a/kmquake2.txt b/kmquake2.txt index 3692f72..bb56b6b 100644 --- a/kmquake2.txt +++ b/kmquake2.txt @@ -113,7 +113,7 @@ How To Run mod's code to run, it must be compiled into a kmq2gamex86.dll (see end of file for instructions). - To connect to standard Quake2 (protocol 34) servers, add + To ping info from and connect to standard Quake2 (protocol 34) servers, add +set cl_servertrick 1 diff --git a/kmquake2_changelog.txt b/kmquake2_changelog.txt index 5c2143a..57f96e1 100644 --- a/kmquake2_changelog.txt +++ b/kmquake2_changelog.txt @@ -21,6 +21,8 @@ Changes as of v0.20 update 8: - Added support for quake2:// URLs. +- Added client auto-reconnect with cl_servertrick set correspondingly when a known "wrong version" rejection message is received. + - Added cel shading support. Uses cvars r_celshading to enable, and r_celshading_width for line width (1-10). - Added horizontal offset to third-person mode. Offset distance is controlled by cvar cg_thirdperson_offset. diff --git a/server/sv_main.c b/server/sv_main.c index f18bc59..b1ef288 100644 --- a/server/sv_main.c +++ b/server/sv_main.c @@ -399,7 +399,8 @@ void SVC_DirectConnect (void) version = atoi(Cmd_Argv(1)); if (version != PROTOCOL_VERSION) { - Netchan_OutOfBandPrint (NS_SERVER, adr, "print\nServer is version %4.2f.\n", VERSION); + // Netchan_OutOfBandPrint (NS_SERVER, adr, "print\nServer is version %4.2f.\n", VERSION); + Netchan_OutOfBandPrint (NS_SERVER, adr, "print\nYou need KMQuake2 version %4.2f to play on this server.\n", VERSION); Com_DPrintf (" rejected connect from version %i\n", version); return; }