vq3srv, config.example.yml: more mod support, set vars from command line

This commit is contained in:
Von Random 2021-02-19 23:43:01 +03:00
parent 10009f0337
commit 582dc79ac7
2 changed files with 17 additions and 8 deletions

View file

@ -1,6 +1,6 @@
user: quake3 user: quake3
cmd: /opt/ioquake3/ioq3ded.x86_64 +exec autoexec.cfg cmd: /opt/ioquake3/ioq3ded.x86_64
autoexec: /home/quake3/.q3a/baseq3/autoexec.cfg exec: /home/quake3/.q3a/baseq3/autoexec.cfg
gamemodes: gamemodes:
ffa: ffa:
maps: [ maps: [
@ -19,6 +19,12 @@ gamemodes:
vars: vars:
fraglimit: 15 fraglimit: 15
timelimit: 5 timelimit: 5
cpma_duel:
maps: [ q3dm6 ]
vars:
sv_game: cpma
fraglimit: 15
timelimit: 15
bots: bots:
level: '3' level: '3'
names: [ names: [

13
vq3srv
View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from argparse import ArgumentParser from argparse import ArgumentParser
from os import system from os import system
from os.path import basename
from random import shuffle from random import shuffle
from sys import exit from sys import exit
from yaml import safe_load from yaml import safe_load
@ -47,7 +48,7 @@ def gen_addbots(count, level='3', names=list()):
def main(): def main():
args = parse_arguments() args = parse_arguments()
cfg_data, bvars, svars = str(), dict(), dict() cfg_data, cmd_vars, bvars, svars = str(), list(), dict(), dict()
try: try:
with open(args.config, 'r') as config_file: with open(args.config, 'r') as config_file:
cfg = safe_load(config_file) cfg = safe_load(config_file)
@ -55,6 +56,7 @@ def main():
with open(args.bootstrap, 'r') as bootstrap_file: with open(args.bootstrap, 'r') as bootstrap_file:
bvars.update(safe_load(bootstrap_file)) bvars.update(safe_load(bootstrap_file))
assert args.gamemode in cfg['gamemodes'] assert args.gamemode in cfg['gamemodes']
exec_filename = basename(cfg['exec'])
except FileNotFoundError as error: except FileNotFoundError as error:
exit('Config `{}` not found!'.format(error.filename)) exit('Config `{}` not found!'.format(error.filename))
except AssertionError: except AssertionError:
@ -66,18 +68,19 @@ def main():
svars.update({'fraglimit': args.fraglimit}) svars.update({'fraglimit': args.fraglimit})
if args.timelimit: if args.timelimit:
svars.update({'timelimit': args.timelimit}) svars.update({'timelimit': args.timelimit})
for param in bvars: for param in bvars:
cfg_data += gen_confline(param, bvars[param], archive=True) cfg_data += gen_confline(param, bvars[param], archive=True)
for param in svars: for param in svars:
cfg_data += gen_confline(param, svars[param]) cmd_vars.append('+set {} {}'.format(param, svars[param]))
cmd_vars.append('+exec {}'.format(exec_filename))
cmd_opts = ' '.join(cmd_vars)
cfg_data += gen_maplist(smaps) cfg_data += gen_maplist(smaps)
if args.bots: if args.bots:
cfg_data += gen_addbots(args.bots, **cfg['bots']) cfg_data += gen_addbots(args.bots, **cfg['bots'])
with open(cfg['autoexec'], 'w+') as config: with open(cfg['exec'], 'w+') as config:
config.write(cfg_data) config.write(cfg_data)
system('sudo -u {} {}'.format(cfg['user'], cfg['cmd'])) system('sudo -u {} {} {}'.format(cfg['user'], cfg['cmd'], cmd_opts))
if __name__ == '__main__': if __name__ == '__main__':