From 8d93157ac0ea12e0e1edea874bf899aea810bad1 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 3 Jun 2024 15:19:28 -0700 Subject: [PATCH] Make it possible to change the port number of the PacketServer --- bin/client_test.dart | 2 +- bin/server_test.dart | 2 +- lib/packets/packets.dart | 12 +++++++----- pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/bin/client_test.dart b/bin/client_test.dart index 2c24380..c215f8b 100644 --- a/bin/client_test.dart +++ b/bin/client_test.dart @@ -8,7 +8,7 @@ void main() async { reg.registerDefaults(); PacketClient client = PacketClient(); - await client.startConnect("127.0.0.1"); + await client.startConnect("127.0.0.1", 25306); S2CResponse response = await client.send(C2SPing(), true); CompoundTag tag = response.contents; diff --git a/bin/server_test.dart b/bin/server_test.dart index 85e65b7..e8a4eac 100644 --- a/bin/server_test.dart +++ b/bin/server_test.dart @@ -1,5 +1,5 @@ import 'package:libac_dart/packets/packets.dart'; void main() async { - await PacketServer.start(); + await PacketServer.start(25306); } diff --git a/lib/packets/packets.dart b/lib/packets/packets.dart index d6243f7..1f6b0eb 100644 --- a/lib/packets/packets.dart +++ b/lib/packets/packets.dart @@ -11,8 +11,8 @@ import '../nbt/impl/StringTag.dart'; class PacketServer { static ServerSocket? socket; static bool shouldRestart = true; - static Future start() async { - socket = await ServerSocket.bind(InternetAddress.anyIPv4, 25306); + static Future start(int port) async { + socket = await ServerSocket.bind(InternetAddress.anyIPv4, port); print("Server now listening on port 25306"); await for (var sock in socket!) { @@ -74,14 +74,16 @@ class PacketClient { Socket? socket; bool connected = false; String lastIP = ""; + int port = 25306; PacketClient(); - Future startConnect(String IPAddress) async { + Future startConnect(String IPAddress, int port) async { try { - socket = await Socket.connect(IPAddress, 25306); + socket = await Socket.connect(IPAddress, port); connected = true; lastIP = IPAddress; + this.port = port; } catch (E, stack) { connected = false; socket = null; @@ -122,7 +124,7 @@ class PacketClient { await onCompletion.future; await close(); - await startConnect(lastIP); + await startConnect(lastIP, port); S2CResponse reply = S2CResponse(); try { reply.decodeTag(ct.get("result")!.asCompoundTag()); diff --git a/pubspec.yaml b/pubspec.yaml index 91e8c0f..98123b4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: libac_dart description: "Aria's Creations code library" -version: 1.0.22 +version: 1.0.23 homepage: "https://zontreck.com"