|
@@ -461,14 +461,16 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
|
|
|
|
|
|
/* Find the matching GRF file */
|
|
|
f = FindGRFConfig(c.grfid, c.md5sum);
|
|
|
if (f == NULL) continue; // The GRF is unknown to this server
|
|
|
|
|
|
/* If the reply might exceed the size of the packet, only reply
|
|
|
* the current list and do not send the other data */
|
|
|
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) + min(strlen(f->name) + 1, NETWORK_GRF_NAME_LENGTH);
|
|
|
* the current list and do not send the other data.
|
|
|
* The name could be an empty string, if so take the filename. */
|
|
|
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) +
|
|
|
min(strlen((f->name != NULL && strlen(f->name) > 0) ? f->name : f->filename) + 1, NETWORK_GRF_NAME_LENGTH);
|
|
|
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply
|
|
|
break;
|
|
|
}
|
|
|
in_reply[in_reply_count] = f;
|
|
|
in_reply_count++;
|
|
|
}
|
|
@@ -476,14 +478,17 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIEN
|
|
|
if (in_reply_count == 0) return;
|
|
|
|
|
|
packet = NetworkSend_Init(PACKET_UDP_SERVER_NEWGRFS);
|
|
|
NetworkSend_uint8 (packet, in_reply_count);
|
|
|
for (i = 0; i < in_reply_count; i++) {
|
|
|
char name[NETWORK_GRF_NAME_LENGTH];
|
|
|
ttd_strlcpy(name, in_reply[i]->name, sizeof(name));
|
|
|
NetworkSend_GRFIdentifier(packet, in_reply[i]);
|
|
|
|
|
|
/* The name could be an empty string, if so take the filename */
|
|
|
ttd_strlcpy(name, (in_reply[i]->name != NULL && strlen(in_reply[i]->name) > 0) ?
|
|
|
in_reply[i]->name : in_reply[i]->filename, sizeof(name));
|
|
|
NetworkSend_GRFIdentifier(packet, in_reply[i]);
|
|
|
NetworkSend_string(packet, name);
|
|
|
}
|
|
|
|
|
|
NetworkSendUDP_Packet(_udp_server_socket, packet, client_addr);
|
|
|
free(packet);
|
|
|
}
|
|
@@ -507,12 +512,16 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVE
|
|
|
char name[NETWORK_GRF_NAME_LENGTH];
|
|
|
GRFConfig c;
|
|
|
|
|
|
NetworkRecv_GRFIdentifier(p, &c);
|
|
|
NetworkRecv_string(&_udp_cs, p, name, sizeof(name));
|
|
|
|
|
|
/* An empty name is not possible under normal circumstances
|
|
|
* and causes problems when showing the NewGRF list. */
|
|
|
if (strlen(name) == 0) continue;
|
|
|
|
|
|
/* Finds the fake GRFConfig for the just read GRF ID and MD5sum tuple.
|
|
|
* If it exists and not resolved yet, then name of the fake GRF is
|
|
|
* overwritten with the name from the reply. */
|
|
|
unknown_name = FindUnknownGRFName(c.grfid, c.md5sum, false);
|
|
|
if (unknown_name != NULL && strcmp(unknown_name, UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) {
|
|
|
ttd_strlcpy(unknown_name, name, NETWORK_GRF_NAME_LENGTH);
|