mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
we get to "spawn". whee. not long now and I'll have to work on the client
side :)
This commit is contained in:
parent
2d8923eaf5
commit
925ea16e1d
10 changed files with 289 additions and 37 deletions
|
@ -65,6 +65,7 @@ int MSG_ReadShort (qmsg_t *msg);
|
|||
int MSG_ReadLong (qmsg_t *msg);
|
||||
float MSG_ReadFloat (qmsg_t *msg);
|
||||
const char *MSG_ReadString (qmsg_t *msg);
|
||||
int MSG_ReadBytes (qmsg_t *msg, void *buf, int len);
|
||||
|
||||
float MSG_ReadCoord (qmsg_t *msg);
|
||||
void MSG_ReadCoordV (qmsg_t *msg, vec3_t coord);
|
||||
|
|
|
@ -45,9 +45,9 @@ typedef struct backbuf_s {
|
|||
} backbuf_t;
|
||||
|
||||
int MSG_ReliableCheckSize (backbuf_t *rel, int maxsize, int minsize);
|
||||
void MSG_ReliableCheckBlock(backbuf_t *rel, int maxsize);
|
||||
sizebuf_t *MSG_ReliableCheckBlock(backbuf_t *rel, int maxsize);
|
||||
void MSG_Reliable_FinishWrite(backbuf_t *rel);
|
||||
void MSG_ReliableWrite_Begin(backbuf_t *rel, int c, int maxsize);
|
||||
sizebuf_t *MSG_ReliableWrite_Begin(backbuf_t *rel, int c, int maxsize);
|
||||
void MSG_ReliableWrite_Angle(backbuf_t *rel, float f);
|
||||
void MSG_ReliableWrite_Angle16(backbuf_t *rel, float f);
|
||||
void MSG_ReliableWrite_Byte(backbuf_t *rel, int c);
|
||||
|
|
|
@ -139,7 +139,10 @@
|
|||
#define qtv_delta 3 // [byte] sequence number, requests delta
|
||||
// compression of message
|
||||
#define qtv_serverdata 4
|
||||
#define qtv_disconnect 5
|
||||
#define qtv_disconnect 5
|
||||
#define qtv_soundlist 6
|
||||
#define qtv_modellist 7
|
||||
#define qtv_signon 8
|
||||
|
||||
// demo recording
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ MSG_ReliableCheckSize (backbuf_t *rel, int maxsize, int minsize)
|
|||
}
|
||||
|
||||
// check to see if client block will fit, if not, rotate buffers
|
||||
void
|
||||
sizebuf_t *
|
||||
MSG_ReliableCheckBlock (backbuf_t *rel, int maxsize)
|
||||
{
|
||||
sizebuf_t *msg = &rel->netchan->message;
|
||||
|
@ -98,19 +98,24 @@ MSG_ReliableCheckBlock (backbuf_t *rel, int maxsize)
|
|||
rel->backbuf.cursize = 0; // don't overflow without
|
||||
// allowoverflow set
|
||||
msg->overflowed = true; // this will drop the client
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
PushBackbuf (rel);
|
||||
}
|
||||
}
|
||||
if (rel->num_backbuf)
|
||||
return &rel->backbuf;
|
||||
return &rel->netchan->message;
|
||||
}
|
||||
|
||||
// begin a client block, estimated maximum size
|
||||
void
|
||||
sizebuf_t *
|
||||
MSG_ReliableWrite_Begin (backbuf_t *rel, int c, int maxsize)
|
||||
{
|
||||
MSG_ReliableCheckBlock (rel, maxsize);
|
||||
sizebuf_t *msg;
|
||||
msg = MSG_ReliableCheckBlock (rel, maxsize);
|
||||
MSG_ReliableWrite_Byte (rel, c);
|
||||
return msg;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -285,6 +285,18 @@ MSG_ReadString (qmsg_t *msg)
|
|||
return string;
|
||||
}
|
||||
|
||||
int
|
||||
MSG_ReadBytes (qmsg_t *msg, void *buf, int len)
|
||||
{
|
||||
if (msg->badread || len > msg->message->cursize - msg->readcount) {
|
||||
msg->badread = true;
|
||||
len = msg->message->cursize - msg->readcount;
|
||||
}
|
||||
memcpy (buf, msg->message->data + msg->readcount, len);
|
||||
msg->readcount += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
float
|
||||
MSG_ReadCoord (qmsg_t *msg)
|
||||
{
|
||||
|
|
|
@ -383,7 +383,7 @@ main (int argc, const char *argv[])
|
|||
Cbuf_Execute_Stack (qtv_cbuf);
|
||||
|
||||
Sys_CheckInput (1, net_socket);
|
||||
realtime = Sys_DoubleTime ();
|
||||
realtime = Sys_DoubleTime () + 1;
|
||||
|
||||
qtv_read_packets ();
|
||||
|
||||
|
|
|
@ -135,6 +135,132 @@ qtv_server_data (server_t *sv)
|
|||
qtv_printf ("%s: gamedir: %s\n", sv->name, sv->gamedir);
|
||||
str = Info_ValueForKey (sv->info, "map");
|
||||
qtv_printf ("%s: (%s) %s\n", sv->name, str, sv->message);
|
||||
|
||||
MSG_WriteByte (&sv->netchan.message, qtv_stringcmd);
|
||||
MSG_WriteString (&sv->netchan.message,
|
||||
va ("soundlist %i %i", sv->spawncount, 0));
|
||||
sv->next_run = realtime;
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_sound_list (server_t *sv)
|
||||
{
|
||||
int numsounds = MSG_ReadByte (net_message);
|
||||
int n;
|
||||
const char *str;
|
||||
|
||||
for (;;) {
|
||||
str = MSG_ReadString (net_message);
|
||||
if (!str[0])
|
||||
break;
|
||||
qtv_printf ("%s\n", str);
|
||||
numsounds++;
|
||||
if (numsounds == MAX_SOUNDS) {
|
||||
while (str[0])
|
||||
str = MSG_ReadString (net_message);
|
||||
MSG_ReadByte (net_message);
|
||||
return;
|
||||
}
|
||||
// save sound name
|
||||
}
|
||||
n = MSG_ReadByte (net_message);
|
||||
if (n) {
|
||||
MSG_WriteByte (&sv->netchan.message, qtv_stringcmd);
|
||||
MSG_WriteString (&sv->netchan.message,
|
||||
va ("soundlist %d %d", sv->spawncount, n));
|
||||
} else {
|
||||
MSG_WriteByte (&sv->netchan.message, qtv_stringcmd);
|
||||
MSG_WriteString (&sv->netchan.message,
|
||||
va ("modellist %d %d", sv->spawncount, 0));
|
||||
}
|
||||
sv->next_run = realtime;
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_model_list (server_t *sv)
|
||||
{
|
||||
int nummodels = MSG_ReadByte (net_message);
|
||||
int n;
|
||||
const char *str;
|
||||
|
||||
for (;;) {
|
||||
str = MSG_ReadString (net_message);
|
||||
if (!str[0])
|
||||
break;
|
||||
qtv_printf ("%s\n", str);
|
||||
nummodels++;
|
||||
if (nummodels == MAX_SOUNDS) {
|
||||
while (str[0])
|
||||
str = MSG_ReadString (net_message);
|
||||
MSG_ReadByte (net_message);
|
||||
return;
|
||||
}
|
||||
// save sound name
|
||||
}
|
||||
n = MSG_ReadByte (net_message);
|
||||
if (n) {
|
||||
MSG_WriteByte (&sv->netchan.message, qtv_stringcmd);
|
||||
MSG_WriteString (&sv->netchan.message,
|
||||
va ("modellist %d %d", sv->spawncount, n));
|
||||
} else {
|
||||
MSG_WriteByte (&sv->netchan.message, qtv_stringcmd);
|
||||
MSG_WriteString (&sv->netchan.message,
|
||||
va ("prespawn %d 0 0", sv->spawncount));
|
||||
}
|
||||
sv->next_run = realtime;
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_sign_on (server_t *sv)
|
||||
{
|
||||
int len;
|
||||
byte *buf;
|
||||
|
||||
len = MSG_ReadShort (net_message);
|
||||
buf = malloc (len);
|
||||
MSG_ReadBytes (net_message, buf, len);
|
||||
free (buf); //XXX
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_cmd_f (server_t *sv)
|
||||
{
|
||||
if (Cmd_Argc () > 1) {
|
||||
MSG_WriteByte (&sv->netchan.message, qtv_stringcmd);
|
||||
SZ_Print (&sv->netchan.message, Cmd_Args (1));
|
||||
}
|
||||
sv->next_run = realtime;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void (*func) (server_t *sv);
|
||||
} svcmd_t;
|
||||
|
||||
svcmd_t svcmds[] = {
|
||||
{"cmd", qtv_cmd_f},
|
||||
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static void
|
||||
qtv_sv_cmd (server_t *sv)
|
||||
{
|
||||
svcmd_t *c;
|
||||
const char *name;
|
||||
|
||||
COM_TokenizeString (MSG_ReadString (net_message), qtv_args);
|
||||
cmd_args = qtv_args;
|
||||
name = Cmd_Argv (0);
|
||||
|
||||
for (c = svcmds; c->name; c++)
|
||||
if (strcmp (c->name, name) == 0)
|
||||
break;
|
||||
if (!c->name) {
|
||||
qtv_printf ("Bad QTV command: %s\n", name);
|
||||
return;
|
||||
}
|
||||
c->func (sv);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -166,6 +292,18 @@ server_handler (connection_t *con, void *object)
|
|||
case qtv_serverdata:
|
||||
qtv_server_data (sv);
|
||||
break;
|
||||
case qtv_soundlist:
|
||||
qtv_sound_list (sv);
|
||||
break;
|
||||
case qtv_modellist:
|
||||
qtv_model_list (sv);
|
||||
break;
|
||||
case qtv_signon:
|
||||
qtv_sign_on (sv);
|
||||
break;
|
||||
case qtv_stringcmd:
|
||||
qtv_sv_cmd (sv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
bail:
|
||||
|
@ -212,10 +350,8 @@ server_connect (connection_t *con, void *object)
|
|||
sv->connected = 1;
|
||||
MSG_WriteByte (msg, qtv_stringcmd);
|
||||
MSG_WriteString (msg, "new");
|
||||
Netchan_Transmit (&sv->netchan, 0, 0);
|
||||
con->handler = server_handler;
|
||||
|
||||
sv->next_run = realtime;
|
||||
con->handler = server_handler;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -365,9 +501,11 @@ server_shutdown (void)
|
|||
static void
|
||||
server_run (server_t *sv)
|
||||
{
|
||||
static byte msg[] = {qtv_nop};
|
||||
Netchan_Transmit (&sv->netchan, sizeof (msg), msg);
|
||||
sv->next_run = realtime + 0.03;
|
||||
//static byte msg[] = {qtv_nop};
|
||||
qtv_printf ("%d\n", sv->netchan.message.cursize);
|
||||
//Netchan_Transmit (&sv->netchan, sizeof (msg), msg);
|
||||
Netchan_Transmit (&sv->netchan, 0, 0);
|
||||
// sv->next_run = realtime + 0.03;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -549,6 +549,8 @@ void SV_FindModelNumbers (void);
|
|||
#define UCMD_OVERRIDABLE 2
|
||||
|
||||
void SV_WriteWorldVars (netchan_t *netchan);
|
||||
void SV_WriteSoundlist (netchan_t *netchan, int n);
|
||||
void SV_WriteModellist (netchan_t *netchan, int n);
|
||||
void SV_ExecuteClientMessage (client_t *cl);
|
||||
void SV_UserInit (void);
|
||||
void SV_TogglePause (const char *msg);
|
||||
|
|
|
@ -47,6 +47,7 @@ static __attribute__ ((unused)) const char rcsid[] =
|
|||
#include "QF/hash.h"
|
||||
#include "QF/idparse.h"
|
||||
#include "QF/info.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "compat.h"
|
||||
#include "server.h"
|
||||
|
@ -103,6 +104,77 @@ qtv_new_f (sv_qtv_t *proxy)
|
|||
SV_WriteWorldVars (&proxy->netchan);
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_soundlist_f (sv_qtv_t *proxy)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
||||
qtv_new_f (proxy);
|
||||
return;
|
||||
}
|
||||
|
||||
n = atoi (Cmd_Argv (2));
|
||||
if (n >= MAX_SOUNDS) {
|
||||
qtv_new_f (proxy);
|
||||
return;
|
||||
}
|
||||
MSG_WriteByte (&proxy->netchan.message, qtv_soundlist);
|
||||
SV_WriteSoundlist (&proxy->netchan, n);
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_modellist_f (sv_qtv_t *proxy)
|
||||
{
|
||||
int n;
|
||||
|
||||
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
||||
qtv_new_f (proxy);
|
||||
return;
|
||||
}
|
||||
|
||||
n = atoi (Cmd_Argv (2));
|
||||
if (n >= MAX_SOUNDS) {
|
||||
qtv_new_f (proxy);
|
||||
return;
|
||||
}
|
||||
MSG_WriteByte (&proxy->netchan.message, qtv_modellist);
|
||||
SV_WriteModellist (&proxy->netchan, n);
|
||||
}
|
||||
|
||||
static void
|
||||
qtv_prespawn_f (sv_qtv_t *proxy)
|
||||
{
|
||||
int buf;
|
||||
int size;
|
||||
const char *command;
|
||||
sizebuf_t *msg;
|
||||
|
||||
if (atoi (Cmd_Argv (1)) != svs.spawncount) {
|
||||
qtv_new_f (proxy);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = atoi (Cmd_Argv (2));
|
||||
if (buf >= sv.num_signon_buffers)
|
||||
buf = 0;
|
||||
|
||||
if (buf == sv.num_signon_buffers - 1)
|
||||
command = va ("cmd spawn %i 0\n", svs.spawncount);
|
||||
else
|
||||
command = va ("cmd prespawn %i %i\n", svs.spawncount, buf + 1);
|
||||
size = 5 + sv.signon_buffer_size[buf] + 1 + strlen (command) + 2;
|
||||
|
||||
msg = MSG_ReliableCheckBlock (&proxy->backbuf, size);
|
||||
|
||||
MSG_WriteByte (msg, qtv_signon);
|
||||
MSG_WriteShort (msg, sv.signon_buffer_size[buf]);
|
||||
SZ_Write (msg, sv.signon_buffers[buf], sv.signon_buffer_size[buf]);
|
||||
|
||||
MSG_WriteByte (msg, qtv_stringcmd);
|
||||
MSG_WriteString (msg, command);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void (*func) (sv_qtv_t *proxy);
|
||||
|
@ -110,10 +182,13 @@ typedef struct {
|
|||
} qcmd_t;
|
||||
|
||||
qcmd_t qcmds[] = {
|
||||
{"drop", drop_proxy},
|
||||
{"new", qtv_new_f},
|
||||
{"drop", drop_proxy},
|
||||
{"new", qtv_new_f},
|
||||
{"soundlist", qtv_soundlist_f},
|
||||
{"modellist", qtv_modellist_f},
|
||||
{"prespawn", qtv_prespawn_f},
|
||||
|
||||
{0, 0},
|
||||
{0, 0},
|
||||
};
|
||||
|
||||
static void
|
||||
|
|
|
@ -186,10 +186,29 @@ SV_New_f (void *unused)
|
|||
host_client->userid));
|
||||
}
|
||||
|
||||
void
|
||||
SV_WriteSoundlist (netchan_t *netchan, int n)
|
||||
{
|
||||
const char **s;
|
||||
|
||||
MSG_WriteByte (&netchan->message, n);
|
||||
for (s = sv.sound_precache + 1 + n;
|
||||
*s && netchan->message.cursize < (MAX_MSGLEN / 2);
|
||||
s++, n++)
|
||||
MSG_WriteString (&netchan->message, *s);
|
||||
|
||||
MSG_WriteByte (&netchan->message, 0);
|
||||
|
||||
// next msg
|
||||
if (*s)
|
||||
MSG_WriteByte (&netchan->message, n);
|
||||
else
|
||||
MSG_WriteByte (&netchan->message, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
SV_Soundlist_f (void *unused)
|
||||
{
|
||||
const char **s;
|
||||
unsigned n;
|
||||
|
||||
if (host_client->state != cs_connected) {
|
||||
|
@ -219,24 +238,31 @@ SV_Soundlist_f (void *unused)
|
|||
}
|
||||
|
||||
MSG_WriteByte (&host_client->netchan.message, svc_soundlist);
|
||||
MSG_WriteByte (&host_client->netchan.message, n);
|
||||
for (s = sv.sound_precache + 1 + n;
|
||||
*s && host_client->netchan.message.cursize < (MAX_MSGLEN / 2);
|
||||
s++, n++) MSG_WriteString (&host_client->netchan.message, *s);
|
||||
SV_WriteSoundlist (&host_client->netchan, n);
|
||||
}
|
||||
|
||||
MSG_WriteByte (&host_client->netchan.message, 0);
|
||||
void
|
||||
SV_WriteModellist (netchan_t *netchan, int n)
|
||||
{
|
||||
const char **s;
|
||||
|
||||
MSG_WriteByte (&netchan->message, n);
|
||||
for (s = sv.model_precache + 1 + n;
|
||||
*s && netchan->message.cursize < (MAX_MSGLEN / 2);
|
||||
s++, n++)
|
||||
MSG_WriteString (&netchan->message, *s);
|
||||
MSG_WriteByte (&netchan->message, 0);
|
||||
|
||||
// next msg
|
||||
if (*s)
|
||||
MSG_WriteByte (&host_client->netchan.message, n);
|
||||
MSG_WriteByte (&netchan->message, n);
|
||||
else
|
||||
MSG_WriteByte (&host_client->netchan.message, 0);
|
||||
MSG_WriteByte (&netchan->message, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
SV_Modellist_f (void *unused)
|
||||
{
|
||||
const char **s;
|
||||
unsigned n;
|
||||
|
||||
if (host_client->state != cs_connected) {
|
||||
|
@ -266,17 +292,7 @@ SV_Modellist_f (void *unused)
|
|||
}
|
||||
|
||||
MSG_WriteByte (&host_client->netchan.message, svc_modellist);
|
||||
MSG_WriteByte (&host_client->netchan.message, n);
|
||||
for (s = sv.model_precache + 1 + n;
|
||||
*s && host_client->netchan.message.cursize < (MAX_MSGLEN / 2);
|
||||
s++, n++) MSG_WriteString (&host_client->netchan.message, *s);
|
||||
MSG_WriteByte (&host_client->netchan.message, 0);
|
||||
|
||||
// next msg
|
||||
if (*s)
|
||||
MSG_WriteByte (&host_client->netchan.message, n);
|
||||
else
|
||||
MSG_WriteByte (&host_client->netchan.message, 0);
|
||||
SV_WriteModellist (&host_client->netchan, n);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue