43 #define DEF_UDP_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(Packet *p, struct sockaddr_in *client_addr) |
43 #define DEF_UDP_RECEIVE_COMMAND(type) void NetworkPacketReceive_ ## type ## _command(Packet *p, struct sockaddr_in *client_addr) |
44 static void NetworkSendUDP_Packet(SOCKET udp, Packet* p, struct sockaddr_in* recv); |
44 static void NetworkSendUDP_Packet(SOCKET udp, Packet* p, struct sockaddr_in* recv); |
45 |
45 |
46 static NetworkClientState _udp_cs; |
46 static NetworkClientState _udp_cs; |
47 |
47 |
48 /** |
|
49 * Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet |
|
50 * @param p the packet to write the data to |
|
51 * @param c the configuration to write the GRF ID and MD5 checksum from |
|
52 */ |
|
53 static void NetworkSend_GRFIdentifier(Packet *p, const GRFConfig *c) |
|
54 { |
|
55 uint j; |
|
56 NetworkSend_uint32(p, c->grfid); |
|
57 for (j = 0; j < sizeof(c->md5sum); j++) { |
|
58 NetworkSend_uint8 (p, c->md5sum[j]); |
|
59 } |
|
60 } |
|
61 |
|
62 /** |
|
63 * Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet |
|
64 * @param p the packet to read the data from |
|
65 * @param c the configuration to write the GRF ID and MD5 checksum to |
|
66 */ |
|
67 static void NetworkRecv_GRFIdentifier(Packet *p, GRFConfig *c) |
|
68 { |
|
69 uint j; |
|
70 c->grfid = NetworkRecv_uint32(&_udp_cs, p); |
|
71 for (j = 0; j < sizeof(c->md5sum); j++) { |
|
72 c->md5sum[j] = NetworkRecv_uint8(&_udp_cs, p); |
|
73 } |
|
74 } |
|
75 |
|
76 DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER) |
48 DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER) |
77 { |
49 { |
78 Packet *packet; |
50 Packet *packet; |
79 // Just a fail-safe.. should never happen |
51 // Just a fail-safe.. should never happen |
80 if (!_network_udp_server) |
52 if (!_network_udp_server) |
171 uint i; |
143 uint i; |
172 uint num_grfs = NetworkRecv_uint8(&_udp_cs, p); |
144 uint num_grfs = NetworkRecv_uint8(&_udp_cs, p); |
173 |
145 |
174 for (i = 0; i < num_grfs; i++) { |
146 for (i = 0; i < num_grfs; i++) { |
175 c = calloc(1, sizeof(*c)); |
147 c = calloc(1, sizeof(*c)); |
176 NetworkRecv_GRFIdentifier(p, c); |
148 NetworkRecv_GRFIdentifier(&_udp_cs, p, c); |
177 |
149 |
178 /* Find the matching GRF file */ |
150 /* Find the matching GRF file */ |
179 f = FindGRFConfig(c->grfid, c->md5sum); |
151 f = FindGRFConfig(c->grfid, c->md5sum); |
180 if (f == NULL) { |
152 if (f == NULL) { |
181 /* Don't know the GRF, so mark game incompatible and the (possibly) |
153 /* Don't know the GRF, so mark game incompatible and the (possibly) |
455 |
427 |
456 for (i = 0; i < num_grfs; i++) { |
428 for (i = 0; i < num_grfs; i++) { |
457 GRFConfig c; |
429 GRFConfig c; |
458 const GRFConfig *f; |
430 const GRFConfig *f; |
459 |
431 |
460 NetworkRecv_GRFIdentifier(p, &c); |
432 NetworkRecv_GRFIdentifier(&_udp_cs, p, &c); |
461 |
433 |
462 /* Find the matching GRF file */ |
434 /* Find the matching GRF file */ |
463 f = FindGRFConfig(c.grfid, c.md5sum); |
435 f = FindGRFConfig(c.grfid, c.md5sum); |
464 if (f == NULL) continue; // The GRF is unknown to this server |
436 if (f == NULL) continue; // The GRF is unknown to this server |
465 |
437 |
510 for (i = 0; i < num_grfs; i++) { |
482 for (i = 0; i < num_grfs; i++) { |
511 char *unknown_name; |
483 char *unknown_name; |
512 char name[NETWORK_GRF_NAME_LENGTH]; |
484 char name[NETWORK_GRF_NAME_LENGTH]; |
513 GRFConfig c; |
485 GRFConfig c; |
514 |
486 |
515 NetworkRecv_GRFIdentifier(p, &c); |
487 NetworkRecv_GRFIdentifier(&_udp_cs, p, &c); |
516 NetworkRecv_string(&_udp_cs, p, name, sizeof(name)); |
488 NetworkRecv_string(&_udp_cs, p, name, sizeof(name)); |
517 |
489 |
518 /* An empty name is not possible under normal circumstances |
490 /* An empty name is not possible under normal circumstances |
519 * and causes problems when showing the NewGRF list. */ |
491 * and causes problems when showing the NewGRF list. */ |
520 if (strlen(name) == 0) continue; |
492 if (strlen(name) == 0) continue; |