1 /*
2 Copyright (C) 1996-2001 Id Software, Inc.
3 Copyright (C) 2002-2009 John Fitzgibbons and others
4 Copyright (C) 2009-2010 Ozkan Sezer
5 Copyright (C) 2010-2014 QuakeSpasm developers
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 
22 */
23 
24 /*
25 	net.h
26 	quake's interface to the networking layer
27 	network functions and data, common to the
28 	whole engine
29 */
30 
31 #ifndef _QUAKE_NET_H
32 #define _QUAKE_NET_H
33 
34 
35 #define	NET_NAMELEN		64
36 
37 #define NET_MAXMESSAGE		64000	/* ericw -- was 32000 */
38 
39 extern int		DEFAULTnet_hostport;
40 extern int		net_hostport;
41 
42 extern cvar_t		hostname;
43 
44 extern	double		net_time;
45 extern	sizebuf_t	net_message;
46 extern	int		net_activeconnections;
47 
48 typedef char qhostaddr_t[NET_NAMELEN];
49 
50 
51 void	NET_Init (void);
52 void	NET_Shutdown (void);
53 
54 struct qsocket_s	*NET_CheckNewConnections (void);
55 // returns a new connection number if there is one pending, else -1
56 
57 struct qsocket_s	*NET_Connect (const char *host);
58 // called by client to connect to a host.  Returns -1 if not able to
59 
60 double NET_QSocketGetTime (const struct qsocket_s *sock);
61 const char *NET_QSocketGetTrueAddressString (const struct qsocket_s *sock);
62 const char *NET_QSocketGetMaskedAddressString (const struct qsocket_s *sock);
63 qboolean NET_QSocketGetProQuakeAngleHack (const struct qsocket_s *sock);
64 int NET_QSocketGetSequenceIn (const struct qsocket_s *sock);
65 int NET_QSocketGetSequenceOut (const struct qsocket_s *sock);
66 void NET_QSocketSetMSS(struct qsocket_s *s, int mss);
67 
68 qboolean NET_CanSendMessage (struct qsocket_s *sock);
69 // Returns true or false if the given qsocket can currently accept a
70 // message to be transmitted.
71 
72 struct qsocket_s *NET_GetServerMessage(void);
73 //returns data in net_message, qsocket says which client its from
74 
75 int NET_ListAddresses(qhostaddr_t *addresses, int maxaddresses);
76 //gets a list of public addresses.
77 
78 int	NET_GetMessage (struct qsocket_s *sock);
79 // returns data in net_message sizebuf
80 // returns 0 if no data is waiting
81 // returns 1 if a message was received
82 // returns 2 if an unreliable message was received
83 // returns -1 if the connection died
84 
85 int	NET_SendMessage (struct qsocket_s *sock, sizebuf_t *data);
86 int	NET_SendUnreliableMessage (struct qsocket_s *sock, sizebuf_t *data);
87 // returns 0 if the message connot be delivered reliably, but the connection
88 //		is still considered valid
89 // returns 1 if the message was sent properly
90 // returns -1 if the connection died
91 
92 int	NET_SendToAll(sizebuf_t *data, double blocktime);
93 // This is a reliable *blocking* send to all attached clients.
94 
95 void	NET_Close (struct qsocket_s *sock);
96 // if a dead connection is returned by a get or send function, this function
97 // should be called when it is convenient
98 
99 // Server calls when a client is kicked off for a game related misbehavior
100 // like an illegal protocal conversation.  Client calls when disconnecting
101 // from a server.
102 // A netcon_t number will not be reused until this function is called for it
103 
104 void	NET_Poll (void);
105 
106 
107 // Server list related globals:
108 extern	qboolean	slistInProgress;
109 extern	qboolean	slistSilent;
110 extern	enum slistScope_e
111 {
112 	SLIST_LOOP,
113 	SLIST_LAN,
114 	SLIST_INTERNET
115 } slistScope;
116 
117 extern	size_t		hostCacheCount;
118 
119 void	NET_Slist_f (void);
120 void	NET_SlistSort (void);
121 const char *NET_SlistPrintServer (size_t n);
122 const char *NET_SlistPrintServerName (size_t n);
123 
124 
125 /* FIXME: driver related, but public:
126  */
127 extern	qboolean	ipxAvailable;
128 extern	qboolean	ipv4Available;
129 extern	qboolean	ipv6Available;
130 extern	char		my_ipx_address[NET_NAMELEN];
131 extern	char		my_ipv4_address[NET_NAMELEN];
132 extern	char		my_ipv6_address[NET_NAMELEN];
133 
134 #endif	/* _QUAKE_NET_H */
135 
136