forked from unimatrix/web
26 lines
1.7 KiB
Python
26 lines
1.7 KiB
Python
import pathlib,re,json,os,stat,time,sys
|
|
mode=sys.argv[1];names=['lobby'] if mode=='lobby' else ['arrakis','caladan','giedi_prime','kaitain','sigma_draconis_iv']
|
|
sections={'revert_on_unclaim','wild_revert_on_mob_explosion','wild_revert_on_block_explosion'}
|
|
for name in names:
|
|
base=pathlib.Path('/opt/dunerealms/lobby' if mode=='lobby' else '/opt/dunerealms/servers/'+name);p=base/'plugins/Towny/settings/config.yml';text=p.read_text();out=[];stack=[];found=set()
|
|
for line in text.splitlines(keepends=True):
|
|
m=re.match(r'^( *)([a-zA-Z0-9_-]+):\s*(.*?)(\r?\n)?$',line)
|
|
if m:
|
|
indent=len(m[1]);key=m[2];value=m[3]
|
|
while stack and stack[-1][0]>=indent:stack.pop()
|
|
path=[k for _,k in stack]+[key]
|
|
if len(path)==4 and path[:2]==['new_world_settings','plot_management'] and path[2] in sections and key=='enabled':
|
|
line=m[1]+key+": 'false'\n";found.add(path[2])
|
|
if not value or value.startswith('#'):stack.append((indent,key))
|
|
out.append(line)
|
|
assert found==sections,(name,found);p.write_text(''.join(out))
|
|
worlds=list((base/'plugins/Towny/data/worlds').glob('*.txt'));commands=['townyadmin reload config']
|
|
for world in worlds:
|
|
assert re.fullmatch('[a-zA-Z0-9_-]+',world.stem)
|
|
for feature in ['revertunclaim','revertentityexpl','revertblockexpl']:commands.append('townyworld '+world.stem+' toggle '+feature+' off')
|
|
fifo=base/'console.fifo';fd=os.open(fifo,os.O_WRONLY|os.O_NONBLOCK|os.O_NOFOLLOW);assert stat.S_ISFIFO(os.fstat(fd).st_mode)
|
|
try:
|
|
for cmd in commands:
|
|
data=(cmd+'\n').encode();assert os.write(fd,data)==len(data);time.sleep(0.15)
|
|
finally:os.close(fd)
|
|
print(json.dumps({'server':name,'futureWorldDefaults':'off','worlds':[w.stem for w in worlds],'commandsSent':len(commands)}),flush=True)
|

Staff