2004-08-21 01:25:48 +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 the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
// net.h -- quake's interface to the networking layer
|
|
|
|
|
|
|
|
#define PORT_ANY -1
|
|
|
|
|
2008-11-09 22:29:28 +00:00
|
|
|
typedef enum {NA_INVALID, NA_LOOPBACK, NA_IP, NA_IPV6, NA_IPX, NA_BROADCAST_IP, NA_BROADCAST_IP6, NA_BROADCAST_IPX, NA_TCP, NA_TCPV6, NA_IRC} netadrtype_t;
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
typedef enum {NS_CLIENT, NS_SERVER} netsrc_t;
|
|
|
|
|
2007-08-30 02:05:50 +00:00
|
|
|
typedef enum {NQP_ERROR, NQP_DATAGRAM, NQP_RELIABLE} nqprot_t;
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
netadrtype_t type;
|
|
|
|
|
|
|
|
union {
|
2005-08-03 23:14:59 +00:00
|
|
|
qbyte ip[4];
|
|
|
|
qbyte ip6[16];
|
|
|
|
qbyte ipx[10];
|
2008-11-09 22:29:28 +00:00
|
|
|
#ifdef IRCCONNECT
|
|
|
|
struct {
|
|
|
|
char user[32];
|
|
|
|
char channel[12];
|
|
|
|
} irc;
|
|
|
|
#endif
|
2006-02-17 02:51:59 +00:00
|
|
|
} address;
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
unsigned short port;
|
2008-11-09 22:29:28 +00:00
|
|
|
unsigned short connum;
|
2004-08-21 01:25:48 +00:00
|
|
|
} netadr_t;
|
|
|
|
|
|
|
|
struct sockaddr_qstorage
|
|
|
|
{
|
2005-01-29 02:26:42 +00:00
|
|
|
short dontusesa_family;
|
|
|
|
unsigned char dontusesa_pad[6];
|
2004-08-21 01:25:48 +00:00
|
|
|
#if defined(_MSC_VER) || defined(MINGW)
|
|
|
|
__int64 sa_align;
|
|
|
|
#else
|
|
|
|
int sa_align[2];
|
|
|
|
#endif
|
|
|
|
unsigned char sa_pad2[112];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-05-26 12:55:34 +00:00
|
|
|
extern netadr_t net_local_cl_ipadr;
|
2004-08-21 01:25:48 +00:00
|
|
|
extern netadr_t net_from; // address of who sent the packet
|
|
|
|
extern sizebuf_t net_message;
|
|
|
|
//#define MAX_UDP_PACKET (MAX_MSGLEN*2) // one more than msg + header
|
|
|
|
#define MAX_UDP_PACKET 8192 // one more than msg + header
|
|
|
|
extern qbyte net_message_buffer[MAX_UDP_PACKET];
|
|
|
|
|
|
|
|
extern cvar_t hostname;
|
|
|
|
|
2006-02-11 14:51:36 +00:00
|
|
|
int TCP_OpenStream (netadr_t remoteaddr); //makes things easier
|
|
|
|
|
2008-11-09 22:29:28 +00:00
|
|
|
struct ftenet_connections_s;
|
2004-08-21 01:25:48 +00:00
|
|
|
void NET_Init (void);
|
|
|
|
void NET_InitClient (void);
|
|
|
|
void NET_InitServer (void);
|
|
|
|
void NET_CloseServer (void);
|
|
|
|
void UDP_CloseSocket (int socket);
|
|
|
|
void NET_Shutdown (void);
|
|
|
|
qboolean NET_GetPacket (netsrc_t socket);
|
|
|
|
void NET_SendPacket (netsrc_t socket, int length, void *data, netadr_t to);
|
2008-11-09 22:29:28 +00:00
|
|
|
int NET_LocalAddressForRemote(struct ftenet_connections_s *collection, netadr_t *remote, netadr_t *local, int idx);
|
|
|
|
void NET_PrintAddresses(struct ftenet_connections_s *collection);
|
|
|
|
qboolean NET_AddressSmellsFunny(netadr_t a);
|
2009-07-05 18:45:53 +00:00
|
|
|
void NET_EnsureRoute(struct ftenet_connections_s *collection, char *routename, char *host, qboolean islisten);
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
qboolean NET_CompareAdr (netadr_t a, netadr_t b);
|
|
|
|
qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b);
|
2008-06-08 14:37:57 +00:00
|
|
|
char *NET_AdrToString (char *s, int len, netadr_t a);
|
|
|
|
char *NET_BaseAdrToString (char *s, int len, netadr_t a);
|
2009-04-01 22:03:56 +00:00
|
|
|
qboolean NET_StringToSockaddr (const char *s, struct sockaddr_qstorage *sadr);
|
|
|
|
qboolean NET_StringToAdr (const char *s, netadr_t *a);
|
2004-08-21 01:25:48 +00:00
|
|
|
qboolean NET_IsClientLegal(netadr_t *adr);
|
|
|
|
|
|
|
|
qboolean NET_IsLoopBackAddress (netadr_t adr);
|
|
|
|
|
2009-04-01 22:03:56 +00:00
|
|
|
qboolean NET_StringToAdrMasked (const char *s, netadr_t *a, netadr_t *amask);
|
2008-06-08 14:37:57 +00:00
|
|
|
char *NET_AdrToStringMasked (char *s, int len, netadr_t a, netadr_t amask);
|
2006-05-22 22:51:14 +00:00
|
|
|
void NET_IntegerToMask (netadr_t *a, netadr_t *amask, int bits);
|
|
|
|
qboolean NET_CompareAdrMasked(netadr_t a, netadr_t b, netadr_t mask);
|
|
|
|
|
2009-11-04 21:16:50 +00:00
|
|
|
|
|
|
|
struct ftenet_generic_connection_s *FTENET_IRCConnect_EstablishConnection(qboolean isserver, const char *address);
|
|
|
|
qboolean FTENET_AddToCollection(struct ftenet_connections_s *col, const char *name, const char *address, struct ftenet_generic_connection_s *(*establish)(qboolean isserver, const char *address), qboolean islisten);
|
|
|
|
|
2004-08-21 01:25:48 +00:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#define OLD_AVG 0.99 // total = oldtotal*OLD_AVG + new*(1-OLD_AVG)
|
|
|
|
|
|
|
|
#define MAX_LATENT 32
|
2008-06-08 14:37:57 +00:00
|
|
|
#define MAX_ADR_SIZE 64
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
qboolean fatal_error;
|
|
|
|
|
|
|
|
#ifdef NQPROT
|
|
|
|
qboolean isnqprotocol;
|
Fixes, workarounds, and breakages. Hexen2 should work much better (-hexen2 says no mission pack, -portals says h2mp). Started working on splitting bigcoords per client, far too much work still to go on that. Removed gl_ztrick entirely. Enabled csprogs download by default. Added client support for fitzquake's 666 protocol, needs testing, some cleanup for dp protocols too, no server support, couldn't selectively enable it anyway. Now attempting to cache shadow meshes for explosions and stuff. Played with lightmaps a little, should potentially run a little faster on certain (intel?) cards. Tweeked npfte a little to try to avoid deadlocks and crashes. Fixed sky worldspawn parsing. Added h2mp's model format. Fixed baseline issue in q2 client, made servers generate q2 baselines. MOVETYPE_PUSH will not rotate extra if rotation is forced. Made status command show allowed client types. Changed lighting on weapons - should now be shaded.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/branches/wip@3572 fc73d0e0-1445-4013-8a0c-d673dee63da5
2010-08-11 03:36:31 +00:00
|
|
|
struct netprim_s netprim;
|
2004-08-21 01:25:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
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;
|
|
|
|
netsrc_t sock;
|
|
|
|
int qport;
|
|
|
|
|
|
|
|
// bandwidth estimator
|
|
|
|
double cleartime; // if realtime > nc->cleartime, free to go
|
2004-10-19 16:10:14 +00:00
|
|
|
// double rate; // seconds / qbyte
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
// sequencing variables
|
2005-05-26 12:55:34 +00:00
|
|
|
int incoming_unreliable; //dictated by the other end.
|
2004-08-21 01:25:48 +00:00
|
|
|
int incoming_sequence;
|
|
|
|
int incoming_acknowledged;
|
|
|
|
int incoming_reliable_acknowledged; // single bit
|
|
|
|
|
|
|
|
int incoming_reliable_sequence; // single bit, maintained local
|
|
|
|
|
2005-05-26 12:55:34 +00:00
|
|
|
int outgoing_unreliable;
|
2004-08-21 01:25:48 +00:00
|
|
|
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
|
|
|
|
qbyte message_buf[MAX_OVERALLMSGLEN];
|
|
|
|
|
2005-05-26 12:55:34 +00:00
|
|
|
//nq has message truncation.
|
2004-08-21 01:25:48 +00:00
|
|
|
int reliable_length;
|
2005-05-26 12:55:34 +00:00
|
|
|
int reliable_start;
|
2004-08-21 01:25:48 +00:00
|
|
|
qbyte reliable_buf[MAX_OVERALLMSGLEN]; // unacked reliable message
|
|
|
|
|
|
|
|
// time and size data to calculate bandwidth
|
|
|
|
int outgoing_size[MAX_LATENT];
|
|
|
|
double outgoing_time[MAX_LATENT];
|
|
|
|
qboolean compress;
|
2004-12-24 08:45:56 +00:00
|
|
|
|
2005-05-26 12:55:34 +00:00
|
|
|
//nq servers must recieve truncated packets.
|
2005-06-04 04:20:20 +00:00
|
|
|
int in_fragment_length;
|
|
|
|
char in_fragment_buf[MAX_OVERALLMSGLEN];
|
|
|
|
int in_fragment_start;
|
2004-08-21 01:25:48 +00:00
|
|
|
} netchan_t;
|
|
|
|
|
|
|
|
extern int net_drop; // packets dropped before this one
|
|
|
|
|
|
|
|
void Netchan_Init (void);
|
2009-06-23 21:49:44 +00:00
|
|
|
int Netchan_Transmit (netchan_t *chan, int length, qbyte *data, int rate);
|
2004-08-21 01:25:48 +00:00
|
|
|
void Netchan_OutOfBand (netsrc_t sock, netadr_t adr, int length, qbyte *data);
|
2009-11-04 21:16:50 +00:00
|
|
|
void VARGS Netchan_OutOfBandPrint (netsrc_t sock, netadr_t adr, char *format, ...) LIKEPRINTF(3);
|
2004-08-21 01:25:48 +00:00
|
|
|
void VARGS Netchan_OutOfBandTPrintf (netsrc_t sock, netadr_t adr, int language, translation_t text, ...);
|
|
|
|
qboolean Netchan_Process (netchan_t *chan);
|
|
|
|
void Netchan_Setup (netsrc_t sock, netchan_t *chan, netadr_t adr, int qport);
|
|
|
|
|
2004-10-19 16:10:14 +00:00
|
|
|
qboolean Netchan_CanPacket (netchan_t *chan, int rate);
|
2009-11-04 21:16:50 +00:00
|
|
|
void Netchan_Block (netchan_t *chan, int bytes, int rate);
|
2004-10-19 16:10:14 +00:00
|
|
|
qboolean Netchan_CanReliable (netchan_t *chan, int rate);
|
2005-06-14 04:52:10 +00:00
|
|
|
#ifdef NQPROT
|
2007-08-30 02:05:50 +00:00
|
|
|
nqprot_t NQNetChan_Process(netchan_t *chan);
|
2005-06-14 04:52:10 +00:00
|
|
|
#endif
|
2004-08-21 01:25:48 +00:00
|
|
|
|
|
|
|
#ifdef HUFFNETWORK
|
|
|
|
int Huff_PreferedCompressionCRC (void);
|
2006-02-11 14:51:36 +00:00
|
|
|
void Huff_EncryptPacket(sizebuf_t *msg, int offset);
|
|
|
|
void Huff_DecryptPacket(sizebuf_t *msg, int offset);
|
2004-08-21 01:25:48 +00:00
|
|
|
qboolean Huff_CompressionCRC(int crc);
|
|
|
|
void Huff_CompressPacket(sizebuf_t *msg, int offset);
|
|
|
|
void Huff_DecompressPacket(sizebuf_t *msg, int offset);
|
2005-01-04 07:54:24 +00:00
|
|
|
int Huff_GetByte(qbyte *buffer, int *count);
|
2005-10-07 16:27:20 +00:00
|
|
|
void Huff_EmitByte(int ch, qbyte *buffer, int *count);
|
2004-08-21 01:25:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NQPROT
|
2005-05-26 12:55:34 +00:00
|
|
|
//taken from nq's net.h
|
|
|
|
//refer to that for usage info. :)
|
|
|
|
|
|
|
|
#define NETFLAG_LENGTH_MASK 0x0000ffff
|
|
|
|
#define NETFLAG_DATA 0x00010000
|
|
|
|
#define NETFLAG_ACK 0x00020000
|
|
|
|
#define NETFLAG_NAK 0x00040000
|
|
|
|
#define NETFLAG_EOM 0x00080000
|
|
|
|
#define NETFLAG_UNRELIABLE 0x00100000
|
|
|
|
#define NETFLAG_CTL 0x80000000
|
|
|
|
|
|
|
|
#define NET_GAMENAME_NQ "QUAKE"
|
|
|
|
#define NET_PROTOCOL_VERSION 3
|
|
|
|
|
|
|
|
|
|
|
|
#define CCREQ_CONNECT 0x01
|
|
|
|
#define CCREQ_SERVER_INFO 0x02
|
|
|
|
#define CCREQ_PLAYER_INFO 0x03
|
|
|
|
#define CCREQ_RULE_INFO 0x04
|
|
|
|
|
|
|
|
#define CCREP_ACCEPT 0x81
|
|
|
|
#define CCREP_REJECT 0x82
|
|
|
|
#define CCREP_SERVER_INFO 0x83
|
|
|
|
#define CCREP_PLAYER_INFO 0x84
|
|
|
|
#define CCREP_RULE_INFO 0x85
|
2005-05-27 05:41:07 +00:00
|
|
|
|
|
|
|
//server->client protocol info
|
|
|
|
#define NQ_PROTOCOL_VERSION 15
|
|
|
|
#define DP5_PROTOCOL_VERSION 3502
|
|
|
|
#define DP6_PROTOCOL_VERSION 3503
|
|
|
|
#define DP7_PROTOCOL_VERSION 3504
|
2004-08-21 01:25:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int UDP_OpenSocket (int port, qboolean bcast);
|
2009-11-04 21:16:50 +00:00
|
|
|
int UDP6_OpenSocket (int port, qboolean bcast);
|
2004-08-21 01:25:48 +00:00
|
|
|
int IPX_OpenSocket (int port, qboolean bcast);
|
2007-08-17 23:24:05 +00:00
|
|
|
int NetadrToSockadr (netadr_t *a, struct sockaddr_qstorage *s);
|
2004-08-21 01:25:48 +00:00
|
|
|
void SockadrToNetadr (struct sockaddr_qstorage *s, netadr_t *a);
|
|
|
|
qboolean NET_Sleep(int msec, qboolean stdinissocket);
|