]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/l_net/l_net.h
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / libs / l_net / l_net.h
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant 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.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 //====================================================================
23 //
24 // Name:                        l_net.h
25 // Function:            -
26 // Programmer:          MrElusive
27 // Last update:         TTimo: cross-platform version, l_net library
28 // Tab size:            2
29 // Notes:
30 //====================================================================
31
32 //++timo FIXME: the l_net code understands that as the max size for the netmessage_s structure
33 //  we have defined unsigned char data[MAX_NETMESSAGE] in netmessage_s but actually it cannot be filled completely
34 //  we need to introduce a new #define and adapt to data[MAX_NETBUFFER]
35 #define MAX_NETMESSAGE      1024
36 #define MAX_NETADDRESS      32
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 #ifndef __BYTEBOOL__
43 #define __BYTEBOOL__
44 typedef enum { qfalse, qtrue } qboolean;
45 typedef unsigned char byte;
46 #endif
47
48 typedef struct address_s
49 {
50         char ip[MAX_NETADDRESS];
51 } address_t;
52
53 typedef struct sockaddr_s
54 {
55         short sa_family;
56         unsigned char sa_data[14];
57 } sockaddr_t;
58
59 typedef struct netmessage_s
60 {
61         unsigned char data[MAX_NETMESSAGE];
62         int size;
63         int read;
64         int readoverflow;
65 } netmessage_t;
66
67 typedef struct socket_s
68 {
69         int socket;                         //socket number
70         sockaddr_t addr;                    //socket address
71         netmessage_t msg;                   //current message being read
72         int remaining;                      //remaining bytes to read for the current message
73         struct socket_s *prev, *next;   //prev and next socket in a list
74 } socket_t;
75
76 //compare addresses
77 int Net_AddressCompare( address_t *addr1, address_t *addr2 );
78 //gives the address of a socket
79 void Net_SocketToAddress( socket_t *sock, address_t *address );
80 //converts a string to an address
81 void Net_StringToAddress( char *string, address_t *address );
82 //set the address ip port
83 void Net_SetAddressPort( address_t *address, int port );
84 //send a message to the given socket
85 int Net_Send( socket_t *sock, netmessage_t *msg );
86 //recieve a message from the given socket
87 int Net_Receive( socket_t *sock, netmessage_t *msg );
88 //connect to a host
89 // NOTE: port is the localhost port, usually 0
90 // ex: Net_Connect( "192.168.0.1:39000", 0 )
91 socket_t *Net_Connect( address_t *address, int port );
92 //disconnect from a host
93 void Net_Disconnect( socket_t *sock );
94 //returns the local address
95 void Net_MyAddress( address_t *address );
96 //listen at the given port
97 socket_t *Net_ListenSocket( int port );
98 //accept new connections at the given socket
99 socket_t *Net_Accept( socket_t *sock );
100 //setup networking
101 int Net_Setup( void );
102 //shutdown networking
103 void Net_Shutdown( void );
104 //message handling
105 void  NMSG_Clear( netmessage_t *msg );
106 void  NMSG_WriteChar( netmessage_t *msg, int c );
107 void  NMSG_WriteByte( netmessage_t *msg, int c );
108 void  NMSG_WriteShort( netmessage_t *msg, int c );
109 void  NMSG_WriteLong( netmessage_t *msg, int c );
110 void  NMSG_WriteFloat( netmessage_t *msg, float c );
111 void  NMSG_WriteString( netmessage_t *msg, char *string );
112 void  NMSG_ReadStart( netmessage_t *msg );
113 int   NMSG_ReadChar( netmessage_t *msg );
114 int   NMSG_ReadByte( netmessage_t *msg );
115 int   NMSG_ReadShort( netmessage_t *msg );
116 int   NMSG_ReadLong( netmessage_t *msg );
117 float NMSG_ReadFloat( netmessage_t *msg );
118 char *NMSG_ReadString( netmessage_t *msg );
119
120 //++timo FIXME: the WINS_ things are not necessary, they can be made portable arther easily
121 char *WINS_ErrorMessage( int error );
122
123 #ifdef __cplusplus
124 }
125 #endif