Skip to content

Commit

Permalink
Fix pack ids with core pack
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeDoctorDE committed Nov 19, 2024
1 parent 1d8879b commit b4abff5
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 43 deletions.
11 changes: 6 additions & 5 deletions api/lib/src/event/process/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ class ServerProcessed {
ServerProcessed processServerEvent(
ServerWorldEvent event,
WorldState state, {
required Map<String, SignatureMetadata> signature,
required List<SignatureMetadata> 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,
Expand Down
7 changes: 5 additions & 2 deletions api/lib/src/services/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ abstract class AssetManager {
Map<String, SignatureMetadata> createSignature([Set<String>? packs]) {
final signature = <String, SignatureMetadata>{};
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) ?? [],
);
}
Expand Down
4 changes: 2 additions & 2 deletions api/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions app/lib/bloc/world/bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:setonix/bloc/multiplayer.dart';
import 'package:setonix_api/setonix_api.dart';

ServerProcessed _compute(
(ServerWorldEvent, WorldState, Map<String, SignatureMetadata>) m) =>
(ServerWorldEvent, WorldState, List<SignatureMetadata>) m) =>
processServerEvent(m.$1, m.$2, signature: m.$3);

SetonixData _saveState(WorldState state) => state.save();
Expand Down Expand Up @@ -56,8 +56,9 @@ class WorldBloc extends Bloc<PlayableWorldEvent, ClientWorldState> {
final signature = state.assetManager.createSignature();
final world = state.world;
final processed = await compute<
(ServerWorldEvent, WorldState, Map<String, SignatureMetadata>),
ServerProcessed>(_compute, (event, world, signature));
(ServerWorldEvent, WorldState, List<SignatureMetadata>),
ServerProcessed>(
_compute, (event, world, signature.values.toList()));
final newWorld = processed.state;
processed.responses.forEach(process);
if (newWorld == null) return;
Expand Down
8 changes: 4 additions & 4 deletions app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -763,17 +763,17 @@ 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"
networker_socket:
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"
Expand Down
4 changes: 2 additions & 2 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 14 additions & 15 deletions server/lib/src/asset.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand All @@ -79,4 +75,7 @@ class ServerAssetManager extends AssetManager {

@override
List<String>? getDownloadUrls(String id) => _metadata[id]?.downloadUrls;

Iterable<String> getPackIds() => _packs.entries.map(
(e) => e.key == kCorePackId ? kCorePackId : e.value.createIdentifier());
}
7 changes: 4 additions & 3 deletions server/lib/src/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:setonix_server/src/programs/stop.dart';
import 'events/model.dart';

Future<ServerProcessed> _computeEvent(ServerWorldEvent event, WorldState state,
Map<String, SignatureMetadata> signature) {
List<SignatureMetadata> signature) {
return Isolate.run(
() => processServerEvent(event, state, signature: signature));
}
Expand Down Expand Up @@ -52,7 +52,8 @@ final class SetonixServer extends Bloc<PlayableWorldEvent, WorldState> {
)) {
on<ServerWorldEvent>((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;
Expand Down Expand Up @@ -105,7 +106,7 @@ final class SetonixServer extends Bloc<PlayableWorldEvent, WorldState> {
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);
}
Expand Down
8 changes: 4 additions & 4 deletions server/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -373,17 +373,17 @@ 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"
networker_socket:
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"
Expand Down
4 changes: 2 additions & 2 deletions server/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b4abff5

Please sign in to comment.