Pryaxis / TShock

☕️⚡️TShock provides Terraria servers with server-side characters, anti-cheat, and community management tools.
GNU General Public License v3.0
2.43k stars 382 forks source link

Re-enable console redirected input #1450

Closed cokll closed 3 years ago

cokll commented 7 years ago

See the feature description by Onsen below. --@hakusaro

Ijwu commented 7 years ago

Your issue title asks how to remove console input but your description suggests you're already unable to enter commands. Please specifically state what the issue you're facing is and describe reproduction steps.

cokll commented 7 years ago

I use the pipeline to start TShock,I sent any instructions to TShock that did not respond. In 1.3.4.4 I removed IsInputRedirected to use the instruction,But 1.3.5.3 I did not find a similar one.

if (Console.IsInputRedirected == true) { Console.WriteLine("TerrariaServer is running in the background and input is disabled."); return; }

cokll commented 7 years ago

@Ijwu so?

Ijwu commented 7 years ago

I apologize for the delay @cokll. To be honest, I've shared this issue with the dev team and we collectively acknowledge that we have no idea what you're asking.

Feel free to get more specific or discuss your expected result.

cokll commented 7 years ago

In 1.3.4.4 there are Console.IsInputRedirected,But 1.3.5.3 I did not find a similar one. @Ijwu

mistzzt commented 7 years ago

Why you are still asking for Console.IsInputRedirected? From what you said

In 1.3.4.4 I removed IsInputRedirected to use the instruction

You just want the TShock send you an instruction like TerrariaServer is running in the background and input is disabled.?

cokll commented 7 years ago

@mistzzt I want to delete IsInputRedirected,I don't want the input to be disabled in the background.

cokll commented 7 years ago

@mistzzt I made a software to manage TShock.If the input is disabled, the status can not be obtained

madman2021 commented 7 years ago

@cokll I'm trying to understand what you are asking, are you trying to use System.Diagnostics.Process to wrap the TShock binary and now it's not working for you ?

OnsenManju commented 7 years ago

Maybe he is asking "how to redirect own text to TShock's console by using pipeline, as if that was typed on console", I guess.

As you developers know, before TShock Mintaka (4.3.21), TerrariaServerAPI/Terraria/Main.cs had the following part:

public static void startDedInput()
{
    if (Console.IsInputRedirected == true)
    {
        Console.WriteLine("TerrariaServer is running in the background and input is disabled.");
        return;
    }

    Thread t = new Thread(Main.startDedInputCallBack);
    t.Name = "Console Input Thread";
    t.IsBackground = true;
    t.Start();
}

public static void startDedInputCallBack(object threadContext)
{
    while (!Netplay.disconnect)
    {
        Console.Write(": ");
        string str = Console.ReadLine();
        ......

Removing the part he said will probably make it possible to use a way like this:

$ mkfifo /tmp/pipe
$ mono TerrariaServer.exe -world my.wld < /tmp/pipe &
$ echo "bc hello" > /tmp/pipe
$ echo "kick badguy" > /tmp/pipe
$ echo "restart" > /tmp/pipe

But now, vanilla part of Terraria is hidden into OTAPI, so people can't hack that easily. I recommend using REST API instead, or making custom plugin which captures Console.ReadLine() in some way, or whatever (not sure).

SignatureBeef commented 7 years ago

Or perhaps the OTAPI 'startDedInput' hook can be used to run the required code as like premintaka

cokll commented 7 years ago

@OnsenManju Yes,So it can not be modified now.

hskrtich commented 6 years ago

I just ran this code via this build and it seems to fix the issue.

QuiCM commented 6 years ago

Closing tentatively based on above feedback. Reopen if this is still an issue

hakusaro commented 4 years ago

I'm not at all convince this is fixed: we got a report in #2003 that says that they want input redirection enabled and then again in Discord. I'm not sure entirely what @bskrtich was referring to other than I think he was wanting it to not crash as per #1487. I think the end solution is going to be having a command line flag to enable or disable input redirection.

hskrtich commented 4 years ago

@hakusaro Correct, the issue I was talking about was the crash fixed by #1487

hakusaro commented 4 years ago

Holy guacamole, you're alive! Thank you for the context! 💚

hskrtich commented 4 years ago

hah! I am! Have to keep my docker container for tshock/vanilla server working. Happy I could help!

dr4xor commented 4 years ago

Hey There, in my case I'm running TShock as a python subprocess. I can write to the stdin stream but because of "TerrariaServer is running in the background and input is disabled" nothing happens.

If it's not possible to make a flag to disable the background mode. How can I trick mono into thinking, that the process is running in the foreground?

Thanks for your help!

hakusaro commented 4 years ago

This is a really reasonable request. Definitely reasonable and definitely something we'd want to get fixed, @dr4xor.