Skip to content

Commit 7ae869f

Browse files
committed
Finish showing kick message
1 parent ac7945c commit 7ae869f

File tree

8 files changed

+46
-32
lines changed

8 files changed

+46
-32
lines changed

app/lib/pages/game/error.dart

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ class GameErrorView extends StatelessWidget {
4141
final link = error.link;
4242
content = [
4343
Text(error.message),
44-
const SizedBox(height: 4),
44+
const SizedBox(height: 8),
4545
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-
),
46+
ConstrainedBox(
47+
constraints:
48+
const BoxConstraints(maxWidth: LeapBreakpoints.compact),
49+
child: TextFormField(
50+
initialValue: link,
51+
readOnly: true,
52+
decoration: InputDecoration(
53+
labelText: AppLocalizations.of(context).link,
54+
filled: true,
55+
suffixIcon: IconButton(
56+
icon: const Icon(PhosphorIconsLight.paperPlaneRight),
57+
onPressed: () => launchUrlString(link,
58+
mode: LaunchMode.externalApplication),
5959
),
60-
))
61-
],
60+
),
61+
),
6262
)
6363
];
6464
}
@@ -67,12 +67,12 @@ class GameErrorView extends StatelessWidget {
6767
alignment: Alignment.center,
6868
children: [
6969
const DotsBackground(),
70-
Card.filled(
70+
Card(
7171
child: Container(
7272
constraints: const BoxConstraints(
73-
maxWidth: LeapBreakpoints.large,
73+
maxWidth: LeapBreakpoints.expanded,
7474
),
75-
padding: const EdgeInsets.all(8.0),
75+
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
7676
child: SingleChildScrollView(
7777
child: Column(
7878
mainAxisSize: MainAxisSize.min,
@@ -106,7 +106,7 @@ class GameErrorView extends StatelessWidget {
106106
),
107107
],
108108
),
109-
if (state.error != null) ...[
109+
if (state.error != null && state.error is! KickMessage) ...[
110110
const SizedBox(height: 16),
111111
Text(state.error.toString()),
112112
],

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: dfc9c68412354184f7e92c4c572634748d855948
844-
resolved-ref: dfc9c68412354184f7e92c4c572634748d855948
843+
ref: "292186c11472eff9a964893b9b7c6027c000fd81"
844+
resolved-ref: "292186c11472eff9a964893b9b7c6027c000fd81"
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: dfc9c68412354184f7e92c4c572634748d855948
63+
ref: 292186c11472eff9a964893b9b7c6027c000fd81
6464
path: packages/networker/networker_socket
6565
swamp_api:
6666
git:

server/lib/src/programs/kick.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:consoler/consoler.dart';
2+
import 'package:setonix_api/event.dart';
23
import 'package:setonix_server/src/server.dart';
34

45
class KickProgram extends ConsoleProgram {
@@ -10,19 +11,28 @@ class KickProgram extends ConsoleProgram {
1011
String getDescription() => "Kick a player";
1112

1213
@override
13-
String getUsage() => 'kick <ID>';
14+
String getUsage() => 'kick <ID> [<Reason>] [<Link>]';
1415

1516
@override
1617
void run(String label, List<String> args) {
17-
if (args.length != 1) {
18+
if (args.isEmpty || args.length > 3) {
1819
server.log("Wrong usage, use ${getUsage()}", level: LogLevel.error);
1920
}
2021
final arg = int.tryParse(args[0]);
2122
if (arg == null) {
2223
server.log("ID should be a number", level: LogLevel.error);
2324
return;
2425
}
25-
final result = server.kick(arg);
26+
KickMessage? reason;
27+
if (args.length > 1) {
28+
final reasonText = args[1];
29+
final link = args.length > 2 ? args[2] : null;
30+
reason = KickMessage(
31+
message: reasonText,
32+
link: link,
33+
);
34+
}
35+
final result = server.kick(arg, reason);
2636
if (result) {
2737
server.log("$arg successfully kicked.", level: LogLevel.info);
2838
} else {

server/lib/src/programs/reset.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ResetProgram extends ConsoleProgram {
1111
"Reset the world. Specify a game mode to allow playing games.";
1212

1313
@override
14-
String getUsage() => 'reset [<World>]';
14+
String getUsage() => '[<World>]';
1515

1616
@override
1717
Future<void> run(String label, List<String> args) async {

server/lib/src/server.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import 'package:setonix_server/src/programs/say.dart';
1616
import 'package:setonix_server/src/programs/stop.dart';
1717
import 'package:setonix_plugin/setonix_plugin.dart';
1818

19+
import 'programs/kick.dart';
20+
1921
String limitOutput(Object? value, [int limit = 500]) {
2022
final string = value.toString();
2123
if (string.length > limit) {
@@ -166,6 +168,7 @@ final class SetonixServer {
166168
'players': PlayersProgram(this),
167169
'say': SayProgram(this),
168170
'reset': ResetProgram(this),
171+
'kick': KickProgram(this),
169172
null: UnknownProgram(),
170173
});
171174
}
@@ -239,10 +242,11 @@ final class SetonixServer {
239242
_onClientEvent(NetworkerPacket(event, kAuthorityChannel), force: force);
240243
}
241244

242-
bool kick(int id) {
245+
bool kick(int id, [KickMessage? reason]) {
243246
final info = _server?.getConnectionInfo(id);
244247
if (info == null) return false;
245-
info.close();
248+
info.close(WebSocketStatus.goingAway,
249+
reason?.toJson() ?? 'You have been kicked from the server.');
246250
return true;
247251
}
248252

server/pubspec.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ packages:
417417
dependency: "direct main"
418418
description:
419419
path: "packages/networker/networker_socket"
420-
ref: c296aa4e7667fad124da675f11ca543c44865a61
421-
resolved-ref: c296aa4e7667fad124da675f11ca543c44865a61
420+
ref: "292186c11472eff9a964893b9b7c6027c000fd81"
421+
resolved-ref: "292186c11472eff9a964893b9b7c6027c000fd81"
422422
url: "https://github.com/LinwoodDev/dart_pkgs.git"
423423
source: git
424424
version: "1.0.0"

server/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ dependencies:
1818
networker_socket:
1919
git:
2020
url: https://github.com/LinwoodDev/dart_pkgs.git
21-
ref: c296aa4e7667fad124da675f11ca543c44865a61
21+
ref: 292186c11472eff9a964893b9b7c6027c000fd81
2222
path: packages/networker/networker_socket
2323
consoler:
2424
git:

0 commit comments

Comments
 (0)