ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.69k stars 623 forks source link

[Feature Request] Implement quick setinfo clean method #2589

Open 2010kohtep opened 5 years ago

2010kohtep commented 5 years ago

I propose to implement the ability to quickly clear the player's userinfo, which is set by the setinfo command. The code from one of my projects that implements this feature is as follows:

char *g_info_numbers[] =
{
    "topcolor",
    "bottomcolor",
    "rate",
    "cl_updaterate",
    "cl_lw",
    "cl_lc",
};

bool IsNumberKey(char *key)
{
    for (auto &&k : g_info_numbers)
    {
        if (!_stricmp(key, k))
            return true;
    }

    return false;
}

void hkCmd_SetInfo()
{
    if (CMD_ARGC() < 2)
        return orgCmd_SetInfo();

    auto key = CMD_ARGV(1);

    if (_stricmp(key, "restore") != 0 && _stricmp(key, "clear") != 0)
        return orgCmd_SetInfo();

    memset(cls.userinfo, 0, MAX_INFO_STRING);

    auto cvars = GET_CVAR_LIST();
    while (cvars)
    {
        if (cvars->flags & FCVAR_USERINFO)
        {
            char *value;

            if (IsNumberKey(cvars->name))
                value = va("%d", atoi(cvars->string));
            else
                value = cvars->string;

            gEngine.pNetAPI->Info_SetValueForStarKey(cls.userinfo, cvars->name, value, MAX_INFO_STRING);
        }

        cvars = cvars->next;
    }

    CON_PRINTF("Setinfo restored.\n");
}

The project works as an add-on that intercepts the setinfo command handler, which explains the orgCmd_SetInfo function that points to the original setinfo callback.

afwn90cj93201nixr2e1re commented 5 years ago

if (_stricmp(key, "restore") != 0 && _stricmp(key, "clear") != 0) -> if (_stricmp(key, "restore") != 0 && _stricmp(key, "clear") != 0 && _stricmp(key, "clean") != 0 && _stricmp(key, "reset") != 0)

afwn90cj93201nixr2e1re commented 5 years ago

@kisak-valve cs label. Coz some son of beaches gonna cry 'bout that can damage old mod's.