From 9683888e7029c556f5187fc7eb71182dd1cfef8d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 8 May 2005 09:10:43 +0000 Subject: [PATCH] prespawn stuff seems to be done (evil hack for signon buffers, but hey:) --- qtv/include/server.h | 5 +++++ qtv/source/client.c | 25 ++++++++++++++++++------- qtv/source/sv_parse.c | 26 ++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/qtv/include/server.h b/qtv/include/server.h index 44f4c8508..6c5b1e56c 100644 --- a/qtv/include/server.h +++ b/qtv/include/server.h @@ -58,6 +58,7 @@ typedef struct frame_s { #define MAX_SV_PLAYERS 32 #define MAX_SV_ENTITIES 512 +#define MAX_SIGNON_BUFFERS 8 typedef struct server_s { struct server_s *next; @@ -65,6 +66,7 @@ typedef struct server_s { const char *address; int qport; int connected; + int signon; struct connection_s *con; netadr_t adr; netchan_t netchan; @@ -82,6 +84,9 @@ typedef struct server_s { char *modellist[MAX_MODELS + 1]; char *lightstyles[MAX_LIGHTSTYLES]; int playermodel; + int num_signon_buffers; + int signon_buffer_size[MAX_SIGNON_BUFFERS]; + byte signon_buffers[MAX_SIGNON_BUFFERS][MAX_DATAGRAM]; struct client_s *clients; diff --git a/qtv/source/client.c b/qtv/source/client.c index d22881321..5170880bd 100644 --- a/qtv/source/client.c +++ b/qtv/source/client.c @@ -161,6 +161,8 @@ cl_prespawn_f (client_t *cl, void *unused) { const char *cmd; server_t *sv = cl->server; + int buf, size; + sizebuf_t *msg; if (!cl->server) return; @@ -169,9 +171,18 @@ cl_prespawn_f (client_t *cl, void *unused) Client_New (cl); return; } - cmd = va ("cmd spawn %i 0\n", cl->server->spawncount); - MSG_ReliableWrite_Begin (&cl->backbuf, svc_stufftext, strlen (cmd) + 2); - MSG_ReliableWrite_String (&cl->backbuf, cmd); + buf = atoi (Cmd_Argv (2)); + if (buf >= sv->num_signon_buffers) + buf = 0; + if (buf == sv->num_signon_buffers - 1) + cmd = va ("cmd spawn %i 0\n", cl->server->spawncount); + else + cmd = va ("cmd prespawn %i %i\n", cl->server->spawncount, buf + 1); + size = sv->signon_buffer_size[buf] + 1 + strlen (cmd) + 1; + msg = MSG_ReliableCheckBlock (&cl->backbuf, size); + SZ_Write (msg, sv->signon_buffers[buf], sv->signon_buffer_size[buf]); + MSG_WriteByte (msg, svc_stufftext); + MSG_WriteString (msg, cmd); } static void @@ -728,10 +739,10 @@ cl_send_messages (client_t *cl) write_player (31, &cl->state, cl->server, &msg); MSG_WriteByte (&msg, svc_packetentities); MSG_WriteShort (&msg, 0); - } - if (cl->datagram.cursize) { - SZ_Write (&msg, cl->datagram.data, cl->datagram.cursize); - SZ_Clear (&cl->datagram); + if (cl->datagram.cursize) { + SZ_Write (&msg, cl->datagram.data, cl->datagram.cursize); + SZ_Clear (&cl->datagram); + } } Netchan_Transmit (&cl->netchan, msg.cursize, msg.data); } diff --git a/qtv/source/sv_parse.c b/qtv/source/sv_parse.c index 83d78957e..0f0e678ed 100644 --- a/qtv/source/sv_parse.c +++ b/qtv/source/sv_parse.c @@ -184,6 +184,9 @@ static void sv_cmd_f (server_t *sv) { if (Cmd_Argc () > 1) { + sv->signon = 0; + if (strcmp (Cmd_Argv (1), "prespawn") == 0) + sv->signon = 1; MSG_WriteByte (&sv->netchan.message, qtv_stringcmd); SZ_Print (&sv->netchan.message, Cmd_Args (1)); } @@ -797,12 +800,28 @@ sv_lightstyle (server_t *sv, qmsg_t *msg) sv->lightstyles[ind] = strdup (style); } +static void +save_signon (server_t *sv, qmsg_t *msg, int start) +{ + int size = msg->readcount - start; + byte *buf = msg->message->data + start; + + if (!size) + return; + + sv->signon_buffer_size[sv->num_signon_buffers] = size; + memcpy (sv->signon_buffers[sv->num_signon_buffers], buf, size); + sv->num_signon_buffers++; +} + void sv_parse (server_t *sv, qmsg_t *msg, int reliable) { int svc; vec3_t v; player_t *pl; + int start = msg->readcount; + int signon_saved = 0; while (1) { svc = MSG_ReadByte (msg); @@ -938,6 +957,10 @@ sv_parse (server_t *sv, qmsg_t *msg, int reliable) sv_serverdata (sv, msg); break; case svc_stufftext: + if (sv->signon && !signon_saved) { + save_signon (sv, msg, start); + signon_saved = 1; + } sv_stringcmd (sv, msg); break; @@ -967,4 +990,7 @@ sv_parse (server_t *sv, qmsg_t *msg, int reliable) break; } } + if (sv->signon && !signon_saved) { + save_signon (sv, msg, start); + } }