net.h 3.3 KB

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