protocol: share configstring convert logic

This commit is contained in:
Denis Pauk 2024-03-23 18:47:17 +02:00
parent b6df49dbb7
commit f5bbf533bc
5 changed files with 164 additions and 44 deletions

View file

@ -997,6 +997,7 @@ CLIENT_OBJS_ := \
src/common/frame.o \ src/common/frame.o \
src/common/netchan.o \ src/common/netchan.o \
src/common/pmove.o \ src/common/pmove.o \
src/common/protocol.o \
src/common/szone.o \ src/common/szone.o \
src/common/zone.o \ src/common/zone.o \
src/common/shared/flash.o \ src/common/shared/flash.o \
@ -1270,6 +1271,7 @@ SERVER_OBJS_ := \
src/common/movemsg.o \ src/common/movemsg.o \
src/common/netchan.o \ src/common/netchan.o \
src/common/pmove.o \ src/common/pmove.o \
src/common/protocol.o \
src/common/szone.o \ src/common/szone.o \
src/common/zone.o \ src/common/zone.o \
src/common/shared/rand.o \ src/common/shared/rand.o \

View file

@ -73,7 +73,7 @@ Maps support:
Note: Note:
* SiN Gold has IBSP/41 format but has different size of lump and is * SiN Gold has IBSP/41 format but has different size of lump and is
unsupported. unsupported.
* Not Quake 2 maps are limmited mostly view only, and could have issues * Non Quake 2 maps are limmited mostly view only, and could have issues
with tranparency or some animations flags and properties. with tranparency or some animations flags and properties.
Goals (finished): Goals (finished):

View file

@ -542,47 +542,6 @@ CL_ParsePacketEntities(frame_t *oldframe, frame_t *newframe)
} }
} }
static int
CL_ConvertConfigStringFrom(int i)
{
if (cls.serverProtocol == PROTOCOL_RELEASE_VERSION ||
cls.serverProtocol == PROTOCOL_DEMO_VERSION ||
cls.serverProtocol == PROTOCOL_XATRIX_VERSION ||
cls.serverProtocol == PROTOCOL_RR97_VERSION)
{
if (i >= CS_MODELS_Q2DEMO && i < CS_SOUNDS_Q2DEMO)
{
i += CS_MODELS - CS_MODELS_Q2DEMO;
}
else if (i >= CS_SOUNDS_Q2DEMO && i < CS_IMAGES_Q2DEMO)
{
i += CS_SOUNDS - CS_SOUNDS_Q2DEMO;
}
else if (i >= CS_IMAGES_Q2DEMO && i < CS_LIGHTS_Q2DEMO)
{
i += CS_IMAGES - CS_IMAGES_Q2DEMO;
}
else if (i >= CS_LIGHTS_Q2DEMO && i < CS_ITEMS_Q2DEMO)
{
i += CS_LIGHTS - CS_LIGHTS_Q2DEMO;
}
else if (i >= CS_ITEMS_Q2DEMO && i < CS_PLAYERSKINS_Q2DEMO)
{
i += CS_ITEMS - CS_ITEMS_Q2DEMO;
}
else if (i >= CS_PLAYERSKINS_Q2DEMO && i < CS_GENERAL_Q2DEMO)
{
i += CS_PLAYERSKINS - CS_PLAYERSKINS_Q2DEMO;
}
else if (i >= CS_GENERAL_Q2DEMO && i < MAX_CONFIGSTRINGS_Q2DEMO)
{
i += CS_GENERAL - CS_GENERAL_Q2DEMO;
}
}
return i;
}
static void static void
CL_ParsePlayerstate(frame_t *oldframe, frame_t *newframe) CL_ParsePlayerstate(frame_t *oldframe, frame_t *newframe)
{ {
@ -718,7 +677,8 @@ CL_ParsePlayerstate(frame_t *oldframe, frame_t *newframe)
if (i == STAT_PICKUP_STRING) if (i == STAT_PICKUP_STRING)
{ {
state->stats[i] = CL_ConvertConfigStringFrom(state->stats[i]); state->stats[i] = P_ConvertConfigStringFrom(state->stats[i],
cls.serverProtocol);
} }
} }
} }
@ -1187,7 +1147,7 @@ CL_ParseConfigString(void)
i = MSG_ReadShort(&net_message); i = MSG_ReadShort(&net_message);
i = CL_ConvertConfigStringFrom(i); i = P_ConvertConfigStringFrom(i, cls.serverProtocol);
if ((i < 0) || (i >= MAX_CONFIGSTRINGS)) if ((i < 0) || (i >= MAX_CONFIGSTRINGS))
{ {

View file

@ -852,6 +852,10 @@ void SV_Init(void);
void SV_Shutdown(char *finalmsg, qboolean reconnect); void SV_Shutdown(char *finalmsg, qboolean reconnect);
void SV_Frame(int usec); void SV_Frame(int usec);
/* Convert protocol */
int P_ConvertConfigStringFrom(int i, int protocol);
int P_ConvertConfigStringTo(int i, int protocol);
/* ======================================================================= */ /* ======================================================================= */
// Platform specific functions. // Platform specific functions.

154
src/common/protocol.c Normal file
View file

@ -0,0 +1,154 @@
/*
* Copyright (C) 1997-2001 Id Software, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* =======================================================================
*
* This file implements protocol conversion functions.
*
* =======================================================================
*/
#include "header/shared.h"
#include "header/common.h"
/* Convert from current protocol to internal */
int
P_ConvertConfigStringFrom(int i, int protocol)
{
if (protocol == PROTOCOL_RELEASE_VERSION ||
protocol == PROTOCOL_DEMO_VERSION ||
protocol == PROTOCOL_XATRIX_VERSION ||
protocol == PROTOCOL_RR97_VERSION)
{
if (i >= CS_MODELS_Q2DEMO && i < CS_SOUNDS_Q2DEMO)
{
i += CS_MODELS - CS_MODELS_Q2DEMO;
}
else if (i >= CS_SOUNDS_Q2DEMO && i < CS_IMAGES_Q2DEMO)
{
i += CS_SOUNDS - CS_SOUNDS_Q2DEMO;
}
else if (i >= CS_IMAGES_Q2DEMO && i < CS_LIGHTS_Q2DEMO)
{
i += CS_IMAGES - CS_IMAGES_Q2DEMO;
}
else if (i >= CS_LIGHTS_Q2DEMO && i < CS_ITEMS_Q2DEMO)
{
i += CS_LIGHTS - CS_LIGHTS_Q2DEMO;
}
else if (i >= CS_ITEMS_Q2DEMO && i < CS_PLAYERSKINS_Q2DEMO)
{
i += CS_ITEMS - CS_ITEMS_Q2DEMO;
}
else if (i >= CS_PLAYERSKINS_Q2DEMO && i < CS_GENERAL_Q2DEMO)
{
i += CS_PLAYERSKINS - CS_PLAYERSKINS_Q2DEMO;
}
else if (i >= CS_GENERAL_Q2DEMO && i < MAX_CONFIGSTRINGS_Q2DEMO)
{
i += CS_GENERAL - CS_GENERAL_Q2DEMO;
}
}
return i;
}
/* Convert from current protocol from internal */
int
P_ConvertConfigStringTo(int i, int protocol)
{
if (protocol == PROTOCOL_RELEASE_VERSION ||
protocol == PROTOCOL_DEMO_VERSION ||
protocol == PROTOCOL_XATRIX_VERSION ||
protocol == PROTOCOL_RR97_VERSION)
{
if (i >= CS_MODELS && i < CS_SOUNDS)
{
i += CS_MODELS_Q2DEMO - CS_MODELS;
if (i >= CS_SOUNDS_Q2DEMO)
{
Com_Error(ERR_DROP, "%s: CS_SOUNDS: bad index %i\n",
__func__, i);
}
}
else if (i >= CS_SOUNDS && i < CS_IMAGES)
{
i += CS_SOUNDS_Q2DEMO - CS_SOUNDS;
if (i >= CS_IMAGES_Q2DEMO)
{
Com_Error(ERR_DROP, "%s: CS_IMAGES: bad index %i\n",
__func__, i);
}
}
else if (i >= CS_IMAGES && i < CS_LIGHTS)
{
i += CS_IMAGES_Q2DEMO - CS_IMAGES;
if (i >= CS_LIGHTS_Q2DEMO)
{
Com_Error(ERR_DROP, "%s: CS_LIGHTS: bad index %i\n",
__func__, i);
}
}
else if (i >= CS_LIGHTS && i < CS_ITEMS)
{
i += CS_LIGHTS_Q2DEMO - CS_LIGHTS;
if (i >= CS_ITEMS_Q2DEMO)
{
Com_Error(ERR_DROP, "%s: CS_ITEMS: bad index %i\n",
__func__, i);
}
}
else if (i >= CS_ITEMS && i < CS_PLAYERSKINS)
{
i += CS_ITEMS_Q2DEMO - CS_ITEMS;
if (i >= CS_PLAYERSKINS_Q2DEMO)
{
Com_Error(ERR_DROP, "%s: CS_PLAYERSKINS: bad index %i\n",
__func__, i);
}
}
else if (i >= CS_PLAYERSKINS && i < CS_GENERAL)
{
i += CS_PLAYERSKINS_Q2DEMO - CS_PLAYERSKINS;
if (i >= CS_GENERAL_Q2DEMO)
{
Com_Error(ERR_DROP, "%s: CS_GENERAL: bad index %i\n",
__func__, i);
}
}
else if (i >= CS_GENERAL && i < MAX_CONFIGSTRINGS)
{
i += CS_GENERAL_Q2DEMO - CS_GENERAL;
if (i >= MAX_CONFIGSTRINGS_Q2DEMO)
{
Com_Error(ERR_DROP, "%s: MAX_CONFIGSTRINGS: bad index %i\n",
__func__, i);
}
}
}
return i;
}