From b4abff51635eefd85ed99a39ad75dbfca79f4f34 Mon Sep 17 00:00:00 2001 From: CodeDoctorDE Date: Tue, 19 Nov 2024 17:13:21 +0100 Subject: [PATCH] Fix pack ids with core pack --- api/lib/src/event/process/server.dart | 11 +++++----- api/lib/src/services/asset.dart | 7 +++++-- api/pubspec.lock | 4 ++-- api/pubspec.yaml | 2 +- app/lib/bloc/world/bloc.dart | 7 ++++--- app/pubspec.lock | 8 ++++---- app/pubspec.yaml | 4 ++-- server/lib/src/asset.dart | 29 +++++++++++++-------------- server/lib/src/server.dart | 7 ++++--- server/pubspec.lock | 8 ++++---- server/pubspec.yaml | 4 ++-- 11 files changed, 48 insertions(+), 43 deletions(-) diff --git a/api/lib/src/event/process/server.dart b/api/lib/src/event/process/server.dart index 872e288e..f431dc94 100644 --- a/api/lib/src/event/process/server.dart +++ b/api/lib/src/event/process/server.dart @@ -83,16 +83,17 @@ class ServerProcessed { ServerProcessed processServerEvent( ServerWorldEvent event, WorldState state, { - required Map signature, + required List signature, }) { if (!isValidServerEvent(event, state)) return ServerProcessed(null); switch (event) { case WorldInitialized(): - final signature = event.packsSignature; - final supported = - signature == null ? true : isServerSupported(signature, signature); + final serverSignature = event.packsSignature; + final supported = serverSignature == null + ? true + : isServerSupported(signature, serverSignature); if (!supported) { - throw InvalidPacksError(signature: signature); + throw InvalidPacksError(signature: serverSignature); } return ServerProcessed(state.copyWith( table: event.table ?? state.table, diff --git a/api/lib/src/services/asset.dart b/api/lib/src/services/asset.dart index dab9b6f5..a1f65392 100644 --- a/api/lib/src/services/asset.dart +++ b/api/lib/src/services/asset.dart @@ -11,10 +11,13 @@ abstract class AssetManager { Map createSignature([Set? packs]) { final signature = {}; for (final entry in this.packs) { - if (!(packs?.contains(entry.key) ?? true)) continue; + final name = entry.key == kCorePackId + ? kCorePackId + : entry.value.createIdentifier(); + if (!(packs?.contains(name) ?? true)) continue; signature[entry.key] = SignatureMetadata( metadata: entry.value.getMetadataOrDefault(), - id: entry.value.createIdentifier(), + id: name, downloadUrls: getDownloadUrls(entry.key) ?? [], ); } diff --git a/api/pubspec.lock b/api/pubspec.lock index 514428c9..fb140858 100644 --- a/api/pubspec.lock +++ b/api/pubspec.lock @@ -340,8 +340,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker" - ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" - resolved-ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" + ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" + resolved-ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" diff --git a/api/pubspec.yaml b/api/pubspec.yaml index 5ef2e54e..c38be537 100644 --- a/api/pubspec.yaml +++ b/api/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: networker: git: url: https://github.com/LinwoodDev/dart_pkgs - ref: 5a3658cad80fcb8594b8be6f84460e77607eb959 + ref: 071e02761bf55a47bcde0cdc2a711b8ff5fbbb18 path: packages/networker/networker dart_leap: git: diff --git a/app/lib/bloc/world/bloc.dart b/app/lib/bloc/world/bloc.dart index 6b2d326f..db60bb03 100644 --- a/app/lib/bloc/world/bloc.dart +++ b/app/lib/bloc/world/bloc.dart @@ -11,7 +11,7 @@ import 'package:setonix/bloc/multiplayer.dart'; import 'package:setonix_api/setonix_api.dart'; ServerProcessed _compute( - (ServerWorldEvent, WorldState, Map) m) => + (ServerWorldEvent, WorldState, List) m) => processServerEvent(m.$1, m.$2, signature: m.$3); SetonixData _saveState(WorldState state) => state.save(); @@ -56,8 +56,9 @@ class WorldBloc extends Bloc { final signature = state.assetManager.createSignature(); final world = state.world; final processed = await compute< - (ServerWorldEvent, WorldState, Map), - ServerProcessed>(_compute, (event, world, signature)); + (ServerWorldEvent, WorldState, List), + ServerProcessed>( + _compute, (event, world, signature.values.toList())); final newWorld = processed.state; processed.responses.forEach(process); if (newWorld == null) return; diff --git a/app/pubspec.lock b/app/pubspec.lock index 9e97dc63..6dd519b8 100644 --- a/app/pubspec.lock +++ b/app/pubspec.lock @@ -763,8 +763,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker" - ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" - resolved-ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" + ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" + resolved-ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" @@ -772,8 +772,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker_socket" - ref: "81fcf2b6c6c3cfe5d36c948e424f4c97e1e5f88b" - resolved-ref: "81fcf2b6c6c3cfe5d36c948e424f4c97e1e5f88b" + ref: "9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c" + resolved-ref: "9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 481b54b5..6c1ec9b8 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -55,12 +55,12 @@ dependencies: networker: git: url: https://github.com/LinwoodDev/dart_pkgs - ref: 5a3658cad80fcb8594b8be6f84460e77607eb959 + ref: 071e02761bf55a47bcde0cdc2a711b8ff5fbbb18 path: packages/networker/networker networker_socket: git: url: https://github.com/LinwoodDev/dart_pkgs - ref: 81fcf2b6c6c3cfe5d36c948e424f4c97e1e5f88b + ref: 9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c path: packages/networker/networker_socket # System Information dynamic_color: ^1.7.0 diff --git a/server/lib/src/asset.dart b/server/lib/src/asset.dart index 87dde2b8..c2fe5d3b 100644 --- a/server/lib/src/asset.dart +++ b/server/lib/src/asset.dart @@ -34,28 +34,24 @@ class ServerAssetManager extends AssetManager { } await for (final file in directory.list()) { if (file is File) { - final data = SetonixData.fromData(await file.readAsBytes()); final fileName = p.basename(file.path); final extension = fileName.split('.').last; - if (extension != _stnxExtension) { - if (extension != _metadataExtension) { - console.print( - 'WARNING: Invalid pack file extension: $fileName. Skipping.', - level: LogLevel.warning); - } + if (extension != _stnxExtension && extension != _metadataExtension) { + console.print( + 'WARNING: Invalid pack file extension: $fileName. Skipping.', + level: LogLevel.warning); continue; } var name = fileName.substring(0, fileName.length - _stnxExtension.length - 1); if (name.isEmpty) name = kCorePackId; - _packs[name] = data; - - final metadataFile = - File(p.join(directory.path, '$name.$_metadataExtension')); - if (await metadataFile.exists()) { - final metadata = ServerDataMetadataMapper.fromJson( - await metadataFile.readAsString()); - _metadata[data.createIdentifier()] = metadata; + if (extension == _stnxExtension) { + final data = SetonixData.fromData(await file.readAsBytes()); + _packs[name] = data; + } else { + final metadata = + ServerDataMetadataMapper.fromJson(await file.readAsString()); + _metadata[name] = metadata; } } } @@ -79,4 +75,7 @@ class ServerAssetManager extends AssetManager { @override List? getDownloadUrls(String id) => _metadata[id]?.downloadUrls; + + Iterable getPackIds() => _packs.entries.map( + (e) => e.key == kCorePackId ? kCorePackId : e.value.createIdentifier()); } diff --git a/server/lib/src/server.dart b/server/lib/src/server.dart index 2c447a1b..52d5d7ac 100644 --- a/server/lib/src/server.dart +++ b/server/lib/src/server.dart @@ -19,7 +19,7 @@ import 'package:setonix_server/src/programs/stop.dart'; import 'events/model.dart'; Future _computeEvent(ServerWorldEvent event, WorldState state, - Map signature) { + List signature) { return Isolate.run( () => processServerEvent(event, state, signature: signature)); } @@ -52,7 +52,8 @@ final class SetonixServer extends Bloc { )) { on((event, emit) async { final signature = assetManager.createSignature(); - final processed = await _computeEvent(event, state, signature); + final processed = + await _computeEvent(event, state, signature.values.toList()); final newState = processed.state; processed.responses.forEach(process); if (newState == null) return; @@ -105,7 +106,7 @@ final class SetonixServer extends Bloc { data = SetonixData.fromData(bytes); } data ??= SetonixData.empty().setInfo(GameInfo( - packs: assetManager.packs.map((e) => e.key).toList(), + packs: assetManager.getPackIds().toList(), )); return SetonixServer._(worldFile, consoler, data, assetManager); } diff --git a/server/pubspec.lock b/server/pubspec.lock index 943ed5a7..9e2e20e8 100644 --- a/server/pubspec.lock +++ b/server/pubspec.lock @@ -373,8 +373,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker" - ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" - resolved-ref: "5a3658cad80fcb8594b8be6f84460e77607eb959" + ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" + resolved-ref: "071e02761bf55a47bcde0cdc2a711b8ff5fbbb18" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" @@ -382,8 +382,8 @@ packages: dependency: "direct main" description: path: "packages/networker/networker_socket" - ref: "81fcf2b6c6c3cfe5d36c948e424f4c97e1e5f88b" - resolved-ref: "81fcf2b6c6c3cfe5d36c948e424f4c97e1e5f88b" + ref: "9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c" + resolved-ref: "9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c" url: "https://github.com/LinwoodDev/dart_pkgs" source: git version: "1.0.0" diff --git a/server/pubspec.yaml b/server/pubspec.yaml index 8c9cd78e..ba6d6a79 100644 --- a/server/pubspec.yaml +++ b/server/pubspec.yaml @@ -13,12 +13,12 @@ dependencies: networker: git: url: https://github.com/LinwoodDev/dart_pkgs - ref: 5a3658cad80fcb8594b8be6f84460e77607eb959 + ref: 071e02761bf55a47bcde0cdc2a711b8ff5fbbb18 path: packages/networker/networker networker_socket: git: url: https://github.com/LinwoodDev/dart_pkgs - ref: 81fcf2b6c6c3cfe5d36c948e424f4c97e1e5f88b + ref: 9085d42cf75c3d3edc8edb9ef22697dbbe2bf38c path: packages/networker/networker_socket consoler: git: