Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and enforce needing SIMULATE_IN_BG on. #2368

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions doc/source/general/telnet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ inside Kerbal Space Program.
<iframe width="560" height="315" src="https://www.youtube.com/embed/CgwRY-OrPhI?list=PLdXwd2JlyAvo_pH1tS3P7elVTYjvmIh-m" frameborder="0" allowfullscreen></iframe>
</div>

.. warning::

To use this feature you **must** make sure you have the main game
option "Simulate in Background" turned **on**. It can be found in
Kerbal Space Program's main menu settings screen, under
"General" settings.

More explanation can be found further down this page in the
section titled "Simulate in Background".

Telnet is an old network protocol designed in the early days of the Internet, long
before World Wide Web. Its purpose was (is) to allow you to get access to the
remote command line interfaces of distant server computers, acting as if the
Expand Down Expand Up @@ -62,6 +72,25 @@ For Linux
distribution. Open an xterm window, and in that window type the telnet
command, as described by the section titled "`HOWTO: Command-line client`_"

Simulate in Background
----------------------

To use the kOS telnet feature, you must have the stock KSP game's
option called "Simulate in Background" turned on. This option
is found on Kerbal Space Program's "General" settings screen
(Note, this is the settings screen you find on the
*title screen* of the game, NOT the smaller subset of settings
you find on the "escape" menu in-game.)

**Why?** Because when that option is turned off, the entire KSP
game is paused any time you switch focus to a different program
on your computer other than KSP. When the game is thusly paused,
the kOS telnet server inside the game is frozen and can't respond
to anything the telnet client sends it. (If you are typing into a
telnet client program on your computer, then *that* will be the
the focussed window instead of the KSP game, so this issue will
come up the majority of the time.)

Using it
--------

Expand Down
58 changes: 51 additions & 7 deletions src/kOS/UserIO/TelnetMainServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public class TelnetMainServer : MonoBehaviour

private bool activeOptInDialog;
private bool activeRealIPDialog;

private Rect optInRect = new Rect( 200, 200, 500, 400);
private Rect realIPRect = new Rect( 240, 140, 500, 400); // offset just in case both are up at the same time, to ensure visible bits to click on. They aren't movable.
private bool activeBgSimDialog;

private Rect optInRect = new Rect( 200, 200, 500, 400);
private Rect realIPRect = new Rect( 240, 140, 500, 400); // offset just in case multiples are up at the same time, to ensure visible bits to click on. They aren't movable.
private Rect bgSimRect = new Rect( 280, 100, 400, 300); // offset just in case multiples are up at the same time, to ensure visible bits to click on. They aren't movable.
private const string HELP_URL = "http://ksp-kos.github.io/KOS_DOC/general/telnet.html";

public TelnetMainServer()
Expand Down Expand Up @@ -178,7 +179,7 @@ public void SetConfigEnable(bool newVal)
if (newVal)
{
bool isLoopback = IPAddress.IsLoopback(bindAddr);
if (tempListenPermission && (tempRealIPPermission || isLoopback))
if (tempListenPermission && (tempRealIPPermission || isLoopback) && GameSettings.SIMULATE_IN_BACKGROUND)
StartListening();
else
{
Expand All @@ -188,11 +189,16 @@ public void SetConfigEnable(bool newVal)
// the dialog box will set EnableTelnet to true again
SafeHouse.Config.EnableTelnet = false;

// Depending on which reason it was for the denial, activate the proper dialog window:
// Depending on which reasons it was for the denial, activate the explanatory dialog windows:
if (!tempListenPermission)
activeOptInDialog = true;
else
activeRealIPDialog = true;
else // If the initial opt-in hasn't been permitted, that should be the only dialog seen. Only show these if that hurdle is passed:
{
if (!isLoopback)
activeRealIPDialog = true;
if (! GameSettings.SIMULATE_IN_BACKGROUND)
activeBgSimDialog = true;
}
}
}
else
Expand Down Expand Up @@ -370,6 +376,9 @@ void OnGUI()
if (activeRealIPDialog)
realIPRect = GUILayout.Window(401124, // any made up number unlikely to clash is okay here
realIPRect, RealIPOnGui, "kOS Telnet Non-Loopback Permisssion");
if (activeBgSimDialog)
bgSimRect = GUILayout.Window(401125, // any made up number unlikely to clash is okay here
bgSimRect, BgSimGui, "kOS Telnet \"Simulate in Background\" notice.");
}

void OptInOnGui(int id)
Expand Down Expand Up @@ -524,6 +533,41 @@ void RealIPOnGui(int id)
GUI.DragWindow();
}

void BgSimGui(int id)
{
string bgSimText =
"<b>The KSP main settings option 'Simulate in Background' is turned off.</b>\n\n" +
"This option must be enabled in order for kOS's telnet server to work.\n" +
"(Leaving it turned off causes the game to pause whenever you switch to another active window," +
"making it impossible to control the game from a telnet client.)\n\n" +
"To allow kOS's telnet server to work, you must perform the following steps:\n\n" +
"(1) Exit back to the first KSP title screen.\n" +
"(2) Click \"Settings\".\n" +
"(3) Click the \"General\" Tab on the settings screen.\n" +
"(4) Enable the setting called \"Simulate in Background\".\n" +
"(5) Click \"Accept\"\n" +
"(6) <b>This is important</b>: Quit and Restart KSP. (The change does not take effect until you do this.)\n" +
"\n" +
"Remember you MUST restart KSP for the change to actually do anything.\n";

// Note, the unnecessary curly braces below are there to help enforce a begin/end indentation that won't be
// clobbered by auto-indenter tools.
GUILayout.BeginVertical();
{
GUILayout.Label(bgSimText, HighLogic.Skin.textArea);
GUILayout.BeginHorizontal();
{
bool OkayClicked = GUILayout.Button("Okay", HighLogic.Skin.button);

if (OkayClicked)
activeBgSimDialog = false; // makes window stop existing.
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
GUI.DragWindow();
}

/// <summary>
/// Return a list of all the addresses that exist on this
/// machine, rendered into strings. (i.e. "127.0.0.1" as
Expand Down