2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
net_vcr.c
|
|
|
|
|
2011-07-26 05:15:41 +00:00
|
|
|
VCR network driver.
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/msg.h"
|
2001-10-28 04:23:37 +00:00
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2003-02-11 22:48:57 +00:00
|
|
|
#include "netmain.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
#include "net_vcr.h"
|
2003-02-11 22:48:57 +00:00
|
|
|
|
|
|
|
#include "../nq/include/server.h"
|
2001-03-27 20:33:07 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// This is the playback portion of the VCR. It reads the file produced
|
|
|
|
// by the recorder and plays it back to the host. The recording contains
|
|
|
|
// everything necessary (events, timestamps, and data) to duplicate the game
|
|
|
|
// from the viewpoint of everything above the network layer.
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static struct {
|
|
|
|
double time;
|
|
|
|
int op;
|
|
|
|
long session;
|
|
|
|
} next;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
VCR_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
net_drivers[0].Init = VCR_Init;
|
|
|
|
|
|
|
|
net_drivers[0].SearchForHosts = VCR_SearchForHosts;
|
|
|
|
net_drivers[0].Connect = VCR_Connect;
|
|
|
|
net_drivers[0].CheckNewConnections = VCR_CheckNewConnections;
|
|
|
|
net_drivers[0].QGetMessage = VCR_GetMessage;
|
|
|
|
net_drivers[0].QSendMessage = VCR_SendMessage;
|
|
|
|
net_drivers[0].CanSendMessage = VCR_CanSendMessage;
|
|
|
|
net_drivers[0].Close = VCR_Close;
|
|
|
|
net_drivers[0].Shutdown = VCR_Shutdown;
|
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &next, sizeof (next));
|
2001-02-19 21:15:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2001-02-26 06:48:02 +00:00
|
|
|
VCR_ReadNext (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-03-30 23:24:57 +00:00
|
|
|
if (Qread (vcrFile, &next, sizeof (next)) == 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
next.op = 255;
|
2002-05-14 06:12:29 +00:00
|
|
|
Sys_Error ("=== END OF PLAYBACK===");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
if (next.op < 1 || next.op > VCR_MAX_MESSAGE)
|
|
|
|
Sys_Error ("VCR_ReadNext: bad op");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2023-06-13 09:06:11 +00:00
|
|
|
VCR_Listen (bool state)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VCR_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
VCR_GetMessage (qsocket_t * sock)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int ret;
|
2008-07-28 01:26:56 +00:00
|
|
|
long *driverdata = (long *) (char *) &sock->driverdata;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (host_time != next.time || next.op != VCR_OP_GETMESSAGE
|
2008-07-19 05:40:57 +00:00
|
|
|
|| next.session != *driverdata)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("VCR missmatch");
|
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &ret, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (ret != 1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VCR_ReadNext ();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &net_message->message->cursize, sizeof (int));
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, net_message->message->data,
|
2001-02-26 06:48:02 +00:00
|
|
|
net_message->message->cursize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VCR_ReadNext ();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
VCR_SendMessage (qsocket_t * sock, sizebuf_t *data)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int ret;
|
2008-08-01 00:48:18 +00:00
|
|
|
long *driverdata = (long *) (char *) &sock->driverdata;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (host_time != next.time || next.op != VCR_OP_SENDMESSAGE
|
2008-07-19 05:40:57 +00:00
|
|
|
|| next.session != *driverdata)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("VCR missmatch");
|
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &ret, sizeof (int));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VCR_ReadNext ();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-13 09:06:11 +00:00
|
|
|
bool
|
2001-02-26 06:48:02 +00:00
|
|
|
VCR_CanSendMessage (qsocket_t * sock)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2023-06-13 09:06:11 +00:00
|
|
|
bool ret;
|
2008-07-28 01:31:20 +00:00
|
|
|
long *driverdata = (long *) (char *) &sock->driverdata;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (host_time != next.time || next.op != VCR_OP_CANSENDMESSAGE
|
2008-07-19 05:40:57 +00:00
|
|
|
|| next.session != *driverdata)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("VCR missmatch");
|
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, &ret, sizeof (int));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
VCR_ReadNext ();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
VCR_Close (qsocket_t * sock)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
2023-06-13 09:06:11 +00:00
|
|
|
VCR_SearchForHosts (bool xmit)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
__attribute__((const)) qsocket_t *
|
2001-07-15 07:04:17 +00:00
|
|
|
VCR_Connect (const char *host)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-09 03:35:01 +00:00
|
|
|
qsocket_t *
|
2001-02-26 06:48:02 +00:00
|
|
|
VCR_CheckNewConnections (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
qsocket_t *sock;
|
2008-07-19 05:40:57 +00:00
|
|
|
long *driverdata;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (host_time != next.time || next.op != VCR_OP_CONNECT)
|
|
|
|
Sys_Error ("VCR missmatch");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!next.session) {
|
2001-02-19 21:15:25 +00:00
|
|
|
VCR_ReadNext ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sock = NET_NewQSocket ();
|
2008-07-28 01:31:20 +00:00
|
|
|
driverdata = (long *) (char *) &sock->driverdata;
|
2008-07-19 05:40:57 +00:00
|
|
|
*driverdata = next.session;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-03-30 23:24:57 +00:00
|
|
|
Qread (vcrFile, sock->address, NET_NAMELEN);
|
2001-02-19 21:15:25 +00:00
|
|
|
VCR_ReadNext ();
|
|
|
|
|
|
|
|
return sock;
|
|
|
|
}
|