Fix optional food startup on Lobby #47
6 changed files with 145 additions and 7 deletions
42
.forgejo/workflows/lobby-food-startup.yml
Normal file
42
.forgejo/workflows/lobby-food-startup.yml
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
name: Lobby Food Startup Build
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: ['fix/lobby-food-startup-*']
|
||||
|
||||
jobs:
|
||||
lobby-food:
|
||||
runs-on: dune-ci
|
||||
steps:
|
||||
- name: Check out exact revision
|
||||
shell: bash
|
||||
env:
|
||||
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git init .
|
||||
git -c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$REPO_TOKEN" | base64 -w0)" fetch --depth=1 https://www.dunerealms.com/git/unimatrix/plugins.git "$GITHUB_SHA"
|
||||
git checkout --detach FETCH_HEAD
|
||||
- uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: '21'
|
||||
- uses: gradle/actions/setup-gradle@v4
|
||||
with:
|
||||
gradle-version: '9.2.1'
|
||||
- name: Build Lobby listener patch
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
gradle --no-daemon -p JarvisConnector test jar
|
||||
python3 tools/test_plugin_fleet_install.py -v
|
||||
mkdir lobby-food-artifacts
|
||||
python3 tools/plugin_lobby_food.py JarvisConnector/build/libs/jarvistranslator.jar lobby-food-artifacts/lobby-food-classes.zip
|
||||
cp tools/{plugin_lobby_food,install-plugin-fleet,write-plugin-manifest,plugin_menu_pack,plugin_backend_abi,plugin_fleet_rollback,plugin_pack_properties,plugin_pillager_abi}.py lobby-food-artifacts/
|
||||
printf '%s\n' "$(git rev-parse HEAD)" > lobby-food-artifacts/SOURCE_COMMIT
|
||||
(cd lobby-food-artifacts && sha256sum -- lobby-food-classes.zip *.py SOURCE_COMMIT > SHA256SUMS)
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: DuneRealms-Lobby-Food-Startup
|
||||
path: lobby-food-artifacts/
|
||||
if-no-files-found: error
|
||||
|
|
@ -37,6 +37,7 @@ final class ArrakisBrewing implements Listener {
|
|||
meta.getPersistentDataContainer().set(BOOSTED,PersistentDataType.BYTE,(byte)1);item.setItemMeta(meta);return item;
|
||||
}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void loaded(ServerLoadEvent event){
|
||||
if(SurvivalFoodRecipes.lobbyProfile(plugin))return;
|
||||
try{water=recipes.nativeItem("jerboa_water_vial");life=recipes.nativeItem("water_of_life");metadata.stamp(water);metadata.stamp(life);
|
||||
var brewer=Bukkit.getPotionBrewer();brewer.removePotionMix(MIX);
|
||||
brewer.addPotionMix(new PotionMix(MIX,water,PotionMix.createPredicateChoice(item->vial(item,"blood_vial")),PotionMix.createPredicateChoice(ArrakisBrewing::spice)));
|
||||
|
|
|
|||
|
|
@ -18,12 +18,18 @@ final class SurvivalFoodRecipes implements Listener {
|
|||
private final ItemMetadataOverlay metadata;
|
||||
private static final NamespacedKey VIALS=new NamespacedKey("dunerealms","imported_water_vials");
|
||||
SurvivalFoodRecipes(Plugin plugin,ItemMetadataOverlay metadata){this.plugin=plugin;this.metadata=metadata;Bukkit.getPluginManager().registerEvents(this,plugin);}
|
||||
static boolean lobbyProfile(Plugin plugin){
|
||||
return "lobby".equalsIgnoreCase(plugin.getConfig().getString("native.server-key",
|
||||
plugin.getDataFolder().getAbsoluteFile().getParentFile().getParentFile().getName()));
|
||||
}
|
||||
@EventHandler(priority=EventPriority.HIGHEST) public void loaded(ServerLoadEvent event){
|
||||
try(var stream=plugin.getResource("survival-food-recipes.json")){
|
||||
if(stream==null)throw new IOException("Missing smoker projection policy");
|
||||
var policy=JsonParser.parseReader(new InputStreamReader(stream,StandardCharsets.UTF_8)).getAsJsonObject();if(policy.get("version").getAsInt()!=1)throw new IOException("Unsupported food policy");
|
||||
boolean lobby=lobbyProfile(plugin);
|
||||
for(var element:policy.getAsJsonArray("smoker")){
|
||||
var spec=element.getAsJsonObject();String id=spec.get("id").getAsString();var key=new NamespacedKey("dunerealms",id);int amount=spec.get("amount").getAsInt();if(amount<1||amount>64)throw new IOException("Invalid smoker quantity");
|
||||
if(lobby&&id.equals("chukka_cooked_meat")){Bukkit.removeRecipe(key);continue;}
|
||||
ItemStack result=nativeItem(spec.get("result").getAsString());result.setAmount(amount);metadata.stamp(result);
|
||||
var variants=new ArrayList<ItemStack>();
|
||||
for(ItemStack input:List.of(nativeItem(spec.get("input").getAsString()),Bukkit.getItemFactory().createItemStack(spec.get("inputCommand").getAsString()))){
|
||||
|
|
@ -33,6 +39,7 @@ final class SurvivalFoodRecipes implements Listener {
|
|||
Bukkit.removeRecipe(key);if(!Bukkit.addRecipe(new SmokingRecipe(key,result,new RecipeChoice.ExactChoice(variants),.35f,100)))throw new IOException("Native smoker recipe rejected: "+id);
|
||||
}
|
||||
plugin.getLogger().info("Survival food smoker recipes registered; native fuel, hoppers and shift extraction retained.");
|
||||
if(lobby){Bukkit.removeRecipe(VIALS);return;}
|
||||
var vials=nativeItem("jerboa_water_vial");metadata.stamp(vials);vials.setAmount(6);
|
||||
Bukkit.removeRecipe(VIALS);var imported=new ShapelessRecipe(VIALS,vials);imported.addIngredient(Material.WATER_BUCKET);if(!Bukkit.addRecipe(imported))throw new IOException("Imported water recipe rejected");
|
||||
}catch(IOException|ReflectiveOperationException|RuntimeException failure){throw new IllegalStateException("Survival food recipe projection unavailable",failure);}
|
||||
|
|
|
|||
|
|
@ -75,9 +75,10 @@ def verify_dunechest_fleet_target(sid, root, unit, incoming, installed):
|
|||
|
||||
def plan(artifacts, inventory, expected_source):
|
||||
mode=inventory.get('mode')
|
||||
if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa','compact-menus'}:
|
||||
if mode not in {'gui-preserve-backends','pillager-preserve-economy','arrakis-crysknife','navigator','planet-dunechest','fleet-dunechest','arrakis-raw-spice','arrakis-jerboa','compact-menus','lobby-food'}:
|
||||
raise ValueError('An explicit supported rollout mode is required')
|
||||
compact_menus=mode=='compact-menus'
|
||||
lobby_food=mode=='lobby-food'
|
||||
jerboa=mode=='arrakis-jerboa'
|
||||
raw_spice=mode=='arrakis-raw-spice'
|
||||
pillager=mode=='pillager-preserve-economy'
|
||||
|
|
@ -98,10 +99,10 @@ def plan(artifacts, inventory, expected_source):
|
|||
raise ValueError('Compact menus require retaining the current resource pack')
|
||||
if jerboa:
|
||||
allowed_names={'DuneTerrain'}
|
||||
if raw_spice:
|
||||
if raw_spice or lobby_food:
|
||||
allowed_names={'JarvisTranslator'}
|
||||
if inventory.get('menuPack') is not None:
|
||||
raise ValueError('Raw spice rollout must retain current resource pack configuration')
|
||||
raise ValueError('Scoped JARVIS rollout must retain current resource pack configuration')
|
||||
files, names = {}, set()
|
||||
for entry in manifest['plugins']:
|
||||
name = entry['filename']
|
||||
|
|
@ -168,7 +169,7 @@ def plan(artifacts, inventory, expected_source):
|
|||
uses_menu=not compact_menus and ('dunemenus' in wanted or bool(menu and menu.get('unified') and not (crysknife or dunechest or jerboa)))
|
||||
if menu and menu.get('unified') and not (crysknife or dunechest or jerboa) and 'dunerealmsgui' not in wanted:
|
||||
raise ValueError('Unified pack rollout must select its matching DunerealmsGUI adapter')
|
||||
if not (pillager or crysknife or navigator or dunechest or raw_spice or jerboa) and wanted - {'dunemenus','dunerealmsgui','dunenpc','dunelobby','mcgui'}:
|
||||
if not (pillager or crysknife or navigator or dunechest or raw_spice or jerboa or lobby_food) and wanted - {'dunemenus','dunerealmsgui','dunenpc','dunelobby','mcgui'}:
|
||||
raise ValueError('GUI rollout must retain working Ess/JARVIS/Core/Terrain binaries')
|
||||
if compact_menus:
|
||||
expected_root = Path('/opt/dunerealms/lobby') if sid == 'lobby' else Path('/opt/dunerealms/servers') / sid
|
||||
|
|
@ -181,6 +182,9 @@ def plan(artifacts, inventory, expected_source):
|
|||
if raw_spice and (sid != 'arrakis' or root != ARRAKIS_ROOT or unit != 'dune-arrakis.service'
|
||||
or wanted != {'jarvistranslator'} or selected_prerequisites):
|
||||
raise ValueError('Raw spice rollout may only replace JARVIS on Arrakis')
|
||||
if lobby_food and (sid != 'lobby' or root != Path('/opt/dunerealms/lobby') or unit != 'dune-lobby.service'
|
||||
or wanted != {'jarvistranslator'} or selected_prerequisites):
|
||||
raise ValueError('Lobby food rollout may only replace JARVIS on Lobby')
|
||||
if crysknife and (
|
||||
sid != 'arrakis' or unit != 'dune-arrakis.service'
|
||||
or root != ARRAKIS_ROOT
|
||||
|
|
@ -366,6 +370,15 @@ def plan(artifacts, inventory, expected_source):
|
|||
replaced = {entry['filename'] for entry in previous}
|
||||
retained = [{'filename': path.name, 'sha256': digest(path), 'metadata': metadata(path)}
|
||||
for path in sorted(plugins.glob('*.jar')) if path.name not in replaced]
|
||||
if lobby_food:
|
||||
from plugin_lobby_food import verify_candidate
|
||||
installed = existing_paths.get('jarvistranslator')
|
||||
if installed is None:
|
||||
raise ValueError('Lobby food rollout requires the retained Lobby JARVIS')
|
||||
verify_candidate(installed, chosen[0]['source'], artifacts, expected_source)
|
||||
replaced = {entry['filename'] for entry in previous}
|
||||
retained = [{'filename': path.name, 'sha256': digest(path), 'metadata': metadata(path)}
|
||||
for path in sorted(plugins.glob('*.jar')) if path.name not in replaced]
|
||||
configurations = []
|
||||
if uses_menu or crysknife or dunechest or jerboa:
|
||||
if menu is None:
|
||||
|
|
|
|||
|
|
@ -55,11 +55,13 @@
|
|||
"JarvisTranslator": {
|
||||
"version": "0.5.39-rawspice1",
|
||||
"changedClasses": [
|
||||
"com/dunerealms/jarvis/ArrakisBrewing.class",
|
||||
"com/dunerealms/jarvis/GuildTransport.class",
|
||||
"com/dunerealms/jarvis/ItemMetadataOverlay.class",
|
||||
"com/dunerealms/jarvis/JarvisTranslator.class",
|
||||
"com/dunerealms/jarvis/OrganisationTransport.class",
|
||||
"com/dunerealms/jarvis/SharedGameApi.class"
|
||||
"com/dunerealms/jarvis/SharedGameApi.class",
|
||||
"com/dunerealms/jarvis/SurvivalFoodRecipes.class"
|
||||
],
|
||||
"baselines": {
|
||||
"663c28c5fb246b3d5c14b2faeaf0b6c000e38a53b3d45459221e4d3b85f242c3": {
|
||||
|
|
@ -68,13 +70,13 @@
|
|||
"com/dunerealms/jarvis/CrysknifeRules.class",
|
||||
"com/dunerealms/jarvis/HomeSmugglerTransport.class"
|
||||
],
|
||||
"retainedTreeSha256": "fa0170f6f542233abc3b918e18fdd5dd40f18f1731792a9cf9237387075b8b0f"
|
||||
"retainedTreeSha256": "8911416b818c4353b1fa582e9cd60e7e9155eebe4c1128b78d36e8e673e116eb"
|
||||
},
|
||||
"1128d8d1a9ab7b0d257089e52c46c9a7dc6096e3b8bfbf241169474d503ee5ab": {
|
||||
"addedClasses": [
|
||||
"com/dunerealms/jarvis/HomeSmugglerTransport.class"
|
||||
],
|
||||
"retainedTreeSha256": "dadf275ef5f27a9a8cba75d80ef3d1a58958c0eb75a767b8b9fb94d30059f891"
|
||||
"retainedTreeSha256": "a2d03421445554b59dd6631282ce8a7f483ad131d9e797e529192f289f864f75"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
73
tools/plugin_lobby_food.py
Normal file
73
tools/plugin_lobby_food.py
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import argparse
|
||||
import hashlib
|
||||
from pathlib import Path
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
|
||||
|
||||
BASELINE = '5c632e3db85fc58e55c1917b29916ef1865b3c9eca3e3e70b9131ef44dad1aaf'
|
||||
CLASSES = tuple(f'com/dunerealms/jarvis/{name}.class'
|
||||
for name in ('ArrakisBrewing', 'SurvivalFoodRecipes'))
|
||||
|
||||
|
||||
def unique_names(archive):
|
||||
names = archive.namelist()
|
||||
if len(names) != len(set(names)):
|
||||
raise ValueError('Duplicate archive entry')
|
||||
return set(names)
|
||||
|
||||
|
||||
def extract(compiled, output):
|
||||
with ZipFile(compiled) as jar, ZipFile(output, 'x', ZIP_DEFLATED) as patch:
|
||||
unique_names(jar)
|
||||
for name in CLASSES:
|
||||
patch.writestr(name, jar.read(name))
|
||||
|
||||
|
||||
def assemble(baseline, patch, output):
|
||||
if hashlib.sha256(baseline.read_bytes()).hexdigest() != BASELINE:
|
||||
raise ValueError('Expected the exact retained Lobby JARVIS baseline')
|
||||
with ZipFile(baseline) as original, ZipFile(patch) as updates:
|
||||
names = unique_names(original)
|
||||
if unique_names(updates) != set(CLASSES) or not set(CLASSES) <= names:
|
||||
raise ValueError('Expected only the two reviewed Lobby recipe listeners')
|
||||
replacements = {name: updates.read(name) for name in CLASSES}
|
||||
if any(not data.startswith(b'\xca\xfe\xba\xbe') or data == original.read(name)
|
||||
for name, data in replacements.items()):
|
||||
raise ValueError('Invalid or unchanged Lobby listener class')
|
||||
with ZipFile(output, 'x', ZIP_DEFLATED) as candidate:
|
||||
for entry in original.infolist():
|
||||
data = replacements[entry.filename] if entry.filename in replacements else original.read(entry)
|
||||
candidate.writestr(entry, data)
|
||||
|
||||
|
||||
def verify_candidate(baseline, candidate, artifact, source):
|
||||
expected_names = {'lobby-food-classes.zip', 'plugin_lobby_food.py', 'SOURCE_COMMIT',
|
||||
'install-plugin-fleet.py', 'write-plugin-manifest.py', 'plugin_menu_pack.py',
|
||||
'plugin_backend_abi.py', 'plugin_fleet_rollback.py', 'plugin_pack_properties.py',
|
||||
'plugin_pillager_abi.py'}
|
||||
sums = dict(line.split(' ', 1)[::-1] for line in (artifact / 'SHA256SUMS').read_text().splitlines())
|
||||
if sums.keys() != expected_names or any(
|
||||
hashlib.sha256((artifact / name).read_bytes()).hexdigest() != sha for name, sha in sums.items()
|
||||
) or (artifact / 'SOURCE_COMMIT').read_text().strip() != source:
|
||||
raise ValueError('Lobby listener patch does not match the selected source and checksums')
|
||||
if hashlib.sha256(baseline.read_bytes()).hexdigest() != BASELINE:
|
||||
raise ValueError('Expected the exact retained Lobby JARVIS baseline')
|
||||
with ZipFile(baseline) as original, ZipFile(candidate) as incoming, ZipFile(artifact / 'lobby-food-classes.zip') as updates:
|
||||
if unique_names(updates) != set(CLASSES) or unique_names(incoming) != unique_names(original):
|
||||
raise ValueError('Unexpected Lobby JARVIS archive contents')
|
||||
for name in incoming.namelist():
|
||||
expected = updates.read(name) if name in CLASSES else original.read(name)
|
||||
if incoming.read(name) != expected:
|
||||
raise ValueError(f'Unexpected Lobby JARVIS entry: {name}')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('input', type=Path)
|
||||
parser.add_argument('output', type=Path)
|
||||
parser.add_argument('--baseline', type=Path)
|
||||
args = parser.parse_args()
|
||||
if args.baseline is None:
|
||||
extract(args.input, args.output)
|
||||
else:
|
||||
assemble(args.baseline, args.input, args.output)
|
||||
Loading…
Reference in a new issue

Staff