shithub: qk1

Download patch

ref: 6172655162d0726b7c0b9ddcd9c3981c31bf5e50
parent: 187cabf909505fac7434b7b5ee7308cc8aa38c74
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Oct 11 22:22:23 EDT 2023

dummy sv protocol change and structures

--- a/cl_parse.c
+++ b/cl_parse.c
@@ -471,7 +471,7 @@
 Server information pertaining to this client only
 ==================
 */
-void CL_ParseClientdata (int bits)
+void CL_ParseClientdata (unsigned int bits)
 {
 	int		i, j;
 	
@@ -580,6 +580,10 @@
 			Sbar_Changed ();
 		}
 	}
+
+	if(cl.viewent.model != cl.model_precache[cl.stats[STAT_WEAPON]]){
+		// FIXME(sigrid) - reset lerp
+	}
 }
 
 /*
@@ -733,7 +737,7 @@
 			break;
 			
 		case svc_clientdata:
-			i = MSG_ReadShort ();
+			i = (ushort)MSG_ReadShort ();
 			CL_ParseClientdata (i);
 			break;
 		
--- a/common.c
+++ b/common.c
@@ -163,9 +163,19 @@
 	MSG_WriteShort (sb, (int)(f*8));
 }
 
+void MSG_WriteCoordInt32 (sizebuf_t *sb, float f)
+{
+	MSG_WriteLong (sb, Qrint(f*16));
+}
+
 void MSG_WriteAngle (sizebuf_t *sb, float f)
 {
 	MSG_WriteByte (sb, ((int)f*256/360) & 255);
+}
+
+void MSG_WriteAngleShort (sizebuf_t *sb, float f)
+{
+	MSG_WriteShort (sb, Qrint(f*65536.0/360.0));
 }
 
 //
--- a/common.h
+++ b/common.h
@@ -59,6 +59,8 @@
 
 //============================================================================
 
+#define Qrint(f) (int)((f) + ((f) >= 0 ? 0.5 : -0.5))
+
 void MSG_WriteChar (sizebuf_t *sb, int c);
 void MSG_WriteByte (sizebuf_t *sb, int c);
 void MSG_WriteShort (sizebuf_t *sb, int c);
@@ -66,7 +68,9 @@
 void MSG_WriteFloat (sizebuf_t *sb, float f);
 void MSG_WriteString (sizebuf_t *sb, char *s);
 void MSG_WriteCoord (sizebuf_t *sb, float f);
+void MSG_WriteCoordInt32 (sizebuf_t *sb, float f);
 void MSG_WriteAngle (sizebuf_t *sb, float f);
+void MSG_WriteAngleShort (sizebuf_t *sb, float f);
 
 extern	int			msg_readcount;
 extern	qboolean	msg_badread;		// set if a read goes beyond end of message
--- a/server.h
+++ b/server.h
@@ -11,9 +11,23 @@
 
 typedef enum {ss_loading, ss_active} server_state_t;
 
+enum {
+	PROTO_NQ,
+	PROTO_RMQ,
+	PROTO_NUM,
+};
+
+typedef struct {
+	int id;
+	char *name;
+	void (*MSG_WriteCoord)(sizebuf_t *sb, float f);
+	void (*MSG_WriteAngle)(sizebuf_t *sb, float f);
+}protocol_t;
+
 typedef struct
 {
 	qboolean	active;				// false if only a net client
+	protocol_t	*protocol;
 
 	qboolean	paused;
 	qboolean	loadgame;			// handle connections specially
--- a/sv_main.c
+++ b/sv_main.c
@@ -7,10 +7,48 @@
 server_t		sv;
 server_static_t	svs;
 
+static protocol_t protos[PROTO_NUM] = {
+	[PROTO_NQ] = {
+		.id = PROTO_NQ,
+		.name = "Quake",
+		.MSG_WriteCoord = MSG_WriteCoord,
+		.MSG_WriteAngle = MSG_WriteAngle,
+	},
+	[PROTO_RMQ] = {
+		.id = PROTO_RMQ,
+		.name = "RMQ",
+		.MSG_WriteCoord = MSG_WriteCoordInt32,
+		.MSG_WriteAngle = MSG_WriteAngleShort,
+	},
+};
+
+// we can't just change protocol mid-game, so it's saved here first
+static protocol_t *sv_protocol = &protos[PROTO_RMQ];
+
 static char	localmodels[MAX_MODELS][8];			// inline model names for precache
 
 //============================================================================
 
+static void
+SV_Protocol_f(void)
+{
+	int n;
+
+	n = Cmd_Argc();
+	if(n == 1)
+		Con_Printf("\"sv_protocol\" is \"%d\" (%s)\n", sv_protocol->id, sv_protocol->name);
+	else if(n == 2){
+		if((n = atoi(Cmd_Argv(1))) < PROTO_NQ || n >= PROTO_NUM)
+			Con_Printf("sv_protocol must be of value from %d to %d\n", PROTO_NQ, PROTO_NUM-1);
+		else{
+			sv_protocol = &protos[n];
+			if(sv.active)
+				Con_Printf("changes will take effect on the next game\n");
+		}
+	}else
+		Con_Printf("usage: sv_protocol <protocol>\n");
+}
+
 /*
 ===============
 SV_Init
@@ -41,6 +79,8 @@
 	Cvar_RegisterVariable (&sv_aim);
 	Cvar_RegisterVariable (&sv_nostep);
 
+	Cmd_AddCommand("sv_protocol", SV_Protocol_f);
+
 	for (i=0 ; i<MAX_MODELS ; i++)
 		sprint (localmodels[i], "*%d", i);
 }
@@ -1056,6 +1096,7 @@
 	memset(&sv, 0, sizeof sv);
 
 	strcpy(sv.name, server);
+	sv.protocol = sv_protocol;
 
 // load progs to get entity field count
 	PR_LoadProgs ();