2013-03-31 04:21:08 +00:00
|
|
|
#include "quakedef.h"
|
2004-11-29 01:21:00 +00:00
|
|
|
|
|
|
|
#ifndef CLIENTONLY
|
2009-11-07 13:29:15 +00:00
|
|
|
#ifdef SERVER_DEMO_PLAYBACK
|
2004-11-29 01:21:00 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
void NPP_MVDWriteByte(qbyte data, client_t *to, int broadcast);
|
|
|
|
|
|
|
|
void SV_New_f (void);
|
|
|
|
|
|
|
|
qboolean SV_GetPacket (void)
|
|
|
|
{
|
|
|
|
return NET_GetPacket (NS_SERVER);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define dem_cmd 0
|
|
|
|
#define dem_read 1
|
|
|
|
#define dem_set 2
|
|
|
|
#define dem_multiple 3
|
|
|
|
#define dem_single 4
|
|
|
|
#define dem_stats 5
|
|
|
|
#define dem_all 6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define svd sv
|
|
|
|
|
|
|
|
//char empty[512];
|
|
|
|
qboolean SV_ReadMVD (void);
|
|
|
|
|
2005-01-26 03:39:47 +00:00
|
|
|
#ifdef SERVERONLY
|
|
|
|
float nextdemotime = 0;
|
|
|
|
float olddemotime = 0;
|
|
|
|
#else
|
|
|
|
extern float nextdemotime;
|
|
|
|
extern float olddemotime;
|
|
|
|
#endif
|
2004-08-23 00:15:46 +00:00
|
|
|
void SV_LoadClientDemo_f (void)
|
|
|
|
{
|
|
|
|
int i;
|
2006-03-11 06:22:54 +00:00
|
|
|
char demoname[MAX_OSPATH];
|
2004-08-23 00:15:46 +00:00
|
|
|
client_t *ohc;
|
|
|
|
if (Cmd_Argc() < 2)
|
|
|
|
{
|
|
|
|
Con_Printf("%s <demoname>: play a server side multi-view demo\n", Cmd_Argv(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svd.demofile)
|
|
|
|
{
|
|
|
|
Con_Printf ("Ending old demo\n");
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_CLOSE(svd.demofile);
|
2004-08-23 00:15:46 +00:00
|
|
|
svd.demofile = NULL;
|
2005-12-21 03:07:33 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
SV_ReadMVD();
|
|
|
|
}
|
|
|
|
|
2006-03-11 06:22:54 +00:00
|
|
|
Q_strncpyz(demoname, Cmd_Argv(1), sizeof(demoname));
|
|
|
|
|
2004-12-08 04:14:52 +00:00
|
|
|
if (!sv.state)
|
|
|
|
Cmd_ExecuteString("map start\n", Cmd_ExecLevel); //go for the start map
|
|
|
|
if (!sv.state)
|
|
|
|
{
|
|
|
|
Con_Printf("Could not activate server\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-12-21 03:07:33 +00:00
|
|
|
svd.demofile = FS_OpenVFS(demoname, "rb", FS_GAME);
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!svd.demofile) //try with a different path
|
2005-12-21 03:07:33 +00:00
|
|
|
svd.demofile = FS_OpenVFS(va("demos/%s", demoname), "rb", FS_GAME);
|
|
|
|
com_filesize = VFS_GETLEN(svd.demofile);
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
if (!svd.demofile)
|
|
|
|
{
|
|
|
|
Con_Printf("Failed to open %s\n", demoname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (com_filesize <= 0)
|
|
|
|
{
|
|
|
|
Con_Printf("Failed to open %s\n", demoname);
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_CLOSE(svd.demofile);
|
2004-08-23 00:15:46 +00:00
|
|
|
svd.demofile = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sv.demostate)
|
|
|
|
{
|
|
|
|
sv.demostatevalid = false;
|
|
|
|
memset(sv.demostate, 0, sizeof(entity_state_t)*MAX_EDICTS);
|
|
|
|
}
|
|
|
|
/*
|
2013-10-29 17:38:22 +00:00
|
|
|
for (i = 0; i < svs.allocated_client_slots; i++)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
host_client = &svs.clients[i];
|
|
|
|
if (host_client->state == cs_spawned)
|
|
|
|
host_client->state = cs_connected;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// SV_BroadcastCommand ("changing\n");
|
|
|
|
|
|
|
|
#ifndef SERVERONLY
|
|
|
|
CL_Disconnect();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
svd.mvdplayback = true;
|
|
|
|
Con_Printf("Playing from %s\n", demoname);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_SIGNON_BUFFERS; i++)
|
|
|
|
sv.demosignon_buffer_size[i] = 0;
|
|
|
|
sv.demosignon.maxsize = sizeof(sv.demosignon_buffers[0]);
|
|
|
|
sv.demosignon.data = sv.demosignon_buffers[0];
|
|
|
|
sv.demosignon.cursize = 0;
|
|
|
|
sv.num_demosignon_buffers = 1;
|
|
|
|
sv.democausesreconnect = false;
|
|
|
|
*sv.demname = '\0';
|
|
|
|
|
|
|
|
svd.lasttype = dem_read;
|
|
|
|
svd.realtime = realtime;
|
|
|
|
nextdemotime = realtime-0.1; //cause read of the first 0.1 secs to get all spawn info.
|
2005-01-26 03:39:47 +00:00
|
|
|
olddemotime = realtime;
|
2004-08-23 00:15:46 +00:00
|
|
|
while (SV_ReadMVD())
|
|
|
|
{
|
|
|
|
sv.datagram.cursize = 0;
|
|
|
|
sv.reliable_datagram.cursize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//if we did need reconnect, continue needing it cos I can't be bothered to play with multiple buffers etc.
|
|
|
|
// if (memcmp(sv.demmodel_precache, sv.model_precache, sizeof(sv.model_precache)) || memcmp(sv.demsound_precache, sv.sound_precache, sizeof(sv.sound_precache)))
|
|
|
|
sv.democausesreconnect = true;
|
|
|
|
if (sv.democausesreconnect)
|
|
|
|
{
|
|
|
|
svs.spawncount++;
|
|
|
|
SV_BroadcastCommand ("changing\n"); //but this arrives BEFORE the serverdata
|
2005-12-21 03:07:33 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
ohc = host_client;
|
2013-12-02 14:30:30 +00:00
|
|
|
for (i=0, host_client = svs.clients ; i<svs.allocated_client_slots ; i++, host_client++)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
if (host_client->state != cs_spawned)
|
|
|
|
continue;
|
|
|
|
host_client->state = cs_connected;
|
|
|
|
host_client->istobeloaded = true; //don't harm the ent
|
|
|
|
SV_New_f ();
|
|
|
|
}
|
|
|
|
host_client = ohc;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean SV_RunDemo (void)
|
|
|
|
{
|
|
|
|
int r, i;
|
|
|
|
float demotime;
|
|
|
|
qbyte c;
|
|
|
|
// usercmd_t *pcmd;
|
2004-12-08 04:14:52 +00:00
|
|
|
// usercmd_t emptycmd;
|
2004-08-23 00:15:46 +00:00
|
|
|
qbyte newtime;
|
|
|
|
|
|
|
|
|
2005-01-26 03:39:47 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
readnext:
|
|
|
|
|
|
|
|
// read the time from the packet
|
|
|
|
if (svd.mvdplayback)
|
|
|
|
{
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_READ(svd.demofile, &newtime, sizeof(newtime));
|
2005-01-26 03:39:47 +00:00
|
|
|
nextdemotime = olddemotime + newtime * (1/1000.0f);
|
2004-08-23 00:15:46 +00:00
|
|
|
demotime = nextdemotime;
|
|
|
|
|
|
|
|
if (nextdemotime > svd.realtime)
|
|
|
|
{
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_SEEK(svd.demofile, VFS_TELL(svd.demofile) - sizeof(newtime));
|
2004-08-23 00:15:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (nextdemotime + 0.1 < svd.realtime)
|
|
|
|
demotime = svd.realtime; //we froze too long.. ?
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_READ(svd.demofile, &demotime, sizeof(demotime));
|
2004-08-23 00:15:46 +00:00
|
|
|
demotime = LittleFloat(demotime);
|
|
|
|
if (!nextdemotime)
|
|
|
|
svd.realtime = nextdemotime = demotime;
|
|
|
|
}
|
|
|
|
|
2005-12-21 03:07:33 +00:00
|
|
|
// decide if it is time to grab the next message
|
2009-11-04 21:16:50 +00:00
|
|
|
if (!sv.paused)
|
|
|
|
{ // always grab until fully connected
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!svd.mvdplayback)
|
|
|
|
{
|
|
|
|
if (svd.realtime + 1.0 < demotime) {
|
|
|
|
// too far back
|
|
|
|
svd.realtime = demotime - 1.0;
|
|
|
|
// rewind back to time
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_SEEK(svd.demofile, VFS_TELL(svd.demofile) - sizeof(demotime));
|
2004-08-23 00:15:46 +00:00
|
|
|
return false;
|
|
|
|
} else if (nextdemotime < demotime) {
|
|
|
|
// rewind back to time
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_SEEK(svd.demofile, VFS_TELL(svd.demofile) - sizeof(demotime));
|
2004-08-23 00:15:46 +00:00
|
|
|
return false; // don't need another message yet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
svd.realtime = demotime; // we're warping
|
|
|
|
}
|
|
|
|
|
2005-01-26 03:39:47 +00:00
|
|
|
olddemotime = demotime;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
// get the msg type
|
2005-12-21 03:07:33 +00:00
|
|
|
if ((r = VFS_READ(svd.demofile, &c, sizeof(c))) != sizeof(c))
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
Con_Printf ("Unexpected end of demo\n");
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_CLOSE(svd.demofile);
|
2004-08-23 00:15:46 +00:00
|
|
|
svd.demofile = NULL;
|
|
|
|
return false;
|
|
|
|
// SV_Error ("Unexpected end of demo");
|
|
|
|
}
|
2005-12-21 03:07:33 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
switch (c & 7) {
|
|
|
|
case dem_cmd :
|
2004-12-08 04:14:52 +00:00
|
|
|
|
|
|
|
Con_Printf ("dem_cmd not supported\n");
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_CLOSE(svd.demofile);
|
2004-12-08 04:14:52 +00:00
|
|
|
svd.demofile = NULL;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
// user sent input
|
|
|
|
// i = svd.netchan.outgoing_sequence & UPDATE_MASK;
|
|
|
|
// pcmd = &cl.frames[i].cmd;
|
2004-12-08 04:14:52 +00:00
|
|
|
// if ((r = fread (&emptycmd, sizeof(emptycmd), 1, svd.demofile)) != 1)
|
|
|
|
// SV_Error ("Corrupted demo");
|
2004-08-23 00:15:46 +00:00
|
|
|
/*
|
|
|
|
// qbyte order stuff
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
pcmd->angles[j] = LittleFloat(pcmd->angles[j]);
|
|
|
|
|
|
|
|
pcmd->forwardmove = LittleShort(pcmd->forwardmove);
|
|
|
|
pcmd->sidemove = LittleShort(pcmd->sidemove);
|
|
|
|
pcmd->upmove = LittleShort(pcmd->upmove);
|
|
|
|
cl.frames[i].senttime = demotime;
|
|
|
|
cl.frames[i].receivedtime = -1; // we haven't gotten a reply yet
|
|
|
|
svd.netchan.outgoing_sequence++;
|
|
|
|
*/
|
2004-12-08 04:14:52 +00:00
|
|
|
// fread (&emptycmd, 12, 1, svd.demofile);
|
2004-08-23 00:15:46 +00:00
|
|
|
/* for (j = 0; j < 3; j++)
|
|
|
|
cl.viewangles[i] = LittleFloat (cl.viewangles[i]);
|
2005-12-21 03:07:33 +00:00
|
|
|
if (cl.spectator)
|
|
|
|
Cam_TryLock ();
|
2004-08-23 00:15:46 +00:00
|
|
|
*/
|
|
|
|
goto readnext;
|
|
|
|
|
|
|
|
case dem_read:
|
|
|
|
readit:
|
|
|
|
// get the next message
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_READ (svd.demofile, &net_message.cursize, 4);
|
2004-08-23 00:15:46 +00:00
|
|
|
net_message.cursize = LittleLong (net_message.cursize);
|
2005-12-21 03:07:33 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!svd.mvdplayback && net_message.cursize > MAX_QWMSGLEN + 8)
|
|
|
|
SV_Error ("Demo message > MAX_MSGLEN + 8");
|
|
|
|
else if (svd.mvdplayback && net_message.cursize > net_message.maxsize)
|
|
|
|
SV_Error ("Demo message > MAX_UDP_PACKET");
|
|
|
|
|
2005-12-21 03:07:33 +00:00
|
|
|
if ((r = VFS_READ(svd.demofile, net_message.data, net_message.cursize)) != net_message.cursize)
|
2004-08-23 00:15:46 +00:00
|
|
|
SV_Error ("Corrupted demo");
|
|
|
|
|
|
|
|
/* if (svd.mvdplayback) {
|
|
|
|
tracknum = Cam_TrackNum();
|
2005-12-21 03:07:33 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
if (svd.lasttype == dem_multiple) {
|
|
|
|
if (tracknum == -1)
|
|
|
|
goto readnext;
|
2005-12-21 03:07:33 +00:00
|
|
|
|
2004-08-23 00:15:46 +00:00
|
|
|
if (!(svd.lastto & (1 << (tracknum))))
|
|
|
|
goto readnext;
|
|
|
|
} else if (svd.lasttype == dem_single) {
|
|
|
|
if (tracknum == -1 || svd.lastto != spec_track)
|
|
|
|
goto readnext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case dem_set:
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_READ(svd.demofile, &i, 4);
|
|
|
|
VFS_READ(svd.demofile, &i, 4);
|
2004-08-23 00:15:46 +00:00
|
|
|
goto readnext;
|
|
|
|
|
|
|
|
case dem_multiple:
|
2005-12-21 03:07:33 +00:00
|
|
|
if ((r = VFS_READ(svd.demofile, &i, 4)) != 1)
|
2004-08-23 00:15:46 +00:00
|
|
|
SV_Error ("Corrupted demo");
|
|
|
|
|
|
|
|
svd.lastto = LittleLong(i);
|
|
|
|
svd.lasttype = dem_multiple;
|
|
|
|
goto readit;
|
|
|
|
|
|
|
|
case dem_single:
|
|
|
|
svd.lastto = c >> 3;
|
|
|
|
svd.lasttype = dem_single;
|
|
|
|
goto readit;
|
|
|
|
case dem_stats:
|
|
|
|
svd.lastto = c >> 3;
|
|
|
|
svd.lasttype = dem_stats;
|
|
|
|
goto readit;
|
|
|
|
case dem_all:
|
|
|
|
svd.lastto = 0;
|
|
|
|
svd.lasttype = dem_all;
|
|
|
|
goto readit;
|
|
|
|
default :
|
|
|
|
SV_Error ("Corrupted demo");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean SV_ReadMVD (void)
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
client_t *cl;
|
|
|
|
|
|
|
|
int oldsc = svs.spawncount;
|
|
|
|
|
|
|
|
if (!svd.demofile)
|
|
|
|
{
|
|
|
|
if (sv.demostate)
|
|
|
|
BZ_Free(sv.demostate);
|
|
|
|
sv.demostate=NULL;
|
|
|
|
sv.demostatevalid = false;
|
|
|
|
if (sv.democausesreconnect)
|
|
|
|
{
|
|
|
|
sv.democausesreconnect = false;
|
|
|
|
svs.spawncount++;
|
|
|
|
|
2013-12-02 14:30:30 +00:00
|
|
|
for (i=0, host_client = svs.clients ; i<svs.allocated_client_slots ; i++, host_client++)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
if (host_client->state != cs_spawned)
|
|
|
|
continue;
|
|
|
|
host_client->state = cs_connected;
|
|
|
|
host_client->istobeloaded = true; //don't harm the ent
|
|
|
|
SV_New_f ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nextdemotime = realtime;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
svd.realtime = realtime;
|
|
|
|
|
|
|
|
if (!SV_RunDemo())
|
|
|
|
{
|
|
|
|
if (!svd.demofile)
|
|
|
|
{ //demo ended.
|
2013-12-02 14:30:30 +00:00
|
|
|
for (i=0, cl = svs.clients ; i<svs.allocated_client_slots ; i++, cl++)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
cl->sendinfo = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!svd.mvdplayback) //broadcast all.
|
|
|
|
{
|
|
|
|
for (c = 0; c < net_message.cursize; c++)
|
|
|
|
NPP_MVDWriteByte(net_message.data[c], NULL, true);
|
|
|
|
|
|
|
|
NPP_MVDForceFlush();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(svd.lasttype)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
Con_Printf("Bad sv.lasttype %i\n", sv.lasttype);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case dem_set: //Unknown stuff. (Got to work out what this is for)
|
|
|
|
case dem_read: //baseline stuff
|
|
|
|
case dem_stats: //contains info read by server
|
|
|
|
case dem_all: //broadcast things (like userinfo)
|
|
|
|
case dem_multiple: //treat these as broadcast (tempents should be treated correctly)
|
|
|
|
for (c = 0; c < net_message.cursize; c++)
|
|
|
|
NPP_MVDWriteByte(net_message.data[c], NULL, true);
|
|
|
|
|
|
|
|
NPP_MVDForceFlush();
|
|
|
|
break;
|
|
|
|
// case dem_read: //baseline stuff
|
|
|
|
case dem_single:
|
2013-12-02 14:30:30 +00:00
|
|
|
for (i=0, cl = svs.clients ; i<svs.allocated_client_slots ; i++, cl++)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
if (!cl->state)
|
|
|
|
continue;
|
|
|
|
// if (!(1 >> 3 & svd.lastto))
|
|
|
|
if (!cl->spec_track)
|
|
|
|
continue;
|
|
|
|
if (!(cl->spec_track >> 3 & svd.lastto))
|
2005-01-26 03:39:47 +00:00
|
|
|
continue;
|
2004-08-23 00:15:46 +00:00
|
|
|
|
|
|
|
for (c = 0; c < net_message.cursize; c++)
|
|
|
|
NPP_MVDWriteByte(net_message.data[c], cl, false);
|
|
|
|
|
|
|
|
NPP_MVDForceFlush();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldsc != svs.spawncount)
|
|
|
|
{
|
2005-12-21 03:07:33 +00:00
|
|
|
VFS_CLOSE(svd.demofile);
|
2004-08-23 00:15:46 +00:00
|
|
|
svd.demofile = NULL;
|
|
|
|
|
2013-12-02 14:30:30 +00:00
|
|
|
for (i=0, host_client = svs.clients ; i<svs.allocated_client_slots ; i++, host_client++)
|
2004-08-23 00:15:46 +00:00
|
|
|
{
|
|
|
|
if (host_client->state != cs_spawned)
|
|
|
|
continue;
|
|
|
|
host_client->state = cs_connected;
|
|
|
|
host_client->istobeloaded = true; //don't harm the ent
|
|
|
|
SV_New_f ();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SV_Demo_Init(void)
|
|
|
|
{
|
2009-11-07 13:29:15 +00:00
|
|
|
Cmd_AddCommand("playmvd", SV_LoadClientDemo_f);
|
|
|
|
Cmd_AddCommand("mvdplay", SV_LoadClientDemo_f);
|
|
|
|
Cmd_AddCommand("svplay", SV_PlayDemo_f);
|
|
|
|
Cmd_AddCommand("svrecord", SV_RecordDemo_f);
|
2004-08-23 00:15:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-07 13:29:15 +00:00
|
|
|
#endif //SERVER_DEMO_PLAYBACK
|
|
|
|
#endif //CLIENTONLY
|