Skip to content

Conversation

@JoinedSenses
Copy link
Contributor

This PR adds a methodmap for clientprefs cookies without breaking changes, considering that the cookie Handle is not always the first param for clientprefs functions.

@JoinedSenses
Copy link
Contributor Author

If there is a better solution for handling the methods where the Handle is not the first param, please let me know.

@psychonic
Copy link
Member

If there is a better solution for handling the methods where the Handle is not the first param, please let me know.

I think for other similar cases, we did the same shim but on the C++ side to give us more flexibility for future.

@JoinedSenses
Copy link
Contributor Author

Happen to have any examples? I spent an hour or two digging for similar cases, but couldnt find anything, although good chance I overlooked it.

By doing it on C++ side, how would it be handled? Creating a new native callback specifically for the methodmap?

@psychonic
Copy link
Member

Yeah, you'd create a native that just either calls the other native (similar to what you did), or one that calls the same internal function that the other native wraps (with the difference in parameters).

f020b56 is an example

@Headline Headline added Feature Request user requested feature WIP work in progress labels May 19, 2019
@JoinedSenses
Copy link
Contributor Author

Merge conflict existing due to moving typedef to top of inc, allowing it to be defined for the methodmap.

Copy link
Member

@Headline Headline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one little comment, I'll be happy to merge after that change

Nice work! 🎉

static cell_t Cookie_Set(IPluginContext *pContext, const cell_t *params)
{
// This version takes (handle, client, value). The original is (client, handle, value).
cell_t new_params[4] = {
Copy link
Member

@Headline Headline May 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you mark this const?

this along with the others

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this then be made const as well, the commit change I used for reference? https://github.com/alliedmodders/sourcemod/blob/master/core/smn_keyvalues.cpp#L1107

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 60e2a30

@Headline Headline removed the WIP work in progress label May 30, 2019
@JoinedSenses
Copy link
Contributor Author

Tested with:

#include <sourcemod>
#include <clientprefs>

Cookie g_hTestCookie;

public void OnPluginStart() {
	RegAdminCmd("sm_testcookie", cmdTestCookie, ADMFLAG_ROOT);

	g_hTestCookie = new Cookie("TestCookie", "", CookieAccess_Private);
}

public Action cmdTestCookie(int client, int args) {
	if (!client) {
		return Plugin_Handled;
	}

	Cookie testcookie = Cookie.Find("TestCookie");
	PrintToChat(client, "%sFound", testcookie == null ? "Not " : "");
	delete testcookie;

	g_hTestCookie.Set(client, "TestValue");
	CreateTimer(5.0, timerCookie, GetClientUserId(client));
	return Plugin_Handled;
}

Action timerCookie(Handle timer, int userid) {
	int client = GetClientOfUserId(userid);
	if (!client) {
		return Plugin_Continue;
	}

	char buffer[10];
	g_hTestCookie.Get(client, buffer, sizeof(buffer));

	PrintToChat(client, "Result: %s", buffer);
	PrintToChat(client, "Time: %i", g_hTestCookie.GetClientTime(client));
	PrintToChat(client, "Level: %i", g_hTestCookie.AccessLevel);
	return Plugin_Continue;
}

Results:

Found
Result: TestValue
Time: 1559265624
Level: 2

Copy link
Member

@Headline Headline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Headline Headline merged commit 352f078 into alliedmodders:master May 31, 2019
@JoinedSenses JoinedSenses deleted the patch-clientprefs branch May 31, 2019 02:38
Headline pushed a commit that referenced this pull request May 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Request user requested feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants