From 582dc79ac7b8dca9885d3ebad7c92dc1445c61ba Mon Sep 17 00:00:00 2001 From: Von Random Date: Fri, 19 Feb 2021 23:43:01 +0300 Subject: [PATCH] vq3srv, config.example.yml: more mod support, set vars from command line --- config.example.yml | 12 +++++++++--- vq3srv | 13 ++++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/config.example.yml b/config.example.yml index 5a1f3a3..4d8e2b1 100644 --- a/config.example.yml +++ b/config.example.yml @@ -1,6 +1,6 @@ user: quake3 -cmd: /opt/ioquake3/ioq3ded.x86_64 +exec autoexec.cfg -autoexec: /home/quake3/.q3a/baseq3/autoexec.cfg +cmd: /opt/ioquake3/ioq3ded.x86_64 +exec: /home/quake3/.q3a/baseq3/autoexec.cfg gamemodes: ffa: maps: [ @@ -19,9 +19,15 @@ gamemodes: vars: fraglimit: 15 timelimit: 5 + cpma_duel: + maps: [ q3dm6 ] + vars: + sv_game: cpma + fraglimit: 15 + timelimit: 15 bots: level: '3' names: [ anarki, angel, crash, doom, hunter, klesk, major, mynx, orbb, slash, xaero - ] \ No newline at end of file + ] diff --git a/vq3srv b/vq3srv index 63f36e4..d095f2d 100755 --- a/vq3srv +++ b/vq3srv @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from argparse import ArgumentParser from os import system +from os.path import basename from random import shuffle from sys import exit from yaml import safe_load @@ -47,7 +48,7 @@ def gen_addbots(count, level='3', names=list()): def main(): args = parse_arguments() - cfg_data, bvars, svars = str(), dict(), dict() + cfg_data, cmd_vars, bvars, svars = str(), list(), dict(), dict() try: with open(args.config, 'r') as config_file: cfg = safe_load(config_file) @@ -55,6 +56,7 @@ def main(): with open(args.bootstrap, 'r') as bootstrap_file: bvars.update(safe_load(bootstrap_file)) assert args.gamemode in cfg['gamemodes'] + exec_filename = basename(cfg['exec']) except FileNotFoundError as error: exit('Config `{}` not found!'.format(error.filename)) except AssertionError: @@ -66,18 +68,19 @@ def main(): svars.update({'fraglimit': args.fraglimit}) if args.timelimit: svars.update({'timelimit': args.timelimit}) - for param in bvars: cfg_data += gen_confline(param, bvars[param], archive=True) 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) if args.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) - system('sudo -u {} {}'.format(cfg['user'], cfg['cmd'])) + system('sudo -u {} {} {}'.format(cfg['user'], cfg['cmd'], cmd_opts)) if __name__ == '__main__':