|
|
1.1 root 1: // net.h -- quake's interface to the networking layer
2:
3: struct qsockaddr
4: {
5: short sa_family;
6: unsigned char sa_data[14];
7: };
8:
9:
10: #define NET_NAMELEN 64
11:
12: #define NET_MAXMESSAGE 8192
13: #define NET_HEADERSIZE (2 * sizeof(unsigned int))
14: #define NET_DATAGRAMSIZE (MAX_DATAGRAM + NET_HEADERSIZE)
15:
16: // NetHeader flags
17: #define NETFLAG_LENGTH_MASK 0x0000ffff
18: #define NETFLAG_DATA 0x00010000
19: #define NETFLAG_ACK 0x00020000
20: #define NETFLAG_NAK 0x00040000
21: #define NETFLAG_EOM 0x00080000
22: #define NETFLAG_UNRELIABLE 0x00100000
23: #define NETFLAG_CTL 0x80000000
24:
25:
26: #define NET_PROTOCOL_VERSION 3
27:
28: // This is the network info/connection protocol. It is used to find Quake
29: // servers, get info about them, and connect to them. Once connected, the
30: // Quake game protocol (documented elsewhere) is used.
31: //
32: //
33: // General notes:
34: // game_name is currently always "QUAKE", but is there so this same protocol
35: // can be used for future games as well; can you say Quake2?
36: //
37: // CCREQ_CONNECT
38: // string game_name "QUAKE"
39: // byte net_protocol_version NET_PROTOCOL_VERSION
40: //
41: // CCREQ_SERVER_INFO
42: // string game_name "QUAKE"
43: // byte net_protocol_version NET_PROTOCOL_VERSION
44: //
45: // CCREQ_PLAYER_INFO
46: // byte player_number
47: //
48: // CCREQ_RULE_INFO
49: // string rule
50: //
51: //
52: //
53: // CCREP_ACCEPT
54: // long port
55: //
56: // CCREP_REJECT
57: // string reason
58: //
59: // CCREP_SERVER_INFO
1.1.1.3 ! root 60: // string server_address
1.1 root 61: // string host_name
62: // string level_name
63: // byte current_players
64: // byte max_players
1.1.1.3 ! root 65: // byte protocol_version NET_PROTOCOL_VERSION
1.1 root 66: //
67: // CCREP_PLAYER_INFO
68: // byte player_number
69: // string name
70: // long colors
71: // long frags
72: // long connect_time
73: // string address
74: //
75: // CCREP_RULE_INFO
76: // string rule
77: // string value
78:
79: // note:
80: // There are two address forms used above. The short form is just a
81: // port number. The address that goes along with the port is defined as
82: // "whatever address you receive this reponse from". This lets us use
83: // the host OS to solve the problem of multiple host addresses (possibly
84: // with no routing between them); the host will use the right address
85: // when we reply to the inbound connection request. The long from is
86: // a full address and port in a string. It is used for returning the
87: // address of a server that is not running locally.
88:
89: #define CCREQ_CONNECT 0x01
90: #define CCREQ_SERVER_INFO 0x02
91: #define CCREQ_PLAYER_INFO 0x03
92: #define CCREQ_RULE_INFO 0x04
93:
94: #define CCREP_ACCEPT 0x81
95: #define CCREP_REJECT 0x82
96: #define CCREP_SERVER_INFO 0x83
97: #define CCREP_PLAYER_INFO 0x84
98: #define CCREP_RULE_INFO 0x85
99:
100: typedef struct qsocket_s
101: {
102: struct qsocket_s *next;
103: double connecttime;
104: double lastMessageTime;
105: double lastSendTime;
106:
107: qboolean disconnected;
108: qboolean canSend;
109: qboolean sendNext;
110:
111: int driver;
112: int landriver;
113: int socket;
114: void *driverdata;
115:
1.1.1.3 ! root 116: unsigned int ackSequence;
1.1 root 117: unsigned int sendSequence;
118: unsigned int unreliableSendSequence;
119: int sendMessageLength;
120: byte sendMessage [NET_MAXMESSAGE];
121:
122: unsigned int receiveSequence;
123: unsigned int unreliableReceiveSequence;
124: int receiveMessageLength;
125: byte receiveMessage [NET_MAXMESSAGE];
126:
127: struct qsockaddr addr;
128: char address[NET_NAMELEN];
129:
130: } qsocket_t;
131:
132: extern qsocket_t *net_activeSockets;
133: extern qsocket_t *net_freeSockets;
134: extern int net_numsockets;
135:
136: typedef struct
137: {
138: char *name;
139: qboolean initialized;
140: int controlSock;
141: int (*Init) (void);
142: void (*Shutdown) (void);
143: void (*Listen) (qboolean state);
144: int (*OpenSocket) (int port);
145: int (*CloseSocket) (int socket);
146: int (*Connect) (int socket, struct qsockaddr *addr);
147: int (*CheckNewConnections) (void);
148: int (*Read) (int socket, byte *buf, int len, struct qsockaddr *addr);
149: int (*Write) (int socket, byte *buf, int len, struct qsockaddr *addr);
150: int (*Broadcast) (int socket, byte *buf, int len);
151: char * (*AddrToString) (struct qsockaddr *addr);
152: int (*StringToAddr) (char *string, struct qsockaddr *addr);
153: int (*GetSocketAddr) (int socket, struct qsockaddr *addr);
154: int (*GetNameFromAddr) (struct qsockaddr *addr, char *name);
155: int (*GetAddrFromName) (char *name, struct qsockaddr *addr);
156: int (*AddrCompare) (struct qsockaddr *addr1, struct qsockaddr *addr2);
157: int (*GetSocketPort) (struct qsockaddr *addr);
158: int (*SetSocketPort) (struct qsockaddr *addr, int port);
159: } net_landriver_t;
160:
161: #define MAX_NET_DRIVERS 8
162: extern int net_numlandrivers;
163: extern net_landriver_t net_landrivers[MAX_NET_DRIVERS];
164:
165: typedef struct
166: {
167: char *name;
168: qboolean initialized;
169: int (*Init) (void);
170: void (*Listen) (qboolean state);
171: void (*SearchForHosts) (qboolean xmit);
172: qsocket_t *(*Connect) (char *host);
173: qsocket_t *(*CheckNewConnections) (void);
1.1.1.3 ! root 174: int (*QGetMessage) (qsocket_t *sock);
! 175: int (*QSendMessage) (qsocket_t *sock, sizebuf_t *data);
1.1 root 176: int (*SendUnreliableMessage) (qsocket_t *sock, sizebuf_t *data);
177: qboolean (*CanSendMessage) (qsocket_t *sock);
178: qboolean (*CanSendUnreliableMessage) (qsocket_t *sock);
179: void (*Close) (qsocket_t *sock);
180: void (*Shutdown) (void);
181: int controlSock;
182: } net_driver_t;
183:
184: extern int net_numdrivers;
185: extern net_driver_t net_drivers[MAX_NET_DRIVERS];
186:
1.1.1.3 ! root 187: extern int DEFAULTnet_hostport;
! 188: extern int net_hostport;
! 189:
1.1 root 190: extern int net_driverlevel;
191: extern cvar_t hostname;
192: extern char playername[];
193: extern int playercolor;
194:
195: extern int messagesSent;
196: extern int messagesReceived;
197: extern int unreliableMessagesSent;
198: extern int unreliableMessagesReceived;
199:
200: qsocket_t *NET_NewQSocket (void);
201: void NET_FreeQSocket(qsocket_t *);
202: double SetNetTime(void);
203:
204:
205: #define HOSTCACHESIZE 8
206:
207: typedef struct
208: {
209: char name[16];
210: char map[16];
211: char cname[32];
212: int users;
213: int maxusers;
214: int driver;
215: int ldriver;
216: struct qsockaddr addr;
217: } hostcache_t;
218:
219: extern int hostCacheCount;
220: extern hostcache_t hostcache[HOSTCACHESIZE];
221:
222: #ifndef _WIN32
223: #ifndef htonl
224: extern unsigned long htonl (unsigned long hostlong);
225: #endif
226: #ifndef htons
227: extern unsigned short htons (unsigned short hostshort);
228: #endif
229: #ifndef ntohl
230: extern unsigned long ntohl (unsigned long netlong);
231: #endif
232: #ifndef ntohs
233: extern unsigned short ntohs (unsigned short netshort);
234: #endif
235: #endif
236:
237: #ifdef IDGODS
238: qboolean IsID(struct qsockaddr *addr);
239: #endif
240:
241: //============================================================================
242: //
243: // public network functions
244: //
245: //============================================================================
246:
247: extern double net_time;
248: extern sizebuf_t net_message;
249: extern int net_activeconnections;
250:
251: void NET_Init (void);
252: void NET_Shutdown (void);
253:
254: struct qsocket_s *NET_CheckNewConnections (void);
255: // returns a new connection number if there is one pending, else -1
256:
257: struct qsocket_s *NET_Connect (char *host);
258: // called by client to connect to a host. Returns -1 if not able to
259:
260: qboolean NET_CanSendMessage (qsocket_t *sock);
261: // Returns true or false if the given qsocket can currently accept a
262: // message to be transmitted.
263:
264: int NET_GetMessage (struct qsocket_s *sock);
265: // returns data in net_message sizebuf
266: // returns 0 if no data is waiting
267: // returns 1 if a message was received
268: // returns 2 if an unreliable message was received
269: // returns -1 if the connection died
270:
271: int NET_SendMessage (struct qsocket_s *sock, sizebuf_t *data);
272: int NET_SendUnreliableMessage (struct qsocket_s *sock, sizebuf_t *data);
273: // returns 0 if the message connot be delivered reliably, but the connection
274: // is still considered valid
275: // returns 1 if the message was sent properly
276: // returns -1 if the connection died
277:
278: int NET_SendToAll(sizebuf_t *data, int blocktime);
279: // This is a reliable *blocking* send to all attached clients.
280:
281:
282: void NET_Close (struct qsocket_s *sock);
283: // if a dead connection is returned by a get or send function, this function
284: // should be called when it is convenient
285:
286: // Server calls when a client is kicked off for a game related misbehavior
287: // like an illegal protocal conversation. Client calls when disconnecting
288: // from a server.
289: // A netcon_t number will not be reused until this function is called for it
290:
291: void NET_Poll(void);
292:
293:
294: typedef struct _PollProcedure
295: {
296: struct _PollProcedure *next;
297: double nextTime;
298: void (*procedure)();
299: void *arg;
300: } PollProcedure;
301:
302: void SchedulePollProcedure(PollProcedure *pp, double timeOffset);
303:
304: extern qboolean serialAvailable;
305: extern qboolean ipxAvailable;
306: extern qboolean tcpipAvailable;
307: extern char my_ipx_address[NET_NAMELEN];
308: extern char my_tcpip_address[NET_NAMELEN];
309: extern void (*GetComPortConfig) (int portNumber, int *port, int *irq, int *baud, qboolean *useModem);
310: extern void (*SetComPortConfig) (int portNumber, int port, int irq, int baud, qboolean useModem);
311: extern void (*GetModemConfig) (int portNumber, char *dialType, char *clear, char *init, char *hangup);
312: extern void (*SetModemConfig) (int portNumber, char *dialType, char *clear, char *init, char *hangup);
313:
314: extern qboolean slistInProgress;
315: extern qboolean slistSilent;
316: extern qboolean slistLocal;
317:
318: void NET_Slist_f (void);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.