mirror of
https://github.com/Tiiffi/mcrcon.git
synced 2025-10-27 11:21:07 -04:00
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:
34
mcrcon.c
34
mcrcon.c
@ -596,22 +596,17 @@ int rcon_command(int sock, char *command)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CAUTION: lets set this always true for testing
|
||||
global_valve_protocol = true;
|
||||
|
||||
// Workaround to handle valve multipacket responses
|
||||
// This one does not require using select()
|
||||
if (global_valve_protocol) {
|
||||
packet = packet_build(0xBADA55, 0xBADA55, "");
|
||||
if (packet == NULL) {
|
||||
log_error("Error: packet build() failed!\n");
|
||||
return 0;
|
||||
}
|
||||
packet = packet_build(0xBADA55, 0xBADA55, "");
|
||||
if (packet == NULL) {
|
||||
log_error("Error: packet build() failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!net_send_packet(sock, packet)) {
|
||||
log_error("Error: net_send_packet() failed!\n");
|
||||
return 0;
|
||||
}
|
||||
if (!net_send_packet(sock, packet)) {
|
||||
log_error("Error: net_send_packet() failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// initialize stuff for select()
|
||||
@ -619,9 +614,10 @@ int rcon_command(int sock, char *command)
|
||||
FD_ZERO(&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};
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_usec = 0;
|
||||
timeout.tv_usec = 500000;
|
||||
|
||||
int incoming = 0;
|
||||
|
||||
@ -638,21 +634,13 @@ int rcon_command(int sock, char *command)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Break out if valve multipacket guard detected
|
||||
if (global_valve_protocol) {
|
||||
if (packet->id == 0xBADA55) break;
|
||||
}
|
||||
if (packet->id == 0xBADA55) break;
|
||||
|
||||
if (!flag_silent_mode) {
|
||||
if (packet->size > 10)
|
||||
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);
|
||||
if (result == -1) {
|
||||
log_error("Error: select() failed!\n");
|
||||
|
||||
Reference in New Issue
Block a user