Skip to content

Commit ac7945c

Browse files
committed
Add kick message
1 parent c07a839 commit ac7945c

File tree

10 files changed

+239
-14
lines changed

10 files changed

+239
-14
lines changed

api/lib/models.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export 'src/models/deck.dart';
66
export 'src/models/definition.dart';
77
export 'src/models/dialog.dart';
88
export 'src/models/info.dart';
9+
export 'src/models/kick.dart';
910
export 'src/models/meta.dart';
1011
export 'src/models/mode.dart';
1112
export 'src/models/server.dart';

api/lib/src/models/config.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ final class SetonixConfig with SetonixConfigMappable {
2929
final String? guestPrefix;
3030
static const String defaultGuestPrefix = 'Guest ';
3131
static const String envGuestPrefix = 'SETONIX_GUEST_PREFIX';
32+
final String? authEndpoint;
33+
static const String defaultAuthEndpoint = '';
34+
static const String envAuthEndpoint = 'SETONIX_AUTH_ENDPOINT';
35+
final String? endpointSecret;
36+
static const String defaultEndpointSecret = '';
37+
static const String envEndpointSecret = 'SETONIX_ENDPOINT_SECRET';
3238

3339
const SetonixConfig({
3440
this.host,
@@ -39,6 +45,8 @@ final class SetonixConfig with SetonixConfigMappable {
3945
this.maxPlayers,
4046
this.description,
4147
this.guestPrefix,
48+
this.authEndpoint,
49+
this.endpointSecret,
4250
});
4351

4452
static const defaultConfig = SetonixConfig(
@@ -50,6 +58,8 @@ final class SetonixConfig with SetonixConfigMappable {
5058
maxPlayers: defaultMaxPlayers,
5159
description: defaultDescription,
5260
guestPrefix: defaultGuestPrefix,
61+
authEndpoint: defaultAuthEndpoint,
62+
endpointSecret: defaultEndpointSecret,
5363
);
5464

5565
static SetonixConfig fromEnvironment() {
@@ -80,6 +90,14 @@ final class SetonixConfig with SetonixConfigMappable {
8090
? String.fromEnvironment(envGuestPrefix,
8191
defaultValue: defaultGuestPrefix)
8292
: null,
93+
authEndpoint: bool.hasEnvironment(envAuthEndpoint)
94+
? String.fromEnvironment(envAuthEndpoint,
95+
defaultValue: defaultAuthEndpoint)
96+
: null,
97+
endpointSecret: bool.hasEnvironment(envEndpointSecret)
98+
? String.fromEnvironment(envEndpointSecret,
99+
defaultValue: defaultEndpointSecret)
100+
: null,
83101
);
84102
}
85103

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

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

api/lib/src/models/kick.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:dart_mappable/dart_mappable.dart';
2+
3+
part 'kick.mapper.dart';
4+
5+
@MappableClass(hook: KickMessageHook())
6+
final class KickMessage with KickMessageMappable {
7+
final String message;
8+
final String? link;
9+
10+
const KickMessage({
11+
required this.message,
12+
this.link,
13+
});
14+
15+
factory KickMessage.fromString(String message) {
16+
try {
17+
return KickMessageMapper.fromJson(message);
18+
} catch (_) {
19+
return KickMessage(message: message);
20+
}
21+
}
22+
}
23+
24+
class KickMessageHook extends MappingHook {
25+
const KickMessageHook();
26+
27+
@override
28+
Object? beforeDecode(Object? value) {
29+
if (value is String) {
30+
return {'message': value};
31+
}
32+
return super.beforeDecode(value);
33+
}
34+
}

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

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

app/lib/bloc/multiplayer.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ class MultiplayerCubit extends Cubit<MultiplayerState> {
225225
final state = await _addNetworker(client);
226226
client.onClosed.listen((_) {
227227
if (isClosed) return;
228-
emit(MultiplayerDisconnectedState(oldState: state, error: _fatalError));
228+
final closeReason = client.closeReason;
229+
emit(MultiplayerDisconnectedState(
230+
oldState: state,
231+
error: _fatalError ??
232+
(closeReason == null
233+
? null
234+
: KickMessage.fromString(closeReason)),
235+
));
229236
_fatalError = null;
230237
}, onError: (e) => emit(MultiplayerDisconnectedState(error: e)));
231238
await client.init();

app/lib/l10n/app_en.arb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,5 +269,6 @@
269269
"reset": "Reset",
270270
"confirm": "Confirm",
271271
"showIntro": "Show intro",
272-
"highlighted": "Highlighted"
272+
"highlighted": "Highlighted",
273+
"link": "Link"
273274
}

app/lib/pages/game/error.dart

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:setonix/bloc/world/bloc.dart';
1010
import 'package:setonix/pages/home/background.dart';
1111
import 'package:setonix/services/file_system.dart';
1212
import 'package:setonix_api/setonix_api.dart';
13+
import 'package:url_launcher/url_launcher_string.dart';
1314

1415
class GameErrorView extends StatelessWidget {
1516
final MultiplayerDisconnectedState state;
@@ -26,15 +27,40 @@ class GameErrorView extends StatelessWidget {
2627
final theme = Theme.of(context);
2728
final error = state.error;
2829
var message = AppLocalizations.of(context).disconnectedMessage;
29-
Widget? content;
30+
List<Widget>? content;
3031
if (error is FatalServerEventError) {
3132
message = switch (error) {
3233
InvalidPacksError() => AppLocalizations.of(context).invalidPacks,
3334
};
3435
content = switch (error) {
35-
InvalidPacksError() =>
36-
_PacksGameErrorView(error: error, onReconnect: onReconnect),
36+
InvalidPacksError() => [
37+
_PacksGameErrorView(error: error, onReconnect: onReconnect)
38+
],
3739
};
40+
} else if (error is KickMessage) {
41+
final link = error.link;
42+
content = [
43+
Text(error.message),
44+
const SizedBox(height: 4),
45+
if (link != null)
46+
Row(
47+
children: [
48+
Expanded(
49+
child: TextFormField(
50+
initialValue: link,
51+
readOnly: true,
52+
decoration: InputDecoration(
53+
labelText: AppLocalizations.of(context).link,
54+
suffixIcon: IconButton(
55+
icon: const Icon(PhosphorIconsLight.paperPlaneRight),
56+
onPressed: () => launchUrlString(link,
57+
mode: LaunchMode.externalApplication),
58+
),
59+
),
60+
))
61+
],
62+
)
63+
];
3864
}
3965
return Scaffold(
4066
body: Stack(
@@ -63,7 +89,7 @@ class GameErrorView extends StatelessWidget {
6389
),
6490
if (content != null) ...[
6591
const SizedBox(height: 16),
66-
content,
92+
...content,
6793
],
6894
const SizedBox(height: 16),
6995
Row(

app/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ packages:
840840
dependency: "direct main"
841841
description:
842842
path: "packages/networker/networker_socket"
843-
ref: ec6f31ba3eb0da17bdef6a8d66ef6caafcabd908
844-
resolved-ref: ec6f31ba3eb0da17bdef6a8d66ef6caafcabd908
843+
ref: dfc9c68412354184f7e92c4c572634748d855948
844+
resolved-ref: dfc9c68412354184f7e92c4c572634748d855948
845845
url: "https://github.com/LinwoodDev/dart_pkgs.git"
846846
source: git
847847
version: "1.0.0"

app/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ dependencies:
6060
networker_socket:
6161
git:
6262
url: https://github.com/LinwoodDev/dart_pkgs.git
63-
ref: ec6f31ba3eb0da17bdef6a8d66ef6caafcabd908
63+
ref: dfc9c68412354184f7e92c4c572634748d855948
6464
path: packages/networker/networker_socket
6565
swamp_api:
6666
git:

0 commit comments

Comments
 (0)