equal
deleted
inserted
replaced
3 #ifdef ENABLE_NETWORK |
3 #ifdef ENABLE_NETWORK |
4 |
4 |
5 #include "../../stdafx.h" |
5 #include "../../stdafx.h" |
6 #include "../../debug.h" |
6 #include "../../debug.h" |
7 #include "../../macros.h" |
7 #include "../../macros.h" |
|
8 #include "../../helpers.hpp" |
8 #include "packet.h" |
9 #include "packet.h" |
9 #include "udp.h" |
10 #include "udp.h" |
10 |
11 |
11 /** |
12 /** |
12 * @file udp.c Basic functions to receive and send UDP packets. |
13 * @file udp.c Basic functions to receive and send UDP packets. |
90 int res; |
91 int res; |
91 |
92 |
92 NetworkSend_FillPacketSize(p); |
93 NetworkSend_FillPacketSize(p); |
93 |
94 |
94 /* Send the buffer */ |
95 /* Send the buffer */ |
95 res = sendto(udp, p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv)); |
96 res = sendto(udp, (const char*)p->buffer, p->size, 0, (struct sockaddr *)recv, sizeof(*recv)); |
96 |
97 |
97 /* Check for any errors, but ignore it otherwise */ |
98 /* Check for any errors, but ignore it otherwise */ |
98 if (res == -1) DEBUG(net, 1, "[udp] sendto failed with: %i", GET_LAST_ERROR()); |
99 if (res == -1) DEBUG(net, 1, "[udp] sendto failed with: %i", GET_LAST_ERROR()); |
99 } |
100 } |
100 |
101 |
112 |
113 |
113 packet_len = sizeof(p.buffer); |
114 packet_len = sizeof(p.buffer); |
114 client_len = sizeof(client_addr); |
115 client_len = sizeof(client_addr); |
115 |
116 |
116 /* Try to receive anything */ |
117 /* Try to receive anything */ |
117 nbytes = recvfrom(udp, p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len); |
118 nbytes = recvfrom(udp, (char*)p.buffer, packet_len, 0, (struct sockaddr *)&client_addr, &client_len); |
118 |
119 |
119 /* We got some bytes for the base header of the packet. */ |
120 /* We got some bytes for the base header of the packet. */ |
120 if (nbytes > 2) { |
121 if (nbytes > 2) { |
121 NetworkRecv_ReadPacketSize(&p); |
122 NetworkRecv_ReadPacketSize(&p); |
122 |
123 |
254 GRFConfig *c, **dst = &info->grfconfig; |
255 GRFConfig *c, **dst = &info->grfconfig; |
255 uint i; |
256 uint i; |
256 uint num_grfs = NetworkRecv_uint8(cs, p); |
257 uint num_grfs = NetworkRecv_uint8(cs, p); |
257 |
258 |
258 for (i = 0; i < num_grfs; i++) { |
259 for (i = 0; i < num_grfs; i++) { |
259 c = calloc(1, sizeof(*c)); |
260 CallocT(&c, 1); |
260 NetworkRecv_GRFIdentifier(cs, p, c); |
261 NetworkRecv_GRFIdentifier(cs, p, c); |
261 HandleIncomingNetworkGameInfoGRFConfig(c); |
262 HandleIncomingNetworkGameInfoGRFConfig(c); |
262 |
263 |
263 /* Append GRFConfig to the list */ |
264 /* Append GRFConfig to the list */ |
264 *dst = c; |
265 *dst = c; |
288 } |
289 } |
289 NetworkRecv_string(cs, p, info->map_name, sizeof(info->map_name)); |
290 NetworkRecv_string(cs, p, info->map_name, sizeof(info->map_name)); |
290 info->map_width = NetworkRecv_uint16(cs, p); |
291 info->map_width = NetworkRecv_uint16(cs, p); |
291 info->map_height = NetworkRecv_uint16(cs, p); |
292 info->map_height = NetworkRecv_uint16(cs, p); |
292 info->map_set = NetworkRecv_uint8 (cs, p); |
293 info->map_set = NetworkRecv_uint8 (cs, p); |
293 info->dedicated = NetworkRecv_uint8 (cs, p); |
294 info->dedicated = (NetworkRecv_uint8 (cs, p) != 0); |
294 } |
295 } |
295 } |
296 } |
296 |
297 |
297 #endif /* ENABLE_NETWORK */ |
298 #endif /* ENABLE_NETWORK */ |