RCON protocol is quite broken and inconsistent across different server implementations. This patch adds handling for the quirks found in the following servers:
- Rust
- Palworld
- Factorio
- rename utf8_getline() to windows_getline()
- windows_getline() should now handle UTF-8 input correctly
- color printing now resets bold/bright status for each line
- remove unnecessary _setmode() calls
- disable color printing if 'valve protocol' detected
- print newline after last packet if last character was not newline
Minecraft servers have a longstanding bug that omits newlines
when sending messages via RCON. This patch manually inserts
newlines to address the issue.
Reference: https://bugs.mojang.com/browse/MC-7569Fixes#1
Send a "multipacket guard" - an empty packet with an invalid 'cmd' field
and a unique packet ID to trigger a reply from the server once the previous
command's reply has been fully sent.
Valve returns an empty payload, while Minecraft includes an error message in the payload.
This workaround ensures that all packets related to the last valid command
are received from the server, avoiding the need to wait for the select() timeout.
- add MAX_COMMAND_LENGTH to define maximum command length
- print auth failed message to stderr instead of stdout
- remove unused net_send() function
- remove unused net_clean_incoming() function
- rewrite net_send_packet() function
- net_recv_packet(): change the type of variable "ret" from int to ssize_t
- net_recv_packet(): fail immediately if the packet size is out of spec
- packet_print(): rename variable "def_color" to "default_color"
- packet_print(): remove unecessary casts
- packet_build(): use MAX_COMMAND_LENGTH
- packet_build(): be more explicit in calculation of packet.size
- packet_build(): use memcpy() instead of strncpy()
- cast second argument of send()/recv() calls to (char *) so Windows is happy
- rcon_auth(): change the return type from int to bool
- run_terminal_mode(): use MAX_COMMAND_LENGTH