Use owner's requested twenty chunk view distance
All checks were successful
Lobby Arrakis View Distance / configuration (push) Successful in 5s
DuneRealms Plugin CI / plugins (push) Successful in 3m5s

This commit is contained in:
unimatrixgit 2026-11-30 18:04:05 +01:00
commit c1bc8b7df7
2 changed files with 7 additions and 7 deletions

View file

@ -1,4 +1,4 @@
"""Set only Lobby's lobby_arrakis view-distance to ten chunks."""
"""Set only Lobby's lobby_arrakis view-distance to twenty chunks."""
import argparse,datetime,hashlib,json,os,re,stat,subprocess,tempfile
from pathlib import Path
ROOT=Path('/opt/dunerealms/lobby')
@ -19,9 +19,9 @@ def patch(data):
if values:
at=values[0];m=re.fullmatch(r' view-distance: (default|[0-9]+)\s*\r?\n?',lines[at])
if not m:raise ValueError('Unsupported world view-distance value')
previous=m[1];lines[at]=' view-distance: 10'+newline
else:previous='inherited';lines.insert(a,' view-distance: 10'+newline)
else:previous='inherited';lines[end:end]=[' lobby_arrakis:'+newline,' view-distance: 10'+newline]
previous=m[1];lines[at]=' view-distance: 20'+newline
else:previous='inherited';lines.insert(a,' view-distance: 20'+newline)
else:previous='inherited';lines[end:end]=[' lobby_arrakis:'+newline,' view-distance: 20'+newline]
return ''.join(lines).encode('utf-8'),previous
def control(*args):return subprocess.run(['systemctl',*args],capture_output=True,text=True,check=False)
def write(path,data,meta):
@ -35,7 +35,7 @@ def main():
target=ROOT/'spigot.yml';world=ROOT/'lobby_base/dimensions/minecraft/lobby_arrakis'
if target.is_symlink() or not target.is_file() or not world.is_dir() or world.is_symlink():raise ValueError('Verified Lobby world/config missing')
before=target.read_bytes();after,previous=patch(before);meta=target.stat()
result={'world':'lobby_arrakis','viewDistance':10,'previousOverride':previous,'beforeSha256':sha(before),'afterSha256':sha(after),'applied':False}
result={'world':'lobby_arrakis','viewDistance':20,'previousOverride':previous,'beforeSha256':sha(before),'afterSha256':sha(after),'applied':False}
if args.apply and before!=after:
state=control('show',UNIT,'--property=ActiveState','--value').stdout.strip()
if state not in ('active','inactive'):raise ValueError('Lobby service is in transition')

View file

@ -4,10 +4,10 @@ spec=importlib.util.spec_from_file_location('view',Path(__file__).with_name('lob
class WorldViewDistance(unittest.TestCase):
def test_adds_only_world_override(self):
before=b'# header\nworld-settings:\n default:\n view-distance: default\n simulation-distance: default\n guild_lobby:\n view-distance: 4\nsettings:\n save-user-cache-on-stop-only: false\n'
after,prior=module.patch(before);self.assertEqual(prior,'inherited');self.assertEqual(after.replace(b' lobby_arrakis:\n view-distance: 10\n',b''),before);self.assertEqual(module.patch(after)[0],after)
after,prior=module.patch(before);self.assertEqual(prior,'inherited');self.assertEqual(after.replace(b' lobby_arrakis:\n view-distance: 20\n',b''),before);self.assertEqual(module.patch(after)[0],after)
def test_preserves_other_world_values_and_line_endings(self):
before=b'world-settings:\r\n lobby_arrakis:\r\n view-distance: 5\r\n simulation-distance: 3\r\n other:\r\n view-distance: 7\r\n'
after,prior=module.patch(before);self.assertEqual(prior,'5');self.assertEqual(after,before.replace(b'view-distance: 5',b'view-distance: 10'))
after,prior=module.patch(before);self.assertEqual(prior,'5');self.assertEqual(after,before.replace(b'view-distance: 5',b'view-distance: 20'))
def test_ambiguous_config_refused(self):
for value in (b'world-settings:\n lobby_arrakis:\n lobby_arrakis:\n',b'world-settings:\n lobby_arrakis:\n view-distance: 5\n view-distance: 7\n',b'world-settings:\nworld-settings:\n'):
with self.assertRaises(ValueError):module.patch(value)