DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
netconn.h
Go to the documentation of this file.
1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3Copyright (C) 2003 Ashley Rose Hale (LadyHavoc)
4
5This program is free software; you can redistribute it and/or
6modify it under the terms of the GNU General Public License
7as published by the Free Software Foundation; either version 2
8of the License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14See the GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20*/
21
22#ifndef NET_H
23#define NET_H
24
25#include <stdarg.h>
26#include "qtypes.h"
27#include "crypto.h"
28#include "lhnet.h"
29#include "common.h"
30struct cmd_state_s;
31
32#define NET_HEADERSIZE (2 * sizeof(unsigned int))
33
34// NetHeader flags
35#define NETFLAG_LENGTH_MASK 0x0000ffff
36#define NETFLAG_DATA 0x00010000
37#define NETFLAG_ACK 0x00020000
38#define NETFLAG_NAK 0x00040000
39#define NETFLAG_EOM 0x00080000
40#define NETFLAG_UNRELIABLE 0x00100000
41#define NETFLAG_CRYPTO0 0x10000000
42#define NETFLAG_CRYPTO1 0x20000000
43#define NETFLAG_CRYPTO2 0x40000000
44#define NETFLAG_CTL 0x80000000
45
46
47#define NET_PROTOCOL_VERSION 3
48#define NET_EXTRESPONSE_MAX 16
49
118
119#define CCREQ_CONNECT 0x01
120#define CCREQ_SERVER_INFO 0x02
121#define CCREQ_PLAYER_INFO 0x03
122#define CCREQ_RULE_INFO 0x04
123#define CCREQ_RCON 0x05 // RocketGuy: ProQuake rcon support
124
125#define CCREP_ACCEPT 0x81
126#define CCREP_REJECT 0x82
127#define CCREP_SERVER_INFO 0x83
128#define CCREP_PLAYER_INFO 0x84
129#define CCREP_RULE_INFO 0x85
130#define CCREP_RCON 0x86 // RocketGuy: ProQuake rcon support
131
132typedef struct netgraphitem_s
133{
134 double time;
138 double cleartime;
139}
141
142typedef struct netconn_s
143{
144 struct netconn_s *next;
145
148
149 // this is mostly identical to qsocket_t from quake
150
153 double timeout;
156
162 unsigned char messagedata[NET_MAXMESSAGE];
164
168 unsigned char sendMessage[NET_MAXMESSAGE];
169
173 unsigned char receiveMessage[NET_MAXMESSAGE];
174
177
179 {
180 unsigned int ackSequence;
181 unsigned int sendSequence;
182
183 unsigned int receiveSequence;
185 }
188 {
189 // QW protocol
191
192 float last_received; // for timeouts
193
194 // the statistics are cleared at each client begin, because
195 // the server connecting process gives a bogus picture of the data
196 float frame_latency; // rolling average
198
201
202 int qport;
203
204 // sequencing variables
205 unsigned int incoming_sequence;
208
210
213 }
215
216 // bandwidth estimator
217 double cleartime; // if realtime > nc->cleartime, free to go
218 double incoming_cleartime; // if realtime > nc->cleartime, free to go (netgraph cleartime simulation only)
219
220 // this tracks packet loss and packet sizes on the most recent packets
221 // used by shownetgraph feature
222#define NETGRAPH_PACKETS 256
223#define NETGRAPH_NOPACKET 0
224#define NETGRAPH_LOSTPACKET -1
225#define NETGRAPH_CHOKEDPACKET -2
230
231 char address[128];
233
234 // statistic counters
244} netconn_t;
245
246extern netconn_t *netconn_list;
247extern struct mempool_s *netconn_mempool;
248
249extern struct cvar_s hostname;
250extern struct cvar_s developer_networking;
251
252#ifdef CONFIG_MENU
253#define SERVERLIST_VIEWLISTSIZE SERVERLIST_TOTALSIZE
254
255typedef enum serverlist_maskop_e
256{
257 // SLMO_CONTAINS is the default for strings
258 // SLMO_GREATEREQUAL is the default for numbers (also used when OP == CONTAINS or NOTCONTAINS
259 SLMO_CONTAINS,
260 SLMO_NOTCONTAIN,
261
262 SLMO_LESSEQUAL,
263 SLMO_LESS,
264 SLMO_EQUAL,
265 SLMO_GREATER,
266 SLMO_GREATEREQUAL,
267 SLMO_NOTEQUAL,
268 SLMO_STARTSWITH,
269 SLMO_NOTSTARTSWITH
270} serverlist_maskop_t;
271
273typedef struct serverlist_info_s
274{
276 char cname[128];
277 unsigned cname_len;
279 int ping;
281 char game[32];
282 unsigned game_len;
284 char mod[32];
285 unsigned mod_len;
287 char map[32];
288 unsigned map_len;
290 char name[128];
291 unsigned name_len;
293 char qcstatus[128];
294 unsigned qcstatus_len;
296 char players[2800];
297 unsigned players_len;
299 int maxplayers;
301 int numplayers;
303 int numbots;
305 int numhumans;
307 int freeslots;
309 int protocol;
313 int gameversion;
314
316 int category;
318 qbool isfavorite;
319} serverlist_info_t;
320
321typedef enum
322{
323 SLIF_CNAME,
324 SLIF_PING,
325 SLIF_GAME,
326 SLIF_MOD,
327 SLIF_MAP,
328 SLIF_NAME,
329 SLIF_MAXPLAYERS,
330 SLIF_NUMPLAYERS,
331 SLIF_PROTOCOL,
332 SLIF_NUMBOTS,
333 SLIF_NUMHUMANS,
334 SLIF_FREESLOTS,
335 SLIF_QCSTATUS,
336 SLIF_PLAYERS,
337 SLIF_CATEGORY,
338 SLIF_ISFAVORITE,
339 SLIF_COUNT
340} serverlist_infofield_t;
341
342typedef enum
343{
344 SLSF_DESCENDING = 1,
345 SLSF_FAVORITES = 2,
347} serverlist_sortflags_t;
348
349typedef struct serverlist_entry_s
350{
352 qbool responded;
354 double querytime;
356 int protocol;
357
358 serverlist_info_t info;
359
360 // legacy stuff
361 char line1[128];
362 unsigned line1_len;
363 char line2[128];
364 unsigned line2_len;
365} serverlist_entry_t;
366
367typedef struct serverlist_mask_s
368{
369 qbool active;
370 serverlist_maskop_t tests[SLIF_COUNT];
371 serverlist_info_t info;
372} serverlist_mask_t;
373
374#define ServerList_GetCacheEntry(x) (&serverlist_cache[(x)])
375#define ServerList_GetViewEntry(x) (ServerList_GetCacheEntry(serverlist_viewlist[(x)]))
376
377extern serverlist_mask_t serverlist_andmasks[SERVERLIST_ANDMASKCOUNT];
378extern serverlist_mask_t serverlist_ormasks[SERVERLIST_ORMASKCOUNT];
379
380extern serverlist_infofield_t serverlist_sortbyfield;
381extern unsigned serverlist_sortflags; // not using the enum, as it is a bitmask
382
383#if SERVERLIST_TOTALSIZE > 65536
384#error too many servers, change type of index array
385#endif
386extern unsigned serverlist_viewcount;
387extern uint16_t serverlist_viewlist[SERVERLIST_VIEWLISTSIZE];
388
389extern unsigned serverlist_cachecount;
390extern serverlist_entry_t *serverlist_cache;
391extern const serverlist_entry_t *serverlist_callbackentry;
392
393void ServerList_GetPlayerStatistics(unsigned *numplayerspointer, unsigned *maxplayerspointer);
394#endif
395
396//============================================================================
397//
398// public network functions
399//
400//============================================================================
401
402extern char cl_net_extresponse[NET_EXTRESPONSE_MAX][1400];
403extern unsigned cl_net_extresponse_count;
404extern unsigned cl_net_extresponse_last;
405
406extern char sv_net_extresponse[NET_EXTRESPONSE_MAX][1400];
407extern unsigned sv_net_extresponse_count;
408extern unsigned sv_net_extresponse_last;
409
410#ifdef CONFIG_MENU
411extern double masterquerytime;
412extern unsigned masterquerycount;
413extern unsigned masterreplycount;
414extern unsigned serverquerycount;
415extern unsigned serverreplycount;
416#endif
417
418extern sizebuf_t cl_message;
419extern sizebuf_t sv_message;
420extern char cl_readstring[MAX_INPUTLINE];
421extern char sv_readstring[MAX_INPUTLINE];
422
423extern struct cvar_s sv_public;
424
425extern struct cvar_s net_fakelag;
426
427extern struct cvar_s cl_netport;
428extern struct cvar_s sv_netport;
429extern struct cvar_s net_address;
430extern struct cvar_s net_address_ipv6;
431extern struct cvar_s net_usesizelimit;
432extern struct cvar_s net_burstreserve;
433
435int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, int burstsize, qbool quakesignon_suppressreliables);
438void NetConn_CloseClientPorts(void);
439void NetConn_OpenClientPorts(void);
440void NetConn_CloseServerPorts(void);
441void NetConn_OpenServerPorts(int opennetports);
442void NetConn_UpdateSockets(void);
445void NetConn_Init(void);
446void NetConn_Shutdown(void);
447netconn_t *NetConn_Open(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress);
448void NetConn_Close(netconn_t *conn);
450int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddress_t *peeraddress);
451int NetConn_Write(lhnetsocket_t *mysocket, const void *data, int length, const lhnetaddress_t *peeraddress);
452int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnetaddress_t *peeraddress);
453int NetConn_IsLocalGame(void);
454void NetConn_ClientFrame(void);
455void NetConn_ServerFrame(void);
456void NetConn_Heartbeat(int priority);
457void Net_Stats_f(struct cmd_state_s *cmd);
458
459#ifdef CONFIG_MENU
460void NetConn_QueryMasters(qbool querydp, qbool queryqw);
461void NetConn_QueryQueueFrame(void);
462void Net_Slist_f(struct cmd_state_s *cmd);
463void Net_SlistQW_f(struct cmd_state_s *cmd);
464void Net_Refresh_f(struct cmd_state_s *cmd);
465
468void ServerList_RebuildViewList(cvar_t* var);
469void ServerList_ResetMasks(void);
470void ServerList_QueryList(qbool resetcache, qbool querydp, qbool queryqw, qbool consoleoutput);
471
473void NetConn_UpdateFavorites_c(struct cvar_s *var);
474#endif
475
476#define MAX_CHALLENGES 128
477typedef struct challenge_s
478{
480 double time;
481 char string[12];
482}
484
486
487#endif
488
protocolversion_t
Definition common.h:132
float mod(float dividend, float divisor)
float ping
GLenum GLuint GLenum GLsizei length
Definition glquake.h:657
GLsizeiptr const GLvoid * data
Definition glquake.h:639
const GLchar * name
Definition glquake.h:601
static int maxplayers
Definition menu.c:3963
const serverlist_entry_t * serverlist_callbackentry
Definition menu.c:5390
float SLSF_FAVORITES
Definition menudefs.qc:595
float SLSF_DESCENDING
Definition menudefs.qc:594
void cmd(string command,...)
float SLSF_CATEGORIES
Definition menudefs.qc:596
double masterquerytime
Definition netconn.c:117
unsigned serverquerycount
Definition netconn.c:120
unsigned masterquerycount
Definition netconn.c:118
static cvar_t gameversion
Definition netconn.c:108
unsigned serverreplycount
Definition netconn.c:121
unsigned masterreplycount
Definition netconn.c:119
struct cvar_s net_fakelag
Definition netconn.c:91
netconn_t * NetConn_Open(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress)
Definition netconn.c:1220
struct cvar_s sv_public
Definition netconn.c:36
void NetConn_Heartbeat(int priority)
Definition netconn.c:3984
struct cvar_s developer_networking
Definition netconn.c:89
struct cvar_s net_address
Definition netconn.c:157
unsigned cl_net_extresponse_last
Definition netconn.c:162
qbool NetConn_CanSend(netconn_t *conn)
Definition netconn.c:789
int NetConn_Write(lhnetsocket_t *mysocket, const void *data, int length, const lhnetaddress_t *peeraddress)
Definition netconn.c:758
int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnetaddress_t *peeraddress)
Definition netconn.c:783
#define NETGRAPH_PACKETS
Definition netconn.h:222
int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddress_t *peeraddress)
Definition netconn.c:726
sizebuf_t cl_message
Definition netconn.c:71
unsigned sv_net_extresponse_count
Definition netconn.c:165
char sv_net_extresponse[NET_EXTRESPONSE_MAX][1400]
Definition netconn.c:164
lhnetsocket_t * NetConn_ChooseClientSocketForAddress(lhnetaddress_t *address)
Definition netconn.c:1198
struct cvar_s sv_netport
Definition netconn.c:156
void NetConn_UpdateSockets(void)
Definition netconn.c:1306
#define NET_EXTRESPONSE_MAX
Definition netconn.h:48
unsigned sv_net_extresponse_last
Definition netconn.c:166
struct cvar_s hostname
Definition netconn.c:88
challenge_t challenges[MAX_CHALLENGES]
Definition netconn.c:123
struct cvar_s net_usesizelimit
Definition netconn.c:79
char cl_readstring[MAX_INPUTLINE]
Definition netconn.c:75
char sv_readstring[MAX_INPUTLINE]
Definition netconn.c:76
qbool NetConn_HaveServerPorts(void)
Definition netconn.c:1057
void NetConn_ClientFrame(void)
Definition netconn.c:2674
lhnetsocket_t * NetConn_ChooseServerSocketForAddress(lhnetaddress_t *address)
Definition netconn.c:1209
unsigned cl_net_extresponse_count
Definition netconn.c:161
void NetConn_Listen(qbool state)
struct mempool_s * netconn_mempool
Definition netconn.c:152
qbool NetConn_HaveClientPorts(void)
Definition netconn.c:1052
void NetConn_Close(netconn_t *conn)
Definition netconn.c:1240
void NetConn_Init(void)
Definition netconn.c:4094
int NetConn_IsLocalGame(void)
Definition netconn.c:1696
struct cvar_s cl_netport
Definition netconn.c:155
struct cvar_s net_burstreserve
Definition netconn.c:80
void NetConn_ServerFrame(void)
Definition netconn.c:3861
void NetConn_Shutdown(void)
Definition netconn.c:4201
struct cvar_s net_address_ipv6
Definition netconn.c:158
void NetConn_OpenServerPorts(int opennetports)
Definition netconn.c:1168
char cl_net_extresponse[NET_EXTRESPONSE_MAX][1400]
Definition netconn.c:160
void NetConn_OpenClientPorts(void)
Definition netconn.c:1098
sizebuf_t sv_message
Definition netconn.c:72
void NetConn_CloseServerPorts(void)
Definition netconn.c:1121
int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, int burstsize, qbool quakesignon_suppressreliables)
Definition netconn.c:844
void Net_Stats_f(struct cmd_state_s *cmd)
netconn_t * netconn_list
Definition netconn.c:151
void NetConn_CloseClientPorts(void)
Definition netconn.c:1062
#define MAX_CHALLENGES
Definition netconn.h:476
#define MAX_INPUTLINE
maximum size of console commandline, QuakeC strings, and many other text processing buffers
Definition qdefs.h:94
#define SERVERLIST_ANDMASKCOUNT
max items in server list AND mask
Definition qdefs.h:161
#define NET_MAXMESSAGE
max reliable packet size (sent as multiple fragments of MAX_PACKETFRAGMENT)
Definition qdefs.h:103
#define SERVERLIST_ORMASKCOUNT
max items in server list OR mask
Definition qdefs.h:162
bool qbool
Definition qtypes.h:9
double time
Definition netconn.h:480
lhnetaddress_t address
Definition netconn.h:479
Definition cvar.h:66
unsigned int sendSequence
Definition netconn.h:181
unsigned int unreliableReceiveSequence
Definition netconn.h:184
unsigned int ackSequence
Definition netconn.h:180
unsigned int receiveSequence
Definition netconn.h:183
int good_count
cleared each level
Definition netconn.h:200
unsigned int last_reliable_sequence
sequence number of last send
Definition netconn.h:212
int drop_count
dropped packets, cleared each level
Definition netconn.h:199
qbool incoming_reliable_sequence
single bit, maintained local
Definition netconn.h:209
unsigned int incoming_acknowledged
Definition netconn.h:206
qbool incoming_reliable_acknowledged
single bit
Definition netconn.h:207
unsigned int incoming_sequence
Definition netconn.h:205
qbool reliable_sequence
single bit
Definition netconn.h:211
int incoming_packetcounter
Definition netconn.h:226
int reliableMessagesReceived
Definition netconn.h:243
double lastMessageTime
Definition netconn.h:154
int outgoing_packetcounter
Definition netconn.h:228
int receiveMessageLength
reliable message that is currently being received (for putting together fragments)
Definition netconn.h:172
double timeout
Definition netconn.h:153
int unreliableMessagesReceived
Definition netconn.h:241
double lastSendTime
Definition netconn.h:155
int packetsSent
Definition netconn.h:235
lhnetaddress_t peeraddress
Definition netconn.h:147
lhnetsocket_t * mysocket
Definition netconn.h:146
struct netconn_s * next
Definition netconn.h:144
int reliableMessagesSent
Definition netconn.h:242
double cleartime
Definition netconn.h:217
unsigned int outgoing_unreliable_sequence
used by both NQ and QW protocols
Definition netconn.h:176
int unreliableMessagesSent
Definition netconn.h:240
double incoming_cleartime
Definition netconn.h:218
int sendMessageLength
reliable message that is currently sending (for building fragments)
Definition netconn.h:167
sizebuf_t message
writing buffer to send to peer as the next reliable message can be added to at any time,...
Definition netconn.h:161
int packetsReceived
Definition netconn.h:237
double connecttime
if this time is reached, kick off peer
Definition netconn.h:152
int packetsReSent
Definition netconn.h:236
int droppedDatagrams
Definition netconn.h:239
struct netconn_t::netconn_qw_s qw
int receivedDuplicateCount
Definition netconn.h:238
struct netconn_t::netconn_nq_s nq
crypto_t crypto
Definition netconn.h:232
double time
Definition netconn.h:134
double cleartime
Definition netconn.h:138
int unreliablebytes
Definition netconn.h:136
int reliablebytes
Definition netconn.h:135