feat: set limits and validation on connection timeout

This commit is contained in:
Ryan Dowling 2022-12-17 13:53:41 +11:00
parent e292d817ab
commit 0ede7e2958
No known key found for this signature in database
GPG key ID: 5539FCDB88950EFD
4 changed files with 16 additions and 2 deletions

View file

@ -29,4 +29,5 @@
],
"java.codeGeneration.generateComments": true,
"git.inputValidationLength": 100,
"java.compile.nullAnalysis.mode": "automatic",
}

View file

@ -10,6 +10,7 @@ This changelog only contains the changes that are unreleased. For changes for in
- Add in support for Modrinth resource packs
- Show if Modpacks.ch pack version is Alpha/Beta
- Add button when allocating more than 8GB ram to explain more
- Set limits and validation on connection timeout
### Fixes
- Issue with skins not updating after changing them [#671]

View file

@ -304,6 +304,8 @@ public class Settings {
validateConcurrentConnections();
validateConnectionTimeout();
validateDateFormat();
validateInstanceTitleFormat();
@ -475,13 +477,21 @@ public class Settings {
}
private void validateConcurrentConnections() {
if (concurrentConnections < 1) {
if (concurrentConnections < 1 || concurrentConnections > 100) {
LogManager.warn("Tried to set the number of concurrent connections to " + concurrentConnections
+ " which is not valid! Must be 1 or more. Setting back to default of 8!");
+ " which is not valid! Must be between 1 and 100. Setting back to default of 8!");
concurrentConnections = 8;
}
}
private void validateConnectionTimeout() {
if (connectionTimeout < 1 || connectionTimeout > 600) {
LogManager.warn("Tried to set the number of connection timeout to " + connectionTimeout
+ " which is not valid! Must be between 1 and 600. Setting back to default of 30!");
connectionTimeout = 30;
}
}
private void validateDateFormat() {
if (!Arrays.asList(Constants.DATE_FORMATS).contains(dateFormat)) {
LogManager.warn("Tried to set the date format to " + dateFormat + " which is not valid! Setting "

View file

@ -81,6 +81,7 @@ public class NetworkSettingsTab extends AbstractSettingsTab implements Relocaliz
SpinnerNumberModel concurrentConnectionsModel = new SpinnerNumberModel(App.settings.concurrentConnections, null,
null, 1);
concurrentConnectionsModel.setMinimum(1);
concurrentConnectionsModel.setMaximum(100);
concurrentConnections = new JSpinner(concurrentConnectionsModel);
add(concurrentConnections, gbc);
@ -99,6 +100,7 @@ public class NetworkSettingsTab extends AbstractSettingsTab implements Relocaliz
SpinnerNumberModel connectionTimeoutModel = new SpinnerNumberModel(App.settings.connectionTimeout, null, null,
1);
connectionTimeoutModel.setMinimum(1);
connectionTimeoutModel.setMaximum(600);
connectionTimeout = new JSpinner(connectionTimeoutModel);
add(connectionTimeout, gbc);