Skip to content

Commit

Permalink
Add workaround to prevent server-side bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiiffi committed Dec 21, 2019
1 parent 3c071c0 commit 876201f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#### Version history:

###### 0.7.1
- Add workaround to prevent server-side bug.
https://bugs.mojang.com/browse/MC-154617

###### 0.7.0
- Add -w option for rcon command throttling
* Thanks HorlogeSkynet @ Github
Expand Down
19 changes: 15 additions & 4 deletions mcrcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <netdb.h>
#endif

#define VERSION "0.7.0"
#define VERSION "0.7.1"
#define IN_NAME "mcrcon"
#define VER_STR IN_NAME" "VERSION" (built: "__DATE__" "__TIME__")"

Expand Down Expand Up @@ -171,7 +171,8 @@ int main(int argc, char *argv[])

// default getopt error handler enabled
opterr = 1;
for (int opt = getopt(argc, argv, "vrtcshw:H:p:P:i"); opt != -1;)
int opt;
while ((opt = getopt(argc, argv, "vrtcshw:H:p:P:i")) != -1)
{
switch (opt) {
case 'H': host = optarg; break;
Expand Down Expand Up @@ -652,6 +653,7 @@ int run_terminal_mode(int sock)
puts("Logged in. Type 'quit' or 'exit' to quit.");

while (global_connection_alive) {
putchar('>');
int len = get_line(command, DATA_BUFFSIZE);

if ((strcmp(command, "exit") && strcmp(command, "quit")) == 0)
Expand All @@ -663,6 +665,17 @@ int run_terminal_mode(int sock)
if(len > 0 && global_connection_alive)
ret += rcon_command(sock, command);

/* Special case for "stop" command to prevent server-side bug.
* https://bugs.mojang.com/browse/MC-154617
*
* NOTE: This is hacky workaround which should be handled better to
* ensure compatibility with other servers using source RCON.
* NOTE: strcasecmp() is POSIX function.
*/
if (strcasecmp(command, "stop") == 0) {
break;
}

command[0] = len = 0;
}

Expand All @@ -672,8 +685,6 @@ int run_terminal_mode(int sock)
// gets line from stdin and deals with rubbish left in the input buffer
int get_line(char *buffer, int bsize)
{
fputs(">", stdout);

char *ret = fgets(buffer, bsize, stdin);
if (ret == NULL)
exit(EXIT_FAILURE);
Expand Down

0 comments on commit 876201f

Please sign in to comment.