mirror of
https://github.com/Tiiffi/mcrcon.git
synced 2025-10-28 11:51:08 -04:00
Fix missing newlines in Minecraft RCON messages:
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-7569 Fixes #1
This commit is contained in:
2
mcrcon.1
2
mcrcon.1
@ -1,7 +1,7 @@
|
|||||||
.\" Process this file with
|
.\" Process this file with
|
||||||
.\" groff -man -Tascii mcrcon.1
|
.\" groff -man -Tascii mcrcon.1
|
||||||
.\"
|
.\"
|
||||||
.TH MCRCON 1 "November 2024" "Version 0.8.0"
|
.TH MCRCON 1 "December 2024" "Version 0.8.0"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
mcrcon \- send rcon commands to a Minecraft server
|
mcrcon \- send rcon commands to a Minecraft server
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
|||||||
47
mcrcon.c
47
mcrcon.c
@ -104,6 +104,7 @@ static int flag_disable_colors = 0;
|
|||||||
static int flag_wait_seconds = 0;
|
static int flag_wait_seconds = 0;
|
||||||
static int global_connection_alive = 1;
|
static int global_connection_alive = 1;
|
||||||
static bool global_valve_protocol = false;
|
static bool global_valve_protocol = false;
|
||||||
|
static bool global_minecraft_newline_fix = false;
|
||||||
static int global_rsock;
|
static int global_rsock;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -493,34 +494,37 @@ void packet_print(rc_packet *packet)
|
|||||||
} else default_color = 0x37;
|
} else default_color = 0x37;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// colors enabled so try to handle the bukkit colors for terminal
|
bool slash = false;
|
||||||
if (flag_disable_colors == 0) {
|
bool colors_detected = false;
|
||||||
for (i = 0; data[i] != 0; ++i) {
|
|
||||||
if (data[i] == 0x0A) print_color(default_color);
|
for (i = 0; data[i] != 0; ++i)
|
||||||
else if(data[i] == 0xc2 && data[i + 1] == 0xa7) {
|
{
|
||||||
i += 2;
|
if (data[i] == 0x0A) {
|
||||||
|
print_color(default_color);
|
||||||
|
}
|
||||||
|
else if(data[i] == 0xc2 && data[i + 1] == 0xa7) {
|
||||||
|
// Disable new line fixes if Bukkit colors are detected
|
||||||
|
colors_detected = true;
|
||||||
|
i += 2;
|
||||||
|
if (flag_disable_colors == 0) {
|
||||||
print_color(data[i]);
|
print_color(data[i]);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
putchar(data[i]);
|
continue;
|
||||||
}
|
}
|
||||||
print_color(default_color); // cancel coloring
|
|
||||||
}
|
if (colors_detected == false && global_minecraft_newline_fix && data[i] == '/') {
|
||||||
// strip colors
|
slash ? putchar('\n') : (slash = true);
|
||||||
else {
|
|
||||||
for (i = 0; data[i] != 0; ++i) {
|
|
||||||
if (data[i] == 0xc2 && data[i + 1] == 0xa7) {
|
|
||||||
i += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
putchar(data[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
putchar(data[i]);
|
||||||
}
|
}
|
||||||
|
print_color(default_color); // cancel coloring
|
||||||
|
|
||||||
// print newline if string has no newline
|
// print newline if string has no newline
|
||||||
if (data[i - 1] != 10 && data[i - 1] != 13) {
|
if (data[i - 1] != '\n') {
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -578,6 +582,9 @@ receive:
|
|||||||
|
|
||||||
int rcon_command(int sock, char *command)
|
int rcon_command(int sock, char *command)
|
||||||
{
|
{
|
||||||
|
if (global_valve_protocol == false && strcasecmp(command, "help") == 0)
|
||||||
|
global_minecraft_newline_fix = true;
|
||||||
|
|
||||||
rc_packet *packet = packet_build(RCON_PID, RCON_EXEC_COMMAND, command);
|
rc_packet *packet = packet_build(RCON_PID, RCON_EXEC_COMMAND, command);
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
log_error("Error: packet build() failed!\n");
|
log_error("Error: packet build() failed!\n");
|
||||||
@ -629,7 +636,7 @@ int rcon_command(int sock, char *command)
|
|||||||
|
|
||||||
if (packet->id == 0xBADA55) break;
|
if (packet->id == 0xBADA55) break;
|
||||||
|
|
||||||
if (!flag_silent_mode) {
|
if (flag_silent_mode == false) {
|
||||||
if (packet->size > 10)
|
if (packet->size > 10)
|
||||||
packet_print(packet);
|
packet_print(packet);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user