-
Notifications
You must be signed in to change notification settings - Fork 4
/
net_vcr.pas
195 lines (150 loc) · 4.65 KB
/
net_vcr.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// ------------------------------------------------------------------------------
// DelphiQuake, Copyright (C) 2005-2011 by Jim Valavanis
// E-Mail: jimmyvalavanis@yahoo.gr
//
// 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 the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// ------------------------------------------------------------------------------
{$I dquake.inc}
{$Z4}
unit net_vcr;
interface
uses
q_delphi,
net,
common;
const
VCR_OP_CONNECT = 1;
VCR_OP_GETMESSAGE = 2;
VCR_OP_SENDMESSAGE = 3;
VCR_OP_CANSENDMESSAGE = 4;
VCR_MAX_MESSAGE = 4;
function VCR_Init: integer;
procedure VCR_ReadNext;
procedure VCR_Listen(state: qboolean);
procedure VCR_Shutdown;
function VCR_GetMessage(sock: Pqsocket_t): integer;
function VCR_SendMessage(sock: Pqsocket_t; data: Psizebuf_t): integer;
function VCR_CanSendMessage(sock: Pqsocket_t): qboolean;
procedure VCR_Close(sock: Pqsocket_t);
procedure VCR_SearchForHosts(xmit: qboolean);
function VCR_Connect(host: PChar): Pqsocket_t;
function VCR_CheckNewConnections: Pqsocket_t;
implementation
uses
net_win,
sys_win,
net_main,
host_h;
// 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.
type
next_t = record
time: double;
op: integer;
session: integer;
end;
var
next: next_t;
function VCR_Init: integer;
begin
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;
Sys_FileRead(vcrFile, @next, SizeOf(next));
result := 0;
end;
procedure VCR_ReadNext;
begin
if Sys_FileRead(vcrFile, @next, SizeOf(next)) = 0 then
begin
next.op := 255;
Sys_Error('=== END OF PLAYBACK==='#10);
end;
if (next.op < 1) or (next.op > VCR_MAX_MESSAGE) then
Sys_Error('VCR_ReadNext: bad op');
end;
procedure VCR_Listen(state: qboolean);
begin
end;
procedure VCR_Shutdown;
begin
end;
function VCR_GetMessage(sock: Pqsocket_t): integer;
begin
if (host_time <> next.time) or (next.op <> VCR_OP_GETMESSAGE) or (next.session <> PInteger(@sock.driverdata)^) then
Sys_Error('VCR missmatch');
Sys_FileRead(vcrFile, @result, SizeOf(integer));
if result <> 1 then
begin
VCR_ReadNext;
exit;
end;
Sys_FileRead(vcrFile, @net_message.cursize, SizeOf(integer));
Sys_FileRead(vcrFile, net_message.data, net_message.cursize);
VCR_ReadNext;
result := 1;
end;
function VCR_SendMessage(sock: Pqsocket_t; data: Psizebuf_t): integer;
begin
if (host_time <> next.time) or (next.op <> VCR_OP_SENDMESSAGE) or (next.session <> PInteger(@sock.driverdata)^) then
Sys_Error('VCR missmatch');
Sys_FileRead(vcrFile, @result, SizeOf(integer));
VCR_ReadNext;
end;
function VCR_CanSendMessage(sock: Pqsocket_t): qboolean;
begin
if (host_time <> next.time) or (next.op <> VCR_OP_CANSENDMESSAGE) or (next.session <> PInteger(@sock.driverdata)^) then
Sys_Error('VCR missmatch');
Sys_FileRead(vcrFile, @result, SizeOf(integer));
VCR_ReadNext;
end;
procedure VCR_Close(sock: Pqsocket_t);
begin
end;
procedure VCR_SearchForHosts(xmit: qboolean);
begin
end;
function VCR_Connect(host: PChar): Pqsocket_t;
begin
result := nil;
end;
function VCR_CheckNewConnections: Pqsocket_t;
begin
if (host_time <> next.time) or (next.op <> VCR_OP_CONNECT) then
Sys_Error('VCR missmatch');
if next.session = 0 then
begin
VCR_ReadNext;
result := nil;
exit;
end;
result := NET_NewQSocket;
PInteger(@result.driverdata)^ := next.session;
Sys_FileRead(vcrFile, @result.address, NET_NAMELEN);
VCR_ReadNext;
end;
end.