예제 #1
0
def omega_manager(directory):
    cfg = None
    with file_writing.f_open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/omega/manager.cfg')) as f:
        cfg = json.load(f)
    cfg['steam'] = {
        'username': auth.get()['steam']['username'],
        'api_key': auth.get()['steam']['api_key'],
        'password': auth.get()['steam']['password'],
        'mobile_authenticator': False
    }
    with file_writing.f_open(pathlib.Path(directory, 'manager.cfg'),
                             mode='w') as f:
        json.dump(cfg, f, indent=2)
예제 #2
0
def priority_queue(directory):
    users = []
    for priority_user in auth.get().get('priority', []):
        users.append(priority_user['steam64'])
        log.info('adding {} to priority queue'.format(priority_user['name']))
    with file_writing.f_open(pathlib.Path(directory, 'priority.txt'), mode='w') as f:
        f.writelines(user + ';' for user in users)
예제 #3
0
def trader_objects_config(directory):
    to = objects.Config()
    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/mods/trader/locations.json')) as f:
        locations = json.load(f)
    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/mods/trader/outfits.json')) as f:
        outfits = json.load(f)
    for name, l_config in locations.items():
        log.info('processing {}'.format(name))
        for trader_name, t in l_config.items():
            new_trader = objects.Trader(t.get('marker'), t.get('location'),
                                        t.get('safezone', 200))
            new_object = objects.Object(
                outfits.get(trader_name).get('class'), t.get('location'),
                t.get('o'))
            for attachment in outfits.get(trader_name).get('attachments'):
                new_object.attachments.append(objects.Attachment(attachment))
            if 'vehicle' in t:
                raw_vehicle = t.get('vehicle')
                new_trader.set_vehicle(
                    objects.Vehicle(raw_vehicle.get('location'),
                                    raw_vehicle.get('o')))
                to.objects.extend(
                    get_cones_for_vehicle(raw_vehicle.get('location'),
                                          raw_vehicle.get('o')))
            to.traders.append(new_trader)
            to.objects.append(new_object)

    with file_writing.f_open(pathlib.Path(directory, 'TraderObjects.txt'),
                             mode='w') as f:
        f.write(to.generate())
예제 #4
0
def remove_spawns_outside_radius(directory):
    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/server/types_universal.json')) as f:
        type_universal_config = json.load(f)
    radius = type_universal_config.get('limit_spawn_locations_radius', 0)
    if radius <= 0:
        return
    p = pathlib.Path(deploydir.get(), 'mpmissions', mission.get(),
                     'mapgrouppos.xml')
    count = 0
    areas = list(mark[1] for mark in locations.marks[:4])
    mapgroups = ElementTree.parse(p).getroot()
    for group in mapgroups.findall('.//group'):
        raw = group.get('pos')
        # log.info('{} {}'.format(group.get('name'), raw))
        x, y, z = (float(i) for i in raw.split(' '))
        is_good = False
        for position in areas:
            if locations.overlaps(position, radius, x, z, 1):
                is_good = True
        if not is_good:
            mapgroups.remove(group)
            count += 1
            log.debug('removed group {}, {}, {}'.format(
                group.get('name'), x, z))

    if count > 0:
        log.info('removed {} groups from {}'.format(count, p.name))
    with file_writing.f_open(pathlib.Path(directory, p.name), mode='w') as f:
        f.write(file_writing.convert_to_string(mapgroups))
예제 #5
0
def spawnable_types_config(directory):
    """
    This configuration operates in an overriding fashion. That is, if a preset or list of items is specified
    for a type in the config, any existing entries for that type with the same tag and attribute will be erased.
    """
    p = pathlib.Path(deploydir.get(), 'mpmissions', mission.get(), 'cfgspawnabletypes.xml')
    with open(p) as f:
        # The parser in ElementTree was having trouble with the comments in the xml file
        # So, we're removing them manually beforehand
        raw = f.read()
        raw = re.sub(r'<!--.*-->', '', raw)
        spawnable_xml = ElementTree.fromstring(raw)
    with open(pathlib.Path(resourcesdir.get(), 'modifications/server/spawnable_types.json')) as f:
        spawnable_modifications = json.load(f)
    for type_config in spawnable_modifications:
        if len(db_types.get().getroot().findall('.//type[@name="{}"]'.format(type_config.get('type')))) == 0:
            continue
        types = spawnable_xml.findall('.//type[@name="{}"]'.format(type_config.get('type')))
        if len(types) == 0:
            new_type = ElementTree.SubElement(spawnable_xml, 'type', dict(name=type_config.get('type')))
            types = [new_type]
        for t in types:
            if 'cargo_presets' in type_config:
                handle_presets(t, 'cargo', type_config.get('cargo_presets'))
            if 'attachments_presets' in type_config:
                handle_presets(t, 'attachments', type_config.get('attachments_presets'))
            if 'cargo_items' in type_config:
                handle_items(t, 'cargo', type_config.get('cargo_items'))
            if 'attachments' in type_config:
                handle_items(t, 'attachments', type_config.get('attachments'))
    with file_writing.f_open(pathlib.Path(directory, 'cfgspawnabletypes.xml'), mode='w') as f:
        f.write(file_writing.convert_to_string(spawnable_xml))
예제 #6
0
def trader_items(directory):
    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/mods/trader/inventory.json')) as f:
        inventory = json.load(f)

    traders_config = config.Config()
    trader_names = [
        TraderName.AUTO, TraderName.CLOTHING, TraderName.FOOD,
        TraderName.WEAPONS, TraderName.ACCESSORIES, TraderName.TOOLS,
        TraderName.BM
    ]
    traders = {}

    for trader_name in trader_names:
        categories = inventory.get(trader_name, list())
        current_trader = config.Trader(trader_name)
        traders[trader_name] = current_trader
        traders_config.traders.append(current_trader)
        for category in categories:
            new_category = config.Category(category.get('category'))
            current_trader.categories.append(new_category)
            build_category(new_category, category)
            log.info('added {} items to {}'.format(len(
                new_category.items), (trader_name, new_category.name)))

    add_dynamic(traders)

    with file_writing.f_open(pathlib.Path(directory, 'TraderConfig.txt'),
                             mode='w') as f:
        f.write(traders_config.generate())
예제 #7
0
def random_presets_config(directory):
    p = pathlib.Path(deploydir.get(), 'mpmissions', mission.get(),
                     'cfgrandompresets.xml')
    with open(p) as f:
        # The parser in ElementTree was having trouble with the comments in the xml file
        # So, we're removing them manually beforehand
        raw = f.read()
        raw = re.sub(r'<!--.*-->', '', raw)
        presets_xml = ElementTree.fromstring(raw)
    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/server/random_presets.json')) as f:
        presets_modifications = json.load(f)
    for entry in presets_modifications:
        if 'cargo' in entry:
            cargo = entry.get('cargo')
            if 'chance' in entry:
                for preset in presets_xml.findall(
                        f'.//cargo[@name="{cargo}"]'):
                    preset.set('chance', entry.get('chance'))
            for item in entry.get('items'):
                for preset in presets_xml.findall(
                        './/cargo[@name="{}"]//item[@name="{}"]'.format(
                            cargo, item.get('name'))):
                    preset.set('chance', item.get('chance'))
        if 'attachments' in entry:
            attachments = entry.get('attachments')
            for item in entry.get('items'):
                for preset in presets_xml.findall(
                        './/attachments[@name="{}"]//item[@name="{}"]'.format(
                            attachments, item.get('name'))):
                    preset.set('chance', item.get('chance'))
    with file_writing.f_open(pathlib.Path(directory, 'cfgrandompresets.xml'),
                             mode='w') as f:
        f.write(file_writing.convert_to_string(presets_xml))
예제 #8
0
def cf_tools_config(directory):
    cfg = {
        'service_api_key': auth.get()['cf']['service_api_key'],
        'service_id': auth.get()['cf']['service_id']
    }
    with file_writing.f_open(pathlib.Path(directory, 'cftools.cfg'),
                             mode='w') as f:
        json.dump(cfg, f, indent=2)
예제 #9
0
def globals_config(directory):
    globals_xml = ElementTree.parse(
        pathlib.Path(deploydir.get(), 'mpmissions', mission.get(), 'db/globals.xml'))
    with open(pathlib.Path(resourcesdir.get(), 'modifications/server/globals.json')) as f:
        globals_modifications = json.load(f)
    for k, v in globals_modifications.items():
        item = globals_xml.getroot().find('.//var[@name="{}"]'.format(k))
        item.set('value', str(v))
    with file_writing.f_open(pathlib.Path(directory, 'globals.xml'), mode='w') as f:
        f.write(file_writing.convert_to_string(globals_xml.getroot()))
예제 #10
0
def trader_file_and_admins(directory):
    files = ['TraderVariables.txt', 'TraderVehicleParts.txt']
    for file in files:
        p = pathlib.Path('resources/original-mod-files/Trader', file)
        file_writing.copy(p, directory)
    with file_writing.f_open(pathlib.Path(directory, 'TraderAdmins.txt'),
                             mode='w') as f:
        for superuser in auth.get().get('superusers', []):
            log.info('adding {} as trader admin'.format(superuser['name']))
            f.write(superuser['steam64'] + '\n')
        f.write('<FileEnd>')
예제 #11
0
def code_lock(directory):
    new_type = ElementTree.parse('resources/original-mod-files/Code lock/types.xml')
    types.get().getroot().append(new_type.getroot())

    with open('resources/original-mod-files/Code lock/CodeLockConfig.json') as f:
        code_lock_config = json.load(f)
    code_lock_config['CanAttachToTents'] = 'true'
    code_lock_config['DestroyTool'] = 'true'
    with file_writing.f_open(pathlib.Path(directory, 'CodeLockConfig.json'), mode='w') as f:
        json.dump(code_lock_config, f, indent=2)
    users = []
    for superuser in auth.get().get('superusers', []):
        users.append({
            'playerId': superuser['steam64'],
            'playerPerms': {
                'CanOpenLocks': "true",
                'CanChangePasscodes': "true",
                'CanRemoveLocks': "true"
            }
        })
        log.info('adding {} as code lock admin'.format(superuser['name']))
    with file_writing.f_open(pathlib.Path(directory, 'CodeLockPerms.json'), mode='w') as f:
        json.dump(users, f, indent=2)
예제 #12
0
def simple_base_profile(directory):
    with open('resources/original-mod-files/Simple Base/types.xml') as f:
        raw = '<types>' + f.read() + '</types>'
        new_types = ElementTree.fromstring(raw)
    types.get().getroot().extend(new_types)
    with open('resources/original-mod-files/Simple Base/ServerProfileFolder/SimpleBase/config.txt') as f:
        lines = f.readlines()
    config = model.Config()
    config.parse_defaults(lines)
    with open(pathlib.Path(resourcesdir.get(), 'modifications/mods/simple_base/config.json')) as f:
        changes = json.load(f)
    for k, v in changes.items():
        config.set(k, v)
    with file_writing.f_open(pathlib.Path(directory, 'config.txt'), mode='w') as f:
        f.write(config.generate())
예제 #13
0
def territory_config(directory):
    with open(pathlib.Path(resourcesdir.get(), 'modifications/server/territories.json')) as f:
        territories_modifications = json.load(f)
    for p in pathlib.Path(deploydir.get(), 'mpmissions', mission.get(), 'env').glob('*.xml'):
        filename = p.name
        territory = ElementTree.parse(p).getroot()

        if filename in territories_modifications.get('ratio', dict()):
            ratio = territories_modifications.get('ratio').get(filename)
            log.info('applying ratio of {} to {}'.format(ratio, filename))
            for zone in territory.findall('.//zone'):
                dmin = zone.get('dmin')
                dmax = zone.get('dmax')
                zone.set('dmin', str(math.floor(int(dmin) * ratio)))
                zone.set('dmax', str(math.floor(int(dmax) * ratio)))

        if filename in territories_modifications.get('radius_ratio', dict()):
            ratio = territories_modifications.get('radius_ratio').get(filename)
            log.info('applying radius ratio of {} to {}'.format(ratio, filename))
            for zone in territory.findall('.//zone'):
                r = zone.get('r')
                zone.set('r', str(math.floor(float(r) * ratio)))

        if filename in territories_modifications.get('blanket', dict()):
            params = territories_modifications.get('blanket').get(filename)
            new_territory = ElementTree.Element('territory', attrib=dict(color='1910952871'))
            count = 0
            for x in range(500, 12600, 1000):
                for z in range(3750, 14850, 1000):
                    count += 1
                    ElementTree.SubElement(new_territory, 'zone', attrib={
                        'name': params.get('name'),
                        'smin': '0',
                        'smax': '0',
                        'dmin': params.get('dmin'),
                        'dmax': params.get('dmax'),
                        'x': str(x),
                        'z': str(z),
                        'r': '500'
                    })
            territory.append(new_territory)
            log.info('added {} zones in a blanket to {}'.format(count, filename))

        if '@Trader' in mods.get():
            remove_zones_if_near_traders(territory, filename)

        with file_writing.f_open(pathlib.Path(directory, filename), mode='w') as f:
            f.write(file_writing.convert_to_string(territory))
예제 #14
0
def omega_config(directory):
    with open(
            pathlib.Path(resourcesdir.get(),
                         'modifications/omega/omega.json')) as f:
        cfg = json.load(f)
    cfg['cftools']['service_api_key'] = auth.get()['cf']['service_api_key']
    cfg['cftools']['service_id'] = auth.get()['cf']['service_id']
    cfg['general']['pre_execution_script'] = {
        'enabled': True,
        'execution_time_limit': 10,
        'path': auth.get()['preexec']['path']
    }
    with open(pathlib.Path(resourcesdir.get(),
                           'modifications/omega/mods.json')) as f:
        mods_config = json.load(f)
    cfg['mods'] = mods_config
    with file_writing.f_open(pathlib.Path(directory, 'omega.cfg'),
                             mode='w') as f:
        json.dump(cfg, f, indent=2)
예제 #15
0
def events_config(directory):
    events_xml = ElementTree.parse(
        pathlib.Path(deploydir.get(), 'mpmissions', mission.get(), 'db/events.xml'))
    with open(pathlib.Path(resourcesdir.get(), 'modifications/server/events.json')) as f:
        events_modifications = json.load(f)
    for mod in events_modifications:
        name_re = re.compile(mod.get('name'))
        for event in events_xml.getroot():
            if name_re.match(event.get('name')):
                ratio = mod.get('ratio')
                if ratio > 0:
                    event.find('active').text = '1'
                    for item in ('nominal',):
                        i = event.find(item)
                        i.text = str(math.floor(max(1, int(i.text)) * ratio))
                else:
                    event.find('active').text = '0'
    with file_writing.f_open(pathlib.Path(directory, 'events.xml'), mode='w') as f:
        f.write(file_writing.convert_to_string(events_xml.getroot()))
예제 #16
0
def remove_building_spawns_near_traders(directory):
    p = pathlib.Path(deploydir.get(), 'mpmissions', mission.get(), 'mapgrouppos.xml')
    count = 0
    mapgroups = ElementTree.parse(p).getroot()
    for group in mapgroups.findall('.//group'):
        raw = group.get('pos')
        # log.info('{} {}'.format(group.get('name'), raw))
        x, y, z = (float(i) for i in raw.split(' '))
        clean_traders = (mark[1] for mark in locations.marks[:4])
        for position in clean_traders:
            if locations.overlaps(position, 200, x, z, 1):
                find_string = './/group[@pos="{}"]...'.format(raw)
                parents = mapgroups.findall(find_string)
                for parent in parents:
                    if group in parent:
                        count += 1
                        parent.remove(group)
                        log.debug('removed group {}, {}, {}'.format(group.get('name'), x, z))
                break
    if count > 0:
        log.info('removed {} groups from {}'.format(count, p.name))
    with file_writing.f_open(pathlib.Path(directory, p.name), mode='w') as f:
        f.write(file_writing.convert_to_string(mapgroups))
예제 #17
0
def airdrop(directory):
    with open('resources/original-mod-files/Airdrop/AirdropSettings.json') as f:
        airdrop_settings = json.load(f)
    with open(pathlib.Path(resourcesdir.get(), 'modifications/mods/airdrop/modifications.json')) as f:
        airdrop_setting_modifications = json.load(f)
    # http://games.digiacom.com/Airdrop_Server_Guide.pdf
    for setting in ('Controls', 'Map', 'Aircraft', 'Messages', 'Container'):
        for k, v in airdrop_setting_modifications.get(setting).items():
            airdrop_settings[setting][k] = v

    drops = []
    drop_defaults = airdrop_setting_modifications.get('DropZoneDefaults')
    for drop in airdrop_setting_modifications.get('DropZones'):
        drops.append({**drop, **drop_defaults})
    airdrop_settings['DropZones'] = drops

    drop_types = []
    drop_type_defaults = airdrop_setting_modifications.get('DropTypeDefaults')
    for drop_type in airdrop_setting_modifications.get('DropTypes'):
        drop_types.append({**drop_type, **drop_type_defaults})
    airdrop_settings['DropTypes'] = drop_types

    with file_writing.f_open(pathlib.Path(directory, 'AirdropSettings.json'), mode='w') as f:
        json.dump(airdrop_settings, f, indent=2)
예제 #18
0
def vanilla_plus_plus_map(directory):
    with file_writing.f_open(pathlib.Path(directory, 'VPPMapConfig.json'),
                             mode='w') as f:
        json.dump(model.get_config(), f, indent=2)
예제 #19
0
def sort_and_write_types_config(directory):
    types.get().getroot()[:] = sorted(types.get().getroot(), key=lambda child: child.get('name').lower())
    with file_writing.f_open(pathlib.Path(directory, 'types.xml'), mode='w') as f:
        f.write(file_writing.convert_to_string(types.get().getroot()))