Remove Valve protocol checks and set select() timeout to 1.5 seconds

Use the same method for handling multipacket responses across all servers.
This commit is contained in:
Tiiffi
2024-12-04 16:30:53 +02:00
committed by Tiiffi
parent 6fed74ba74
commit 5f460e8912

View File

@ -596,22 +596,17 @@ int rcon_command(int sock, char *command)
return 0; return 0;
} }
// CAUTION: lets set this always true for testing
global_valve_protocol = true;
// Workaround to handle valve multipacket responses // Workaround to handle valve multipacket responses
// This one does not require using select() // This one does not require using select()
if (global_valve_protocol) { packet = packet_build(0xBADA55, 0xBADA55, "");
packet = packet_build(0xBADA55, 0xBADA55, ""); if (packet == NULL) {
if (packet == NULL) { log_error("Error: packet build() failed!\n");
log_error("Error: packet build() failed!\n"); return 0;
return 0; }
}
if (!net_send_packet(sock, packet)) { if (!net_send_packet(sock, packet)) {
log_error("Error: net_send_packet() failed!\n"); log_error("Error: net_send_packet() failed!\n");
return 0; return 0;
}
} }
// initialize stuff for select() // initialize stuff for select()
@ -619,9 +614,10 @@ int rcon_command(int sock, char *command)
FD_ZERO(&read_fds); FD_ZERO(&read_fds);
FD_SET(sock, &read_fds); FD_SET(sock, &read_fds);
// Set 1.5 second timeout in case there is no response for multipacket guard
struct timeval timeout = {0}; struct timeval timeout = {0};
timeout.tv_sec = 1; timeout.tv_sec = 1;
timeout.tv_usec = 0; timeout.tv_usec = 500000;
int incoming = 0; int incoming = 0;
@ -638,21 +634,13 @@ int rcon_command(int sock, char *command)
return 0; return 0;
} }
// Break out if valve multipacket guard detected if (packet->id == 0xBADA55) break;
if (global_valve_protocol) {
if (packet->id == 0xBADA55) break;
}
if (!flag_silent_mode) { if (!flag_silent_mode) {
if (packet->size > 10) if (packet->size > 10)
packet_print(packet); packet_print(packet);
} }
// NOTE: Workaround to prevent waiting for timeout.
// This is not reliable way to detect last packet
if (global_valve_protocol == false && packet->size < MAX_PACKET_SIZE)
break;
int result = select(sock + 1, &read_fds, NULL, NULL, &timeout); int result = select(sock + 1, &read_fds, NULL, NULL, &timeout);
if (result == -1) { if (result == -1) {
log_error("Error: select() failed!\n"); log_error("Error: select() failed!\n");