2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
net.h
|
|
|
|
|
|
|
|
quake's interface to the networking layer
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NET_H
|
|
|
|
#define _NET_H
|
|
|
|
|
2001-03-27 20:33:07 +00:00
|
|
|
#include "QF/gcc_attr.h"
|
2001-03-28 17:17:56 +00:00
|
|
|
#include "QF/qdefs.h"
|
|
|
|
#include "QF/sizebuf.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-11-03 00:27:01 +00:00
|
|
|
#include "bothdefs.h"
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#define PORT_ANY -1
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2001-02-22 19:00:34 +00:00
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
byte ip[16];
|
|
|
|
#else
|
2001-02-19 21:15:25 +00:00
|
|
|
byte ip[4];
|
2001-02-22 19:00:34 +00:00
|
|
|
#endif
|
2001-02-19 21:15:25 +00:00
|
|
|
unsigned short port;
|
|
|
|
unsigned short family; // used to be pad, before IPV6
|
|
|
|
} netadr_t;
|
|
|
|
|
|
|
|
extern netadr_t net_local_adr;
|
|
|
|
extern netadr_t net_from; // address of who sent the packet
|
2001-02-23 23:16:13 +00:00
|
|
|
extern struct msg_s *net_message;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-31 03:41:35 +00:00
|
|
|
extern struct cvar_s *hostname;
|
2001-10-27 08:28:15 +00:00
|
|
|
extern struct cvar_s *qport;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
extern int net_socket;
|
|
|
|
|
|
|
|
void NET_Init (int port);
|
|
|
|
void NET_Init (int port);
|
|
|
|
void NET_Shutdown (void);
|
|
|
|
qboolean NET_GetPacket (void);
|
|
|
|
void NET_SendPacket (int length, void *data, netadr_t to);
|
|
|
|
|
|
|
|
qboolean NET_CompareAdr (netadr_t a, netadr_t b);
|
|
|
|
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
|
2001-07-15 07:04:17 +00:00
|
|
|
const char *NET_AdrToString (netadr_t a);
|
|
|
|
const char *NET_BaseAdrToString (netadr_t a);
|
|
|
|
qboolean NET_StringToAdr (const char *s, netadr_t *a);
|
2001-02-19 21:15:25 +00:00
|
|
|
qboolean NET_IsClientLegal(netadr_t *adr);
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#define OLD_AVG 0.99 // total = oldtotal*OLD_AVG + new*(1-OLD_AVG)
|
|
|
|
|
|
|
|
#define MAX_LATENT 32
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
qboolean fatal_error;
|
|
|
|
|
|
|
|
float last_received; // for timeouts
|
|
|
|
|
|
|
|
// the statistics are cleared at each client begin, because
|
|
|
|
// the server connecting process gives a bogus picture of the data
|
|
|
|
float frame_latency; // rolling average
|
|
|
|
float frame_rate;
|
|
|
|
|
|
|
|
int drop_count; // dropped packets, cleared each level
|
|
|
|
int good_count; // cleared each level
|
|
|
|
|
|
|
|
netadr_t remote_address;
|
|
|
|
int qport;
|
|
|
|
|
|
|
|
// bandwidth estimator
|
|
|
|
double cleartime; // if realtime > nc->cleartime, free to go
|
|
|
|
double rate; // seconds / byte
|
|
|
|
|
|
|
|
// sequencing variables
|
|
|
|
int incoming_sequence;
|
|
|
|
int incoming_acknowledged;
|
|
|
|
int incoming_reliable_acknowledged; // single bit
|
|
|
|
|
|
|
|
int incoming_reliable_sequence; // single bit, maintained local
|
|
|
|
|
|
|
|
int outgoing_sequence;
|
|
|
|
int reliable_sequence; // single bit
|
|
|
|
int last_reliable_sequence; // sequence number of last send
|
|
|
|
|
|
|
|
// reliable staging and holding areas
|
|
|
|
sizebuf_t message; // writing buffer to send to server
|
|
|
|
byte message_buf[MAX_MSGLEN];
|
|
|
|
|
|
|
|
int reliable_length;
|
|
|
|
byte reliable_buf[MAX_MSGLEN]; // unacked reliable message
|
|
|
|
|
|
|
|
// time and size data to calculate bandwidth
|
|
|
|
int outgoing_size[MAX_LATENT];
|
|
|
|
double outgoing_time[MAX_LATENT];
|
|
|
|
} netchan_t;
|
|
|
|
|
|
|
|
extern int net_drop; // packets dropped before this one
|
|
|
|
|
|
|
|
void Netchan_Init (void);
|
|
|
|
void Netchan_Init_Cvars (void);
|
|
|
|
void Netchan_Transmit (netchan_t *chan, int length, byte *data);
|
|
|
|
void Netchan_OutOfBand (netadr_t adr, int length, byte *data);
|
2001-07-15 07:04:17 +00:00
|
|
|
void Netchan_OutOfBandPrint (netadr_t adr, const char *format, ...) __attribute__((format(printf,2,3)));
|
2001-02-19 21:15:25 +00:00
|
|
|
qboolean Netchan_Process (netchan_t *chan);
|
|
|
|
void Netchan_Setup (netchan_t *chan, netadr_t adr, int qport);
|
|
|
|
|
|
|
|
qboolean Netchan_CanPacket (netchan_t *chan);
|
|
|
|
qboolean Netchan_CanReliable (netchan_t *chan);
|
|
|
|
|
2001-10-24 15:23:02 +00:00
|
|
|
int Net_Log_Init (const char **sound_precache);
|
|
|
|
void Log_Incoming_Packet (const char *p, int len);
|
|
|
|
void Log_Outgoing_Packet (const char *p, int len);
|
|
|
|
void Net_LogStop (void);
|
2002-11-05 19:12:51 +00:00
|
|
|
void Analyze_Client_Packet (const byte * data, int len);
|
|
|
|
void Analyze_Server_Packet (const byte * data, int len);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-05-31 15:38:08 +00:00
|
|
|
extern struct cvar_s *net_packetlog;
|
|
|
|
|
2001-10-28 04:23:37 +00:00
|
|
|
extern qboolean is_server;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#endif // _NET_H
|