mirror of
https://github.com/Tiiffi/mcrcon.git
synced 2025-10-28 03:41: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:
16
mcrcon.c
16
mcrcon.c
@ -596,12 +596,8 @@ 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");
|
||||||
@ -612,16 +608,16 @@ int rcon_command(int sock, char *command)
|
|||||||
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()
|
||||||
fd_set read_fds;
|
fd_set read_fds;
|
||||||
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 (global_valve_protocol) {
|
|
||||||
if (packet->id == 0xBADA55) break;
|
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");
|
||||||
|
|||||||
Reference in New Issue
Block a user