Skip to content

Track the creating plugin for convars#1537

Merged
asherkin merged 1 commit intomasterfrom
feature-1492
Jul 18, 2021
Merged

Track the creating plugin for convars#1537
asherkin merged 1 commit intomasterfrom
feature-1492

Conversation

@asherkin
Copy link
Member

Similar to the recent work for commands, track and expose the creating
plugin for convars. The first plugin to register a given cvar becomes
the owner until that plugin is unloaded. If a plugin attempts to
register a convar that was already registered and the originally
registering plugin has been unloaded, that plugin becomes the owner.
This isn't quite as nice as the way commands shift "ownership" as
plugins are unloaded, but we don't have a sane data structure currently
to implement that, and it seemed like a lot of unnecessary work as there
shouldn't really be multiple plugins with conflicting cvars.

Closes #1492

Similar to the recent work for commands, track and expose the creating
plugin for convars. The first plugin to register a given cvar becomes
the owner until that plugin is unloaded. If a plugin attempts to
register a convar that was already registered and the originally
registering plugin has been unloaded, that plugin becomes the owner.
This isn't quite as nice as the way commands shift "ownership" as
plugins are unloaded, but we don't have a sane data structure currently
to implement that, and it seemed like a lot of unnecessary work as there
shouldn't really be multiple plugins with conflicting cvars.

Closes #1492
@asherkin asherkin requested a review from Headline July 17, 2021 21:18
@asherkin
Copy link
Member Author

Tested with:

public void OnPluginStart()
{
    PrintConVar("sm_chat_mode");
    PrintConVar("sv_alltalk");
}

void PrintConVar(const char[] name)
{
    ConVar cvar = FindConVar(name);
    Handle plugin = cvar.Plugin;

    char filename[PLATFORM_MAX_PATH];
    if (plugin)
        GetPluginFilename(plugin, filename, sizeof(filename));

    PrintToServer(">>> %s: %x %x - \"%s\"", name, cvar, plugin, filename);
}

Unloaded, loaded, reloaded basechat (provider of sm_chat_mode) and the test plugin several times in various orders to ensure there were no dangling references and everything was updated correctly.

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.

All this looks good - thanks!

}

/* Clear any references to this plugin as the convar creator */
for (List<ConVarInfo *>::iterator iter = m_ConVars.begin(); iter != m_ConVars.end(); ++iter)
Copy link
Member

Choose a reason for hiding this comment

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

We should probably get used to using ranged-for, but it's just a nit

@asherkin asherkin merged commit 6a2ac98 into master Jul 18, 2021
@asherkin asherkin deleted the feature-1492 branch July 18, 2021 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ConVar.PluginHandle property

2 participants