Skip to content

Commit 2751cc8

Browse files
authored
Merge pull request #599 from cjakeman/menu-option02l
02l: Removes web-server option. Now always available.
2 parents df1b190 + 2832044 commit 2751cc8

File tree

5 files changed

+25
-53
lines changed

5 files changed

+25
-53
lines changed

Source/Documentation/Manual/options.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,12 @@ Disable TCS scripts
142142
This option disables the train control system scripts for locomotives where
143143
these have been implemented.
144144

145-
Enable web server
145+
Web server port
146146
-----------------
147147

148-
This option enables an internal web server that can be used to display game and
149-
train status information in a web browser, intended for use on secondary screens.
150-
151-
When activated, the server can be accessed from a browser on the local machine at
148+
The web server can be accessed from a browser on the local machine at
152149
``http://localhost:<port>``, where ``<port>`` is the specified port number.
150+
Change the default value of 2150 if it conflicts with other services.
153151

154152
If you `open
155153
<https://www.howtogeek.com/394735/how-do-i-open-a-port-on-windows-firewall/>`_

Source/Menu/Options.Designer.cs

Lines changed: 2 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/Menu/Options.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ public OptionsForm(UserSettings settings, UpdateManager updateManager, bool init
150150
comboPressureUnit.Text = Settings.PressureUnit;
151151
comboOtherUnits.Text = settings.Units;
152152
checkDisableTCSScripts.Checked = Settings.DisableTCSScripts;
153-
checkEnableWebServer.Checked = Settings.WebServer;
154153
numericWebServerPort.Value = Settings.WebServerPort;
155154

156155
// Audio tab
@@ -431,7 +430,7 @@ void buttonOK_Click(object sender, EventArgs e)
431430
Settings.PressureUnit = comboPressureUnit.SelectedValue.ToString();
432431
Settings.Units = comboOtherUnits.SelectedValue.ToString();
433432
Settings.DisableTCSScripts = checkDisableTCSScripts.Checked;
434-
Settings.WebServer = checkEnableWebServer.Checked;
433+
Settings.WebServerPort = (int)numericWebServerPort.Value;
435434

436435
// Audio tab
437436
Settings.SoundVolumePercent = (int)numericSoundVolumePercent.Value;
@@ -820,7 +819,6 @@ private void InitializeHelpIcons()
820819
(pbPressureUnit, new Control[] { labelPressureUnit, comboPressureUnit }),
821820
(pbOtherUnits, new Control[] { labelOtherUnits, comboOtherUnits }),
822821
(pbDisableTcsScripts, new[] { checkDisableTCSScripts }),
823-
(pbEnableWebServer, new[] { checkEnableWebServer }),
824822
(pbOverspeedMonitor, new[] { checkOverspeedMonitor }),
825823
};
826824
foreach ((PictureBox pb, Control[] controls) in helpIconControls)
@@ -878,10 +876,6 @@ private void HelpIcon_Click(object sender, EventArgs _)
878876
pbDisableTcsScripts,
879877
baseUrl + "/options.html#disable-tcs-scripts"
880878
},
881-
{
882-
pbEnableWebServer,
883-
baseUrl + "/options.html#enable-web-server"
884-
},
885879
{
886880
pbOverspeedMonitor,
887881
baseUrl + "/options.html#overspeed-monitor"

Source/ORTS.Settings/UserSettings.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ public enum DirectXFeature
153153
public bool IsModeActivity { get; set; } // false indicates Timetable mode
154154

155155
// General settings:
156-
157-
[Default(false)]
158-
public bool WebServer { get; set; }
159156
[Default(2150)]
160157
public int WebServerPort { get; set; }
161158

Source/RunActivity/Viewer3D/Processes/WebServerProcess.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
using System.IO;
2727
using System.Windows.Forms;
2828
using CancellationTokenSource = System.Threading.CancellationTokenSource;
29+
using System.Net.Sockets;
30+
using System.Diagnostics;
31+
using System;
2932

3033
namespace Orts.Viewer3D.Processes
3134
{
@@ -60,13 +63,25 @@ void WebServerThread()
6063
{
6164
Profiler.SetThread();
6265
Game.SetThreadLanguage();
63-
if (!Game.Settings.WebServer)
64-
return;
6566

6667
string myWebContentPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Content\\Web");
6768
EndPointManager.UseIpv6 = true;
68-
using (EmbedIO.WebServer server = WebServer.CreateWebServer($"http://*:{Game.Settings.WebServerPort}", myWebContentPath))
69-
server.RunAsync(StopServer.Token).Wait();
69+
try
70+
{
71+
using (EmbedIO.WebServer server = WebServer.CreateWebServer($"http://*:{Game.Settings.WebServerPort}", myWebContentPath))
72+
server.RunAsync(StopServer.Token).Wait();
73+
}
74+
catch(AggregateException ex)
75+
{
76+
if (ex.InnerException is SocketException)
77+
{
78+
Trace.TraceWarning($"Port {Game.Settings.WebServerPort} is already in use. Continuing without webserver");
79+
}
80+
else
81+
{
82+
throw ex;
83+
}
84+
}
7085
}
7186
}
7287
}

0 commit comments

Comments
 (0)