MinecraftServerControl / mscs

Powerful command-line control for UNIX and Linux powered Minecraft servers
https://minecraftservercontrol.github.io
BSD 2-Clause "Simplified" License
485 stars 62 forks source link

Connect to native Forge console #282

Open rwtallant13 opened 3 years ago

rwtallant13 commented 3 years ago

The forge console by default allows you to use the arrow keys, autocomplete commands and stores a history you can go back through for commands, you can get a similar console experience with Fabric with the mod "JLine for Dedicated Server" which i also use.

Is it possible to connect to this console while using this control script in any way? Maybe through the use of something like screen or tmux.

sandain commented 3 years ago

We don't use screen or tmux anymore in this script, instead piping console output to the file console.out, and input from the user to the file console.in. I'm not sure what would be breaking autocomplete commands, but I would think it would be possible without going back to tmux/screen.

sandain commented 3 years ago

I just ran some tests and I think this can be done. I played around with two terminals. In the first one, I ran:

touch something && tail -f something

And in the second I ran:

while read -r -n1 LINE; do echo "$LINE" >> something; done

When typing in the second terminal, it was echoed in the first.

I don't have any servers setup right now to test this change because I am in the middle of a move. However, if you change Line 1304, it might work:

-  while read LINE; do
+  while read -r -n1 LINE; do

If you can test this change and let me know how it works, I can submit a patch (unless you want to).

sandain commented 3 years ago

On further thought, I think the patch needs to also modify the echo on Line 1305 to a printf to avoid extra line endings being added in between each character. I have submitted PR #283 to make this easier to test.

sandain commented 3 years ago

This seems to work a lot better. This patch boils down to the following run in two terminals:

For the first terminal:

touch something && tail -f something

And in the second:

while read -r -n1 CHAR; do printf "$CHAR" >> something; done

You can actually see the cursor moving around in the second terminal window as expected.

sandain commented 3 years ago

This is actually much harder than I expected. I'm working on a patch, but it is not yet fully working. Watch PR #283 for further updates.