Skip to content

Commit 20b9e3a

Browse files
committed
Add api endpoint config
1 parent 64c4769 commit 20b9e3a

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

api/lib/src/models/config.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ final class SetonixConfig with SetonixConfigMappable {
3535
final bool? accountRequired;
3636
static const bool defaultAccountRequired = true;
3737
static const String envAccountRequired = 'SETONIX_ACCOUNT_REQUIRED';
38+
final String? apiEndpoint;
39+
static const String defaultApiEndpoint = "";
40+
static const String envApiEndpoint = 'SETONIX_API_ENDPOINT';
3841
final String? endpointSecret;
3942
static const String defaultEndpointSecret = '';
4043
static const String envEndpointSecret = 'SETONIX_ENDPOINT_SECRET';
@@ -50,6 +53,7 @@ final class SetonixConfig with SetonixConfigMappable {
5053
this.guestPrefix,
5154
this.whitelistEnabled,
5255
this.accountRequired,
56+
this.apiEndpoint,
5357
this.endpointSecret,
5458
});
5559

@@ -64,6 +68,7 @@ final class SetonixConfig with SetonixConfigMappable {
6468
guestPrefix: defaultGuestPrefix,
6569
whitelistEnabled: defaultWhitelistEnabled,
6670
accountRequired: defaultAccountRequired,
71+
apiEndpoint: defaultApiEndpoint,
6772
endpointSecret: defaultEndpointSecret,
6873
);
6974

@@ -103,6 +108,10 @@ final class SetonixConfig with SetonixConfigMappable {
103108
? bool.fromEnvironment(envAccountRequired,
104109
defaultValue: defaultAccountRequired)
105110
: null,
111+
apiEndpoint: bool.hasEnvironment(envApiEndpoint)
112+
? String.fromEnvironment(envApiEndpoint,
113+
defaultValue: defaultApiEndpoint)
114+
: null,
106115
endpointSecret: bool.hasEnvironment(envEndpointSecret)
107116
? String.fromEnvironment(envEndpointSecret,
108117
defaultValue: defaultEndpointSecret)
@@ -119,8 +128,9 @@ final class SetonixConfig with SetonixConfigMappable {
119128
maxPlayers: other.maxPlayers ?? maxPlayers,
120129
description: other.description ?? description,
121130
guestPrefix: other.guestPrefix ?? guestPrefix,
122-
endpointSecret: other.endpointSecret ?? endpointSecret,
123131
accountRequired: other.accountRequired ?? accountRequired,
124132
whitelistEnabled: other.whitelistEnabled ?? whitelistEnabled,
133+
apiEndpoint: other.apiEndpoint ?? apiEndpoint,
134+
endpointSecret: other.endpointSecret ?? endpointSecret,
125135
);
126136
}

api/lib/src/models/config.mapper.dart

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

metadata/en-US/changelogs/7.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* Add account system
2+
* Add auth system
3+
* Add loading screen
4+
* Add server list
5+
* Add kick message
6+
* Add user system on server
7+
* Local database
8+
* Remote endpoint
9+
* Add whitelist system on server
10+
11+
Read more here: https://linwood.dev/setonix/0.5.0

server/lib/src/config.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class ConfigManager {
6363
bool get accountRequired =>
6464
_mergedConfig.accountRequired ?? SetonixConfig.defaultAccountRequired;
6565

66+
String get apiEndpoint =>
67+
_mergedConfig.apiEndpoint ?? SetonixConfig.defaultApiEndpoint;
68+
6669
String get endpointSecret =>
6770
_mergedConfig.endpointSecret ?? SetonixConfig.defaultEndpointSecret;
6871
}

server/lib/src/server.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import 'package:setonix_server/src/programs/stop.dart';
1818
import 'package:setonix_plugin/setonix_plugin.dart';
1919
import 'package:setonix_server/src/programs/whitelist.dart';
2020
import 'package:setonix_server/src/services/user/file.dart';
21+
import 'package:setonix_server/src/services/user/remote.dart';
2122

2223
String limitOutput(Object? value, [int limit = 500]) {
2324
final string = value.toString();
@@ -93,8 +94,15 @@ final class SetonixServer {
9394
consoler, () => assetManager.init(console: consoler));
9495
final configManager = ConfigManager(argsConfig: argsConfig);
9596
await configManager.loadConfig();
96-
final userService = FileUserService();
97-
await userService.setup();
97+
final apiEndpoint = configManager.apiEndpoint;
98+
UserService userService;
99+
if (apiEndpoint.isNotEmpty) {
100+
userService = RemoteUserService(apiEndpoint: apiEndpoint);
101+
} else {
102+
final fileService = FileUserService();
103+
await fileService.setup();
104+
userService = fileService;
105+
}
98106
final userManager = UserManager(
99107
guestPrefix: configManager.guestPrefix,
100108
service: userService,

0 commit comments

Comments
 (0)