alliedmodders / stripper-source

Stripper:Source
Other
63 stars 16 forks source link

Reading configuration files with incomplete map name #18

Closed Alexeyt89 closed 2 years ago

Alexeyt89 commented 3 years ago

I suggest to add support for configuration files with incomplete map names. Example: de.cfg // Such config file would be applied for all de maps after applying global_filter.cfg and before applying configs with full name. Here is a way to implement it:

Add this code to support.cpp->parse_map after global_filters.cfg reader:

char subName[256] = "\0";
const char* mapName = map;

size_t underscoreIndex = 0;
while(underscoreIndex != 255)
{
    if(*mapName == '\0')
        break;

    subName[underscoreIndex++] = *mapName;
    if(*mapName != '_')
    {
        ++mapName;
        continue;
    }

    subName[underscoreIndex] = '\0';

    stripper_game.path_format(path,
            sizeof(path),
            "%s/%s/maps/%s.cfg",
            stripper_game.game_path,
            stripper_game.stripper_cfg_path,
            subName);

    fp = fopen(path, "rt");
    if (fp)
    {
        fclose(fp);
        g_Stripper.ApplyFileFilter(path);
    }

    break;
}
Adrianilloo commented 2 years ago

I completely second the basic idea, as I've realized the need for my server to split some edits done in global_filters.cfg as a way to cover multiple maps for a certain gamemode without happening on the rest.

But I think manually checking for underscore is a too highly coupled, non-generic approach. Instead I think it would be almost completely agreeable to replace the default pattern matching with partial searches (from the name beginning).