2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
22 //====================================================================
\r
26 // Programmer: MrElusive
\r
27 // Last update: TTimo: cross-platform version, l_net library
\r
30 //====================================================================
\r
32 //++timo FIXME: the l_net code understands that as the max size for the netmessage_s structure
\r
33 // we have defined unsigned char data[MAX_NETMESSAGE] in netmessage_s but actually it cannot be filled completely
\r
34 // we need to introduce a new #define and adapt to data[MAX_NETBUFFER]
\r
35 #define MAX_NETMESSAGE 1024
\r
36 #define MAX_NETADDRESS 32
\r
42 #ifndef __BYTEBOOL__
\r
43 #define __BYTEBOOL__
\r
44 typedef enum { qfalse, qtrue } qboolean;
\r
45 typedef unsigned char byte;
\r
48 typedef struct address_s
\r
50 char ip[MAX_NETADDRESS];
\r
53 typedef struct sockaddr_s
\r
56 unsigned char sa_data[14];
\r
59 typedef struct netmessage_s
\r
61 unsigned char data[MAX_NETMESSAGE];
\r
67 typedef struct socket_s
\r
69 int socket; //socket number
\r
70 sockaddr_t addr; //socket address
\r
71 netmessage_t msg; //current message being read
\r
72 int remaining; //remaining bytes to read for the current message
\r
73 struct socket_s *prev, *next; //prev and next socket in a list
\r
77 int Net_AddressCompare(address_t *addr1, address_t *addr2);
\r
78 //gives the address of a socket
\r
79 void Net_SocketToAddress(socket_t *sock, address_t *address);
\r
80 //converts a string to an address
\r
81 void Net_StringToAddress(char *string, address_t *address);
\r
82 //set the address ip port
\r
83 void Net_SetAddressPort(address_t *address, int port);
\r
84 //send a message to the given socket
\r
85 int Net_Send(socket_t *sock, netmessage_t *msg);
\r
86 //recieve a message from the given socket
\r
87 int Net_Receive(socket_t *sock, netmessage_t *msg);
\r
89 // NOTE: port is the localhost port, usually 0
\r
90 // ex: Net_Connect( "192.168.0.1:39000", 0 )
\r
91 socket_t *Net_Connect(address_t *address, int port);
\r
92 //disconnect from a host
\r
93 void Net_Disconnect(socket_t *sock);
\r
94 //returns the local address
\r
95 void Net_MyAddress(address_t *address);
\r
96 //listen at the given port
\r
97 socket_t *Net_ListenSocket(int port);
\r
98 //accept new connections at the given socket
\r
99 socket_t *Net_Accept(socket_t *sock);
\r
101 int Net_Setup(void);
\r
102 //shutdown networking
\r
103 void Net_Shutdown(void);
\r
105 void NMSG_Clear(netmessage_t *msg);
\r
106 void NMSG_WriteChar(netmessage_t *msg, int c);
\r
107 void NMSG_WriteByte(netmessage_t *msg, int c);
\r
108 void NMSG_WriteShort(netmessage_t *msg, int c);
\r
109 void NMSG_WriteLong(netmessage_t *msg, int c);
\r
110 void NMSG_WriteFloat(netmessage_t *msg, float c);
\r
111 void NMSG_WriteString(netmessage_t *msg, char *string);
\r
112 void NMSG_ReadStart(netmessage_t *msg);
\r
113 int NMSG_ReadChar(netmessage_t *msg);
\r
114 int NMSG_ReadByte(netmessage_t *msg);
\r
115 int NMSG_ReadShort(netmessage_t *msg);
\r
116 int NMSG_ReadLong(netmessage_t *msg);
\r
117 float NMSG_ReadFloat(netmessage_t *msg);
\r
118 char *NMSG_ReadString(netmessage_t *msg);
\r
120 //++timo FIXME: the WINS_ things are not necessary, they can be made portable arther easily
\r
121 char *WINS_ErrorMessage(int error);
\r