Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/csm/Networking/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ public bool Connect(ClientConfig clientConfig)
_netClient.Stop();
}

_netClient.DisconnectTimeout = CSM.Settings.ConnectionTimeoutMs;

// Start the client, if client setup fails, return out and
// tell the user
bool result = _netClient.Start();
Expand Down
2 changes: 2 additions & 0 deletions src/csm/Networking/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public bool StartServer(ServerConfig serverConfig)
// Let the user know that we are trying to start the server
Log.Info($"Attempting to start server on port {Config.Port}...");

_netServer.DisconnectTimeout = CSM.Settings.ConnectionTimeoutMs;

// Attempt to start the server
bool result = _netServer.Start(Config.Port);

Expand Down
15 changes: 15 additions & 0 deletions src/csm/Panels/SettingsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ public static void Build(UIHelperBase helper, Settings settings)
});
portInput.numericalOnly = true;

UITextField timeoutInput = null;
timeoutInput = (UITextField) advancedGroup.AddTextfield("Connection timeout (seconds)", settings.ConnectionTimeoutSeconds.value.ToString(), text => {}, text =>
{
if (int.TryParse(text, out int seconds) && seconds >= Settings.MinConnectionTimeoutSeconds && seconds <= Settings.MaxConnectionTimeoutSeconds)
{
settings.ConnectionTimeoutSeconds.value = seconds;
}
else
{
timeoutInput.text = settings.ConnectionTimeoutSeconds.value.ToString();
}
});
timeoutInput.numericalOnly = true;
timeoutInput.tooltip = "How long without response before a player is disconnected. Increase it if players with slower PCs get kicked while loading (5-600). Applies the next time you host or join.";

UIHelperBase buttonsGroup = helper.AddGroup("Buttons");
buttonsGroup.AddButton("Show Release Notes", () =>
{
Expand Down
10 changes: 10 additions & 0 deletions src/csm/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public Settings()
private const string DefaultLastSeenReleaseNotes = "0.0";
private const string DefaultApiServer = "api.citiesskylinesmultiplayer.com";
private const int DefaultApiServerPort = 4240;
// LiteNetLib's built-in default; going lower risks dropping healthy peers between 1 s keepalive pings
public const int MinConnectionTimeoutSeconds = 5;
public const int MaxConnectionTimeoutSeconds = 600;

public readonly SavedBool DebugLogging =
new SavedBool(nameof(DebugLogging), SettingsFile, DefaultDebugLogging, true);
Expand Down Expand Up @@ -46,5 +49,12 @@ public bool UseChirper

public readonly SavedInt ApiServerPort =
new SavedInt(nameof(ApiServerPort), SettingsFile, DefaultApiServerPort, true);

public readonly SavedInt ConnectionTimeoutSeconds =
new SavedInt(nameof(ConnectionTimeoutSeconds), SettingsFile, MinConnectionTimeoutSeconds, true);

// The settings file can be edited by hand, so the saved value is not trusted to be in range
public int ConnectionTimeoutMs =>
System.Math.Min(System.Math.Max(ConnectionTimeoutSeconds.value, MinConnectionTimeoutSeconds), MaxConnectionTimeoutSeconds) * 1000;
}
}