]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - misc/mediasource/netradiant-src/libs/l_net/l_net.h
Move all other sources in a separate subfolder
[voretournament/voretournament.git] / misc / mediasource / netradiant-src / libs / l_net / l_net.h
1 /*
2 Copyright (C) 1999-2006 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 void WinPrint(const char *format, ...);
77
78 //compare addresses
79 int Net_AddressCompare(address_t *addr1, address_t *addr2);
80 //gives the address of a socket
81 void Net_SocketToAddress(socket_t *sock, address_t *address);
82 //converts a string to an address
83 void Net_StringToAddress(const char *string, address_t *address);
84 //set the address ip port
85 void Net_SetAddressPort(address_t *address, int port);
86 //send a message to the given socket
87 int Net_Send(socket_t *sock, netmessage_t *msg);
88 //recieve a message from the given socket
89 int Net_Receive(socket_t *sock, netmessage_t *msg);
90 //connect to a host
91 // NOTE: port is the localhost port, usually 0
92 // ex: Net_Connect( "192.168.0.1:39000", 0 )
93 socket_t *Net_Connect(address_t *address, int port);
94 //disconnect from a host
95 void Net_Disconnect(socket_t *sock);
96 //returns the local address
97 void Net_MyAddress(address_t *address);
98 //listen at the given port
99 socket_t *Net_ListenSocket(int port);
100 //accept new connections at the given socket
101 socket_t *Net_Accept(socket_t *sock);
102 //setup networking
103 int Net_Setup(void);
104 //shutdown networking
105 void Net_Shutdown(void);
106 //message handling
107 void  NMSG_Clear(netmessage_t *msg);
108 void  NMSG_WriteChar(netmessage_t *msg, int c);
109 void  NMSG_WriteByte(netmessage_t *msg, int c);
110 void  NMSG_WriteShort(netmessage_t *msg, int c);
111 void  NMSG_WriteLong(netmessage_t *msg, int c);
112 void  NMSG_WriteFloat(netmessage_t *msg, float c);
113 void  NMSG_WriteString(netmessage_t *msg, char *string);
114 void  NMSG_ReadStart(netmessage_t *msg);
115 int   NMSG_ReadChar(netmessage_t *msg);
116 int   NMSG_ReadByte(netmessage_t *msg);
117 int   NMSG_ReadShort(netmessage_t *msg);
118 int   NMSG_ReadLong(netmessage_t *msg);
119 float NMSG_ReadFloat(netmessage_t *msg);
120 char *NMSG_ReadString(netmessage_t *msg);
121
122 //++timo FIXME: the WINS_ things are not necessary, they can be made portable arther easily
123 const char *WINS_ErrorMessage(int error);
124
125 #ifdef __cplusplus
126 }
127 #endif