View Single Post
Author Message
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 12-28-2012 , 22:28   [INCLUDE] AutoExecConfig: Read and append to auto configs
Reply With Quote #1

What is this?
In short, this provides the missing functionality to update your autoconfig if you add new convars to your plugins.
When i wrote this I've worked on a bigger project where convars were added very often and telling people to rewrite their configs made me hesitant to add them.
In times of plugins like the updater people expect to not have to add new convars by hand.
The most important things i had in mind were security, performance, easy implementation and consistent files (white spaces, newlines)

I've came up with a working but relatively slow solution with some limitations.


How does it work?
If you add a convar with the appropriate function it will be searched in the auto-config-file you have set before.
If it can't be found within the file it will add it with the information you created the convar with.
After that, the file can be cleaned from unnecessary white spaces created by the user or autoexecconfig itself. This is done purely for the viewer's pleasure and to conserve some bytes.


The source / Download
You can view the source and some more information on Github.
Feel free to send pull requests, ideas, criticism or enhancements.


Limitations
Although most functions return something, some also multiple defined values/codes, you currently can't get the return of the parser/appender while adding a convar.
This could be fixed with a by ref value, but i feel that, in some cases, it would make the command longer than it needs to be.
As a workaround this can be retrieved directly after you created a convar with one of the AutoExecConfig_Get*Result functions.



Notes
This include requires a sourcemod compiler with version 1.7+, see here for more information.
The prototype or name of some functions may be changed or even removed in later versions, but this will not cause compatibility issues with plugins.
Convars with a FCVAR_DONTRECORD flag will be skipped by the appender.
The parser will ignore spaces between convars and values, inside values or behind values for security.
The search, by default, is case sensitive.
The cleaner will format your file the way autoexecconfig does, 2 spaces after information, 1 after convars.
The value of a convar must be quoted, otherwise the parser will not find it.
Please let me know if you find a bug or have suggestions.


Implementing
Here is a basic example of the usage. Please also take a look at the include file and the test plugin for more functions.
PHP Code:
public void OnPluginStart()
{
    
// Set the file for the include, the extension can be omitted
    
AutoExecConfig_SetFile("plugin.myplugin");

    
AutoExecConfig_CreateConVar("sm_myplugin_enabled""1""Whether or not this plugin is enabled");
    
AutoExecConfig_CreateConVar("sm_myplugin_chattrigger""myplugin""Chattrigger to open the menu of this plugin");
    
AutoExecConfig_CreateConVar("sm_myplugin_adminflag""b""Adminflag needed to use the chattrigger");

    
// This makes an internal call to AutoExecConfig with the given configfile
    
AutoExecConfig_ExecuteFile();

    
// Cleaning should be done at the end
    
AutoExecConfig_CleanFile();

__________________

Last edited by Impact123; 04-09-2021 at 13:42.
Impact123 is offline