Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Implement quick setinfo clean method #2589

Open
2010kohtep opened this issue Jul 16, 2019 · 2 comments
Open

[Feature Request] Implement quick setinfo clean method #2589

2010kohtep opened this issue Jul 16, 2019 · 2 comments

Comments

@2010kohtep
Copy link

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
Copy link

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
Copy link

afwn90cj93201nixr2e1re commented Jul 16, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants