1/* 2Copyright (C) 1996-1997 Id Software, Inc. 3 4This program is free software; you can redistribute it and/or 5modify it under the terms of the GNU General Public License 6as published by the Free Software Foundation; either version 2 7of the License, or (at your option) any later version. 8 9This program is distributed in the hope that it will be useful, 10but WITHOUT ANY WARRANTY; without even the implied warranty of 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13See the GNU General Public License for more details. 14 15You should have received a copy of the GNU General Public License 16along with this program; if not, write to the Free Software 17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19*/ 20// net.h -- quake's interface to the networking layer 21 22#define PORT_ANY -1 23 24typedef struct 25{ 26 byte ip[4]; 27 unsigned short port; 28 unsigned short pad; 29} netadr_t; 30 31extern netadr_t net_local_adr; 32extern netadr_t net_from; // address of who sent the packet 33extern sizebuf_t net_message; 34 35extern cvar_t hostname; 36 37extern int net_socket; 38 39void NET_Init (int port); 40void NET_Shutdown (void); 41qboolean NET_GetPacket (void); 42void NET_SendPacket (int length, void *data, netadr_t to); 43 44qboolean NET_CompareAdr (netadr_t a, netadr_t b); 45qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b); 46char *NET_AdrToString (netadr_t a); 47char *NET_BaseAdrToString (netadr_t a); 48qboolean NET_StringToAdr (char *s, netadr_t *a); 49qboolean NET_IsClientLegal(netadr_t *adr); 50 51//============================================================================ 52 53#define OLD_AVG 0.99 // total = oldtotal*OLD_AVG + new*(1-OLD_AVG) 54 55#define MAX_LATENT 32 56 57typedef struct 58{ 59 qboolean fatal_error; 60 61 float last_received; // for timeouts 62 63// the statistics are cleared at each client begin, because 64// the server connecting process gives a bogus picture of the data 65 float frame_latency; // rolling average 66 float frame_rate; 67 68 int drop_count; // dropped packets, cleared each level 69 int good_count; // cleared each level 70 71 netadr_t remote_address; 72 int qport; 73 74// bandwidth estimator 75 double cleartime; // if realtime > nc->cleartime, free to go 76 double rate; // seconds / byte 77 78// sequencing variables 79 int incoming_sequence; 80 int incoming_acknowledged; 81 int incoming_reliable_acknowledged; // single bit 82 83 int incoming_reliable_sequence; // single bit, maintained local 84 85 int outgoing_sequence; 86 int reliable_sequence; // single bit 87 int last_reliable_sequence; // sequence number of last send 88 89// reliable staging and holding areas 90 sizebuf_t message; // writing buffer to send to server 91 byte message_buf[MAX_MSGLEN]; 92 93 int reliable_length; 94 byte reliable_buf[MAX_MSGLEN]; // unacked reliable message 95 96// time and size data to calculate bandwidth 97 int outgoing_size[MAX_LATENT]; 98 double outgoing_time[MAX_LATENT]; 99} netchan_t; 100 101extern int net_drop; // packets dropped before this one 102 103void Netchan_Init (void); 104void Netchan_Transmit (netchan_t *chan, int length, byte *data); 105void Netchan_OutOfBand (netadr_t adr, int length, byte *data); 106void Netchan_OutOfBandPrint (netadr_t adr, char *format, ...); 107qboolean Netchan_Process (netchan_t *chan); 108void Netchan_Setup (netchan_t *chan, netadr_t adr, int qport); 109 110qboolean Netchan_CanPacket (netchan_t *chan); 111qboolean Netchan_CanReliable (netchan_t *chan); 112 113